Check
The program reads like a line of text until it needs to loop. Then it turns into a grid.
Challenger5, 2017 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 5 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Challenger5 made Check in May 2017. It mixes two ways of running code. Stack work happens in 1-D mode, where the pointer reads each line left to right and then moves on to the next line, like ordinary text. Control flow happens in 2-D mode, where arrows steer the pointer around the grid in the style of Befunge.
Read the story
# switches between the modes, and ? switches to 2-D mode only when the top of the stack is truthy. That is the only branch. A loop is a line of 1-D code that ends in ?, with a 2-D path that leads back to its start. When the test is false the pointer stays in 1-D mode, runs off the end of the program and stops.
The machine
One stack of integers and lists, with a register on the side.
| Code | Does |
|---|---|
> 0-9 | Push 0; a digit d turns the top n into 10n + d, so >42 is 42 |
"..." | Push the character codes as a list |
+ - * % $ | Arithmetic; + also joins lists, $ halves |
) ( _ ! | Add one, take one, negate, logical not |
[ ] & , = . | Empty list, wrap, spread, length or range, index, pack the whole stack |
: \ @ ; ' d | Duplicate, swap, rotate three, rotate n either way, drop |
r R | Store in the register, fetch it |
o p < | Print as characters, print as a value, print a newline |
# ? | Switch modes; switch to 2-D if the top is truthy |
> v < ^ | In 2-D mode, point the pointer |
In 2-D mode > and < are arrows, in 1-D mode they push 0 and print a newline. The input is the reference's command-line arguments, integers or lists that start out on the stack.
Example
The reference's own counting example takes n and prints 1 to n.
The reference's own counting example takes n and prints 1 to n. The first line duplicates n and drops into 2-D mode, and v sends the pointer down to the loop on the second line.
:#v
#(.:+&-pd<?
The loop keeps a countdown c under n. It lowers c, packs both into a list, joins the list with itself, spreads the four numbers back out and subtracts, which leaves n minus c on top to print. ? loops while c is not 0. In 2-D mode the pointer crosses the spaces to the right edge, wraps round and meets # again.
Patterns it teaches
- Two-dimensional control flow: only the jumps are drawn on the grid; everything else is read like a line of text.
- Stack machines: a stack of integers and lists, with rotations to dig into it.
Further
- esolangs.org/wiki/Check
- The reference interpreter, in Python, first published as check-lang
See also
Also in Spatial (2D and up)
Write your own in Run Convert a program from Check
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: check-lang.
Command line
shib run check-lang -e '>6>7*p'shib manual check-langSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/check-lang.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org