3 ms·
Well actually, I did end up writing Lisp on top of Javascript this way: http://github.com/spencertipping/caterwaul http://github.com/spencertipping/caterwaul.
by spencertipping 16y ago
Well actually, I did end up writing Lisp on top of Javascript this way: http://github.com/spencertipping/caterwaul http://github.com/spencertipping/caterwaul.
The basic mechanism is to call f.toString() on some function, then construct a new one the way you want it using either eval() (for non-IE browsers), or new Function(code) (for all browsers). Caterwaul leverages this by implementing a JS parser, defining a macro syntax, and letting you determine how the code gets rewritten. (So you can do things like let[x = 5] in x + 1, which is valid JS to begin with but nobody would ever use it :) )