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
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.
| Char | Does |
|---|---|
* \ / _ | At the start: launch bees in all six directions, or along one axis |
> d b < p q | Aim right, up, up-left, left, down, down-right |
a x s t u j k l O | Turn and mirror |
X E H W | Clone the bee into other directions |
m n o # | Catch and remove bees from some directions |
' " K L Q | Skip the next cell if top = 0, top > 0, top = 2nd, top > 2nd, always |
v ^ | Wait one or two ticks |
0-9 P M | Set the top; increment; decrement |
+ - . : % B | top = top op 2nd: add, subtract, multiply, divide, modulo, power |
& \| $ ! ( ) [ ] | Bitwise and, or, xor, not, shifts, rotations |
~ @ F z | Swap top and 2nd; swap top and 3rd; fill with top; zero |
f g e U | Push top to the global stack; copy its top back; flush all three; take three |
= ? A y h | Global stack: dup, pop, push length, rotate |
D G Y Z | Write or read a cell, absolute or relative; J jumps |
, T i V | Read a character, an integer, an integer or a line onto the global stack |
{ } I C N | Print 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
- Two-dimensional control flow: six directions on a hexagonal grid, with mirrors along three axes.
- Stack machines: a tiny local stack per bee and one shared stack.
- Self-modifying code:
DandYwrite characters into the honeycomb, and can grow it. - Turing completeness: the specification translates every Brainfuck command into beeswax.
Try this
- Print
Hiand a newline with one bee. - Read two integers with
Tand print their product. - Hard: print 10 down to 1, one per line, with a loop like the 1 to 100 program in the specification.
Further
See also
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 beeswaxSource
- 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