B^2
BASIC made even more basic. Two types, arithmetic in prefix, and one output per program, because it compiles to WebAssembly.
2020 · Turing complete: with unbounded memory · ●○○ easy · esolangs.org
Tested with 10 known programs · Test method
Run it
The idea
B^2, said bee-squared, stands for Basic Basic. It was made in 2020 to be very easy to learn, with words taken from Python and C. Its editor compiles a program to WebAssembly text, and the odd parts come from there. There are no strings, so there is no Hello World. A program gives exactly one output, the one value its WebAssembly function returns. A number is 32 bits and a decimal 64, so the specification calls B^2 a bounded-storage machine.
The machine
Words are separated by spaces, and a statement ends with a ; of its own. A comment runs from // to /;, so a comment can sit in the middle of a line.
| Words | Does |
|---|---|
number x = e ; decimal x = e ; | Declare a 32-bit integer or a 64-bit float |
x = e ; | Set a variable |
add a b sub mul div | Arithmetic, written in prefix |
toDecimal x toNumber x round x | Convert and round |
input | The next number of the input |
if ( c ) { } else { } while ( c ) { } | Branch and loop |
for ( number i = 0 ; i to 10 ; i = add i 1 ; ) { } | Count |
output e ; | Give the one result and stop |
Conditions compare with < > <= >= == != and %%, which asks whether one number divides by another, and join with && and ||. The two types never mix. The specification's output add z x ;, with z a number and x a decimal, stops with the compiler's type mismatch on line 2, word 3, both counted from 0.
Example
A while loop counts to 5.
A while loop counts to 5.
Its FizzBuzz has no strings to print, so it answers 1 for fizz, 2 for buzz and 3 for fizzbuzz. On 15 it gives 3.
The Disan Count program wants to print every even number up to the input. One output is all it gets, so it adds them up; up to 10 that is 0 + 2 + 4 + 6 + 8 + 10.
Further
See also
Also in Jokes
Write your own in Run Convert a program from B^2
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: b-2.
Command line
shib run b-2 -e 'number x = input ;
output x ;' --input '42'shib manual b-2Source
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/b-2.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org