Whitespace (programming language)



Whitespace is an esoteric programming language with syntax where only whitespace characters (space, tab and linefeed) have meaning contrasting typical languages that largely ignore whitespace characters.

As a consequence of its syntax, Whitespace source code can be contained within the whitespace of code written in a language that ignores whitespace making the text a polyglot.

Whitespace is an imperative, stack-based language. The programmer can push arbitrary-width integer values onto a stack and access a heap to store data.

An interpreter, along with its Haskell source code, is provided by the Whitespace creators.

History
Edwin Brady and Chris Morris, who also developed the Kaya and Idris languages, created Whitespace in 2002 at the University of Durham. Slashdot published a review on April Fool's Day 2003.

The idea of using whitespace characters as operators for the C++ language had been facetiously suggested five years earlier by Bjarne Stroustrup.

Syntax
Whitespace defines a command as a sequences of whitespace characters. For example,  performs arithmetic addition of the top two elements on the stack.

A command is written as an instruction modification parameter (IMP) followed by an operation and then any parameters.

IMP sequences include:

Operator sequences, organized by IMP, include:

The copy and slide operations were added in Whitespace 0.3.

Comments
Characters other than,   and   are ignored and thus can be used for comments.

Numbers
A numeric value is represented as a sequence of  and   characters that represent 0 and 1 respectively and terminated by a. The first character represents the sign of the value   for positive and   for negative. Subsequent characters before the terminator represent the binary digits of a value.

For example:


 * [space][tab][space][space][tab][space][tab][tab][linefeed] (STSSTSTTL) is positive since starts with  and represents 1001011 binary which is 75 decimal
 * [tab][tab][tab][space][space][tab][space][linefeed] (TTTSSTSL) is negative since starts with  and represents -110010 binary which is −50 decimal

Labels
A label is used for control flow. It is a -terminated sequence of  and   characters. As there is only one namespace, all labels must be unique.

Sample code
The following source code is for a Whitespace "Hello, world!" program. For clarity, it is annotated with,   and   before each ,, and.

S &#32; S &#32; S &#32; T &#9; S &#32; S &#32; T &#9; S &#32; S &#32; S &#32; L:Push_+1001000=72='H'_onto_the_stack&#10;T &#9; L&#10;S &#32; S &#32; :Output_'H';_S &#32; S &#32; S &#32; T &#9; T &#9; S &#32; S &#32; T &#9; S &#32; T &#9; L:Push_+1100101=101='e'_onto_the_stack&#10;T &#9; L&#10;S &#32; S &#32; :Output_'e';_S &#32; S &#32; S &#32; T &#9; T &#9; S &#32; T &#9; T &#9; S &#32; S &#32; L:+1101100=108='l'&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; T &#9; S &#32; T &#9; T &#9; S &#32; S &#32; L:+1101100=108='l'&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; T &#9; S &#32; T &#9; T &#9; T &#9; T &#9; L:+1101111=111='o'&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; S &#32; T &#9; T &#9; S &#32; S &#32; L:+101100=44=','&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; S &#32; S &#32; S &#32; S &#32; S &#32; L:+100000=32=Space&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; T &#9; T &#9; S &#32; T &#9; T &#9; T &#9; L:+1110111=119='w'&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; T &#9; S &#32; T &#9; T &#9; T &#9; T &#9; L:+1101111=111='o'&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; T &#9; T &#9; S &#32; S &#32; T &#9; S &#32; L:+1110010=114='r'&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; T &#9; S &#32; T &#9; T &#9; S &#32; S &#32; L:+1101100=108='l'&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; T &#9; S &#32; S &#32; T &#9; S &#32; S &#32; L=+1100100=100='d'&#10;T &#9; L&#10;S &#32; S &#32; S &#32; S &#32; S &#32; T &#9; S &#32; S &#32; S &#32; S &#32; T &#9; L:+100001=33='!'&#10;T &#9; L&#10;S &#32; S &#32; :Output_'!';_L&#10;L&#10;L:End_the_program&#10;

When Whitespace source code is displayed in some browsers, the horizontal spacing produced by a tab character is not fixed, but depends on its location in the text relative to the next horizontal tab stop. Depending on the software, tab characters may also get replaced by the corresponding variable number of space characters.