
26 Jan
2011
26 Jan
'11
11:07 a.m.
Thanks for the great extra info on JMacro. I think haskellers would enjoy hearing about it and how you use it as a blog post. Hi! Author of JMacro here. You're right that JMacro has a few less features than CoffeeScript. In particular, it lacks pattern matching. Outside of that, however, most CoffeeScript features are to make CoffeeScript more rubylike in syntax. Haskell-style anonymous lambdas coupled with whitespace function application on their own, however, suffice to allow exceedingly Haskell/ML-like code. JMacro can be used as a nicer syntax for JavaScript, but the big win is that it is a better way to *generate* JavaScript -- in particular via hygiene and a shared namespace with surrounding Haskell code. So bear in mind also that JMacro syntax is infinitely-extensible in the sense that you can not only write JavaScript combinators in JMacro, but Haskell combinators which produce JMacro that can be spliced directly back into a block of code. Jeff and I have, for instance, written a tiny set of infix combinators for chaining jQuery selectors. coffee-script isn't designed to give javascript a ruby-like syntax. It is designed to add useful language level features and get rid of superfluous syntax, which Ruby and haskell also try to do. Maintaining a certain amount of javascript compatibility makes it look more like Ruby and less like Haskell. But there are definitely influences from other languages. For example, it uses layout syntax instead of an 'end' keyword (or brackets) in ruby. You can use groovy's existential operator. >From looking at the jmacro README I am slightly confused as to what syntaxes are required, and which are optional, but it seems like the following features are in coffee script but not jMacro * no need for the var keyword, scope is intelligently taken care of. * no need for semi-colons * no need for parentheses around conditionals for ifg * list comprehensions (as in python), an extremely useful feature. * removal of brackets and commas for objects * argument splats * single line conditionals * ranges * class/super class conveniences * 'this.' aliased to '@' * multi-line strings * string and regular expression variable interpolation There are other things that might be missing/different, but I can't tell because they aren't documented, such as: * removal of triple-equal- double equal acts as triple equal (or is this in just the lambda syntax?) Another feature of JMacro as opposed to CoffeeScript is that almost all valid JavaScript code is *also* valid JMacro. So you can take a code-sample or snippet from the web and place it directly into your application, refactoring it into a more functional style incrementally and at whatever pace you want. CoffeeScript allows for "escaping" into raw javascript, but that's in my opinion a much weaker alternative. This is also true of coffeescript, but to a lesser extent. Function syntax must be converted, and the var keyword removed. After that, plain javascript should works, and there are usually many improvements that can be made incrementally. While this provides some downside, it also provides upside- there is one unified function syntax that is as convenient as the haskell anonymous lamba syntax instead of 2 different function syntaxes with different rules. I really like what you have done with jMacro. My previous comments were really directed to thinking about it in a different context. I think we just need to clarify that these are different tools for different jobs. For the goal of writing javascript instead of generating it, coffee-script holds a lot of advantages over jMacro. For the goal of generating javascript from haskell (which you are using it for), jMacro seems like the perfect tool, and I will definitely look into using it for that purpose in the Yesod framework or my Yesod applications. Greg Weber