[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Macros; lexcial scope
In article <8805251659.AA00682@tub.UUCP> net@TUB.BITNET (Oliver Laumann)
writes:
>Consider the following example:
> (define x 1)
> (define-macro (m) x)
> (let ((x 2))
> (m))
>Would you expect that (m) evaluates to 1 or to 2? In both Common Lisp
>(using a different syntax, of course) and C-Scheme, (m) returns 1 in the
>example above. Thus, it looks as if the first time the macro body is
>evaluated, the evaluation takes place in the lexical scope of the
>define-macro.
Rather, that the macro is evaluated in the lexical scope in which it was
defined, just like regular functions.
>Now consider a slighly more complex example:
> (define x 1)
> (let ((x 2))
> (define-macro (m) x)
> (let ((x 3))
> (m)))
>In both Common Lisp and C-Scheme, this evaluates to 1.
T's DEFINE-SYNTAX does what you want in both of these cases, evaluating to 1
in the first case and 2 in the second case.
Bruce Krulwich