Skip to content

Instantly share code, notes, and snippets.

@mcheshkov
Last active August 29, 2015 14:22
Show Gist options
  • Save mcheshkov/581b4645cd5fc37b6088 to your computer and use it in GitHub Desktop.
Save mcheshkov/581b4645cd5fc37b6088 to your computer and use it in GitHub Desktop.
Short lambda macro #1
class ShortLambdaMacroTest {
static function other(i:Int){
trace('ok, so $i');
}
static function using(){
Lambda.iter([1,2,3], function(i){trace(i);});
Lambda.iter([1,2,3], f(i => trace(i)));
Lambda.iter([1,2,3], f(i => {trace(i + 1); other(i);}));
}
static macro function f(e){
switch(e.expr){
case EBinop(OpArrow, el, er):
var argName = "";
switch(el.expr){
case EConst(CIdent(i)):
argName = i;
default: throw "Unexpected arg $el";
}
return macro function($argName){ return $er; };
default: throw 'Unexpected $e';
}
throw false;
}
}
@mcheshkov
Copy link
Author

Oh, sorry, didn't see "line 3" part :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment