lnlang
Every line is a sum of calls, kept under its number. Number a line out of order and it jumps.
Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
A line in lnlang starts with a number and holds calls such as get(1) or print(3). Every call gives a number, and the line's sum is added to the value kept for its number. A line that runs ten times holds the total of ten runs. Lines that do not start with a number are comments.
Read the story
There is no goto call. A line whose number is not one more than the numbered line above it jumps, once it has run, to the line numbered one higher. A line 00 at the end sends the run back to line 01, and that is how loops are made.
The machine
| Call | Does |
|---|---|
nop() | Gives 0 |
get(n) | Gives the value of line n |
print(n) write(n) | Writes line n as a number or as a character |
input() read() | Gives a number or a byte from the input |
eq(a, b) lt(a, b) gt(a, b) | Gives 1 if lines a and b compare so, else 0 |
assert(n) | Skips the rest of this line and the next line when line n is 0 |
call(n) | Runs line n in place, without jumping there |
stop() | Halts |
A ~ before a call turns its result n into -n-1, and a ! turns 0 into 1 and anything else into 0. There is no subtraction, so ~get(2) !nop() is how a program takes line 2 away.
Example
The multiplication.
The multiplication. Line 3 adds the first number once per pass and line 4 counts the passes. The last line, 02, is out of order and jumps back to line 03, until line 5 sees the count equal the second number.
The doubling. Line 1 holds 1 + 1 and line 2 adds line 1 twice.
The truth machine on 0 prints line 0, which never ran and so holds 0. On 1 it loops between line 04 and the second line 03 and prints 1 forever.
Patterns it teaches
- Counter machines: every line is a counter that can only add.
Further
See also
Also in Strange time
Write your own in Run Convert a program from lnlang
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: lnlang.
Command line
shib run lnlang -e '01 !nop() !nop()
02 get(1) get(1)
03 print(2)'shib manual lnlangSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/lnlang.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org