Introduction
Martin Fowler has a good introduction to closures on his bliki.
Syntax
There are two syntaxes for closures: a block based syntax with syntactically significant whitespace and a braces based that ignores whitespace.
Block based syntax
Braces based
Semantics
Boo closures have have full access (to read and write) to their enclosing lexical environment. For Instance:
The best source of information right now are the test cases for closures in the tests/testcases/integration directory.
Closures vs. Functions
See Functions As Objects.
Some things you can do with named functions that you cannot with closures include recursion and overloading:
This will not work because "c" is unknown from inside the closure:
so you can use a regular named function or else create a 2nd callable to hold the name:
And you can use regular named functions to overload a method:

2 Comments
Hide/Show CommentsAug 16, 2011
Philip Peterson
Is there a difference between do(): ... and def(): ... ?
Aug 16, 2011
Philip Peterson
Also I'd like to point out that you can fix that problem of recursion simply by declaring the variable before initializing it:
c as callable
c = do(x as int): ....
And you won't get the unknown identifier problem.