evanrmurphy / SweetScript

A lispy language that compiles into JavaScript, strongly influenced by Arc.
https://github.com/evanrmurphy/SweetScript
14 stars 4 forks source link

Write an Underscore helper macro that works #2

Open evanrmurphy opened 13 years ago

evanrmurphy commented 13 years ago

Tried to write it as follows, but doesn't work because of recursive call to _:

; Underscore helper
;  Only needed when using Underscore in the
;  object-oriented style: 
;   http://documentcloud.github.com/underscore/#styles
;  So that we can write:
;   (_ [1 2 3] (map (fn (n) (* n 2))))
;  Instead of:
;   (.. (_ [1 2 3]) (map (fn (n) (* n 2))))

(mac _ (object . args)
  `(.. (_ ,object) ,@args))
evanrmurphy commented 13 years ago

Related trouble with the jQuery helper macro isn't as severe. It can't be named jQuery and use the jQuery jQuery object, or be named $ and use the $ jQuery object. It must be named one and use the other to avoid a recursive macro call.