<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>But I never defined or used those variables. </div><div>All I did was save the parsed pattern in a syntax-property and have the parse function look at that syntax-property. </div><br><div><div>On Aug 3, 2014, at 1:40 PM, Matthias Felleisen <<a href="mailto:matthias@ccs.neu.edu">matthias@ccs.neu.edu</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>That means you are defining and using recursive variables before the initialization is done. </div><div><br></div><br><div><div>On Aug 3, 2014, at 1:31 PM, Alexander D. Knauth wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>I tried it but got weird errors like this:</div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo; background-color: rgb(146, 146, 146);">idle-rest: undefined;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; background-color: rgb(146, 146, 146);"> cannot use before initialization</div></div><div>And this:</div><div><div style="margin: 0px; font-size: 11px; font-family: Menlo; background-color: rgb(146, 146, 146);">wrkr: undefined;</div><div style="margin: 0px; font-size: 11px; font-family: Menlo; background-color: rgb(146, 146, 146);"> cannot use before initialization</div></div><div><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></div><br><div><div>On Aug 3, 2014, at 12:32 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">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></blockquote></div><br></div>____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></div></blockquote></div><br></body></html>