Stack Operations ---------------- **Pushing Instructions** ~~~~~~~~~~~~~~~~~~~~~~~~ Instructions can be pushed onto the stack by enclosing them in square brackets []. These instructions can then be executed using the `apply` operation. Example: .. code-block:: text [1] [2 3 +] [[7.0293 6.8933]] [[2 3 4 5] 3 4 *] **drop** ~~~~~~~~ The `drop` operation removes the first value from the stack. Example: .. code-block:: text 5 3 drop => 5 **dup** ~~~~~~~ The `dup` operation (usage: dup or dup0, dup1, dup2, ...) duplicates a value on the stack and pushes the duplicate onto the stack. Example: .. code-block:: text 4 dup => 4 4 5 3 2 4 dup3 => 5 3 2 4 5 Alternatively you can duplicate 2 values with the instruction dup(instruction) where the command `instruction` is executed, then it pops from the stack the index of the value to duplicate .. code-block:: text 7 8 dup(5 1) => 7 8 5 dup(1) => 7 8 5 5 23 2 5 3 1 dup(size 1 -) => 23 2 5 3 1 23 **swap** ~~~~~~~~ The `swap` operation (usage same as dup: swap0 do nothing, swap or swap1, swap2, swap3 ...) swaps the positions of the first value on the stack with another specified (default 1). Example: .. code-block:: text 5 3 swap => 3 5 7 2 4 3 22 swap4 => 22 2 4 3 7 Alternatively you can swap 2 values with the instruction swap(instruction) where the command `instruction` is executed, then it pops from the stack the index to swap with .. code-block:: text 5 3 swap(1 2) => 5 3 1 swap(2) => 1 3 5 7 2 4 3 22 swap(size 1 -) => 22 2 4 3 7 **top** ~~~~~~~~~~ The `top` operation duplicates the top (the first value pushed in the stack) value on the stack and pushes it onto the stack without removing the original (the same of duptop). Example: .. code-block:: text 4 5 7 3 2 1 top => 4 5 7 3 2 1 4 **compose** ~~~~~~~~~~~ The `compose` operation composes a new instruction by popping the first two instructions on the stack and concatenating them, then it pushes the result onto the stack. Example: .. code-block:: text [swap] [apply] compose => [swap apply] **apply** ~~~~~~~~~ The `apply` operation pops a quoted instruction from the stack and execute it. (It executes the instructions pushed onto the stack using square brackets) Example: .. code-block:: text [3 4 *] apply => 12 **quote** ~~~~~~~~~ The `quote` operation quotes the first value on the stack. .. code-block:: text 2 7 4 5 1 3 quote => 2 7 4 5 1 [3] [swap /] quote => [[swap /]] **clear** ~~~~~~~~~ The `clear` operation clears the entire stack. **Special Values** ~~~~~~~~~~~~~~~~~~ - `last`: A boolean value indicating whether the current value is the last pushed onto the stack. - `empty`: A boolean value indicating whether the stack is empty. - `size`: The current size of the stack. When executed, it pushes the size onto the stack.