<div dir="ltr">I'm not sure how gensym fixes this:<br><br><div>#lang racket</div><div><br></div><div>(require (for-syntax syntax/parse racket/syntax racket/format))</div><div><br></div><div>(define-for-syntax funny #f)</div>
<div><br></div><div>(define-syntax (make-funny-set! stx)</div><div> (syntax-parse stx</div><div> [(_ v) #`(define #,(begin (set! funny (datum->syntax #f (gensym))) funny) v)]))</div><div><br></div><div>(define-syntax (funny-ref stx)</div>
<div> (syntax-parse stx</div><div> [(_) funny]))</div><div><br></div><div>(define-syntax (funny-set! stx)</div><div> (syntax-parse stx</div><div> [(_ v) #`(set! #,funny v)]))</div><div><br></div><div>(make-funny-set! 2)</div>
<div>(void (void (void (funny-set! 3))))</div><div>(funny-ref)<br><br>errors with:<br><br><div> g27591: unbound identifier;</div><div> also, no #%top syntax transformer is bound in: g27591<br><br>regardless of how many calls to void there are (inclusive of 0). This makes sense, as the syntax marks don't add up. The calls to "syntax-local-introduce" in the original program aught to solve this, but as we saw... `/me points to robby's email`<br>
<br><br><br>And removing the datum->syntax errors with:<br><br><div> funny-ref: received value from syntax expander was not syntax</div><div> received: 'g27876<br><br>Which also makes sense: a symbol is not Syntax.<br>
<br><br></div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 15, 2014 at 4:56 PM, Robby Findler <span dir="ltr"><<a href="mailto:robby@eecs.northwestern.edu" target="_blank">robby@eecs.northwestern.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">How does this help us understand the original, strange program?<br>
<br>
Robby<br>
<br>
On Thu, May 15, 2014 at 4:51 PM, Matthias Felleisen<br>
<div class="HOEnZb"><div class="h5"><<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>> wrote:<br>
><br>
> Then use gensym instead of g and "~a" instead.<br>
><br>
><br>
><br>
> On May 15, 2014, at 5:38 PM, Matthias Felleisen <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>> wrote:<br>
><br>
>><br>
>> Did you want this:<br>
>><br>
>> #lang racket<br>
>><br>
>> (require (for-syntax syntax/parse racket/syntax))<br>
>><br>
>> (define-for-syntax funny #f)<br>
>><br>
>> (define-syntax (make-funny-set! stx)<br>
>> (syntax-parse stx<br>
>> [(_ v) #`(define #,(begin (set! funny (format-id stx "g")) funny) v)]))<br>
>><br>
>> (define-syntax (funny-ref stx)<br>
>> (syntax-parse stx<br>
>> [(_) funny]))<br>
>><br>
>> (define-syntax (funny-set! stx)<br>
>> (syntax-parse stx<br>
>> [(_ v) #`(set! #,funny v)]))<br>
>><br>
>> (make-funny-set! 2)<br>
>> (void (void (void (funny-set! 3))))<br>
>> (funny-ref)<br>
>><br>
>> [I had to write such a macro a while back, and the above is roughly what I remember doing. Note the lexical context]<br>
>><br>
>><br>
>> On May 15, 2014, at 5:25 PM, Spencer Florence <<a href="mailto:spencer@florence.io">spencer@florence.io</a>> wrote:<br>
>><br>
>>> I'm attempting to write a macro which introduces a new id, then another macro that set!s that id.<br>
>>> Example:<br>
>>><br>
>>> #lang racket<br>
>>> (require (for-syntax syntax/parse racket/syntax))<br>
>>> (define-for-syntax funny #f)<br>
>>> (define-syntax (make-funny-set! stx)<br>
>>> (syntax-parse stx<br>
>>> [(_ v)<br>
>>> (define unmarked (generate-temporary))<br>
>>> (set! funny (syntax-local-introduce unmarked))<br>
>>> #`(define #,unmarked v)]))<br>
>>> (define-syntax (funny-ref stx)<br>
>>> (syntax-parse stx<br>
>>> [(_)<br>
>>> funny]))<br>
>>> (define-syntax (funny-set! stx)<br>
>>> (syntax-parse stx<br>
>>> [(_ v)<br>
>>> #`(set! #,(syntax-local-introduce funny) v)]))<br>
>>><br>
>>> (make-funny-set! 2)<br>
>>> (funny-set! 3)<br>
>>> (funny-ref)<br>
>>><br>
>>> This program works as I expect, evaluating to 3. However if I change (funny-set! 3) to (void (funny-set! 3)) I get the error: "set!: unbound identifier in module in: g1"<br>
>>><br>
>>> I do not get this error if I change (funny-ref) to (void (funny-ref)).<br>
>>><br>
>>> If I look at the expansion of the (void (funny-set! 3)) program in drracket's macro stepper the the g1 in (define g1 2) and the g1 in (void (set! g1 3)) have the same color.<br>
>>><br>
>>> To keep on with the strange, if I change the #,(syntax-local-introduce funny) inside of funny-set! to #,funny inside the behavior of all programs remains the same.<br>
>>><br>
>>> Could someone explain whats going on?<br>
>>><br>
>>> --Spencer<br>
>>> ____________________<br>
>>> Racket Users list:<br>
>>> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
>><br>
>><br>
>> ____________________<br>
>> Racket Users list:<br>
>> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
><br>
><br>
> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
</div></div></blockquote></div><br></div>