Question about macros

49 views
Skip to first unread message

jeremys

unread,
Jun 24, 2013, 9:12:15 AM6/24/13
to lispy...@googlegroups.com
Hi,

I have a question about the macro system. I wanted to write a macro for the meteor api with the following behavior:

(deftemplatehelpers foo
  {bar: "baz"
   fooo: (function () 3)})

expands to somthing like:

(Template.foo.helpers
  {bar: "baz"
   fooo: (function () 3)})

The goals is to have a shortcut to create template helpers functions.

Can I do that? How?
.
Cheers,

Jeremys

Santosh Rajan

unread,
Jun 24, 2013, 9:24:35 AM6/24/13
to lispy...@googlegroups.com
Use LispyScript `object` instead of Javascript object literal. And use . notation.

See docs for both.


--
You received this message because you are subscribed to the Google Groups "lispyscript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lispyscript...@googlegroups.com.
To post to this group, send an email to lispy...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/lispyscript/7c866563-2680-4ce5-95cf-4c592c1ee751%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--

jeremys

unread,
Jun 24, 2013, 10:13:09 AM6/24/13
to lispy...@googlegroups.com
the macro looks like this now:

(macro deftemplateHelpers (tpl rest...)
       (Template.~tpl.helpers
(object ~rest...)))

(deftemplateHelpers foo 
   bar "baz"
   fooo (function () 3))

compiles to

Template.~tpl.helpers({
    bar: "baz",
    fooo: function() {
        return 3;
    }
});

and doesn't work because of the "Template.~tpl.helpers" part. How can I have "Template.foo.helpers" the desired effect with the . notation ?

Santosh Rajan

unread,
Jun 24, 2013, 10:43:54 AM6/24/13
to lispy...@googlegroups.com
(macro deftemplateHelpers (tpl rest...)
      ( (.helpers (~tpl Template)
(object ~rest...))))

(deftemplateHelpers .foo 
   bar "baz"
   fooo (function () 3))

notice i am using '.foo' as the ar to the macro.




For more options, visit https://groups.google.com/groups/opt_out.
 
 

jeremys

unread,
Jun 24, 2013, 10:54:21 AM6/24/13
to lispy...@googlegroups.com
Thanks a lot Santosh it's a big help to make neet little DSLs for meteor. Sorry to pick your brain so much
but I am more used to clojure macros, I needed some tips !

Thanks again !

Santosh Rajan

unread,
Jun 24, 2013, 10:57:22 AM6/24/13
to lispy...@googlegroups.com
You can't use '.' in a clojure token. So it is just about getting used to that.



For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages