3 ms·
Parenscript already provides macros. You can write in parenscript and output a .js file. Example usage (taken from the mailing list): 1. standard with-foo mac
by nunb 17y ago
Parenscript already provides macros. You can write in parenscript and output a .js file.
Example usage (taken from the mailing list):
1. standard with-foo macro
(with-elements-by-ids (mydiv (other "otherdiv"))
(setf mydiv.inner-h-t-m-l other.inner-h-t-m-l))
2. multiple-value return in javascript
(defun divmod (a b)
(return (values (/ a b) (% a b))))
(receive (div mod) (divmod 10 3)
(debug (+ "div: " div ", mod: " mod)))
Since JS has true closures and a flexible object model (someone wrote a CLOS-y layer for it recently) there is no need to take the JSR way and try and push for a community-accepted broken macro system. Besides, as someone (Jason Dominus?) posted to the perl list, lisp macro's are regular and do not break, unlike every other proposal that uses infix syntax.
- jrockway 17y agoThere are infix-sytnax macro systems that work. See metalua, for example.
- mnemonik 17y agoYes, if you really want the power of macros inside a browser ParenScript is the only real choice. I mentioned ParenScript at the end of the post. A ParenScript and Hunchentoot project is definitely on my TODO list for whenever I next have time off of school and work. I'm sure Douglas Crockford would agree with you and say that JavaScript already has too many nasty and broken features (ie the DOM and "with") but I was just having some fun on my day off from work. As others have pointed out, the expander can't even survive expansion, and using regexes for code parsing is a poor choice. Maybe, I haven't emphasized it enough, but I was just having some fun and imagining what it would be like to code with real macros in JS. I'm not advocating anyone actually use this code in any of their projects, nor that ECMAscript include simple template style macros in the spec. That said, I wouldn't mind if someone built real lispy macros into a JavaScript implementation by forking Rhino or Spider Monkey. I'm convinced that this is possible despite the verbose syntax. Check this out: http://javascript.crockford.com/tdop/tdop.html http://javascript.crockford.com/tdop/tdop.html