Skip to content

Instantly share code, notes, and snippets.

@satyr
Created December 8, 2011 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satyr/1446167 to your computer and use it in GitHub Desktop.
Save satyr/1446167 to your computer and use it in GitHub Desktop.
{Fun, Unary} = Coco.ast
uplus = -> it instanceof Unary and it.op is \+
<- Coco.on \compile
<- it.ast.traverseChildren ..., true
# +->
if uplus it and (fun = it.it) instanceof Fun
delete it[k] for k in it
fun = it <<< {fun.__proto__, ...fun}
# <-+
else if uplus it.head and not it.tails.1 and
(call = it.getCall!) and (fun = call.args.0) instanceof Fun
callee = it.head.it
# <-+ f x, ...
if callee.getCall!
{call.args} = that
break if a.filler for a, pos of call.args
call.args[pos] = fun
callee.=head
it.head = callee
else return
Object.defineProperty fun, \void value: true
void
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment