Selt
There are no variables. To keep a number, a program writes it into its own text, after a label.
Zip, 2022 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 9 known programs · Test method
Run it
The idea
Zip made Selt in 2022. A program is a list of lines, each a label, a colon and a command. The assignment x = 5 does not set a variable. It replaces the text after the label x with 5, and @x reads that text back. Every value is a string without quotes, so a space or an operator inside text needs a backslash in front of it.
Read the story
Selt has no if either. A program joins a label name to the result of a comparison, as in goto say~(@stdin == Hello), and lands on say1 or say0.
The machine
| Command | Does |
|---|---|
print e println e | Print a value, and a line feed after println |
goto e call e | Jump to the label named e, or call it |
return | Go back after the last call; with none open, end the program |
x = e | Replace the text after the label x |
| Operator | Does |
|---|---|
@x &x | The text at the label x; its line number |
?e e.i | The length; the character at index i |
!e | 0 for 1, and 1 for anything else |
+ - * / % | Integer arithmetic |
== != < <= > >= | 1 or 0 |
&& | 1 when both sides are 1 |
~ | Join two strings |
A bar before a number gives the text of that line, two bars are or, and @stdin reads a line of input. The binding order is odd. The prefix operators and . bind tightest, then or, and, the comparisons, * / %, + -, and ~ loosest of all. So @n+1 and say~(@x > 1) mean what they look like, but a comparison inside an or needs its own brackets.
Example
The quine prints the text of line 1, which is the whole program.
The quine prints the text of line 1, which is the whole program.
Line 1 holds only the label x. Line 2 writes 5 after it, so the program now reads x:5, and line 3 prints it. Jumping back to x would run 5 as a command and stop with an error.
The truth machine joins branch and the input into the label it jumps to.
The alphabet program keeps the letters on 26 lines and prints the line at &alphabet plus the input. Its 99 bottles of beer, its cat and its Deadfish and brainfuck interpreters also work.
Ideas it shows
See also
Self-modifying
Write your own in Run Convert a program from Selt
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: selt.
Command line
shib run selt -e 'print |1'shib manual seltSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/selt.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org