I was reading the chapter on anaphoric macros in Paul Graham's _On
Lisp_ coming across this paragraph:
> Whenever a macro which does intentional variable capture is exported to
> another package, it is necessary also to export the symbol being captured. For
> example, wherever aif is exported, it should be as well. Otherwise the it which
> appears in the macro definition would be a different symbol from an it used in a
> macro call.
>
> (pg 195)
He writes aif like so,
> (defmacro aif (test-form then-form &optional else-form)
> ‘(let ((it ,test-form))
> (if it ,then-form ,else-form)))
I wonder if it would be possible to write aif so that it grabs the
package it's being expanded in at macroexpansion time and ensures that
the it symbol being let is defined within the current package.
Something like,
(defmacro aif (test-form then-form &optional else-form)
`(let ((,*package*::it ,test-form))
(if ,*package*::it ,then-form ,else-form)))
Although this very poor example does not work at all since the
interpreter tries to get the value of package at that very moment.
I'm not well enough versed to figure this out, but it seems it might be
possible. Anyone have an idea/implementation/reason why it can't
happen? It seems possible that something in the mechanics of export or
something about macroexpansion I don't yet grasp might muck it up.
I'm really curious if there's any drawback from defining aif the way
you suggested, because it's rather neat that you don't have to export
the symbol "it".
Both pg, marco baringer and Nikodemus Siivola's anaphoric module export
the symbol "it " so they don't mix well together.