<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>I'm not sure why this works and that doesn't, but try passing n as an argument to the match expander: </div><div><br></div><div><div><font class="Apple-style-span" face="'Courier New'">#lang racket</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(require rackunit)</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(define-match-expander num:</font></div><div><font class="Apple-style-span" face="'Courier New'"> (λ(stx)</font></div><div><font class="Apple-style-span" face="'Courier New'"> (syntax-case stx ()</font></div><div><font class="Apple-style-span" face="'Courier New'"> [(num: n)</font></div><div><font class="Apple-style-span" face="'Courier New'"> #'(? number? n)])))</font></div><div><font class="Apple-style-span" face="'Courier New'"><br></font></div><div><font class="Apple-style-span" face="'Courier New'">(check-equal? (match 1 [(num: n) n]) 1)</font></div><div><font class="Apple-style-span" face="'Courier New'">(check-equal? (match 'x [(num: n) n] [_ 2]) 2)</font></div></div><div><br></div><div>I think it might have something to do with the Macro-Introduced Bindings section of the Syntax Model page in the documentation. </div><br><div><div>On Dec 26, 2013, at 2:45 PM, Jens Axel Søgaard wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>The match pattern (? number? n) matches number and<br>binds it to n.<br><br><blockquote type="cite">(match 1 [(? number? n) n])<br></blockquote> 1<br><br>I'd like to write (match 1 [n:num n]) instead.<br><br>Since there is no define-identifier-match-expander I have<br>tried to make (match 1 [(n:num) n]) work. I need a hint.<br><br>Here is a non-working attempt:<br><br>(define-match-expander n:num<br> (λ(stx)<br> (syntax-case stx ()<br> [(id)<br> (with-syntax ([n (syntax/loc #'id n)])<br> #'(? number? n))])))<br><br><br>(check-equal? (match 1 [(n:num) n]) 1)<br>(check-equal? (match 'x [(n:num) n] [_ 2]) 2)<br><br>/Jens Axel<br><br><br><br><br><br><br>--<br>Jens Axel Søgaard<br><br>____________________<br> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></div></blockquote></div><br></body></html>