How do you deal with lambdas in boo? Is "callable" the same thing? How do you define a method that takes a lambda as a parameter?
+9
A:
Boo does support lambda expression syntax:
foo = {x|x+2}
seven = foo(5)
def TakeLambda(expr as callable(int) as int):
return expr(10)
twelve = TakeLambda(foo)
In this example, foo
is a function that accepts a number x and returns x + 2. So calling foo(5)
returns the number 7. TakeLambda
is a function that accepts foo
and evaluates it at 10.
Greg
2008-11-09 07:37:35
how do I accept a lambda as a method argument?
mmiika
2008-11-09 07:44:14
I hope that helps!
Greg
2008-11-09 08:08:16
Thanks, i see most cases just "as callable" is enough
mmiika
2008-11-09 08:22:26
I wish .NET delegates were more like callable in boo. this would make life so much easier in so many cases...
Krzysztof Koźmic
2009-02-27 17:24:58
@Krzysztof Koźmic: F#'s notation is nice: `TakeLambda : (int -> int) -> int`
Dario
2010-02-15 20:12:17