It was noticed that, in the field of esoteric programming languages, there was a particular and surprising void: no programming language known to the author was specifically designed to be difficult to program in.
Certainly, there were languages which were difficult to write in, and far more were difficult to read (see: Befunge, False, TWDL, RUBE...). But even INTERCAL and BrainF***, the two kings of mental torment, were designed with other goals: INTERCAL to have nothing in common with any major programming language, and BrainF*** to be a very tiny, yet still Turing-complete, language.
INTERCAL's constructs are certainly tortuous, but they are all too flexible; you can, for instance, quite easily assign any number to a variable with a single statement.
BrainF*** is lacking the flexibility which is INTERCAL's major weakness, but it fails in that its constructs are far, far too intuitive. Certainly, there are only 8 instructions, none of which take any arguments--but it is quite easy to determine how to use those instructions. Subtract 8 from the current number? With a simple '--------' you are done! This kind of simple answer was unacceptable to the author.
Hence the author created Malbolge. It borrows from machine, BrainF***, and tri-INTERCAL, but put together in a unique way. It was designed to be difficult to use, and so it is. It is designed to be incomprehensible, and so it is.
So far, no Malbolge programs have been written. Thus, we cannot give an example.
"Malbolge" is the name of Dante's Eighth Circle of Hell, in which practitioners of deception (seducers, flatterers, simonists, thieves, hypocrites, and so on) spend eternity.
Environment ^^^^^^^^^^^
In many languages, the environment is easy to understand. In Malbolge, it is best to understand the runtime environment before you ever see a command.
The environment is, roughly, that of a primitive trinary CPU. Both code and data share the same space (the machine's memory segment), and there are three registers. Machine words are ten trits (trinary digits) wide, giving a maximum possible value of 59048 (all numbers are unsigned). Memory space is exactly 59049 words long.
The three registers are A, C, and D. A is the accumulator, used for data manipulation. A is implicitly set to the value written by all write operations on memory. (Standard I/O, a distinctly non-chip-level feature, is done directly with the A register.)
C is the code pointer. It is automatically incremented after each instruction, and points the instruction being executed.
D is the data pointer. It, too, is automatically incremented after each instruction, but the location it points to is used for the data manipulation commands.
All registers begin with the value 0.
When the interpreter loads the program, it ignores all whitespace. If it encounters anything that is not one of an instruction and is not whitespace, it will give an error, otherwise it loads the file, one non- whitespace character per cell, into memory. Cells which are not initialized are set by performing op on the previous two cells repetitively.
Commands ^^^^^^^^
When the interpreter tries to execute a program, it first checks to see if the current instruction is a graphical ASCII character (33 through 126). If it is, it subtracts 33 from it, adds C to it, mods it by 94, then uses the result as an index into the following table of 94 characters:
It then checks it against the characters listed below, and performs an appropriate action.
If the result is not one of the characters listed below, it is treated as a nop. If the original character is not graphic ASCII, the program is immediately ended.
When the interpreter parses the input file, it checks each non- whitespace character with the process above. If any result is not one of the eight characters below, the file will be rejected.
After the instruction is executed, 33 is subtracted from the instruction at C, and the result is used as an index in the table below. The new character is then placed at C, and then C is incremented.
j sets the data pointer to the value in the cell pointed to by the current data pointer.
i sets the code pointer to the value in the cell pointed to be the current data pointer.
* rotates the trinary value of the cell pointed to by D to the right 1. The least significant trit becomes the most significant trit, and all others move one position to the left.
p performs a tritwise "op" on the value pointed to by D with the contents of A. The op (don't look for pattern, it's not there) is:
< reads an ASCII value from the stdin and converts it to Trinary, then stores it in A. 10 (line feed) is considered 'newline', and 2222222222t (59048 dec.) is EOF.
/ converts the value in A to ASCII and writes it to stdout. Writing 10 is a newline.
v indicates a full stop for the machine.
o does nothing, except increment C and D, as all other instructions do.
Turing-Completeness ^^^^^^^^^^^^^^^^^^^
Though I have not proven it, I _think_ Malbolge to be Turing-complete. To be Turing-complete, there must be some data construct which can be used to do any mathematical calculation. I believe that using *p in various clever ways on the tritwords can fulfill this requirement.
Turing-completeness also requires three code constructs: sequential execution (which Malbolge obviously has), repetition (provided by the i and, indirectly, j instructions), and conditional-execution (provided, I believe, by self-modifying code and altering i destinations).
I do have my doubts, particularly about data constructs, but I *think* this works...