[Openmcl-devel] OpenMCL 1.0, compilation units and macroexpansion bug?

Gary Byers gb at clozure.com
Sat Nov 10 16:51:40 PST 2007

See section " Processing of Defining Macros" in the ANSI CL
spec; there may be another section where this is discussed in more
detail, but I can't find it at the moment.

Basically, implementations are allowed to process defining-macros
(like DEFMACRO) that appear in files being compiled in several ways.
In DEFMACRO's case, They can:

(a) make the macroexpansion function available globally, 
(b) add it to the lexical environment so that it's visible in the rest of
the compilation, or 
(c) both.

OpenMCL generally tries to do (b).  Many other implementations tend to
do (a).  Both behaviors are correct (though I think that OpenMCL's is
more useful.)

If you want a macro definition to be accessible "in the global environment"
(in the case of your example, don't want to have to use &environment),
you can portably do:

(eval-when (:compile-toplevel ...)
   (defmacro ...))

If you -wanted- to restrict the compile-time side-effects to (b) above ...
well, I can't think of a good way to do this (which is part of the
reason that I think that (b) is better default behavior.)

On Sat, 10 Nov 2007, Vyacheslav Akhmechet wrote:

> My apologies, adding &environment and passing the value to
> macroexpand-1 explicitly *does* make a difference. Does that mean that
> all other implementations support behavior that isn't required by the
> spec?
> On 11/10/07, Vyacheslav Akhmechet <coffeemug at gmail.com> wrote:
>> Hello,
>> I'm running OpenMCL 1.0 on PPC. I'm having trouble with the following
>> test snippet:
>> (defmacro foo (a)
>>   `(+ ,a ,a))
>> (defmacro bar ()
>>   `(print ',(macroexpand-1 '(foo 5))))
>> (defun baz ()
>>   (bar))
>> When run from the REPL, calling (baz) returns (+ 5 5), as expected.
>> However, when the definitions are placed into a file OpenMCL returns
>> (foo 5), while all other implementations I've tested on return (+ 5
>> 5). It seems that OpenMCL doesn't add the macro FOO to the null
>> environment when MACROEXPAND-1 is called manually. I tried passing
>> &environment explicitly, but got the same result.
>> The spec for DEFMACRO says: "If a defmacro form appears as a top level
>> form, the compiler must store the macro definition at compile time, so
>> that occurrences of the macro later on in the file can be expanded
>> correctly." Is this a bug or am I misunderstanding the spec?
>> Regards,
>> Slava Akhmechet
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list