[Top][All Lists]

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

Re: macros, procedure->macro

From: Dirk Herrmann
Subject: Re: macros, procedure->macro
Date: Sun, 14 Jul 2002 23:35:45 +0200 (CEST)

On 14 Jul 2002, Neil Jerram wrote:

> >>>>> "Dirk" == Dirk Herrmann <address@hidden> writes:
>     Dirk> On 13 Jul 2002, Neil Jerram wrote:
>     >> Thanks, that's helpful.  So we won't support references to a macro
>     >> that is defined in a following top-level form, as in:
>     >> 
>     >> (define-macro (foo x) `(list ,(bar x) ,x))
>     >> (define-macro (bar x) `(* ,x ,x))
>     >> 
>     >> or is there a cunning plan that still allows us to support this?
>     Dirk> I don't see why recursive macros shouldn't be possible.
>     Dirk> However, there are things that won't work any more:
>     Dirk>   (define (foo) (bar))
>     Dirk>   (define-macro (bar) #f)
>     Dirk>   (foo)
> For the purposes of current discussion, I don't see the difference
> between this example and my one above.  (Note that my `(bar x)' above
> is unquoted, so equivalent to your `(bar)'.)  What do you intend to be
> the key difference?  (Perhaps you meant `(define foo (bar))'?)

To clarify I would like to re-state my answer to a previous mail to you:

On 10 Jul 2002, Neil Jerram wrote:

> I think the perhaps the point is not at what stage macro expansion
> happens, but how universal it is.  In other words, is macro expansion
> performed universally like reading, and so only blocked by quoting, or
> is it performed like evaluation, and so blocked/delayed by any number
> of special forms including lambda and if.

Macro expansion is neither performed like reading, nor like evaluation.
Macro expansion is blocked by quoting _and_ macro definitions.  It is not
blocked by lambda or other special forms.  Since macro expansion is
blocked by macro definitions, recursive macro definitions are possible.

Given this, it should be clear why
  (define (foo) (bar))
  (define-macro (bar) #f)
will not work:  The first line is expanded at once.  In contrast,
  (define-macro (foo x) `(list ,(bar x) ,x))
  (define-macro (bar x) `(* ,x ,x))
will work, because the macro definition will not be expanded.

However, it may be that different macro implementations with different
behaviours can co-exist.  For example, I don't see why you shouldn't be
able to mix calls to procedure->memoizing-macro with calls to
define-macro.  Then, for each of the different macro systems the behaviour
would have to be defined separately.  Not all possible systems will comply
with the demand for a system that supports compilation and efficient
execution, though.

Best regards,
Dirk Herrmann

reply via email to

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