Common expression blocks allows factoring out repeated subexpressions in a longer expression, giving it a name and giving the compiler a chance to avoid repeated evaluation.
Common expression blocks are very similar to using statements:
using identifier := expression , ... do core-expression
The result type of the whole expression is the type of the core-expression. Local variables are created and initialized for each assignmens from the header. After this, the core expression is evaluated and its value is returned. The scope of the created local variables is restricted to the core expression.
Common expression blocks are very useful for inline implementations like this:
method Normalize: Vector => using len := self.Length do if len = 0 then self else self / len;
The Freya Programming Language
Expressions
Conditional expressions
The null coalescing operator
if statement
The Freya Programming Language