Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Whitespace (programming language)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Esoteric programming language}} {{Use dmy dates|date=April 2021}} {{For|syntactically significant whitespace in non-esoteric programming languages|Off-side rule}} [[File:Whitespace in vim2.png|right|206px|thumb|Whitespace [[hello world program]] with syntax highlighting {{legend|#0000ab|tabs}} {{legend|#ab0000|spaces}}]] <!-- make SVG file --> '''Whitespace''' is an [[esoteric programming language|esoteric]] [[programming language]] with [[syntax]] where ''only'' [[whitespace characters]] ([[Space character|space]], [[Tab character|tab]] and [[linefeed]]) have meaning {{endash}} contrasting typical languages that largely ignore whitespace characters. <ref name="whitespace">{{cite web|url=http://compsoc.dur.ac.uk/whitespace/tutorial.php|title=Whitespace|website=Compsoc|access-date=2015-12-08|url-status=dead|archive-url=https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php|archive-date=18 June 2015}}</ref><ref name=parker>{{cite book|title=Humble Pi: a comedy of maths errors|publisher=Allen Lane|date=2019|first=Matt|last=Parker|author-link=Matt Parker|ISBN=978-0-241-36023-1|page=21}}</ref> As a consequence of its syntax, Whitespace [[source code]] can be contained within the whitespace of code written in a language that ignores whitespace {{endash}} making the text a [[polyglot (computing)|polyglot]].<ref name=parker /> Whitespace is an [[imperative programming|imperative]], [[stack-oriented programming|stack-based]] language. The programmer can push arbitrary-width [[integer]] values onto a [[Stack (abstract data type)|stack]] and access a [[dynamic memory allocation|heap]] to store data. An [[Interpreter (computing)|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 (programming language)|Idris]] languages, created Whitespace in 2002 at the [[University of Durham]]. [[Slashdot]] published a review on [[April Fool's Day]] 2003.<ref>{{Cite web |url=http://developers.slashdot.org/story/03/04/01/0332202/New-Whitespace-Only-Programming-Language |title=New Whitespace-Only Programming Language |date=2003-04-01 |website=Slashdot |author=Timothy |access-date=2014-01-23}}</ref> The idea of using whitespace characters as operators for the [[C++]] language had been facetiously suggested five years earlier by [[Bjarne Stroustrup]].<ref>{{cite web |url=http://www.stroustrup.com/whitespace98.pdf |title=Generalizing Overloading for C++2000 |first=Bjarne |last=Stroustrup |publisher=AT&T Labs |location=Florham Park, NJ, USA |access-date=2014-01-23}}</ref> == Syntax == Whitespace defines a command as a sequences of whitespace characters. For example, <code>[Tab][Space][Space][Space]</code> 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. <ref name="whitespace" /> IMP sequences include: {| class="wikitable" |- ! IMP !! Meaning |- | [Space] || Stack Manipulation |- | [Tab][Space] || Arithmetic |- | [Tab][Tab] || Heap Access |- | [LineFeed] || Flow Control |- | [Tab][LineFeed] || I/O |} Operator sequences, organized by IMP, include:<ref name="whitespace"/> {| class="wikitable" |- ! IMP !! Operator !! Parameter !! Meaning !Minimum size of the stack required* |- | [Space] || [Space] || Number || Push the number onto the stack |0 |- | [Space] || [LF][Space] || - || Duplicate the top item on the stack |1 |- | [Space] || [Tab][Space] || Number ''n''|| Copy the nth item on the stack (given by the argument) onto the top of the stack** |''n''+1 |- | [Space] || [LF][Tab] || - || Swap the top two items on the stack |2 |- | [Space] || [LF][LF] || - || Discard the top item on the stack |1 |- | [Space] || [Tab][LF] || Number ''n''|| Slide n items off the stack, keeping the top item** |may be less than '''''n''+1''', but at least 1 item (top of the stack) is required |- | [Tab][Space] || [Space][Space] || - || Addition |2 |- | [Tab][Space] || [Space][Tab] || - || Subtraction |2 |- | [Tab][Space] || [Space][LF] || - || Multiplication |2 |- | [Tab][Space] || [Tab][Space] || - || Integer division |2 (top may not be 0) |- | [Tab][Space] || [Tab][Tab] || - ||[[Modulo operation|Modulo]] |2 (top may not be 0) |- | [Tab][Tab] || [Space] || - || Store in heap |2 |- | [Tab][Tab] || [Tab] || - || Retrieve from heap |1 |- | [LF] || [Space][Space] || Label || Mark a location in the program |0 |- | [LF] || [Space][Tab] || Label || Call a subroutine |0 |- | [LF] || [Space][LF] || Label || Jump to a label |0 |- | [LF] || [Tab][Space] || Label || Jump to a label if the top of the stack is zero |1 |- | [LF] || [Tab][Tab] || Label || Jump to a label if the top of the stack is negative |1 |- | [LF] || [Tab][LF] || - || End a subroutine and transfer control back to the caller |0 ''(callstack: 1)'' |- | [LF] || [LF][LF] || - || End the program |0 |- | [Tab][LF] || [Space][Space] || - || Output the character at the top of the stack |1 |- | [Tab][LF] || [Space][Tab] || - || Output the number at the top of the stack |1 |- | [Tab][LF] || [Tab][Space] || - || Read a character and place it in the location given by the top of the stack |1 |- | [Tab][LF] || [Tab][Tab] || - || Read a number and place it in the location given by the top of the stack |1 |} <nowiki>*</nowiki>Due to Haskell being lazily evaluated, the effect of the stack being too small may only show when, for example, invoking the ''outputting a number'' side-effect. <nowiki>**</nowiki>The ''copy'' and ''slide'' operations were added in Whitespace 0.3.<ref name="whitespace" /> === Comments === Characters other than <code>space</code>, <code>tab</code> and <code>linefeed</code> are ignored and thus can be used for comments. === Numbers === A numeric value is represented as a sequence of <code>space</code> and <code>tab</code> characters that represent 0 and 1 respectively and terminated by a <code>linefeed</code>. The first character represents the [[Sign (mathematics)|sign]] of the value {{endash}} <code>space</code> for positive and <code>tab</code> 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 it starts with <code>space</code> and represents 1001011 in binary, which is 75 in decimal. * [tab][tab][tab][space][space][tab][space][linefeed] (TTTSSTSL) is negative since it starts with <code>tab</code> and represents -110010 in binary which is β50 in decimal. === Labels === A label is used for [[control flow]]. It is a <code>linefeed</code>-terminated sequence of <code>space</code>and <code>tab</code> characters. As there is only one namespace, all labels must be unique. <ref name="whitespace"/> ==Sample code== <!--NOTE: Please be careful when copying/editing the code below. Some user agents may automatically insert linefeed characters for text wrapping, which will cause the code to run incorrectly.--> The following source code is for a Whitespace [[Hello world program|"Hello, world!"]] program. For clarity, it is annotated with <code>S</code>, <code>T</code> and <code>L</code> before each <code><span style="color:#ffffff;background:#ff9999">space</span></code>, <code><span style="color:#ffffff;background:#9999ff">tab</span></code>, and <code>linefeed</code>. S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>L:Push_+1001000=72='H'_onto_the_stack T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>:Output_'H';_S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>L:Push_+1100101=101='e'_onto_the_stack T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>:Output_'e';_S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>L:+1101100=108='l' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>L:+1101100=108='l' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>L:+1101111=111='o' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>L:+101100=44=',' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>L:+100000=32=Space T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>L:+1110111=119='w' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>L:+1101111=111='o' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>L:+1110010=114='r' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>L:+1101100=108='l' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>L=+1100100=100='d' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>T<span style="background:#9999ff">	</span>L:+100001=33='!' T<span style="background:#9999ff">	</span>L S<span style="background:#ff9999"> </span>S<span style="background:#ff9999"> </span>:Output_'!';_L L L:End_the_program 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 [[Tab key#HTML|horizontal tab stop]]. Depending on the software, tab characters may also get replaced by the corresponding variable number of space characters. ==References== <references/> ==External links== *{{Official website|https://www.espacoinvisivel.net/}} *[http://developers.slashdot.org/article.pl?sid=03/04/01/0332202 Release announcement on Slashdot] *[https://github.com/wspace/corpus The Whitespace Corpus] A collection of interpreters, compilers, and programs for Whitespace *[https://github.com/hostilefork/whitespacers/ Collection of Whitespace interpreters in various script languages] *[http://metacpan.org/module/Acme::Bleach Acme::Bleach] A [[Perl]] module that rewrites the body of your module to a whitespace-only encoding ("for ''really'' clean programs"). [[Category:Non-English-based programming languages]] [[Category:Esoteric programming languages]] [[Category:Whitespace]] [[Category:Programming languages created in 2002]] [[Category:Stack-oriented programming languages]] {{Esoteric programming languages}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite book
(
edit
)
Template:Cite web
(
edit
)
Template:Endash
(
edit
)
Template:Esoteric programming languages
(
edit
)
Template:For
(
edit
)
Template:Legend
(
edit
)
Template:Official website
(
edit
)
Template:Short description
(
edit
)
Template:Use dmy dates
(
edit
)