esolang

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

Expected: Hello, World!

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

BuiltinDoes
TRUE FALSE NULLConstants
= x v ; a bAssign; run a, then give b
+ - * / % ^Arithmetic; + joins and * repeats strings
< > ? & | !Compare and test equality; and, or, not
IF c a b WHILE c bodyChoose; loop
BLOCK x CALL b EVAL sDelay code; run it; run a string
OUTPUT x PROMPTPrint a line; read a line
GET s i n SUBSTITUTE s i n tTake a part of a string; replace it
LENGTH ASCII RANDOM DUMP QUITOther 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.
Expected: 4
Expected: 22
Expected: 1 2 3 4 5
Expected: Hello

A FizzBuzz to 100 also works, with IF nested three deep inside OUTPUT.

Patterns it teaches

  • Code as data: BLOCK keeps code to run later, EVAL runs a string.

Further

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 knight

Source

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