Stacks of Queues
Every bracket opens a new stack or queue, and values travel up and down between them one at a time.
Jemhunter · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 13 known programs · Test method
Run it
The idea
Jemhunter made Stacks of Queues to explore stacks and queues side by side. A program is brackets. ( ) opens a stack and { } a queue, and the same commands work on both; a pop takes from the end of a stack and from the front of a queue. Inside a structure the work is close to ><> and Befunge, without the grid.
Read the story
There are no jumps. Loops are < > and [ ], a stack and a queue that start over empty each time their end is reached. The only way out is ?, which takes a value and skips the next character when it is 0 or less. A skipped end bracket ends the structure for good, and a skipped start bracket skips it whole.
When the outermost structure ends, it prints what it still holds.
The machine
| Command | Does |
|---|---|
( ) { } | A stack; a queue |
< > [ ] | A stack; a queue, run again and again |
0-9 a-z | Add 0 to 35 |
'text' | Add each character's code |
+ - * / \ % | Arithmetic on the two top values |
= M W | 1 if equal, greater or less, else 0 |
R S D P L | Reverse, swap, copy, drop, length |
F B | Rotate the top to the bottom, or back |
T G | Take a value from the parent; give one to it |
? | Skip the next character if the value taken is 0 or less |
X Y Z I | Read a character, a line or a number |
C N O | Print characters or numbers; print one value |
Taking from an empty structure gives -1, and a negative value prints nothing in character mode. The interpreter is Python, so whole numbers have no size limit and / gives a float.
Example
The text goes onto the stack backwards, R turns it around, and C makes the final print show characters.
The text goes onto the stack backwards, R turns it around, and C makes the final print show characters.
The specification's own walk through. A sub stack takes the 3, multiplies it by 4 and gives back 12. The stack prints from the top, numbers with spaces between.
The double cat reads a line into a queue, marks its end with -1 and runs two loops over it. The first prints each value and sends a copy round to the back of the queue; the second prints it again.
Zeller's congruence asks for a date and names its weekday. 19 November 2026 is a Thursday.
Patterns it teaches
- Stack machines: with a queue beside every stack.
- Tag systems: the specification compiles any 2-tag system into one repeating queue, which is how it shows the language is Turing complete.
See also
Queue-based
Stack-based
Write your own in Run Convert a program from Stacks of Queues
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: stacks-of-queues.
Command line
shib run stacks-of-queues -e '{CYI}' --input 'Hello
'shib manual stacks-of-queuesSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/stacks-of-queues.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org