Skip to end of metadata
Go to start of metadata


Martin Fowler has a good introduction to closures on his bliki.


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


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:

See Also

Functions, Parameters, Callable Types, Events

  • No labels


  1. Is there a difference between do(): ... and def(): ... ?

  2. 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.