
Hup, a few operators
Arithmetic operators are as you'd expect them: add with "+", subtract with "-", multiply with "*", divide with "/".
If a stack is preceded by the Shaped operator "$", its length will be modified to fit the length of the "previous" operand. If it's too long, it gets truncated. If it's too short, it wraps around. Shaping is automatic on stacks of length 1.
[ tens | 10 | 20 | 30 | 40 | 50 | 60 | 70 | 80 ]
[ units | 1 | 2 | 3 ]
[
units wrapping around
= [tens] + $[units]
| 11
| 22
| 33
| 41
| 52
| 63
| 71
| 82
]
Boolean operators are: Greater than ">", Less than "<", Greater than or equal ">=", Less than or equal "<=", Equal "==", Different "!=".
There's also And "&&", Or "||", Not "!".
They return 1 if true, and 0 if false.
[
units greater than one= [units] > 1| 0| 1| 1]
There is a Copy operator "&". It will repeat the items of a stack a certain number of times, possibly zero times.
[
units twice
= [units] & 2
| 1 | 1 | 2 | 2 | 3 | 3
]
[
handpicked tens
= [tens] & 0 0 2 0 1 0 0 0
| 30
| 30
| 50
]When copying zero times, it acts as a filter. It can be used in conjunction with Boolean operators.
[
keep tens greater than thirty= [tens] &( [tens] > 30 )| 40| 50| 60| 70| 80]
To check whether certain items can be found in a stack and count them, the Count operator "€" can be used.
[
counting= [tens] € 10 10 20 30 50 80| 2| 1| 1| 0| 1| 0| 0| 1]
Together they can make selections.
[ a | 1 | 2 | 3 | 3 ][ b | 2 | 3 | 4 | 4 ][
in 'a' only what you find in 'b'= [a] &( [a] € [b] )| 2| 3
| 3][
in 'b' only what you find in 'a'= [b] &( [b] € [a] )| 2| 3
| 3]
In case you're wondering, concatenations are merely juxtapositions.
[concatenation of 'a' and 'b'= [a] [b]
| 1 | 2 | 3 | 3 | 2 | 3 | 4 | 4]
There are Union "°" and Intersection "^" operators. As you can see, they get rid of duplicates in the process.
[union of 'a' and 'b'= [a] ° [b]| 1| 2| 3| 4][intersection of 'a' and 'b'= [a] ^ [b]| 2| 3]
The From operator "?" references items in a stack.
[
indices 2 and 3 from tens= 2 3 ? [tens]| 30| 40]
The other way around, the Find operator "@" finds (the first occurrence of) items in a stack.
[
in tens find thirty and forty= [tens] @ 30 40| 2| 3]
Then you can do combinations.
[ A | 100 | 200 | 300 | 400 ][ B | 500 | 600 | 700 | 800 ][
what's to B what 200 and 300 are to A= [A] @ 200 300 ? [B]| 600| 700]
There's no need for a "ternary if" operator. In fact ? can act as a switch, because Boolean operators return 0 or 1.
[
a thousand when true= [tens] > 30 ? 500 1000| 500| 500| 500
| 1000| 1000| 1000| 1000| 1000]
The Reduce "\" operator can be used to transform a stack into a single value by applying another operator repeatedly to each of its values.
[sum of units= [units] \+| 6]
Finally, a formula can begin with an update delay, expressed in milliseconds, followed either by a comma "," (delay after first change) or a semi-colon ";" (delay after last change). These two are not really operators, rather interpreter directives.
[
jumpy= 50, [units] * 2| 2| 4| 6][
patient= 2000; [units] * 2| 2| 4| 6]
The jumpy table will plan an update 50ms after a change, unless an update is already planned. The patient table will plan an update 2 seconds after a change, cancelling any previously planned update.
When time has come to apply an update, if updating wouldn't change the values of a table, the update is cancelled. So for instance, the jumpy table will only get updated if units becomes different AND if it's still different 50ms later. If, in the meantime, units gets back to its initial values, jumpy won't update.
The default is, immediate update.