On 06/03/2008, <b class="gmail_sendername">Yariv Sadan</b> <<a href="mailto:yarivsadan@gmail.com">yarivsadan@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi, I think I found a bug in lfe_eval.<br> <br> I created the following macro:<br> <br> (define-syntax bar<br>  (macro<br>   ((vals)<br>    (: lists map (lambda (x) (: io format '"~p~n" x)) vals) ())))<br> <br>
 and the following function:<br> <br> (define (foo)<br>  (bar (1 2 3)))<br> <br> When I call '(foo)' I get the following error:<br> <br> ** exception error: lfe_eval:'-eval_lambda/2-fun-0-'/2 called with one argument<br>
     in function  lists:map/2<br>     in call from lfe_eval:eval_body/2<br>     in call from lfe_macro:macro/3<br>     in call from lfe_macro:expand_tail/3<br>     in call from lfe_macro:expand/2<br>     in call from lfe_macro:expand_top_forms/2<br>
     in call from lfe_macro:expand_top_forms/2<br>     in call from lfe_macro:expand_file/2</blockquote><div><br>That's a  bug, but it has now been fixed. I have released a patch on <a href="http://trapexit.org">trapexit.org</a> with a fix and a few other goodies.<br>
</div><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Also, can you please explain the difference between 'macro' and<br> 'syntax-rules'? 'macro' seems to do what I expect and I'm not sure<br>
 when syntax-rules would be a better option.</blockquote><div><br>'syntax-rules' are simpler and are taken from Scheme. Each rule consists of (pattern expansion) where pattern is matched against the arguments of the macro call and the values of the variables from pattern are substituted into the expansion which is then returned. It is like a simple form of backquote macro where the only possible unquoting is symbol names. You can't "do" anything in the pattern except return it. So for example a simple recursive definition of let* (sequential let) would be:<br>
<br>(define-syntax let*<br>  (syntax-rules<br>    ([(vb . vbs) . b] [let (vb) (let* vbs . b)])<br>    ([() . b] [begin . b])))<br><br></div>Here I also use [...] as alternative to (...) to mark out the patterns and the expansion.<br>
<br>Syntax-rules are useful when the macro can be written as a simple expansion, although there is not much difference in using macro with a simple backquote. See test_macro.lfe for an example of the same macro written in both ways. Macro needs the evaluator to evaluate the body while syntax-rules does not.<br>
<br>I am thinking of changing the names to defsyntax and defmacro :<br><br>(defsyntax let*<br>  (pat1 exp1)<br>  ... )<br><br>(defmacro let*<br>  (pat1 . body1)<br>  ... )<br><br>What does the "user community" feel about that? Having both under one define-syntax maybe a clearer way to express the intention though.<br>
<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"> Thanks,<br> <br>Yariv<br></blockquote></div><br>Robert<br><br>