esolang

2KWLang

Two keywords, import and print. There is no loop, so a program writes its next round into a file and runs it.

PythonshellDebugwindow, 2020 · Turing complete: yes · ●●○ moderate · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: Hello, World!

The idea

PythonshellDebugwindow made 2KWLang in 2020 and named it after its two keywords. A program is a set of named files. print writes to the screen or appends to a file, and import runs a file, reads a line of input or, as import print, gives back what a file holds. There are no conditions and no jumps.

Read the story

So a counter builds the text of its next step, writes it to a file and imports it. A test is a file name made from a comparison. range.test.1 exists and range.test.0 does not, and importing the missing one raises an exception that ends the file.

The machine

StatementDoes
=nameStarts a file; the one ending in ! runs first
print x;Prints x and a line feed
print x | "";Prints x alone
print x > "f";Appends x and a line feed to file f; an empty x empties it
print import "f";Prints file f
import "f";Runs file f
import 0;Reads a line of input; \0 in a string stands for it
import print "f"The text of file f, as a value

Numbers are exact fractions, so 7 / 2 is 3.5. The comparisons == != < > <= >= bind tighter than * / %, which bind tighter than + -. An exception, such as a missing file or a division by 0, ends the running file and returns to the one that imported it.

Example

2 == 2 is worked out first and gives 1, so the second line prints 2.
Expected: 3.5 2

2 == 2 is worked out first and gives 1, so the second line prints 2.

The truth machine reads a line and imports the file named after it. File 1.2kwl prints 1 and imports itself forever; file 0.2kwl prints 0 once.

Expected: 0

The quine prints its header and then its own file, read back with import print.

Expected: =main.2kwl! print "=main.2kwl!"; print import print "main.2kwl" | "";

Patterns it teaches

Further

Also in Hostile

Write your own in Run Convert a program from 2KWLang

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: 2kwlang.

Command line

shib run 2kwlang -e '=hello.2kwl!
  print "Hello, World!";'
shib manual 2kwlang

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/2kwlang.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org