Syntax
Syntactic sugar

Syntactic Sugar

Flow is built with very few concepts, so its core syntax is minimal.

However, using only the minimal syntax can make programs verbose. To address this, Flow supports syntactic sugar.

Infix Operators

Nodes like + and - can be written as infix operators (interpreted as nodes taking two inputs).

> 1 + 2 -> output
3.

This is interpreted as:

(1 ->) (2 ->) + -> output

Infix operators can be combined:

> 1 + 2 * 3 - 4 -> output
3.

Application

You can also pass inputs using function-application style syntax like in functional languages:

> output 1
1.

This is interpreted as:

(1 ->) output

You can combine this with infix operators. In the following example, (1 == 2) is passed as input using application:

> if (1 == 2) (then:-> "true!" -> output) (else:-> "false!" -> output)
false!.

This is interpreted as:

((1 ->) (2 ->) == ->) if (then:-> "true!" -> output) (else:-> "false!" -> output)

Multiple arguments can be applied as well. f a b is interpreted as (a ->) (b ->) f.

Partial Application

Arguments can also be partially applied. Partially applied arguments are prioritized (considered applied earlier), so b -> f a is interpreted as (a ->) (b ->) f.

Concrete examples are given later.

Sections

A section is a partially applied infix operator (same as in Haskell).

> 1 -> + 2 -> output
3.

When partially applying from the left, parentheses are required:

> 1 -> (3 -) -> output
2.

If the partially applied expression is complex, do not omit parentheses. Example: + (2 * 3)

Examples of Partial Application and Sections

In the previous chapter, we discussed the second argument of if. This specifies the value actually passed downstream. For example:

> 2 -> if (1 == 2) (then:-> * 2 -> output) (else:-> - 1 -> output)
1.
> 2 -> if (1 == 1) (then:-> * 2 -> output) (else:-> - 1 -> output)
4.

Here, if is partially applied, and sections * 2 and - 1 appear.
The first program is interpreted as:

((1 ->) (2 ->) == ->) (2 ->) if (then:-> (2 ->) * -> output) (else:-> (1 ->) - -> output)