[plt-scheme] 'eval at expansion time

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Mon Jul 20 10:12:17 EDT 2009

macro generating macro? staged macro?

On Jul 20, 2009, at 6:16 AM, Tom Schouten wrote:

>>  (define-syntax (show stx)
>>    (syntax-case stx ()
>>      [(_ e)
>>       #'(let-syntax ([exp
>>                       (lambda (stx)
>>                         (with-syntax ([v e])
>>                           #`(printf "~s yields ~s\n" 'e 'v)))])
>>           (exp))]))
>
> ...
>
>>
>> where `e' is in an expression position in the right-hand size of the
>> `let-syntax', so it gets evaluated at expansion time. The main  
>> trick is
>> to invent a local name (in this case `exp') to house the expand-time
>> expression and trigger its evaluation in an expression position.
>>
>
> Exactly what I was looking for.
>
>> As you suggest, this approach requires a macro-generating `show',  
>> which
>> is in some sense a "higher order macro".
>
> Looks like "higher order macro" isn't really a good term for this.
> I'm not sure where I saw it used.  Does the term mean something
> different?
>
>> Your example doesn't seem to involve any bindings like `plus' or
>> `times', and, offhand, I can't think of another concrete reason that
>> "arith.ss" is better than "arith-ct.ss" plus "use-arith.ss". Less
>> concretely, though, the reflection in the latter seems to me more
>> difficult to reason about.
>
> I see.
>
> Thanks for clarifying!
>
> Tom
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.