Reader Operators¶
Reader operators allow the reader to re-arrange expressions before passing them onto the evaluator.
The obvious use of operators is for infix expressions like regular arithmetic, 1 + 2. Idio expects the function to be the first element of any form so without any re-arrangement it would try to invoke the function 1.
You can define postfix operators as well although there are very few defined by default.
Arithmetic is usually a binary operation in that it expects a number
either side of the operator. Other infix operators like
job-control’s |
operator can expect
any number of arguments either side of the operator and potentially
more than one instance of itself in the same expression.
Like C arithmetic precedence, operators are given a precedence which allows them to gather elements of expressions into groups before recursing the operator expansion code on those groups.
Consider:
find . -name foo 2> "/dev/null" | xargs wc -l
Here we would expect |
to have a high precedence to construct two
sub-expressions:
find . -name foo 2> "/dev/null"
xargs wc -l
Recursing the operator expansion into the first sub-expression we
would find the I/O redirection operator, 2>
, also from
job-control
, which would distinguish find . -name foo
from the
I/O redirection target "/dev/null"
Operators are another spin on templates and like them are regular functions which return an expression to be evaluated.
The actual expansion of the |
operator is pages of code, see
lib/job-control.idio
for more details.
Last built at 2024-12-21T07:10:42Z+0000 from 62cca4c (dev) for Idio 0.3.b.6