<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;"><br><div><div>On Aug 1, 2014, at 5:37 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">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></blockquote><div><br></div><div>The reason I can’t do that is because in the real program, sender is actually a match-expander. </div><br><blockquote type="cite">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.</blockquote>...<br><div><br></div><div><div>On Aug 1, 2014, at 5:39 PM, Ryan Culpepper <<a href="mailto:ryanc@ccs.neu.edu">ryanc@ccs.neu.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">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></blockquote>...</div><div><br></div><div>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.</div><div><div>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?</div><div><br></div></div><div><div><font face="Courier New">#lang racket</font></div><div><font face="Courier New">(require racket/stxparam</font></div><div><font face="Courier New"> (for-syntax syntax/parse</font></div><div><font face="Courier New"> racket/syntax</font></div><div><font face="Courier New"> racket/set))</font></div><div><font face="Courier New">;; current-defs : (syntax-parameter-of (or/c set-mutable? #f))</font></div><div><font face="Courier New">(define-syntax-parameter current-defs #f)</font></div><div><font face="Courier New">(define-match-expander sender</font></div><div><font face="Courier New"> (lambda (stx)</font></div><div><font face="Courier New"> (syntax-parse stx</font></div><div><font face="Courier New"> [(sender x)</font></div><div><font face="Courier New"> #:with tmp (generate-temporary #'x)</font></div><div><font face="Courier New"> (define defs (syntax-parameter-value #'current-defs))</font></div><div><font face="Courier New"> (set-add! defs (syntax-local-introduce #'(define x tmp)))</font></div><div><font face="Courier New"> #'tmp])))</font></div><div><font face="Courier New">(define-syntax reciever</font></div><div><font face="Courier New"> (lambda (stx)</font></div><div><font face="Courier New"> (syntax-parse stx</font></div><div><font face="Courier New"> [(reciever)</font></div><div><font face="Courier New"> (define defs (syntax-parameter-value #'current-defs))</font></div><div><font face="Courier New"> (with-syntax ([(def ...) (map syntax-local-introduce (set->list defs))])</font></div><div><font face="Courier New"> #'(begin def ...))])))</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(syntax-parameterize ([current-defs (mutable-set)])</font></div><div><font face="Courier New"> (match-define (sender x) 1)</font></div><div><font face="Courier New"> (reciever)</font></div><div><font face="Courier New"> x)</font></div></div></div><font face="Courier New"><br></font><div><div><font face="Courier New">;x3: unbound identifier;</font></div><div><font face="Courier New">; also, no #%top syntax transformer is bound in: x3</font></div></div><div><br></div><div><br></div></body></html>