Strange macro behavior #24

Closed
sjl opened this Issue Nov 17, 2012 · 5 comments

Comments

Projects
None yet
2 participants

sjl commented Nov 17, 2012

I'm trying to make a simple macro to save myself some typing:

(macro onload (body...)
  ($ (function ()
       ~@body...
       null)))

(onload
  (alert (+ 1 2))
  (alert (+ 2 3)))

($ (function ()
     (alert (+ 1 2))
     (alert (+ 2 3))
     null))

I expect the onload form to expand into something like the last form there, and then get compiled. But when I compile this I get the following javascript:

// Generated by LispyScript v0.2.9
$(function() {
    alert;
    (1 + 2);
    return null;
});
$(function() {
    alert((1 + 2));
    alert((2 + 3));
    return null;
});

I have no idea what the heck is happening here since Lispyscript macros are a templating language instead of real Lisp macros (and aren't really documented (I think the ~@ char splices?)). Is this a bug or am I doing something wrong?

Owner

santoshrajan commented Nov 17, 2012

use rest... and ~rest... to dereference. rest... is a special case that will have the rest of the expressions bound to it. No need to use @ to dereference it.

sjl commented Nov 17, 2012

Oh god, I figured it out. The name rest... is somehow magical. If I rename body... to rest... it works. Could you maybe document that somewhere?

Owner

santoshrajan commented Nov 17, 2012

It is documented in the let macro example in the macro docs. But yes I need to improve the docs though. Maybe not very clear. Thanks.

sjl commented Nov 17, 2012

Happening to use the name "rest..." in an example is not the same as saying "the name rest... is treated specially". I read the example but just thought you picked "rest" because you felt like it.

On Nov 17, 2012, at 1:44 AM, Santosh Rajan notifications@github.com wrote:

It is documented in the let macro example in the macro docs. But yes I need to improve the docs though. Maybe not very clear. Thanks.


Reply to this email directly or view it on GitHub.

Owner

santoshrajan commented Nov 17, 2012

Yes I will make it explicit in the docs. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment