[boo]
boo 0.4 is out
[ bamboo ] 16:49, Tuesday, 14 September 2004

Grab yours here!

Tons of improvements in this version, true closures are my favorite one since they allow ruby-like things such as:

def each(items, closure as callable):
    for item in items:
         closure(item)

items = [1, 2, 3, 4, 5]
value = 0
each(items) do (item as int):
     value += item
print(value)


In this example the closure is constructed with the do keyword and is automagically passed as the last argument to the each function. Cool or what?

TrackBack
Comments

Another way to write this:

each(items) do (item as int):
value += item

would be:

each(items, { item as int | value += item })

The second way seems clearer to me - why does "do" create a closure in the first example and it add it to the call to "each"?

--Bill Wood, October 10, 2004 07:38 PM

Bill,

"do" is just ruby-like syntactic sugar and it does exactly that, it creates a closure and passes it as the last argument for the method invocation on its left.

"do" makes it convenient to write little "template method" algorithms:

WithTransaction(connection) do (transaction):
   print("inside transaction ${transaction}")

cheers,
Rodrigo

--Rodrigo B. de Oliveira, October 10, 2004 08:52 PM
Post a comment









Remember personal info?