Prelude

From Esolang
Jump to navigation Jump to search

Prelude is an esoteric programming language created by Nikita Ayzikovsky in 2005. It uses several "voices", or "parts", each with its own stack, executing instructions in parallel. It is Turing-complete (it is trivial to compile Brainfuck into Prelude using just two voices).

Prelude is the ASCII representation of Fugue, which is the same language but using polyphonic music as source code.

Basics

A program is a set of instructions given for several "voices", one voice per line of text. Each voice has its own stack, initially containing an infinite supply of zeroes. Instructions given on the same column (i.e., for different voices but at the same time) are executed simultaneously. All stacks are updated atomically after the simultaneous instructions complete.

The actual type of numbers of the stack is left to the implementation, however it should allow negative numbers. The reference implementation uses signed integers of unlimited size.

Instructions

Command Description
+ Pop two values, add them, and push the result.
- Pop two values, subtract the top one from the bottom one, and push the result.
# Pop a value and discard it.
( If the top value on the stack is zero, skip past the matching ).
) If the top value on the stack is nonzero, skip back past the matching (.
^ Push the top value from the stack of the voice above this one.
v Push the top value from the stack of the voice below this one.
? Input a character and push it. EOF = 0.
! Pop a value and output it as a character.
0..9 Pushes the appropriate one-digit number.

Anything else is treated as a nop.

( and ) do not have to be on the same line. It is an error to use both of them, or multiple instances of either, at the same time in different voices.

v used in the bottom voice pushes the value from the top voice; ^ used in the top voice pushes the value from the bottom voice. [citation needed]

Formatting

Instructions for the second voice are given below the first, and so on. A line of code can be broken by placing a line with just a single asterisk (*) after it.

External resources

See also