Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lambdas in Boo?

Tags:

syntax

lambda

boo

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?

like image 260
mmiika Avatar asked Nov 09 '08 07:11

mmiika


1 Answers

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.

like image 191
Greg Avatar answered Sep 21 '22 02:09

Greg