<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>What if match-define did something like this to store the parsed pat in a syntax-property?:</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 #'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 (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"><span class="Apple-tab-span" style="white-space:pre">                            </span>      [(pat) (values . vars)])))))]))</font></div></div><div>And parse did something like this:</div><div><div><font face="Courier New">(define (parse stx)</font></div><div><font face="Courier New">  (or</font></div><div><font face="Courier New">   (syntax-property stx ‘parsed-pat)</font></div></div><div><font face="Courier New">   (let ()</font></div><div><font face="Courier New">     ...</font></div><div><font face="Courier New">     )))</font></div><br><div><div>On Aug 1, 2014, at 9:13 PM, Alexander D. Knauth <<a href="mailto:alexander@knauth.org">alexander@knauth.org</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><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><blockquote type="cite">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></blockquote>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><blockquote type="cite"> (reciever)<br> x)<br>; =><br>(syntax-parameterize ([current-defs (mutable-set #’(define x x3)])<br> (define x3 (match 1 [x3 x3]))</blockquote><blockquote type="cite"> (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><blockquote type="cite">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></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><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>