<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>Yes, being forced to use 'stx' as context is suspicious, too. It injects the identifier into the scope and a program may accidentally see it then. </div><div><br></div><div><br></div><br><div><div>On May 15, 2014, at 7:20 PM, Robby Findler wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">We have a work around. (In the larger program there is one is that comes from the input and one that doesn't. We can just bind it to a pair instead.)<div><br></div><div>This program seems quite suspicious. I can't quite bring myself to call it a bug because it is sucks widely used part of things tho!</div>
<div><br></div><div>Robby</div><div><br>On Thursday, May 15, 2014, Matthias Felleisen <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word"><div><br></div><div><br></div><div><div style="font-family:monospace">On May 15, 2014, at 5:56 PM, Robby Findler wrote:</div><span style="font-family:monospace"><br></span><blockquote type="cite" style="font-family:monospace">
<span style="border-collapse:separate;font-family:'Lucida Grande';font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium"><span style="font-family:monospace">How does this help us understand the original, strange program?</span></span></blockquote>
</div><div><span style="border-collapse:separate;font-family:'Lucida Grande';font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;font-size:medium"><span style="font-family:monospace"><br>
</span></span></div><div><font face="monospace">I am providing a work-around because I recognize the idiom. </font></div><div><font face="monospace">I can't explain the original. </font></div><div><font face="monospace"><br>
</font></div><div><font face="monospace"><br></font></div><div><br></div><div><div>On May 15, 2014, at 6:23 PM, Spencer Florence wrote:</div><br><blockquote type="cite"><div dir="ltr">I'm not sure how gensym fixes this:<br>
</div></blockquote><div><br></div><div><br></div><div><div>Not #f, stx: </div><div><br></div><div><div>(define-syntax (make-funny-set! stx)</div><div> (syntax-parse stx</div><div> [(_ v) #`(define #,(begin (set! funny (datum->syntax stx (gensym))) funny) v)]))</div>
</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div><br></div><br><blockquote type="cite"><div dir="ltr"><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><br><br><div>On Thu, May 15, 2014 at 4:56 PM, Robby Findler <span dir="ltr"><<a>robby@eecs.northwestern.edu</a>></span> wrote:<br>
<blockquote 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><div><<a>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>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>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</div></div></blockquote></div></div></blockquote>
</div><br></div></blockquote></div>
</blockquote></div><br></body></html>