smol
Every character means two things. A semicolon says which.
Conor O'Brien · Turing complete: no · ●●○ moderate
Tested with 6 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Conor O'Brien's smol reads its program in two modes. It starts in collect mode, where each character is a literal pushed on the stack: digits and letters are the numbers 0 to 61, . is an empty list and `c is the code of c. A ; switches to evaluate mode, where the same characters are commands. So a is 10 in one mode and a range in the other.
Read the story
The stack holds 64-bit integers and lists. A string in quotes is a list of character codes, and @ runs a list as commands. That is the only way to repeat anything.
The machine
| In evaluate mode | Does |
|---|---|
0…9 | Push the digit |
X Y Z / x y z | Pop into a register, push it back |
R r | Store into register n, load register n |
+ , | Add two integers, join two values into a list |
a A | Range from lower to upper, without and with a step |
: d | Duplicate the same list, copy it |
o | Drop the last element of the list on top |
. p ? | Print as characters, print as a value, print the whole stack |
@ | Run each element of a list as a command |
'text' pushes the codes of the text in either mode, and ; switches modes. A character collect mode does not know, a space included, pushes -1337, smol's error value. The reference is smol.c in github.com/ConorOBrien-Foxx/smol.
Example
The second collects 3, 3 and 10, then prints 10 and the sum of the two 3s.
The second collects 3, 3 and 10, then prints 10 and the sum of the two 3s. The last two show the difference between : and d. After : both stack entries are the same list, so o shortens both; after d only the copy loses its c.
Patterns it teaches
Without input or a real loop it is not Turing complete.
- Stack machines: one stack of numbers and lists.
- Code as data: a string is a list, and
@runs it.
Without input or a real loop it is not Turing complete.
Further
See also
Also in Golfing
Write your own in Run Convert a program from smol
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: smol.
Command line
shib run smol -e '05;ap'shib manual smolSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/smol.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language