esolang

Bur

The only arithmetic is division, and dividing by zero flips a coin.

Zane Porter, 2018 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 5 known programs · Test method

Run it

Expected: Hello, World!

The idea

Zane Porter made Bur in 2018 and named it after cockleburs, because its instructions look small and prickly. It is a stack language with functions and no loops. A loop is a function that calls itself, and an if is a call that happens only when the top two numbers compare the right way.

Read the story

The one arithmetic operation is division. Divide by zero and the numerator comes back one higher or one lower, at random. The specification builds addition from that. Its addOne divides by zero and calls itself again whenever the coin went the wrong way, so it always ends with one more.

The machine

CodeDoes
~@name ... ;Declare a function; the main one is called ,
#12!Push 12
~$foo? ~$foo!Pop into the variable foo; push its value
Division? moves the result back from the math stack, where ` puts the second number divided by the top one
! !v !. !v.Pop and print a number, with a line feed, as a character, or both
@name@Call a function
‽(name*Pop a, pop b, call name if a > b; = ) [ ] test ==, <, >=, <=
"text"A comment

White space is ignored everywhere, even inside a number. A function can call itself and the functions declared above it. Variables are shared by all functions, and addOne depends on that. The coin is a fixed random sequence, so a run always replays the same way.

The specification's prime and FizzBuzz programs write `114 , a division with a number after it, which the specification never explains. This implementation stops on it with an error, so those two do not run.

Example

The printing example, without its comments.
Expected: 2

The printing example, without its comments. It pushes four 65s and prints them four ways.

Expected: 6565 AA

addOne, called on 41. Each time the coin gives 40, it calls itself again on 41.

Expected: 42

A test of x against zero, with x set to 3 first.

Expected: >

Patterns it teaches

  • Stack machines: arguments and results travel on the stack, and every function cleans up after itself.
  • Nondeterminism: a random step, and a retry loop that makes the result certain anyway.

Further

Nondeterministic

Stack-based

Write your own in Run Convert a program from Bur

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: bur.

Command line

shib run bur -e '~@,#16!#8!`?!;'
shib manual bur

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/bur.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org