Skip to content

NEP5 Sequence Operator

Greg Hewgill edited this page Jul 25, 2019 · 1 revision

Often expressions end up being a sequence of function calls, such as

print(str(abs(x)))

In expressions like the above, the order of function calls as seen in the source is the opposite of the order functions are actually called. This is because function calls normally use a prefix notation.

This proposal implements a new sequence operator (|), which turns around the function calls:

print(x | abs | str)

In general, the expression x | f is equivalent to f(x). The function on the right hand side of | must (currently) take exactly one parameter. The | operator is left associative, so x | f | g is equivalent to (x | f) | g, or g(f(x)).

The | operator has the lowest precedence of binary operators, so one can write x + y | str which means str(x + y).

This notation was inspired by the command shell pipe notation.

Prototype working branch: https://github.com/ghewgill/neon-lang/tree/wip-sequence