esolang

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

Expected: Hello, World!

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.

CodeDoes
> 0-9Push 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
: \ @ ; ' dDuplicate, swap, rotate three, rotate n either way, drop
r RStore 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.
Expected: 42

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<?
Expected: 1 2 3

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

Further

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-lang

Source

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