Rotary is an esoteric programming language created by User:InputUsername in September 2014. Rotary was made to be confusing, not usable. It was loosely based on BrainFuck, sharing some of its features like a data tape and single-character instructions. However, there are many more interesting differences than similarities.
First of all, programs are restricted to a specific format: a circle (hence the name). A typical Rotary program looks like this:
###x## ### ### # # # # # # # # # # ### ### ######
(where '#' and 'x' represent any valid Rotary instruction)
Execution starts at the position indicated with an x, and goes clockwise. Every program runs until the last instruction of a circle has been executed.
A program can contain multiple circles. Every circle must be separated by a blank line, like this:
# # ### ### ###### ###### ### ### # #
The currently executing circle can be changed using built-in instructions.
As said before, the main form of memory is a tape of unsigned bytes (values 0-255) and a stack, also containing unsigned bytes.
Another feature is the fact that there are independent input and output pointers. Any instruction that puts input onto the tape will put this input in the cell under the input pointer (called INPP from now on). Likewise, any output instruction will use the data in the cell pointed to by the output instruction (OUTP). The INPP and OUTP will start at the first cell. There are instructions to manipulate the I/O pointers.
If a program file contains characters that are not instructions, the interpreter will show an error and halt. This makes it impossible to comment your code; however, behaviour might change in the future.
Any piece of code that is not formatted as a circle will be ignored.
Similar to BrainFuck
|>||Move the INPP right|
|<||Move the INPP left|
|/||Move the OUTP right|
|\||Move the OUTP left|
|+||Increase the value in the cell under the INPP|
|-||Decrease the value in the cell under the INPP|
|.||Output the data in the cell under the OUTP as an 8-bit (0-255) character|
|,||Get character input and insert the character's decimal representation into the cell under the INPP|
As can be seen, the [ and ] instructions are missing, as they can, with some effort, be emulated using other instructions.
|v||Increase the circle pointer (*)|
|^||Decrease the circle pointer (*)|
|#||Output the data in the cell under the OUTP as a number|
|?||Execute the next instruction if the cell under the OUTP is 0, else do nothing (**)|
|*||Execute the next instruction if the cell under the OUTP is not 0, else do nothing (**)|
|$||Push the value of the cell under the OUTP to the stack|
|~||Pop a value off the stack into the INPP; pops 0 if the stack is empty|
|@||Rotate the stack (top becomes bottom)|
|!||NOP (do nothing)|
|r||Replace the cell under the INPP with a pseudo-random number between 0 and 255|
|s||Pop a number 'n'; then output each cell from OUTP+1 to OUTP+n as a character (***)|
|%||Pop a number 'n'; then push <<n MOD the value under the OUTP>> (***)|
|x||Pop a number 'n'; then set the circle pointer to that number, ie. jump to the n-minus-one-th circle (***)|
* Won't do anything if there's only one circle. Will wrap the CP. ** These only work if they're not the last instruction, of course. *** Won't do anything if the stack is empty.
More information on program flow
Rotary programs consist of circles. The instruction pointer will move clockwise from the starting point to the end of a circle. If the end of a circle is reached, the program exits, even if there are circles before or after the current circle. There are instructions to manipulate the circle pointer (which indicates the currently executing circle). Therefore it is possible to make infinite loops. The CP will wrap if it moves before or after the first or last circle.
It is believed, but not yet proven, that Rotary is Turing complete. It should be, as with some effort it can do anything a BrainFuck program can.
InputUsername is currently writing an interpreter in Ruby. Others are encouraged to write implementations, preferably in a language other than Ruby.
As the implementation is not working yet, none of these programs have been tested yet.
A program that does absolutely nothing. It looks something like this:
!!!!!! !!! !!! ! ! ! ! ! ! ! ! ! ! !!! !!! !!!!!!
A program which copies its input to its output; loops infinitely.
!!!,.v !!! !!! ! ! ! ! ! ! ! ! ! ! !!! !!! !!!!!! !!!,.^ !!! !!! ! ! ! ! ! ! ! ! ! ! !!! !!! !!!!!!
About this specification
This is version 1.2 of the Rotary specification. Anyone who wishes to write a standards-compliant implementation must implement all of the features listed on this page. To make that task harder, this specification was written with the intention of being confusing, unreadable and possibly even lacking important information. Figuring out the correct specification is left as an exercise to the reader.