[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Emacs-diffs] trunk r117002: Correctly treat progn contents as tople

From: Daniel Colascione
Subject: Re: [Emacs-diffs] trunk r117002: Correctly treat progn contents as toplevel forms when byte compiling
Date: Tue, 22 Apr 2014 13:10:17 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0

On 04/22/2014 12:59 PM, Drew Adams wrote:
>> The SBCL and ECL behavior is what I'd expect from reading the spec, but
>> maybe I misunderstood something.
> Hm.  What part of the spec do you think gives the impression that
> `defmacro' behavior is defined only at top level?

defmacro is specced to "define[] name as a macro by associating a macro
function with that name in the global environment". Like any form, it's
supposed to do that when it's evaluated, and forms inside defuns aren't
evaluated when they're loaded or compiled: they're evaluated when the
defun is called. So you should expect a defmacro inside a defun to have
no effect unti lthe defun is called.

Likewise, if a defmacro appears at top level, it should ordinarily be
evaluated only when the file that contains it is loaded, just like any
other toplevel form. So, without special provisions, defmacro should not
be expanded inside forms that happen to be in the same file.

But this behavior isn't very useful, so as a special case, CL specifies
that "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. Users must ensure
that the body of the macro can be evaluated at compile time if it is
referenced within the file being compiled."

It's because of this special case that a normal defmacro, not wrapped in
an eval-when, has any effect on compilation of forms in the same file. A
defmacro inside a defun isn't covered by this special case, so its
behavior should revert to the normal behavior for forms. SBCL and ECL
implement this model of evaluation. CLISP's behavior appears to be
incorrect here.

The behavior I'm proposing for Emacs is identical to what SBCL and ECL
do. Stefan is proposing that we adopt CLISP behavior.

Attachment: signature.asc
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]