Monday, March 21, 2011

Adventures in special forms

As I start to flesh out QuasiScript, I am making choices about the initial set of special forms to choose.  Special forms are the basic structures (similar to the keywords in an infix language like C, Pascal, etc.) used to define the core of the language.  Other structures can be built up as macros (once I have them!) and functions.

Initially I chose special forms close to Scheme, or Arc, or CoffeeScript, but as I progress I am leaning towards making the core much more like "JavaScript with a lispy coating".

E.g. What started as "(def x 5)" now reads as "(var x 5)", and translates to js as "var x = 5;".  This lowers the cognitive switching between js and qs. 

Similarly, at first I wanted everything to be an expression (i.e. return a value), but this does not make for particularly idiomatic javascript output, at least not without adding a smart phase to the compiler to eliminate redundant closures.  So I'm taking more of an 80/20 approach to keep things idiomatic, but eliminate common returns.  E.g. "(fun (x) (* 2 x))" -> "function (x) { return 2*x; }".  Of course, something like arc's "[* 2 _]" for the same expression would be even nicer, but that's sugar for later.

Later, with macros, it should be possible to build from the core up to a more powerful language, with plenty of good stuff out-of-the-box.

No comments:

Post a Comment