Sequence Operations
Equivalent functions exist to apply all of the relational, logical and arithmetic operators described above,
as well as the math routines described in
Library Routines, to entire sequences as
well as to single numbers (atoms).
The sq_uminus() function applies the unary (one operand) minus operator to each element of a sequence to yield a sequence of results of the same length. If one of these elements is itself a sequence then the same rule is applied again recursively. e.g.
The sq_uminus() function applies the unary (one operand) minus operator to each element of a sequence to yield a sequence of results of the same length. If one of these elements is itself a sequence then the same rule is applied again recursively. e.g.
x = sq_uminus({1, 2, 3, {4, 5}}) -- x is {-1, -2, -3, {-4, -5}}If a binary (two-operand) operator function is passed two sequences then they must be of the same length. The binary operation is then applied to corresponding elements taken from the two sequences to get a sequence of results, with the function applied recursively if required. e.g.
x = sq_add({5, 6, 7, {8, 9}}, {10, 20, 30, {40, 50}}) -- x is {15, 26, 37, {48, 59}}If a binary operator function is passed one sequence while the other parameter is a single number (atom) then the single number is effectively repeated to form a sequence of equal length to the sequence operand. The rules for operating on two sequences then apply. Should both parameters be atom then it behaves as an infix operator. Some examples:
x = sq_add({5, 6, 7, {8, 9}}, {10, 20, 30, 40}) -- x is {15, 26, 37, {48, 49}} x = sq_add({5, 6, 7, {8, 9}}, 10) -- x is {15, 16, 17, {18, 19}} x = {1, 2, 3} y = {4, 5, 6} w = sq_mul(5,y) -- w is {20, 25, 30} z = sq_add(x,y) -- z is {5, 7, 9} z = sq_lt(x,y) -- z is {1, 1, 1} w = {{1, 2}, {3, 4}, {5}} w = sq_mul(w,y) -- w is {{4, 8}, {15, 20}, {30}} w = sq_and({1, 0, 0, 1},{1, 1, 1, 0}) -- {1, 0, 0, 0} w = sq_not({1, 5, -2, 0, 0}) -- w is {0, 0, 0, 1, 1} w = sq_eq({1, 2, 3},{1, 2, 4}) -- w is {1, 1, 0} w = ({1, 2, 3} = {1, 2, 4}) -- w is 0 (a singular false) w = sq_add(1,2) -- w is 3 (just like 1 + 2)The functions listed below accept either sequence or atom argument(s), unlike the "sq_"-less functions and infix operators which only accept atoms (apart from the first two columns, however those infix operators/sq-less functions always yield a single boolean result). You can find their actual implementations in builtins\psqop.e, which is automatically included when needed.