esolang

Cardinal

Pointers fly out of every % in all four directions, and each carries only two numbers.

Madk, 2010 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Hello World on Try It Online: identical except the line end · Test method

Run it

Expected: Hello, world!

The idea

Madk named Cardinal after the four cardinal directions. Execution happens on a grid, like Befunge, but there is no stack. Each instruction pointer holds just two values, one active and one inactive. Anything bigger needs many pointers working at once.

Read the story

So pointers are cheap. Every % launches four at the start, # splits one into three, and x, ? and ! remove them. A pointer that walks off the grid is gone too. Loops are paths that a pointer keeps circling, and other pointers act as timers that end the program with @.

The mirrors / and \ flip each time a pointer hits them, so the grid changes as it runs. The specification says Cardinal is likely Turing complete because it can run Rule 110, but no proof is given.

The machine

Each pointer has a position, a direction and two integer values. Every tick, each pointer moves one cell and obeys it, oldest first. The program ends at @ or when no pointers are left.

CharDoes
%At the start, sends pointers up, right, down and left
^ > v <Steer; U R D L steer only if the active value is above 0
#Split: go on, and also turn both ways
x ? !Remove the pointer; if its value is 0; if it is not 0
@End the whole program
/ \Mirror, then flip to the other mirror
O oTurn clockwise, anticlockwise
N Z IBounce horizontal movers, vertical movers, all
~ =Swap active and inactive; copy active into inactive
+ - 0Increment, decrement, zero the active value
t d * ' MMultiply, divide, add, subtract, modulo by the inactive value
& \| XAnd, or, xor with the inactive value
: . , ;Read a number; print it as a number, as a character; print a newline
"Print every cell passed until the next "
n u ( )Write the value into the cell they point to, read the cell behind
A V { }Remove pointers moving down, up, right, left
8 $ J jWait three ticks; jump to (active, inactive); skip if above 0, if 0

The cat, %:.x, only echoes digits, because : reads a number and . prints one.

Example

Four pointers leave the %.

Four pointers leave the %. Three walk off the grid at once and vanish. The one moving right enters print mode at ", prints Hello, world! cell by cell, leaves it at the second ", prints a newline at ; and dies at x.

Patterns it teaches

Try this

  1. Print your name followed by a newline.
  2. Print the numbers 1 to 5 with one pointer that loops and a second one that counts down to @.
  3. Hard: follow the Fibonacci program and find which pointer decides when it stops.

Further

Two-dimensional languages

Cell-based

Write your own in Run Convert a program from Cardinal

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run cardinal -e '%"Hello, world!";x'
shib manual cardinal

Source

Module
langs/stack/ports.js
Interpreter
langs/stack/cardinal.js

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

Source esolangs.org (CC0) · Edit on esolangs.org