On Wed, 16 Sep 2009, Ray Dillinger wrote:
> On Wed, 2009-09-16 at 16:08 -0500, Brian Mastenbrook wrote:
>
>> I don't understand why the time when macros are expanded has anything
>> to do with the scoping rules of the language, unless you're trying to
>> do things which are not possible in a lexically scoped environment.
>
> There are two different issues here. One is scope, the other is
> extent. Scope governs *where* a definition is visible; Extent
> governs *when* the definition is usable. In order to work, a
> syntax invocation or a procedure call has to appear within the
> scope of the corresponding form *AND* get executed during the
> extent of the form.
Exactly! Thank you!
> That means disallowing mutually-recursive macros.
Actually no. There is no problem at all with mutually recursive
macros such as:
(define-syntax even
(syntax-rules ()
((_ n) (.......(odd (- n 1)))
(define-syntax odd
(syntax-rules ()
((_ n) (.......(even (- n 1)))
This works perfectly well in a REPL, because neither macro
is used (invoked) during this interaction. This is different
from
(even 1)
(define-syntax even .......)
which won't work in a REPL, because here is an attempt to use
the macro before it is available. For Brian, even though EVEN
is visible (in scope) in the first line, it is not within the
extent of the syntax definition, in a REPL interaction.
ANdre
_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss