Grok
Befunge as a Vim user would write it. hjkl steer, i starts typing and a backtick escapes.
AarMil42, 2021 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
AarMil42 made Grok in 2021, after Befunge, ><> and the Vim editor. The program is a grid, the wordbox, and the pointer moves through it, wrapping around at the edges. The letters are chosen so that someone who knows Vim can guess them. h j k l move left, down, up and right, x deletes, y yanks and p puts.
Read the story
A capital letter works on the register instead of the stack, which Grok calls the Document. The register holds one value. Text goes in through insert mode, i, which collects every character the pointer passes until it meets a backtick.
The machine
| Command | Does |
|---|---|
h j k l | Move left, down, up, right |
{ } | Pop; turn left or right if it was 0 |
i ... ` | Push the text in reverse, so its first character is on top, or one number if it is all digits | |
I | Put one character or one number in the register |
` | Outside insert mode, skip the next cell | |
x X | Drop the top, empty the register |
y Y | Copy the nth value, or the top, to the register |
p P | Move or copy the register to the Document |
d | Pop n, then drop n values |
w z | Pop and print as a character or a number; W Z print the register |
: | Read a line of input the way insert mode reads text |
+ - * / % > = ! | Arithmetic, compare and not |
0 to 9 | Push a digit |
q | Stop |
An empty Document reads as 0. The programs need that, as their loops stop when ! meets an empty Document and pushes 1.
Example
The cat and truth machine.
The cat and truth machine.
The cat reads the whole line, first character on top. The loop copies the top to the register with Y, drops it with ! and turns down on the 0 that ! leaves. On the second row it goes left, puts the character back with p, prints it with w and climbs up with k into the loop again. On 1 the truth machine prints 1 for ever.
The Hello world uses the same loop. The specification shows its output as Hello, world!, but the program has no comma in it.
Patterns it teaches
- Two-dimensional control flow: loops drawn as rings on the grid.
- Stack machines: one stack and one register.
Further
- esolangs.org/wiki/Grok
- Befunge and ><>, its models.
See also
Two-dimensional languages
Stack-based
Write your own in Run Convert a program from Grok
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: grok.
Command line
shib run grok -e ':lY!}q
kwph' --input 'Hello, Waffles!'shib manual grokSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/grok.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org