Node:Reduce, Next:Inverse, Up:Operators
(NOTE: WORK IN PROGRESS!)
To reduce a sequence using a binary infix function
is to combine the elements of the sequence by place the
operator "between" each element. For example,
the reduction of [2 3 4]
using +
is 2+3+4
.
The symbol @
is used for reduction. This use of @
is related to its use for making tuples. See Tuples.
A recursive definition:
[] @OP R == R (x,L) @OP R == x OP (L @OP R) [] @OP == left_identity OP # If defined [x] @OP == x (x,L) @OP == x OP (L @OP)
L OP@ [] == L L OP@ (x,R) == (L OP x) OP@ RNote that right(?)-reduction
OP@
uses
the same syntax as tupling: X@
.
However, the former requires OP
to be
a binary function, while the latter requires
X
to be a sequence.
Note that @,
is append
,
while @@,
appends all the elements.
The operator |
is syntax, not a function.
However, it is convenient to define @|
and |@
using the same definitions as before (NOT IMPLEMENTED).
The left_identity
and right_identity
of |
are assumed to be (;)
(i.e. the empty sequence).
It is also convenient to define
~|@ EXPR
to collect each result from
evaluating EXPR, and make a sequence of them all.