Crazy Programming Languages Challenge - Part 3 - Whitespace

For your enjoyment and my own, I am trying out some crazy programming languages:

  1. Brainfuck
  2. LOLCODE
  3. Whitespace <- You are here
  4. Piet
  5. MalbolgeZombie

This week, I am trying out Whitespace.

Overview

Whitespace is a language designed as it says on the tin. The only characters that it contains are whitespaces: Space, Tab and Line Feed.

This means an entire program just looks like a blank document if you do not highlight it. It is also incredibly harder to program in as you quite literally can't see what you are doing.

It works using a stack and heap model. The commands involving putting things on top of the stack and interacting with those elements.

For example, SPACE-SPACE-NUMBER will put a number on the top of a stack. A number is represented as a binary string where SPACE is 0 and a TAB is 1.

Similar to Brainfuck, characters are represented in their ASCII number equivalent.

This [website](http://progopedia.com/language/whitespace/
) has a full list of commands available. I am not going to list them all out here.

Installing and Running

It was actually very tricky to find the official resources for this program as a lot of links are now dead. Luckily, the Wayback Machine saved copies of the relevant web pages and I was able to obtain what I needed.

Here is a link to the website stored on the web archive.

The compiler that I chose is on [Github here](https://github.com/hostilefork/whitespacers/tree/master/c
). I chose this one because it was the most straightforward to set up. I was unable to get any of the official ones to work.

Once you download the C file, you will need to run:

  gcc whitespace.c -o wspace

Then you can simply run:

 ./wspace /path/to/file.ws

Notice that I use the .ws extension to my whitespace file.

I recommend using Sublime to write this code as it is able to show tabs and spaces a little clearer. Just highlight the whole text and you will see the spaces are represented by . and the tabs represented by -:

You can type normal text to annotate the code to make it easier to read, the compiler will simply ignore anything that is not whitespace.

Building "Hello, World!"

Last week, LOLCODE was reasonably straightforward, so I was able to build something a little more complex than "Hello, World!". I tried to do this again, but I could not get input from the terminal to work correctly, so we are back to "Hello, World!".

It is a little easier than in Brainfuck as all you have to do is add the number to the top of the stack and then run the command for printing the top item.

So the first letter H, is ASCII number 72. To put it in the stack, it needs to be converted to binary first. 72 is: 01001000. The command is two spaces followed by a number where space is 0 and 1 is tab. Then it ends with a line feed. This would look like this:

  {            }
;      

I have put in the curly braces as nothing would show otherwise! I think it is safe to say that would easier if I represent everything with words:

[SPACE][SPACE][SPACE][TAB][SPACE][SPACE][TAB][SPACE][SPACE][SPACE][LF]

To print the top of the stack, the code is:

[TAB][LF]
[SPACE][SPACE]

It is incredibly tempting to add a new line each time you want to begin a new operation but it is important not to.

Storing the next letter, e, would begin straight after the previous [SPACE].

So, if we continue this pattern of storing a letter to the top of the stack and then printing it, our code looks a little like this:

[SPACE][SPACE][SPACE][TAB][SPACE][SPACE][TAB][SPACE][SPACE][SPACE][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][TAB][SPACE][SPACE][TAB][SPACE][TAB][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][TAB][SPACE][TAB][TAB][SPACE][SPACE][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][TAB][SPACE][TAB][TAB][SPACE][SPACE][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][TAB][SPACE][TAB][TAB][TAB][TAB][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][SPACE][TAB][TAB][SPACE][SPACE][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][SPACE][SPACE][SPACE][SPACE][SPACE][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][SPACE][TAB][SPACE][TAB][TAB][TAB][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][TAB][SPACE][TAB][TAB][TAB][TAB][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][TAB][TAB][SPACE][SPACE][TAB][SPACE][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][TAB][SPACE][TAB][TAB][SPACE][SPACE][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][TAB][SPACE][SPACE][TAB][SPACE][SPACE][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][SPACE][SPACE][SPACE][SPACE][TAB][LF]
[TAB][LF]
[SPACE][SPACE][SPACE][SPACE][SPACE][TAB][SPACE][TAB][SPACE][LF][TAB][LF]
[SPACE][SPACE][LF]

Try it out yourself by pasting it into a text editor and finding and replacing all of the characters (Note, however, I added newlines next to [LF] to visualise here correctly, so you would have to replace [LF]\n). When I run it, I successfully get the message:

Summary

A very tricky language to code in mostly because you can't see what you are doing. Other than the visual difficulties, it is not actually that hard to understand and there is plenty of built in operations that would allow for fairly complex programs to be built.

The other difficulty was also finding the resources to actually run the programs and learn the language. Once again, the resources that I used were:

Next week, the challenge continues with Piet.


© 2012-2017