Skip to content

Stack Manipulation

Push

The Push command pushes a value onto the top of the stack.

Syntax

CommandUnobsfucated
Nospace​​ZWSP, ZWSP
Whitespace Space, Space
NossemblyPush-

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

CommandUnobsfucated
Nospace​‍​ZWSP, ZWJ, ZWSP
Whitespace Space, Newline, Space
NossemblyDuplicate-

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

CommandUnobsfucated
Nospace​‍‌ZWSP, ZWJ, ZWNJ
Whitespace Space, Newline, Tab
NossemblySwap-

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

CommandUnobsfucated
Nospace​‍‍ZWSP, ZWJ, ZWJ
Whitespace Space, Newline, Newline
NossemblyPop-

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

CommandUnobsfucated
Nospace​‌​ZWSP, ZWNJ, ZWSP
Whitespace Space, Tab, Space
NossemblyCopy-

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

CommandUnobsfucated
Nospace​‌‍ZWSP, ZWNJ, ZWJ
Whitespace Space, Tab, Newline
NossemblySlide-

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

​​​‌‍​​​‌​‍​​​‌‌‍​‌‍​‌​‍

  1. “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