Plugh

From Esolang
Jump to navigation Jump to search

Plugh is a stack based language which is missing one of the key features of stack based languages: a push operation. Working around this is somewhat annoying to do.

Syntax

The language has 10 commands. The first eight are represented by octal digits and the last two are "xyzzy" and "plugh". The digits can be concatenated without any whitespace, but the words must have spaces on each end. All sequences of these are valid Plugh programs.

Operation

A program starts at the top of an infinite stack initialized with the natural numbers (that is to say, the top value on the stack is 0, followed by 1, then 2, et cetera.)

Each command is then executed in sequence. The actions performed by each command follow.

The 0 command duplicates the top value on the stack.

The 1 command deletes the top stack value, removing it forever.

The 2 and 3 commands do something different. They move the top of the "active" stack. When this has been moved below some elements, those elements effectively don't exist until it's moved back up. For example, imagine the stack S 1 2 3 4, where S is the stack pointer. When 2 is run, it looks like: 1 S 2 3 4. If 1 is then run, it looks like this: 1 S 2 2 3 4. If 3 is then run, it looks like this: S 1 2 2 3 4. Note: these commands always move up or down by the top value on the stack, stopping when they reach the top.

The 4 command copies an element from the top of the "active" stack to the top of the actual stack (which can also be changed; see commands 6 and 7.) For example, the stack looks like 1 S 2 3 4. If 4 is run, it looks like 2 1 S 2 3 4.

5 does the opposite, copying from the top of the actual stack to the active stack.