[plt-dev] Symptom of REPL's hopelessness?

From: Carl Eastlund (carl.eastlund at gmail.com)
Date: Thu Oct 1 16:17:19 EDT 2009

On Thu, Oct 1, 2009 at 4:11 PM, Sam TH <samth at ccs.neu.edu> wrote:
> On Thu, Oct 1, 2009 at 4:01 PM, Casey Klein
> <clklein at eecs.northwestern.edu> wrote:
>> Can someone explain why this macro expands without error in a module
>> but not in the REPL?
>> (define-syntax (m stx)
>>  (syntax-case stx ()
>>   [(_ x)
>>    (with-syntax ([(y) (generate-temporaries (syntax (x)))])
>>      (syntax (define (y) y)))]))
>>> (m q)
>> compile: unbound identifier (and no #%top syntax transformer is bound) in: q1
> This version of the macro works:
> (define-syntax (m stx)
>  (syntax-case stx ()
>  [(_ x)
>   (with-syntax ([(y) (list (gensym (syntax-e #'x)))])
>     (syntax (define (y) y)))]))

...at the top level.  Who knows what craziness will happen if you put
this in other contexts.  (For instance, in a compiled module, I think
gensym'd identifiers can wreak havoc, but don't quote[*] me.)  I would
not recommend Sam's code as a general purpose fix.

Personally, I think you have run into a generate-temporaries bug.  But
we won't know for sure until Matthew either corrects your code or
responds with "Fixed in svn." ;)


[*] Don't quote, quasiquote, syntax, syntax/loc, quasisyntax,
quasisyntax/loc, or quote-syntax me on this one.  If you're using PLT
Redex, don't term me either.

Posted on the dev mailing list.