esolang

Beeswax

Bees crawl over a hexagonal honeycomb, each carrying a stack of three numbers.

Manuel Lohmann (Albedo), 2015 · Turing complete: yes · ●●● hard · esolangs.org

Tested with 4 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: Enter number: 12 squared=144

The idea

Manuel Lohmann (Albedo on esolangs.org) made beeswax in 2015. It takes ideas from Cardinal and from Hive, a board game with hexagonal pieces. The instruction pointers are bees, and every cell of the honeycomb has six neighbours.

Read the story

The honeycomb is stored as an ordinary rectangle of text. The hexagons come from how you read it: each row counts as shifted half a cell to the right of the row above. So a bee can move right, left, up, up-left, down and down-right, but never up-right in the text.

Each bee carries a local stack of exactly three 64-bit unsigned numbers. All arithmetic happens there. For anything bigger, bees drop values onto one shared global stack and pick them up again. Bees can also write into the honeycomb and read from it, which makes the program self-modifying, and writing past the edge makes the honeycomb grow.

The machine

Each bee has a position, a direction and a stack [3rd, 2nd, top]. Every tick the newest bee acts first. A bee that leaves the honeycomb dies, and the program ends when no bees are left.

CharDoes
* \ / _At the start: launch bees in all six directions, or along one axis
> d b < p qAim right, up, up-left, left, down, down-right
a x s t u j k l OTurn and mirror
X E H WClone the bee into other directions
m n o #Catch and remove bees from some directions
' " K L QSkip the next cell if top = 0, top > 0, top = 2nd, top > 2nd, always
v ^Wait one or two ticks
0-9 P MSet the top; increment; decrement
+ - . : % Btop = top op 2nd: add, subtract, multiply, divide, modulo, power
& \| $ ! ( ) [ ]Bitwise and, or, xor, not, shifts, rotations
~ @ F zSwap top and 2nd; swap top and 3rd; fill with top; zero
f g e UPush top to the global stack; copy its top back; flush all three; take three
= ? A y hGlobal stack: dup, pop, push length, rotate
D G Y ZWrite or read a cell, absolute or relative; J jumps
, T i VRead a character, an integer, an integer or a line onto the global stack
{ } I C NPrint top as a number or character; global top likewise; newline
` | Print every cell passed until the next `
;End

The specification's table makes O turn like j, but its description says "opposite direction". This implementation reverses on O. File reading and writing (r, w) do nothing.

Example

_ launches two bees, right and left.

_ launches two bees, right and left. The left one falls off at once. The right one prints the prompt in text mode, reads 12 into its top with T, prints a newline and the 12, then the text squared=. Its stack is now [0, 0, 12]. ~ swaps it to [0, 12, 0], + adds to get [0, 12, 12], . multiplies to get 144, and { prints it.

Patterns it teaches

Try this

  1. Print Hi and a newline with one bee.
  2. Read two integers with T and print their product.
  3. Hard: print 10 down to 1, one per line, with a loop like the 1 to 100 program in the specification.

Further

Self-modifying

Two-dimensional languages

Write your own in Run Convert a program from Beeswax

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run beeswax -e '_`Hello, World!'
shib manual beeswax

Source

Module
langs/stack/ports.js
Interpreter
langs/stack/beeswax.js

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

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