<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 just thought: I could do syntax-local-introduce on the pattern before it gets passed to parse-id, and then do syntax-local-introduce on the bound-vars of that, except that it still doesn’t work.</div><div><br></div><div>Well, I’m probably still missing the syntax-mark of the match*/derived form. Although I could write a sort of syntax-local-introduce/pattern that would recursively apply syntax-local-introduce to all of the identifiers in a parsed pattern. </div><div><br></div><div><div><font face="Courier New">(define-syntax (match-define stx)</font></div><div><font face="Courier New"> (syntax-parse stx</font></div><div><font face="Courier New"> [(_ pat rhs:expr)</font></div><div><font face="Courier New"> (let ([p (parse-id (syntax-local-introduce #'pat))])</font></div><div><font face="Courier New"> (with-syntax ([pat (syntax-property #'pat 'parsed-pat p)]</font></div><div><font face="Courier New"> [vars (map syntax-local-introduce (bound-vars p))])</font></div><div><font face="Courier New"> (quasisyntax/loc stx</font></div><div><font face="Courier New"> (define-values vars (match*/derived (rhs) #,stx</font></div><div><font face="Courier New"> [(pat) (values . vars)])))))]))</font></div></div><br><div><div>On Aug 3, 2014, at 2:12 PM, Alexander D. Knauth <<a href="mailto:alexander@knauth.org">alexander@knauth.org</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Oh. <br><br>I have no idea what to do then. I can’t even do syntax-local-introduce or (datum->syntax stx (syntax->datum stx)) on it because it’s not a syntax object. <br><br>On Aug 3, 2014, at 1:59 PM, J. Ian Johnson <<a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a>> wrote:<br><br><blockquote type="cite">This is the problem of not introducing the right marks. He wants<br>(define-values (x) (match blah [x x]))<br><br>but is getting<br><br>(define-values (x) (match blah [x-barf x]))<br><br>Just pre-parsing won't get you all the way. You need to have a way to introduce to x-barf the marks between the outer match-define application and the inner match-expander transformer application.<br>P.S. your match-define/values calls parse-id within the bound-vars call. You want to use the syntax-property there too.<br>-Ian<br>----- Original Message -----<br>From: "Matthias Felleisen" <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>><br>To: "Alexander D. Knauth" <<a href="mailto:alexander@knauth.org">alexander@knauth.org</a>><br>Cc: "J. Ian Johnson" <<a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a>>, "racket users list" <<a href="mailto:users@racket-lang.org">users@racket-lang.org</a>><br>Sent: Sunday, August 3, 2014 1:53:49 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>From where I sit your syntactic abstraction generates code of this shape: <br><br><br>---> (define-values vars (match*/derived (rhs) #,stx [(pat) (values . vars ;; <---- <br><br><br>This introduces vars ___and___ uses them before the right-hand side is evaluated. <br><br><br>-- Matthias <br><br><br><br><br><br><br><br><br><br>On Aug 3, 2014, at 1:50 PM, Alexander D. Knauth wrote: <br><br><br><br><br>But I never defined or used those variables. <br>All I did was save the parsed pattern in a syntax-property and have the parse function look at that syntax-property. <br><br><br>On Aug 3, 2014, at 1:40 PM, Matthias Felleisen < <a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a> > wrote: <br><br><br><br><br><br><br>That means you are defining and using recursive variables before the initialization is done. <br><br><br><br><br>On Aug 3, 2014, at 1:31 PM, Alexander D. Knauth wrote: <br><br><br><br><br>I tried it but got weird errors like this: <br><br>idle-rest: undefined; <br>cannot use before initialization <br>And this: <br><br>wrkr: undefined; <br>cannot use before initialization <br><a href="https://github.com/AlexKnauth/racket/compare/match-define-save-parsed-pattern">https://github.com/AlexKnauth/racket/compare/match-define-save-parsed-pattern</a> <br><br><br>On Aug 3, 2014, at 12:32 PM, J. Ian Johnson < <a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a> > wrote: <br><br><br>Try it and report back. <br>-Ian <br>----- Original Message ----- <br>From: "Alexander D. Knauth" < <a href="mailto:alexander@knauth.org">alexander@knauth.org</a> > <br>To: "J. Ian Johnson" < <a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a> > <br>Cc: "racket users list" < <a href="mailto:users@racket-lang.org">users@racket-lang.org</a> > <br>Sent: Sunday, August 3, 2014 12:22: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>What if match-define did something like this to store the parsed pat in a syntax-property?: <br><br>(define-syntax (match-define stx) <br>(syntax-parse stx <br>[(_ pat rhs:expr) <br>(let ([p (parse-id #'pat)]) <br>(with-syntax ([pat (syntax-property #'pat 'parsed-pat p)] <br>[vars (bound-vars p)]) <br>(quasisyntax/loc stx <br>(define-values vars (match*/derived (rhs) #,stx <br>[(pat) (values . vars)])))))])) <br>And parse did something like this: <br><br>(define (parse stx) <br>(or <br>(syntax-property stx ‘parsed-pat) <br>(let () <br>... <br>))) <br><br><br>On Aug 1, 2014, at 9:13 PM, Alexander D. Knauth < <a href="mailto:alexander@knauth.org">alexander@knauth.org</a> > wrote: <br><br><br><br>On Aug 1, 2014, at 8:46 PM, Alexander D. Knauth < <a href="mailto:alexander@knauth.org">alexander@knauth.org</a> > wrote: <br><br><br><br>What do you mean? <br>Shouldn’t it go something like this: <br>(syntax-parameterize ([current-defs (mutable-set)]) <br>(match-define (sender x) 1) <br>(reciever) <br>x) <br>; => <br>(syntax-parameterize ([current-defs (mutable-set #’(define x x3)]) <br>(match-define x3 1) <br>(reciever) <br>x) <br>; => <br>(syntax-parameterize ([current-defs (mutable-set #’(define x x3)]) <br>(define x3 (match 1 [x3 x3])) <br>I just looked at the macro stepper again and saw something similar to this: (I replaced match*/derived with match and () with []) <br>(define-values (x3) (match 1 [(sender x) (values x3)])) <br>Why doesn’t match-define reuse the expanded match pattern instead of expanding it twice? <br><br><br>(reciever) <br>x) <br>; => <br>(syntax-parameterize ([current-defs (mutable-set #’(define x x3)]) <br>(define x3 (match 1 [x3 x3])) <br><br>(define x x3) <br>x) <br><br>The match-define form never defines “x” as anything, but the receiver should, right? <br><br>On Aug 1, 2014, at 8:12 PM, J. Ian Johnson < <a href="mailto:ianj@ccs.neu.edu">ianj@ccs.neu.edu</a> > wrote: <br><br><br><br>Ah, okay, so... this macro expander you give is fundamentally flawed because match-define does an initial parse (which uses the match expander) to get the identifiers it is going to define. So, when you expand to x3 as the match pattern, you end up returning x3 as one of the values that the match-define -> define-values is going to define. It does not ever define "x" as anything because that was just arbitrary syntax that was given to the match expander. This x3 is x3 definition leads to a use-before-initialization error. <br><br>Do you have a different example that doesn't fail in this way? <br>-Ian <br><br><br>____________________ <br>Racket Users list: <br><a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a> <br><br><br>____________________ <br>Racket Users list: <br><a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a> <br><br><br>____________________ <br>Racket Users list: <br><a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a> <br><br><br><br></blockquote><br><br>____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>