Hi all - <br><br>I run into a problem that are better explained via the example, but basically I am having difficulty to get syntax-rules' literals and module interactions correct, and need some help understanding where it all goes awry.
<br><br>What I want to do is to write a macro that would match on a sexp that does different things based on the app-position token. The example just prints the sexp out as is without nesting.<br><br>expected behavior:<br>
(m (< 5 10)) ; => (< 5 10)<br>(m (> 5 10)) ; => (> 5 10)<br>
<br>So I write a macro like below:<br><br>(define-syntax m<br> (syntax-rules (> <)<br> ((_ (> exp exp2))<br> '(> exp exp2))<br> ((_ (< exp exp2))<br> '(< exp exp2))<br> ))<br><br>
and it works as expected on REPL.<br><br>However, if I put the above into a module and run within REPL, then I ran into bad-syntax error.<br><br>(module foo mzscheme<br>(define-syntax m<br> (syntax-rules (> <)<br>
((_ (> exp exp2))
<br> '(> exp exp2))<br> ((_ (< exp exp2))<br> '(< exp exp2))<br> ))<br>(provide (all-defined)))<br>(require foo)<br>(m (< 5 10)) ; => m: bad syntax in: (m (< 5 10))<br>(m (> 5 10)) ; => m: bad syntax in: (m (> 5 10))
<br><br>But if I eval m in another module instead of REPL, then it seems to work:<br><br>(module foo mzscheme<br> (define-syntax m<br> (syntax-rules (> <)<br> ((_ (> exp exp2))<br> '(> exp exp2))
<br> ((_ (< exp exp2))<br> '(< exp exp2))<br> ))<br> (provide (all-defined)))<br><br>(module bar mzscheme <br> (require foo)<br>(display (m (< 5 10)))<br>(newline)<br>(display (m (> 5 10))))
<br><br>(require bar) <br>; prints below<br>; (< 5 10)<br>; (> 5 10)<br><br>Any thoughts on why it behaves this way? I guess I lacked some simple understanding here and appreciate the pointers.<br><br>Thanks,<br>yc
<br><br><br>