Syntax Strange boo language

I came across a strange syntax in the Boo Language Guide :

setter = { value | a = value }

What does | operator mean?

+3
source share
4 answers

The Boo documentation seems to be missing in this area - it seems like

setter = { value | a = value }

is short for

setter = def(value):
    a = value
+5
source

Well, I never used Boo, my (educated) guess is that it is for passing a parameter to the lambda-style close function. In this case {p | C} refers to an anonymous function containing a single parameter associated with p in C.

+4
source

Adam is right. An example point is to show that lambdas in boo have read and write access to the enclosing area.

+2
source

This syntax for specifying code blocks (anonymous functions) was borrowed from Ruby and Smalltalk.

0
source

Source: https://habr.com/ru/post/1696611/


All Articles