esolang

Rotor

A golfing language of wheels. Turn the wheel and the same letters mean something else.

quartata · Turing complete: unknown · ●●○ moderate

Tested with 6 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Hello, World!

The idea

Rotor is a stack-based golfing language by quartata, after CJam, GolfScript, Gibberish and Enema, as its README says. The symbols are core commands that always work. The letters belong to wheels, and only the current wheel's meaning counts. N is the natural logarithm on the math wheel and a newline on the string wheel. > turns to the next wheel.

Read the story

Two wheels exist, and the README calls the language very much a work in progress. The input sets the first wheel, math for a number and strings for text or no input. At the end the whole stack is printed, bottom first, so a bare string is already a Hello World.

The machine

The interpreter is a Groovy script, and the values are Groovy's. Dividing two integers gives an exact decimal, or one rounded to 10 places when it does not end, so 1/3 is 0.3333333333.

CharDoes
0-9 `123 "..." 'c | Push a digit, a number, a string, a character
+ - * / %Arithmetic, the top value first, so 53- is 3 minus 5
= $Equal, equal to the value below
? !Pop and skip the next instruction when false or when true
_ ) @ ; (Dup, swap, bring up the third, drop, reverse
. , [ ]Get and set by index, spread a list, pack the stack into one
{...} # \ \|A block, run it, run it over a range, run it while the top is true
& ~Store and push the register
> ^ :Turn the wheel, pick a wheel, copy a letter from another wheel
lettersThe current wheel's commands, such as p for pi and S for a square root

Several letters on the math wheel are Groovy snippets that do not compile, so they stop the run, and so does <, whose code names a variable that does not exist.

Example

The Hello World from Try It Online is one unclosed string literal, printed when the program ends.

The Hello World from Try It Online is one unclosed string literal, printed when the program ends.

Expected: 0.2857142857

72/ divides the top value 2 by the 7 below it. A block run over the range 1 to 5 pushes each counter, and ~ pushes it once more from the register.

Expected: 1122334455

Patterns it teaches

  • Code golf: one character per command, and wheels to reuse the letters.
  • Stack machines: a stack of a host language's values.

Further

Also in Golfing

Write your own in Run Convert a program from Rotor

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: rotor.

Command line

shib run rotor -e '_*' --input '7
'
shib manual rotor

Source

Module
langs/tio/ports.js
Interpreter
langs/tio/rotor.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language