Thursday, January 20, 2011

Esoteric is as Esoteric does

There is a whole realm of esoteric programming languages, languages which really serve no purpose other than existing. One example is lolcode, the programming language of lolcats. A quick example program in lolcode looks like:

HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE

This code is nothing more than hello world, "HAI" and "KTHXBYE" represent the open and close blocks, CAN HAS is the equivalent of an import or include statement, with STDIO being the namespace for standard input and output. Finally VISIBLE is the command to print out to the screen, followed by the string literal "HAI WORLD!", which is what would be printed out to the screen.

Of course, lolcode is not the only esoteric programming language out there. Another esoteric language is the aptly named Brainfuck. Learning this language will fry your mind worse than any night binging on whiskey and vodka. Once again we are going to start out with the simplest program, hello world.

++++++++++
[>+++++++>++++++++++>+++>+<<<<-]
>++.>+.+++++++..+++.>++.
<<+++++++++++++++.
>.+++.------.--------.>+.>.

Right now you are probably saying "What the fu...", but what you should be saying is "What the brainfu..." Brainfuck uses only 8 symbols and runs using a set of counters. In this example there are 5 elements in an array, '<' and '>' iterate through the array, '+' and '-' increment and decrement the values respectively, '[' and ']' denotes a loop and '.' prints to the screen. So to start with the array[1] is set to 10, this is the constraints for the loop. The loop then iterates 10 times (notice the - at the end of the loop when the pointer has returned to the first element) Since this happens 10 times array[2] becomes 70, array[3] becomes 100, array[4] becomes 30 and array[5] becomes 10.

With these values the letters can start to be printed. Array[2] becomes 72 and is printed out, 72 being the ascii value for 'H'. Next 101 is printed ('e'), 108 ('l') is printed twice, and so on, using < > + and - to change the ascii values that are printed.

These are far from being the only esoteric languages out there, but they manage to show a good glimpse at what you can expect from extremely bored programmers.

No comments:

Post a Comment