Created
July 26, 2008 05:48
-
-
Save nowelium/2608 to your computer and use it in GitHub Desktop.
js like apply, bind, curry...
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
Block apply := method(target, args, | |
args = if(args isNil, list(), args) | |
target = if(target isNil, scope, target) | |
self setScope(target) | |
self performWithArgList("call", args) | |
) | |
Block bind := method( | |
args := call message argsEvaluatedIn(call sender) | |
target := args at(0) | |
args = args slice(1) | |
b := self | |
return block( | |
b apply(target, args union(call message argsEvaluatedIn(call sender))) | |
) | |
) | |
Block curry := method( | |
args := call message argsEvaluatedIn(call sender) | |
if(args size < 1) then ( | |
return self | |
) | |
/* | |
target := args at(0) | |
args = args slice(1) | |
*/ | |
b := self | |
return block( | |
b apply(scope, args union(call message argsEvaluatedIn(call sender))) | |
) | |
) | |
hoge := Object clone do( | |
message := "ishoge" | |
) | |
foo := Object clone do( | |
message := "isfoo" | |
) | |
promp := block(a, b, | |
"#{self message} at #{a}, #{b}" asMutable interpolate println | |
) | |
promp setScope(hoge) | |
a := promp curry("aaa") | |
a call("bbb") | |
b := promp bind(foo, "ccc") | |
b call("ddd") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment