<HTML><BODY><p>I like to make syntax-optimized functions.<br><br>(define-syntax (square stx)<br> (syntax-case stx (square expt)<br> [(square (square expr)) #'(expt expr 4)]<br> [(square (expt expr n)) (if (number? (syntax-e #'n))<br> #`(expt expr #,(* (syntax-e #'n) 2))<br> #'(expt expr (* n 2)))]<br> [(square x) #'(* x x)]<br> [square #'(lambda (x) (* x x))]))<br><br>So I can write (square (expt x 5)) and have evaluate (expt x 10) and I can write (map square '(1 2 3)) and it is also works.<br><br>But I dislike to repeate the body of the function in last two cases.<br><br>I tryed <br><br></p><p>(define-syntax (square stx)<br> (let ([body #'(* x x)])<br> (syntax-case stx (square expt)<br> ...<br> ...<br> [(square x) body]<br> [square #'(lambda (x) #`body)]))<br><br>but hygiene prevents me from that: x: unbound identifier in module in: x</p>How can I bind template body with some variable? Or how to rewrite the syntax to evade duplication?<br><br>-- <br>Roman Klochkov</BODY></HTML>