Bundle Bungle

From Esolang
Jump to navigation Jump to search

Bundle Bungle is an esolang created by User:RhubarbJayde in 2024. It operates on a "quasi-stack", which is a data structure with a read head, where pushing and popping act at the read head and don't automatically move it.

A quasi-stack can obviously emulate a stack and can be emulated by a combination of a stack and a queue (the former holds everything below and at the head, the latter holds everything above the head): pushing X to the quasi-stack pops from the stack to Y, enqueues Y, and pushes X to the stack. Popping X from the quasi-stack pops X from the stack, dequeues to Y, and pushes Y to the stack. And manually moving the head up/down either pops and enqueues are pushes and dequeues. A quasi-stack cannot easily itself emulate a queue or a deque, as one would need to move the head all the way to the back when enqueueing and move it back to the front when dequeueing.

After popping, the read head may now be out of bounds as it is not automatically moved; trying to then pop terminates the program and trying to push will automatically move the head to just above the top of the quasi-stack and then pushes. Bundle Bungle is akin to traditional esolangs such as Befunge and ><>, as it operates on an infinite sequence of quasi-stacks, denoted Q0, Q1, ... and features self-modifying code.

Specification

Q0 is the program quasi-stack: the first instruction is at the base, the next instruction is above, etc. It’s initialized at runtime and modifying it leads to the aforementioned self-modifying behaviour. Therefore the interpreter itself acts like the Q0 read head. As reading requires popping (and then pushing again; i.e. peeking), the program terminates execution once it reaches its end. Instructions are encoded as numbers 0-15, and the program can also be aborted by pushing something greater than 15 to Q0 and making the interpreter go down (thereby reading what was just pushed). Q1, Q2, ... are data quasi-stacks, each initialized as having a single element, 1, 2, ... This allows one to retrieve constant numbers without needing an explicit "push constant" instruction.

At any point, the interpreter keeps an active quasi-stack, which starts out as Q1, which is currently being acted upon. The instructions are the following:

Command Description
, Copies all the data above the active read head onto the next quasi-stack, leaving the head now at the top of the active stack.
- Pop at the active read head and discard the result.
! Move to the next quasi-stack (i.e. increment the active quasi-stack index). The read head is reset to the bottom.
# Move to the previous quasi-stack; nop if the active quasi-stack is Q0.
$ Move the read head up.
% Move the read head down; nop if it’s at the bottom.
* Push user input at the active read head.
< Copy value at the active read head and push it right below the Q0 read head.
& Pop at the active read head and print it to standard output.
' Copy value right below the Q0 read head and push it at the active read head. Nop if this is at the start of the program.
( Execute code before matching ), break once the read head is 0 or the active quasi-stack is empty.
) Marks the end of a loop.
+ Move active read head up until 0 or the top of the quasi-stack is encountered.
. Move active read head down until 0 or the bottom of the quasi-stack is encountered.
: Pop at the active read head, increment, and push.
; Pop at the active read head, decrement, and push.

Example programs


The null program does nothing and immediately halts.

()

A simple infinite loop which does nothing forever; the value at the active read head will always be 1.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<'&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<'&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!<'&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&

This prints "Hello, World!" making use of the fact that, for i > 0, Qi is initialized to hold i. For the duplicate "l", it has to use <' to make two copies, as the & instruction pops.

*&

A cat.

(*&)

A cat which repeats infinitely, rather than just retrieving input once.

Open: how to make a truth machine, quine or self-interpreter.