Grapheme
Twenty-six commands, and every one of them is a capital letter.
PythonshellDebugwindow, 2020 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
PythonshellDebugwindow made Grapheme in 2020. A program may only use the letters A to Z, so strings, numbers and functions have to be written in letters too. Three letters open and close them. E starts and ends a string, F a number and H a function. Since E ends a string, no string can hold an E, and the Hello World in the specification prints HLLOWORLD.
Read the story
Numbers are letters as well. Inside F...F each letter is one decimal place, A to I for 1 to 9 and Z for 0, so FABF is 12. The formula adds each letter before it multiplies by 10, which would make FABF 120, but its truth machine prints 1 with FAF, so Grapheme reads plain decimal digits.
The machine
One stack holds integers, strings and functions, and variables map any value to any value.
| Letter | Does |
|---|---|
A B S R | Add, subtract, multiply, floor divide the top two |
C D | Set a variable; push a variable |
G I Q Z | Run code; run a function; run it if true; run it while the stack is not empty |
J N | Turn the top into a number or a string |
K L M P | Duplicate, swap, drop, reverse the stack |
O T | Length of a string; not |
U V X | Skip the next command, the next n commands, or one of the next two |
W Y | Read a line; print |
False is 0, the empty string and the empty function.
Example
The second adds 12 and 3.
The second adds 12 and 3. The third pushes the string FAFY and runs it as code with G.
The truth machine from the specification. HFAFYH is a function that prints 1, WJ reads a line and turns it into a number, and U skips the loop Z when that number is 0. Input is letters too, so 0 is typed as Z.
Read as written, Z pops the function before it looks at the stack. On 1 the stack is then empty, so the loop never runs and this truth machine prints 0 as well.
Patterns it teaches
- Stack machines: every command works on one stack of mixed values.
- Code as data: a string or a function can be run with
G.
Further
See also
Stack-based
Write your own in Run Convert a program from Grapheme
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: grapheme.
Command line
shib run grapheme -e 'EHLLOWORLDEY'shib manual graphemeSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/grapheme.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org