Two macros:
(defmacro my-export1 (x)
`(progn
(defstruct ,x)
(export ',(intern (format nil "MAKE-~A" x)))))
(defmacro my-export2 (x)
`(progn
(defstruct ,x)
(export ',(find-symbol (format nil "MAKE-~A" x)))))
both macroexpand (macroexpand '(my-export? A)) to:
(PROGN (DEFSTRUCT A) (EXPORT (QUOTE MAKE-A)))
(my-export1 A)
exports MAKE-A,
(my-export2 A)
does not (in LispWorkds, CMUCL, CLISP). What am I missing?
David
In article <·······················@f14g2000cwb.googlegroups.com>,
············@gmail.com wrote:
> Two macros:
>
> (defmacro my-export1 (x)
> `(progn
> (defstruct ,x)
> (export ',(intern (format nil "MAKE-~A" x)))))
>
> (defmacro my-export2 (x)
> `(progn
> (defstruct ,x)
> (export ',(find-symbol (format nil "MAKE-~A" x)))))
>
> both macroexpand (macroexpand '(my-export? A)) to:
>
> (PROGN (DEFSTRUCT A) (EXPORT (QUOTE MAKE-A)))
>
> (my-export1 A)
>
> exports MAKE-A,
>
> (my-export2 A)
> does not (in LispWorkds, CMUCL, CLISP). What am I missing?
Think about the difference between macro-expansion time and runtime.
Perhaps this will help:
[ start a new lisp, or define & enter a new package ]
CL-USER> (defmacro my-export3 (x)
`(progn
(defstruct ,x)
(print ',(find-symbol (format nil "MAKE-~A" x)))))
MY-EXPORT3
CL-USER> (macroexpand-1 '(my-export3 a))
(PROGN (DEFSTRUCT A) (PRINT 'NIL))
T
CL-USER> (my-export3 a)
NIL
NIL
CL-USER> (macroexpand-1 '(my-export3 a))
(PROGN (DEFSTRUCT A) (PRINT 'MAKE-A))
T
The FIND-SYMBOL runs *before* the DEFSTRUCT.
-- Larry