Special Arity Rules
The so-called complement is usually number negation for numbers, or reversing for strings/lists.
You push a nilad along with its complement, the complement is pushed after the original nilad.
You apply the defined operation, along with a "complement-operation". The result of the complement operation is pushed after the intended operation.
With two list operands, it vectorizes, if possible (unless the instruction defines otherwise). When the TOS is a list operand, it reduces the dyad by the list.
With a list operand on the bottom and a number operand on the top, the instruction implements its own method of evaluation.
|Instruction||Main behavior||Complement behavior|
||Triple swap: a b c -> c a b||-|
||Vectorizing addition/string concatenation||-|
||Vectorizing Multiplication/string repeat||-|
||Swap two items on the stack||-|
||Return the top operand, pop the second-to-top operand||-|
||1-range, reverse for lists||Reverse 1-range, identity for lists|
||Remove the last item of the list||Remove the first item of the list|
||Pop the stack||Duplicate the stack|
||Pops + Outputs TOS, disables implicit output. (exception to the monad rule)||-|
||Push "xyz"||Push "xyz" reversed|
||Push the number formed by the construction||Push the negative of the number formed by the construction|
||Push the input (exception to the nilad rule)||-|
There's implicit input, but you can also take explicit input via
The whole stack's content is joined and outputted at the end of the program.
Is it odd or even?
Assume the input = 3 right now. R 1-range. Push [1, 2, 3] (original function) and [3, 2, 1] (complement function) = Vectorizing equality. Push [0, 1, 0] + Sum the list. Push 1 (If the stack only has one list item, DDuuaall reduces over the list by the dyadic operation)
"Hello, World!" String literal. Push "Hello, World!" (original) and "!dlroW, olleH" (complement) 0 Number literal. Push 0 and -0 (aka push 2 0's) + Add the two copies of 0. * Repeat the complement string by 0. + Join the empty string by the original string.
Assume input = 4 here. R Range. [1, 2, 3, 4] and [4, 3, 2, 1] L Left. [1, 2, 3, 4] ~ Pop. [1, 2, 3] and [2, 3, 4] U Intersect. [2, 3] I Input. [2, 3], 4, -4 $ Swap. [2, 3], -4, 4 L Left. [2, 3], 4 $ Swap. 4, [2, 3] % Mod. [1, 0] 0 Zero. [1, 0], 0, 0 + Add. [1, 0], 0 = Equals?[0, 1] + Sum 1 0 Output. OUT:1