I like to define functions as helpers for macro expansions, then use them
in the same file, in this manner:
(defun hi-there ()
:do-nothing)
(defmacro doing-nothing ()
`(defconstant +nothing+ ,(hi-there)))
(doing-nothing)
The reason is that I find hi-there to be useful in runtime code. (In the
sense of hi-there as a metasyntactic variable, of course.) I also
sometimes like to do this:
(defun hi-there ()
:do-nothing)
(eval-when (:compile-toplevel :load-toplevel)
(hi-there))
Unfortunately, both of these trigger errors at compile-time or load-time
(at least in SBCL and CLISP, anyway). I have found 2 alternatives:
1. Put hi-there in a separate file, then use ASDF to guarantee that said
file is compiled/loaded before the file with the defmacro/expansion or
eval-when.
2. Wrap hi-there's definition in an eval-when.
Both of these seem kind of ugly; thus far, I have preferred the spurious
load-time warnings of option 2 to the extra clutter of 1. What is a less
problematic way, if any, to define a function for such use? Perhaps
more importantly, am I an idiot for wanting to do this?
--
Stephen Compall
Email: My username is s11. My domain is member..org, but insert the
abbreviation for `Free Software Foundation' between the dots.
In article <······························@nocandysw.com>,
Stephen Compall <···············@gmail.com> wrote:
> I like to define functions as helpers for macro expansions, then use them
> in the same file, in this manner:
>
> (defun hi-there ()
> :do-nothing)
>
> (defmacro doing-nothing ()
> `(defconstant +nothing+ ,(hi-there)))
>
> (doing-nothing)
>
> The reason is that I find hi-there to be useful in runtime code. (In the
> sense of hi-there as a metasyntactic variable, of course.) I also
> sometimes like to do this:
>
> (defun hi-there ()
> :do-nothing)
>
> (eval-when (:compile-toplevel :load-toplevel)
> (hi-there))
>
> Unfortunately, both of these trigger errors at compile-time or load-time
> (at least in SBCL and CLISP, anyway). I have found 2 alternatives:
>
> 1. Put hi-there in a separate file, then use ASDF to guarantee that said
> file is compiled/loaded before the file with the defmacro/expansion or
> eval-when.
>
> 2. Wrap hi-there's definition in an eval-when.
That's the proper solution if you want them in the same file. If you
don't define the helper function at compile time with eval-when, it
won't exist in the compile-time environment, so can't be used by macro
functions in that file.
--
Barry Margolin, ······@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***