<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>I found this on line 2327 of racket/src/racket/src/env.c:</div><div><pre style="box-sizing: border-box; overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; margin-top: 0px; margin-bottom: 0px; color: rgb(51, 51, 51); line-height: 18px;"><div class="line" id="LC2327" style="box-sizing: border-box; padding-left: 10px; height: 18px; background-color: rgb(255, 255, 204);"><span class="k" style="box-sizing: border-box; font-weight: bold;">static</span> <span class="n" style="box-sizing: border-box;">Scheme_Object</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">*</span></div><div class="line" id="LC2328" style="box-sizing: border-box; padding-left: 10px; height: 18px;"><span class="nf" style="box-sizing: border-box; color: rgb(153, 0, 0); font-weight: bold;">local_introduce</span><span class="p" style="box-sizing: border-box;">(</span><span class="kt" style="box-sizing: border-box; color: rgb(68, 85, 136); font-weight: bold;">int</span> <span class="n" style="box-sizing: border-box;">argc</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">Scheme_Object</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">*</span><span class="n" style="box-sizing: border-box;">argv</span><span class="p" style="box-sizing: border-box;">[])</span></div><div class="line" id="LC2329" style="box-sizing: border-box; padding-left: 10px; height: 18px;"><span class="p" style="box-sizing: border-box;">{</span></div><div class="line" id="LC2330" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="n" style="box-sizing: border-box;">Scheme_Comp_Env</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">*</span><span class="n" style="box-sizing: border-box;">env</span><span class="p" style="box-sizing: border-box;">;</span></div><div class="line" id="LC2331" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="n" style="box-sizing: border-box;">Scheme_Object</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">*</span><span class="n" style="box-sizing: border-box;">s</span><span class="p" style="box-sizing: border-box;">;</span></div><div class="line" id="LC2332" style="box-sizing: border-box; padding-left: 10px; height: 18px;"><br style="box-sizing: border-box;"></div><div class="line" id="LC2333" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="n" style="box-sizing: border-box;">env</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">scheme_current_thread</span><span class="o" style="box-sizing: border-box; font-weight: bold;">-></span><span class="n" style="box-sizing: border-box;">current_local_env</span><span class="p" style="box-sizing: border-box;">;</span></div><div class="line" id="LC2334" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="p" style="box-sizing: border-box;">(</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="n" style="box-sizing: border-box;">env</span><span class="p" style="box-sizing: border-box;">)</span></div><div class="line" id="LC2335" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="n" style="box-sizing: border-box;">not_currently_transforming</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: rgb(221, 17, 68);">"syntax-local-introduce"</span><span class="p" style="box-sizing: border-box;">);</span></div><div class="line" id="LC2336" style="box-sizing: border-box; padding-left: 10px; height: 18px;"><br style="box-sizing: border-box;"></div><div class="line" id="LC2337" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="n" style="box-sizing: border-box;">s</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">argv</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: border-box;">];</span></div><div class="line" id="LC2338" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="p" style="box-sizing: border-box;">(</span><span class="o" style="box-sizing: border-box; font-weight: bold;">!</span><span class="n" style="box-sizing: border-box;">SCHEME_STXP</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">s</span><span class="p" style="box-sizing: border-box;">))</span></div><div class="line" id="LC2339" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="n" style="box-sizing: border-box;">scheme_wrong_contract</span><span class="p" style="box-sizing: border-box;">(</span><span class="s" style="box-sizing: border-box; color: rgb(221, 17, 68);">"syntax-local-introduce"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="s" style="box-sizing: border-box; color: rgb(221, 17, 68);">"syntax?"</span><span class="p" style="box-sizing: border-box;">,</span> <span class="mi" style="box-sizing: border-box; color: rgb(0, 153, 153);">0</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">argc</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">argv</span><span class="p" style="box-sizing: border-box;">);</span></div><div class="line" id="LC2340" style="box-sizing: border-box; padding-left: 10px; height: 18px;"><br style="box-sizing: border-box;"></div><div class="line" id="LC2341" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">if</span> <span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">scheme_current_thread</span><span class="o" style="box-sizing: border-box; font-weight: bold;">-></span><span class="n" style="box-sizing: border-box;">current_local_mark</span><span class="p" style="box-sizing: border-box;">)</span></div><div class="line" id="LC2342" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="n" style="box-sizing: border-box;">s</span> <span class="o" style="box-sizing: border-box; font-weight: bold;">=</span> <span class="n" style="box-sizing: border-box;">scheme_add_remove_mark</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">s</span><span class="p" style="box-sizing: border-box;">,</span> <span class="n" style="box-sizing: border-box;">scheme_current_thread</span><span class="o" style="box-sizing: border-box; font-weight: bold;">-></span><span class="n" style="box-sizing: border-box;">current_local_mark</span><span class="p" style="box-sizing: border-box;">);</span></div><div class="line" id="LC2343" style="box-sizing: border-box; padding-left: 10px; height: 18px;"><br style="box-sizing: border-box;"></div><div class="line" id="LC2344" style="box-sizing: border-box; padding-left: 10px; height: 18px;"> <span class="k" style="box-sizing: border-box; font-weight: bold;">return</span> <span class="n" style="box-sizing: border-box;">s</span><span class="p" style="box-sizing: border-box;">;</span></div><div class="line" id="LC2345" style="box-sizing: border-box; padding-left: 10px; height: 18px;"><span class="p" style="box-sizing: border-box;">}</span></div></pre><div>What would happen if <span style="background-color: rgb(255, 255, 255); color: rgb(51, 51, 51); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 18px; white-space: pre;">match-expander-transform</span> somehow set <span class="n" style="color: rgb(51, 51, 51); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 18px; white-space: pre; box-sizing: border-box;">scheme_current_thread</span><span class="o" style="color: rgb(51, 51, 51); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 18px; white-space: pre; box-sizing: border-box; font-weight: bold;">-></span><span class="n" style="color: rgb(51, 51, 51); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; line-height: 18px; white-space: pre; box-sizing: border-box;">current_local_mark</span> to the mark produced by the new syntax-introducer? And would that even be possible? (without fundamental changes to racket)</div></div><div><br><div><div>On Aug 1, 2014, at 6:45 PM, J. Ian Johnson <<a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Well one problem is expander application his its own mark to deal with, so you can't cancel the mark on x.<br><br><a href="https://github.com/plt/racket/blob/master/racket/collects/racket/match/parse-helper.rkt#L157">https://github.com/plt/racket/blob/master/racket/collects/racket/match/parse-helper.rkt#L157</a><br><br>Another problem is expecting the implementation of match-define to not have any inner macros that would change syntax-local-introduce to a less helpful extent.<br>What would be ideal is if racket/match could change some "parameter" so that syntax-local-introduce used the introducer defined in the above link, since the generated temporary does not have x's mark that x has annihilated. Instead x's mark will be added to tmp after the transformer returns, and there's nothing you can do about it :(<br><br>-Ian<br>----- Original Message -----<br>From: "Alexander D. Knauth" <alexander@knauth.org><br>To: "J. Ian Johnson" <ianj@ccs.neu.edu><br>Cc: "racket users list" <users@racket-lang.org><br>Sent: Friday, August 1, 2014 6:31:59 PM GMT -05:00 US/Canada Eastern<br>Subject: Re: [racket] getting one macro to tell another macro to define something<br><br>Well, if the match-expander is invoked in the “dynamic extent” of the match-define form, then would syntax-local-introduce apply that syntax-mark? <br><br>On Aug 1, 2014, at 6:20 PM, J. Ian Johnson <ianj@ccs.neu.edu> wrote:<br><br><blockquote type="cite">Well that's a pickle. I can tell you that (mac . args) gets expanded as (X[mac^m] . X[args^m])^m where m is a fresh mark and X expands a form. If m is applied to something with m already, they annihilate each other (see Syntactic Abstraction in Scheme for how this totally works).<br>The syntax-local-introduce form allows you to apply the macro application's mark to an arbitrary piece of syntax, so later on the application's mark will annihilate it and voila`, it's like it was textually given to the macro application itself.<br><br>Here, however, a match expander is not treated as a macro invocation. There is no mark for that match-expander use to introduce. There is, however, the mark from match-define that you'll want to introduce to this temporary you've generated. I think. I haven't quite worked out how to make this work.<br>-Ian<br>----- Original Message -----<br>From: "Alexander D. Knauth" <alexander@knauth.org><br>To: "racket users list" <users@racket-lang.org><br>Sent: Friday, August 1, 2014 5:55:57 PM GMT -05:00 US/Canada Eastern<br>Subject: Re: [racket] getting one macro to tell another macro to define something<br><br><br><br><br><br>On Aug 1, 2014, at 5:37 PM, J. Ian Johnson < ianj@ccs.neu.edu > wrote: <br><br><br>It's best to expand into a begin-for-syntax that does the desired mutation, rather than mutate within the transformer. You currently _cannot_ do this outside top level forms. <br><br><br><br>The reason I can’t do that is because in the real program, sender is actually a match-expander. <br><br><br>You are also right about the marks. The call to receiver adds additional marks to the definitions that it pulls out, so you'll need to apply syntax-local-introduce. ... <br><br><br><br><br>On Aug 1, 2014, at 5:39 PM, Ryan Culpepper < ryanc@ccs.neu.edu > wrote: <br><br><br>Use syntax-local-introduce when putting syntax into a side-channel or getting it back out across macro calls. This only matters when the syntax represents a definition or more generally contains binders whose references are not all in the same syntax. <br>... <br><br><br>Thanks, the syntax-local-introduce got it working for that example, but for some reason it’s not working when sender is a match-expander. <br><br>I’m still not very clear on when to use syntax-local-introduce and when not to, or even what it does (other than get that example working), so could someone point me in the right direction? <br><br><br><br>#lang racket <br>(require racket/stxparam <br>(for-syntax syntax/parse <br>racket/syntax <br>racket/set)) <br>;; current-defs : (syntax-parameter-of (or/c set-mutable? #f)) <br>(define-syntax-parameter current-defs #f) <br>(define-match-expander sender <br>(lambda (stx) <br>(syntax-parse stx <br>[(sender x) <br>#:with tmp (generate-temporary #'x) <br>(define defs (syntax-parameter-value #'current-defs)) <br>(set-add! defs (syntax-local-introduce #'(define x tmp))) <br>#'tmp]))) <br>(define-syntax reciever <br>(lambda (stx) <br>(syntax-parse stx <br>[(reciever) <br>(define defs (syntax-parameter-value #'current-defs)) <br>(with-syntax ([(def ...) (map syntax-local-introduce (set->list defs))]) <br>#'(begin def ...))]))) <br><br><br>(syntax-parameterize ([current-defs (mutable-set)]) <br>(match-define (sender x) 1) <br>(reciever) <br>x) <br><br><br>;x3: unbound identifier; <br>; also, no #%top syntax transformer is bound in: x3 <br><br><br><br><br>____________________<br> Racket Users list:<br> http://lists.racket-lang.org/users<br></blockquote><br></blockquote></div><br></div></body></html>