sb
23 one-character commands on a stack, a while loop, memory and eval. Nothing is ever printed.
2025 · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 5 known programs · Test method
Run it
The idea
sb is a stack language from 2025. Its values are integers, strings, characters and arrays, and this implementation keeps a character as a string one long. It has no output at all. The truth machine says so itself, since on 1 it keeps pushing 1 where another language would print it. What a program leaves on the stack is its result.
Read the story
Input comes in as text. $ reads a line and pushes it as a string, and ; runs a string as sb code. So $; turns the line 5 into the number 5.
The machine
| Command | Does |
|---|---|
42 "text" 'c | Push a number, a string or one character |
+ - * / % | Pop a, then b, push b op a |
_ | Negate |
: \ ~ | Duplicate, drop, swap |
? | Pop a, b and c, push b if c is true, else a |
= < ! | Equal, less than and not, as 1 or 0 |
& | Join two strings, or add an item to an array |
. , @ | An empty array; the length; item a of b |
( ) | Pop a and b and set memory b to a; push memory a |
$ ; | Read a line; run a string as code |
{ ... } | Loop while the top is true |
The loop looks at the top without popping it, which the factorial needs. The specification does not say how division rounds, and this implementation rounds toward 0. This implementation prints the final stack, bottom first, one item per line.
Example
The factorial starts with 1 under n.
The factorial starts with 1 under n. Each pass keeps n in memory 0, multiplies it into the result, takes it back out and counts it down by 1. When n reaches 0 the loop ends, and \ drops the 0.
The truth machine compares the input with 1. On 0 the loop is skipped, the 0 is dropped and a fresh 0 is pushed. On 1 the loop pushes 1 forever.
Patterns it teaches
- Stack machines: every command takes from the top and gives back to it.
- Code as data:
;runs a string, so a program can build the code it runs.
Further
See also
Stack-based
Write your own in Run Convert a program from sb
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: sb.
Command line
shib run sb -e '$' --input 'Hello, sb'shib manual sbSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/sb.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org