puffnfresh/sweet-fantasies — pull request #9 by robotlolita (2014-06-15 14:43:34+00:00)
Title: Updates macros for Sweet.js 0.6.x

This addresses (https://github.com/puffnfresh/sweet-fantasies/issues/8), it's mainly a complete rewrite of the `do` notation macro. Other macros should probably be dropped now and rewritten using Sweet.js's custom operators (http://sweetjs.org/doc/main/sweet.html#custom-operators), as they make more sense as infix.

This patch also supports having a naked action as the last expression, so:

```js
var a = $do {
x <- f()
y <- g()
h(x, y)
}
```

Works and gets desugared as expected:

```js
var a = (function() {
return f().chain(function(x) {
return g().chain(function(y) {
return h(x, y)
})
})
}())
```

A couple of things worth noting about this patch:

1. Actions that aren't bound to an explicit identifier gets bound to `_it`. This was mainly for simplicity dealing with all the cases, so: `$do { a; b }` gets desugared to `a.chain(_it => b)`. I'm unsure if this is much of a problem, though this does introduce an implicit new binding in the scope, which might lead to some awkward things(?)

2. Do blocks are wrapped in a immediately forced thunk. This was again mainly for simplicity with dealing with variable bindings.

3. The patch makes use of an experimental feature in Sweet.js 0.6.x (http://sweetjs.org/doc/main/sweet.html#custom-pattern-classes-experimental) to abstract over some patterns. This is mainly to allow constructs to be optionally separated with a semicolon, I'm unsure to which extent this is actually useful.