Betaload
Underload with environments. Each environment keeps its own stack, and an environment can be turned back into code.
Challenger5, 2016 · Turing complete: yes · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Challenger5 made Betaload in 2016 to make Underload more usable. It adds input and a kind of object, the environment. An environment has two stacks, one of strings as in Underload and one of environments inside it. Code can step into the top environment, work there and step out again.
Read the story
Each environment is in one of two modes. In S-mode the stack commands work on strings, in E-mode on environments. Every Underload program that uses only Underload's commands runs the same.
The machine
| Command | S-mode | E-mode |
|---|---|---|
(x) | Push the string x | Same |
~ : ! | Swap, copy, drop strings | Swap, copy, drop environments |
* ^ S | Join, run, print strings | Same |
a | Wrap the top string in brackets | Pop an environment, push the code that makes it |
> | Move a string into the top environment | Pop an environment into the new top one |
< | Move a string out of the top environment | Move an environment out of it |
; | Switch to E-mode | Switch to S-mode |
# | Push a new environment | Same |
{c} | Run c inside the top environment | Same |
R builds a table from one character strings and the strings under them, reads a line and pushes it with each character replaced from the table. As in the reference implementation, { and } are two commands, so a string can step out of an environment and back in. Any other character is an error, and the specification's cat wraps its line feeds in (...)! for that reason.
Example
The first is the specification's example of a in E-mode, with S added to print what it pushes.
The first is the specification's example of a in E-mode, with S added to print what it pushes. It builds an environment holding bar, foo and an environment with baz, then turns it back into the code that makes it. The second makes three environments and turns the deepest to the top with ;aa;~*;a;*^, which writes the three out as code, joins them in a new order and runs the result. The third is a quirk of the specification, with *S added to join and print the two strings. The string }(bar){ steps out of the environment to push bar, then steps back in.
The specification's cat is untested, and this implementation reads one line. It builds its loop string (...):^ but never runs it.
Patterns it teaches
- Stack machines: a stack of strings in every environment.
- Concatenative: programs are strings joined and run, as in Underload.
- Code as data:
aturns an environment back into the code that makes it.
Further
See also
Stack-based
Write your own in Run Convert a program from Betaload
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: betaload.
Command line
shib run betaload -e '(foo)#{(}(bar){)^}'shib manual betaloadSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/betaload.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org