Sorted! is an esoteric programming language designed and implemented in 2000 by Gerson Kurz. I won't put too much effort into describing the language here, Gerson does that better than I could, but here is his "Hello, World." program to demonstrate:
This code uses the numbers zero, one, seventy two, one hundred and one, one hundred eight, two hundred, one hundred eleven, fortyfour, thirtytwo, eightyseven, twohundred one, onehundred fourteen, two hundred two, onehundred, fortysix, and twohundredtwentytwo. This code always goes to the first label, and sometimes goes to the second label if the first condition is true. This code writes the cell indexed by the first number as a character. This code cannot read. This code uses the sum of the first number and the second number. This code uses the condition that the sixteenth number is equal to the cell indexed by the first number. This code uses two labels. This code does not use any ordered differences. This code assigns the fifth number to the sixth number, the first number to the sixteenth number, the first sum to the first number, the seventh number to the eleventh number, and the fifth number to the thirteenth number. This code does not use any products. This code implements the first assignment, the second assignment, the third assignment, the fourth assignment, the third assignment, the fifth assignment, the third assignment, the first label, the second jump, the first output, the third assignment, the first jump, and the second label. This code does not use any ratios. This code does not use any logical operations. Cool.
or in German / aus Deutsch:
Dieses Programm benutzt die Zahlen Null, Eins, Zweiundsiebzig, Siebenundneunzig, Einhundertacht, Zweihundert, Einhundertelf, Vierundvierzig, Zweiunddreissig, Siebenundachtzig, Einhunderteins, Zweihundertzwei, Einhundertsechzehn, Sechsundvierzig, und Zweihundertzweiundzwanzig. Dieses Programm springt immer an das erste Sprungziel, und springt manchmal an das zweite Sprungziel wenn die erste Bedingung wahr ist. Dieses Programm schreibt diejenige Zelle die indiziert wird durch die erste Zahl als ein Zeichen. Dieses Programm kann nicht lesen. Dieses Programm benutzt die Summe aus der ersten Zahl und der zweiten Zahl. Dieses Programm benutzt die Bedingung dass die sechzehnte Zahl ist gleich diejenige Zelle die indiziert wird durch die erste Zahl. Dieses Programm benutzt zwei Sprungziele. Dieses Programm benutzt keine geordneten Differenzen. Dieses Programm weisst zu die fuenfte Zahl an die sechsten Zahl, die erste Zahl an die fuenfzehnte Zahl, die erste Summe an die erste Zahl, die siebente Zahl an die zweihundertelfte Zahl, und die fuenfte Zahl an die zwoelfte Zahl. Dieses Programm benutzt keine Produkte. Dieses Programm implementiert die erste Zuweisung, die zweite Zuweisung, die dritte Zuweisung, die vierte Zuweisung, die dritte Zuweisung, die fuenfte Zuweisung, die dritte Zuweisung, den ersten Sprungziel, der zweite Sprungbefehl, die erste Ausgabe, die dritte Zuweisung, den ersten Sprungbefehl, und das zweite Sprungziel. Dieses Programm benutzt keine Verhaeltnisse. Dieses Programm ist unlogisch. Cool.
The most obvious feature of Sorted! (other than being bilingual) is the order in which the code is sorted. Numbers, then jumps, output, input and so on. This can lead to a remarkable efficiency: while a typical program may frequently repeat a condition such as "i < n", a Sorted! program need only specify once that "This code uses the condition that the ninth number is less than the fourteenth number." and then refer to "the first condition" when needed.
We now arrive at the main purpose of this page: while Gerson's 2000 compiler/interpreter correctly interprets the programs supplied with it, it is lacking in many regards; most obviously that reads and logical operations do not actually function. I have made a number of fixes and improvements to the compiler (including reading and logic) and am providing it here.
- Smithers's Sorted! distribution v0.1 for Linux
- Download source (tar.gz)
This fixed compiler/interpreter can now be used, for example, with this program, which solves the Snapper Chain problem from 2010's Google Code Jam and is very likely the largest Sorted! program ever written. Alas that it was written after the contest, but in 2012 I used Sorted! during the competition to solve Speaking in Tongues and my solution is here. Note in both cases that while Sorted! does not support comments, I have used its preprocessor to declare /(anything)
as a macro which evaluates to nothing, thereby functioning as a comment.