From Esolang
Jump to navigation Jump to search

Betaload is an esoteric programming language created by user:Challenger5. It is a derivative of Underload.

Betaload adds the concept of environments: An environment is a space where commands can be executed. Each environment has two stacks: the standard Underload stack of strings, and a stack of sub-environments.

Each Betaload environment can be in one of two possible modes: S-mode or E-mode. These affect whether certain commands act on the string stack or the environment stack. It is recommended that code should generally stay in S-mode; all code on E-mode should be enclosed between ; (the command to toggle modes) and should avoid using instructions that only affect the string stack.

Betaload was designed to make Underload more usable by providing a mechanism for input as well as for a form of object-orientation (or at least grouping of related functionality). It is backwards compatible with Underload (provided that no invalid commands are used).


Command Alias Effect in S-mode Effect in E-mode
~ swap Swap the two values on top of the string stack. Swap the two values on top of the environment stack.
: dup Duplicate the value on top of the string stack. Duplicate the value on top of the environment stack.
! drop Delete the value on top of the string stack. Delete the value on top of the environment stack.
* cat Concatenate the values on top of the string stack.
(x) push Push the string onto the string stack.
a esc Enclose the top value on the string stack in parenthesis. Behavior described below.
^ exec Execute the value on top of the string stack.
S write Print the value on top of the string stack.
R read Behavior described below.
; mode Switch to E-mode. Switch to S-mode.
# env Create a new environment and put it on top of the stack.
> send Move a string from the current environment to the one on top of the stack. Pop an environment and put it into the new top environment.
< extract Move a string from the environment on top of the stack to the current one. Move an environment from the top environment's stack to this one.
{c} enter Execute the code c from the frame of reference of the top environment.

Complex Commands

The command a, when executed in E-mode, will pop an environment from the stack and push onto the string stack the code necessary to create that environment. For example, #{(foo)(bar)~(baz)#>};a; will push #{(bar)(foo)#{(baz)}} onto the string stack. It essentially un-evals the environment, just like executing a on a string unevals that string. This allows for environments to be manipulated like strings on the string stack. For example, ;aa;~*;a;*^ will rotate the top three environments on the environment stack.

The command R, when executed, will create a dictionary mapping characters to strings. While the top value on the stack is a single character, it will pop that character, pop another string from the stack, and add them to the dictionary. Then, it will read input from STDIN. Every character in the string read will be replaced with its corresponding value in the dictionary (unless the value is not in the dictionary, in which case it will be ignored.) This new string will be pushed to the stack.


Cat Program (only functions with digits 0-9):

(a(:^)*(This string is here to act as a stopping point for R.
It will be removed by R.

It infinitely reads a string of digits and replaces them with the code to print that digit, and then executes the resulting string. Note that it has not been tested and might not work.


An implementation can be found on github. Note that it has some weird quirks like treating { and } separately (so you can have things like (foo)#{(}(bar){)^}), but it supports all the specified behavior correctly.