Created
July 16, 2012 21:48
-
-
Save Nek/3125306 to your computer and use it in GitHub Desktop.
Declare lambda functions easily (Haxe 2.10).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import haxe.macro.Expr; | |
class EasyLambda { | |
@:macro public static function f(p:Expr, e:Expr) : Expr { | |
var res:Expr = macro function(a) {return $e;}; | |
var params = macro $p; | |
var pname = | |
switch (params.expr) { | |
case EConst(i):switch (i) { | |
case CIdent(v): v; | |
default: null; | |
}; | |
default: null; | |
}; | |
switch (res.expr) { | |
case EFunction(name,f): | |
f.args[0].name = pname; | |
default:null; | |
} | |
return res; | |
} | |
static function main() { | |
trace(f(a,a+5)(1)); | |
var add = f(a,f(b,a+b)); | |
trace(add(1)(2)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment