[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: special form and macro
From: |
alin.s |
Subject: |
Re: special form and macro |
Date: |
Sun, 21 Feb 2010 14:46:52 -0800 (PST) |
Harald Hanche-Olsen wrote:
>
> + "alin.s" <address@hidden>:
>
>> What difference exists between a macro and a user-defined special form?
>
> I am not sure the emacs developers' list is the appropriate forum for
> this kind of question - the lack of answers is a pretty strong
> indication that people think it's not - so I'll be brief. If you need
> a more detailed answer, may I suggest the newsgroup gnu.emacs.help?
>
>> In emacs the user cannot define special forms, maybe because the macros
>> keep
>> the place of special forms?
>>
>> A special form should be defined as
>>
>> (special (var1 ... varn) (lambda () ... ))
>>
>> During application, var1 ... varn should be initialized temporary inside
>> the
>> environment with the unevaluated values of the call. (name val1 ...
>> valn).
>>
>> But this is exactly the definition of a macro. Is there a difference . Is
>> there a computation that one can do and the other not?
>
> The difference is that a macro expands into a form that is then
> evaluated, whereas a user-defined special form, as you define it,
> would typically have to do its own evaluation. See section 13 (Macros)
> in the elisp manual. I think it's safe to say that a macro can do
> anything a user-defined special form can, but not vice versa (both
> because macro expansion and evaluation of the resulting form can take
> place at different times, and because of lexical scoping issues).
>
> - Harald
>
>
>
>
EVAL function seems to treat them identically, apart from a minor
difference: the "backtrace"
SPECIAL:
if (XSUBR (fun)->max_args == UNEVALLED)
{
backtrace.evalargs = 0;
val = (*XSUBR (fun)->function) (args_left);
goto done;
}
MACRO:
if (EQ (funcar, Qmacro))
val = Feval (apply1 (Fcdr (fun), original_args));
So they are absolutely identical .
I think that gnu.emacs.help is the worst choice for this kind of questions.
Probably comp.compilers would be better?
--
View this message in context:
http://old.nabble.com/special-form-and-macro-tp27666297p27677293.html
Sent from the Emacs - Dev mailing list archive at Nabble.com.