Artem Tikhomirov
Artem Tikhomirov

Reputation: 21726

Strange boo language syntax

I've run into a strange syntax in Boo Language Guide :

setter = { value | a = value }

What does the | operator mean?

Upvotes: 3

Views: 1134

Answers (4)

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99750

That syntax for specifying code blocks (anonymous functions) has been borrowed from Ruby and Smalltalk

Upvotes: 0

Frep D-Oronge
Frep D-Oronge

Reputation: 2646

Adam is correct. The point of the example is to show that lambdas in boo have read and write access to enclosing scope.

Upvotes: 2

dF.
dF.

Reputation: 75825

The documentation of Boo seems to be lacking in this area -- it seems that

setter = { value | a = value }

is shorthand for

setter = def(value):
    a = value

Upvotes: 5

Adam Wright
Adam Wright

Reputation: 49386

Well, having never used Boo, my (educated) guess is that it's for passing parameter to the closure lambda-style functions. In this case, { p | C } refers to an anonymous function taking a single parameter bound to p within the code C.

Upvotes: 4

Related Questions