Clockwise
A pointer that can only turn right, and a program that ends when it comes home.
PythonshellDebugwindow, 2020 · Turing complete: no · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
PythonshellDebugwindow made Clockwise in 2020. It is a two-dimensional language where every turn is 90 degrees clockwise, so going left takes three right turns. The run ends when the pointer comes back to the top left corner, where it started.
Read the story
There is one counter, and input and output go one bit at a time. Each ; pushes the counter's lowest bit, and every 7 bits make a character. One counter is not enough for Turing completeness, and esolangs.orgplaces Clockwise with the push-down automata.
The machine
| Command | Does |
|---|---|
R | Turn 90 degrees clockwise |
? | Turn if the counter is not 0 |
! | Turn if the counter is 0 |
+ - | Add or take away 1 |
S | Set the counter to 0 |
. | Read the next input bit into the counter's lowest bit |
; | Push the counter's lowest bit to the output |
| space | Nothing |
The input goes into a queue at the start, highest bit first, and . puts each bit it reads back at the end, so the input goes round and round. The specification does not say how many bits an input character has. Its truth machine reads 7 and prints them, so it is 7, as for output. The specification does not say what happens at the edge either; the pointer comes back in at the other side.
Example
Hello World pushes its 77 bits along the edge of the program and ends in the corner it started from.
Hello World pushes its 77 bits along the edge of the program and ends in the corner it started from.
The truth machine reads a character and prints its 7 bits. When the last bit is 0, as it is for the character 0, the pointer goes on round to the corner and stops. When it is 1, ? turns it into a loop, and as the input goes round, it prints the same character for ever.
The cat reads and prints one bit per lap. Since the input never runs out, it prints the input again and again and never stops.
Patterns it teaches
- Two-dimensional control flow: with only right turns, every loop is a ring.
- Counter machines: a single counter, which the specification shows is one short of Turing completeness.
Further
See also
Two-dimensional languages
Write your own in Run Convert a program from Clockwise
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: clockwise.
Command line
shib run clockwise -e '+-?.;.;.;.;.;.;.;?R
R R
R R' --input '0'shib manual clockwiseSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/clockwise.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org