dhanushka madushan

@madushandhanushka

Weird Programming Languages That You May Have Not Heard

Weird Programming Languages

More than a thousand programming languages have been invented and only about one hundred of them are commonly used. Among these, there are some weird ones, so labeled because of their syntax and the way it represents its code. In this article, we will look into some of these languages and syntax.

Legit

Have you ever landed on a Github project that prints “hello world” program, but without any visible code or any content. Check this link https://github.com/blinry/legit-hello and you will see nothing in this repository. But trust me, there is hidden code in this project.

If you see the commit section, you can reveal the magic. It’s storing the “hello world” code inside git commit history. If you clone this project and run the following command, then you can see the hidden code in this project.

git log --graph --oneline

Here are the supported instructions.

  • “[<tag>]”: jump to the specified Git tag. For example, [loop] will jump to the tag loop.
  • “quit”: stop the program.
  • “get”: read a char from standard input and place its ASCII value on the stack. On EOF, push a 0.
  • “put:’ pop top stack value and write it to standard output as a char. The value is always truncated to an unsigned byte.
  • “<Number>”: push the specified integer on the stack. For example, 42 will push the value 42.
  • “<Letters>”: unescape string, then push the individual ASCII characters on the stack. For example, “Hi\n” will push the numbers 72, 105, and 10.
  • “dup”: duplicate top stack value
  • “pop”: pop top stack value and discard it
  • “add”: pop two topmost stack values, add them, push result on the stack
  • “sub”: pop two topmost stack values, subtract top one from bottom one, push result on the stack
  • “cmp”: pop two topmost stack values, pushes 1 if bottommost one is larger, 0 otherwise
  • “read”: place value of current tape cell on the stack
  • “write”: pop top stack value and write it to the current tape cell
  • “left”: pop top stack value, move tape head left for that many places
  • “right”: pop top stack value, move tape head right for that many places

Legit programming language source code hosted in Github and you can try out yourself. Read out more about Legit.

Folder

Here’s another one which does not maintain any code inside its repository. This language keeps its code as folders. Instructions are read according to the order of the folders. Inside these folders, there are three folders to represent Type, Command, and Expression. The number of folders in inside these folders represent relevant mapping with type, command or expression.

Read full description of this language in here

Befunge

This is another interesting programming language which represents its code in two-dimensional space. Take a look following code of infinite loop.

>v
^<

Did you get that? Execution starts with the first line “>” character. It means to execute the next instruction on the right side, and the right side instruction is “v”. This means to execute down instruction. This continues as an infinite loop. Here I added some of its instructions.

  • “+” Addition: Pop two values a and b, then push the result of a+b
  • “-” Subtraction: Pop two values a and b, then push the result of b-a
  • “*” Multiplication: Pop two values a and b, then push the result of ab
  • “/” Integer division: Pop two values a and b, then push the result of b/a, rounded down. According to the specifications, if a is zero, ask the user what result they want.
  • “%” Modulo: Pop two values a and b, then push the remainder of the integer division of b/a.
  • “!” Logical NOT: Pop a value. If the value is zero, push 1; otherwise, push zero.
  • “`” Greater than: Pop two values a and b, then push 1 if b>a, otherwise zero.
  • “>” PC direction right
  • “<” PC direction left
  • “^” PC direction up
  • “v” PC direction down
  • “?” Random PC direction
  • “_” Horizontal IF: pop a value; set direction to the right if value=0, set to left otherwise

Read complete language specifications here. 3D represented languages also built called “Suzy” based on this language. Here below an example of finding factorial with Befunge language

&>:1-:v v *_$.@ 
 ^    _$>\:^

Brainfuck

This language was invented in 1993, as an attempt to create the smallest possible compiler. This compiler allows only eight commands to write a program and operate based on memory cell which is also known as tapes. Here is the list of command Brainfuck supports.

  • “>” Move the pointer to the right
  • “<” Move the pointer to the left
  • “+” Increment the memory cell under the pointer
  • “-” Decrement the memory cell under the pointer
  • “.” Output the character signified by the cell at the pointer
  • “,” Input a character and store it in the cell at the pointer
  • “[“ Jump past the matching ] if the cell under the pointer is 0
  • “]” Jump back to the matching [ if the cell under the pointer is nonzero

Here below how hello world application implemented in Brainfuck language.

1 +++++ +++               Set Cell #0 to 8
 2 [
 3     >++++               Add 4 to Cell #1; this will always set Cell #1 to 4
 4     [                   as the cell will be cleared by the loop
 5         >++             Add 4*2 to Cell #2
 6         >+++            Add 4*3 to Cell #3
 7         >+++            Add 4*3 to Cell #4
 8         >+              Add 4 to Cell #5
 9         <<<<-           Decrement the loop counter in Cell #1
10     ]                   Loop till Cell #1 is zero
11     >+                  Add 1 to Cell #2
12     >+                  Add 1 to Cell #3
13     >-                  Subtract 1 from Cell #4
14     >>+                 Add 1 to Cell #6
15     [<]                 Move back to the first zero cell you find; this will
16                         be Cell #1 which was cleared by the previous loop
17     <-                  Decrement the loop Counter in Cell #0
18 ]                       Loop till Cell #0 is zero
19 
20 The result of this is:
21 Cell No :   0   1   2   3   4   5   6
22 Contents:   0   0  72 104  88  32   8
23 Pointer :   ^
24 
25 >>.                     Cell #2 has value 72 which is 'H'
26 >---.                   Subtract 3 from Cell #3 to get 101 which is 'e'
27 +++++ ++..+++.          Likewise for 'llo' from Cell #3
28 >>.                     Cell #5 is 32 for the space
29 <-.                     Subtract 1 from Cell #4 for 87 to give a 'W'
30 <.                      Cell #3 was set to 'o' from the end of 'Hello'
31 +++.----- -.----- ---.  Cell #3 for 'rl' and 'd'
32 >>+.                    Add 1 to Cell #5 gives us an exclamation point
33 >++.                    And finally a newline from Cell #6

This can be represented in one line as follows.

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

Piet

As you see it, it is a programming language where the programmer needs to color a grid instead of coding words. Pointer used to move around the bitmap image and execute command relevant to each color code. There are twenty colors used to represent command and white color does not represent any operation. when the pointer tries to enter a black region, the rules of choosing the next block are changed instead. Here below the sample program to print “Piet”.

Malbolge

Last but not least, this language is known as “Programming from hell”. The idea is that programming should be hard. Therefore, there is no point in discussing language syntax any further. An interesting fact of this language is that even the inventor of this language could not write a program by himself. However, Here an example program of hello world in Malbolge language.

(=<`#9]~6ZY32Vx/4Rs+0No-&Jk)"Fh}|Bcy?`=*z]Kw%oG4UUS0/@-ejc(:'8dc

Conclusion

I have listed down below other programming languages that I have found for further reading. An interesting fact about most of these languages was these are Turing complete, meaning you can implement any computer program that other programming languages can do. Even though these programming languages seem useless, it opens our minds to look at things differently.

Hope you enjoy reading this article. If you have any comment, you can find me on Twitter. Follow me for more interesting stories. Feel free to comment down your thoughts. See you in another article. Cheers :)

More by dhanushka madushan

Topics of interest

More Related Stories