Chapter 4. Code Blocks

In all but the simplest programs, you structure your code using blocks. Like in commonplace languages of C descent, a block starts with a left curly brace, followed by zero or more statements, and ends with a right curly brace. An example:

{
    let a: int = 2
    let b: int = 3
    a + b
}

But there are important differences to C and friends:

First, code blocks are expressions - they may return a value. Because of this, if the last statement of a code block is an expression, the value which is returned by that statement is the value which the code block returns. Obviously, our example block returns an int whose value is 5, and therefore is a valid Scaly program.

Second, the statements of a block can be executed in any order as far as data dependencies and the pureness of called functions allow. That is the main selling point of Scaly - it automatically schedules parallel and even distributed computation wherever possible.