Stack Manipulation
Push
The Push command pushes a value onto the top of the stack.
Syntax
| Command | Unobsfucated | |
|---|---|---|
| Nospace | | ZWSP, ZWSP |
| Whitespace |
| Space, Space |
| Nossembly | Push | - |
Parameters
Int- the value to push to the stack
Stack parameters
The Push command takes no stack parameters.
Example
Duplicate
The Duplicate command duplicates the item at the top of the stack.
Syntax
| Command | Unobsfucated | |
|---|---|---|
| Nospace | | ZWSP, ZWJ, ZWSP |
| Whitespace |
| Space, Newline, Space |
| Nossembly | Duplicate | - |
Parameters
The Duplicate command takes no parameters.
Stack parameters
The Duplicate command takes no stack parameters.
Example
Swap
The Swap command swaps the item at the top of the stack with the item second from the top.
Syntax
| Command | Unobsfucated | |
|---|---|---|
| Nospace | | ZWSP, ZWJ, ZWNJ |
| Whitespace |
| Space, Newline, Tab |
| Nossembly | Swap | - |
Parameters
The Swap command takes no parameters.
Stack parameters
The Swap command takes no stack parameters.
Example
Pop
The Pop command discards the item at the top of the stack.
Syntax
| Command | Unobsfucated | |
|---|---|---|
| Nospace | | ZWSP, ZWJ, ZWJ |
| Whitespace |
| Space, Newline, Newline |
| Nossembly | Pop | - |
Parameters
The Pop command takes no parameters.
Stack parameters
The Pop command takes no stack parameters.
Example
If there are no items on the stack, Nospace may produce a compile-time error:
TypeError: Cannot perform pop as this would result in a stack underflow.
Copy
The Copy command copies the Nth item on the stack onto the top of the stack. It was added in Whitespace v0.31.
Syntax
| Command | Unobsfucated | |
|---|---|---|
| Nospace | | ZWSP, ZWNJ, ZWSP |
| Whitespace |
| Space, Tab, Space |
| Nossembly | Copy | - |
Parameters
Int- the index from the top of the stack to copy the item from.
Stack parameters
The Copy command consumes no stack parameters, however will copy the Nth item as per the parameter provided.
Example
Slide
The Slide command keeps the top item of the stack, but removes N items beneth it. It was added in Whitespace v0.31.
Syntax
| Command | Unobsfucated | |
|---|---|---|
| Nospace | | ZWSP, ZWNJ, ZWJ |
| Whitespace |
| Space, Tab, Newline |
| Nossembly | Slide | - |
Parameters
Int- the number of items to discard off the stack.
Stack parameters
The Slide command will remove N items beneth the top item on the stack, however it’s behavior will not change based upon the values removed.
Example
- “The copy and slide instructions are an extension implemented in Whitespace 0.3 and are designed to facilitate the implementation of recursive functions. The idea is that local variables are referred to using [Space][Tab][Space], then on return, you can push the return value onto the top of the stack and use [Space][Tab][LF] to discard the local variables.” - Durham University Computing Society: Whitespace Tutorial