DDuuaall
DDuuaall is a language invented by User:A, inspired by Vyxal's zipmap.
Special Arity Rules
The so-called complement is usually number negation for numbers, or reversing for strings/lists.
Nilads
You push a nilad along with its complement, the complement is pushed after the original nilad.
Monads
You apply the defined operation, along with a "complement-operation". The result of the complement operation is pushed after the intended operation.
Dyads
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 list
Instruction | Main behavior | Complement behavior |
---|---|---|
\ (Triad) |
Triple swap: a b c -> c a b | - |
= (Dyad) |
Vectorizing equality | - |
+ (Dyad) |
Vectorizing addition/string concatenation | - |
- (Dyad) |
Vectorizing subtraction | - |
* (Dyad) |
Vectorizing Multiplication/string repeat | - |
/ (Dyad) |
Vectorizing division | - |
$ (Dyad) |
Swap two items on the stack | - |
% (Dyad) |
Vectorizing modulus | - |
~ (Dyad) |
Remove items | - |
L (Dyad) |
Return the top operand, pop the second-to-top operand | - |
R (Monad) |
1-range, reverse for lists | Reverse 1-range, identity for lists |
~ (Monad) |
Remove the last item of the list | Remove the first item of the list |
_ (Monad) |
Pop the stack | Duplicate the stack |
O (Monad) |
Pops + Outputs TOS, disables implicit output. (exception to the monad rule) | - |
"xyz" (Nilad) |
Push "xyz" | Push "xyz" reversed |
0-9 (Nilad) |
Push the number formed by the construction | Push the negative of the number formed by the construction |
I (Nilad) |
Push the input (exception to the nilad rule) | - |
I/O Specifications
There's implicit input, but you can also take explicit input via I
.
The whole stack's content is joined and outputted at the end of the program.
Example programs
Is it odd or even?
R=+
Explanation
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!
"Hello, World!"0+*+
Explanation
"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.
Primalty Tester
RL~UI$L$%0+=+0
Explanation
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