Knight
A language built to be easy to implement, which is why it has more than 20 official interpreters.
Sampersand, 2021 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 4 known programs · Test method
Run it
The idea
Sampersand made Knight in April 2021. Every builtin has a fixed number of arguments and comes first, in Polish notation, so a parser needs no precedence and no brackets. Brackets, parentheses and : are whitespace, there only to make a program readable.
Read the story
A builtin is named by its first letter. OUTPUT, OUT and O are the same thing, and the specification notes that WHY_WOULD_ANYONE_DO_THIS is a while loop. Most builtins turn the second argument into the type of the first, so + 2 "2" is 4 and + "2" 2 is "22".
The machine
| Builtin | Does |
|---|---|
TRUE FALSE NULL | Constants |
= x v ; a b | Assign; run a, then give b |
+ - * / % ^ | Arithmetic; + joins and * repeats strings |
< > ? & | ! | Compare and test equality; and, or, not |
IF c a b WHILE c body | Choose; loop |
BLOCK x CALL b EVAL s | Delay code; run it; run a string |
OUTPUT x PROMPT | Print a line; read a line |
GET s i n SUBSTITUTE s i n t | Take a part of a string; replace it |
LENGTH ASCII RANDOM DUMP QUIT | Other builtins |
OUTPUT adds a line break, unless the text ends in a backslash. Numbers are 32-bit whole numbers. The backtick, which runs a shell command, is not implemented.
Example
A FizzBuzz to 100 also works, with IF nested three deep inside OUTPUT.
A FizzBuzz to 100 also works, with IF nested three deep inside OUTPUT.
Patterns it teaches
- Code as data:
BLOCKkeeps code to run later,EVALruns a string.
Further
See also
Also in Functional and concatenative
Write your own in Run Convert a program from Knight
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: knight.
Command line
shib run knight -e 'O"Hello, World!"'shib manual knightSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/knight.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org