eWagon
One store that is a stack or a queue, whichever you switch to, and a second queue for every command's arguments.
Orangeyy · Turing complete: unknown · ●●○ moderate · esolangs.org
Tested with 2 known programs · Test method
Run it
The idea
Orangeyy made eWagon. The name stands for Esolang Without A Good Name. All values live in one store. After ` it works as a stack and after ~ as a queue, and a program can switch as often as it likes. ^ moves a value from the store to the back of an argument queue and % copies one there. Arithmetic, output, loops and ifs never read the store; they take their operands from the front of that queue, and what they make goes back in the store. The quotes come from Befunge.
The machine
| Command | Does |
|---|---|
'12' | Add the number 12 to the store |
"text" | Add the code of each character in turn |
^ % | Move or copy a value from the store to the argument queue |
, | Throw away a value from the store |
+ - * / | | Add, subtract, multiply, divide or take the modulo of two arguments |
= _ > < | 1 or 0 for equal, not equal, greater, less |
$ # | Print an argument as a number, with or without a line break |
@ ! | Print an argument as a character, with or without a line break |
& ? | Read a line as a number, or as its characters |
{ ... } | Go back to the { while the argument } takes is 1 |
[ ... ] | Run what is between only if the argument is 1 |
a backtick, ~ | Stack mode, queue mode |
. | Stop |
Both modes add at the back. The stack takes from the back and the queue from the front. A command with two arguments takes the first from the front of the argument queue, then the second. Every other character is a comment. The specification does not say which mode comes first; in this implementation it is the stack.
Example
The Hello world pushes its text backwards, so H is on top.
The Hello world pushes its text backwards, so H is on top. The loop prints the top, compares it with ! and goes round while they differ. The version ends with '0'^@, which prints the character with code 0 and a line break; this one stops before that.
The same subtraction in both modes. In stack mode 2 comes off first, in queue mode 9.
The truth machine. On 0 it skips the loop and prints 0. On 1 the loop starts with % while the stack is empty, and that stops the program.
The Fibonacci, '0''1'{~%$^%+`'1'^}, never stops. Queue mode prints the front number and adds the sum at the back; stack mode pushes the 1 that keeps the loop going. It prints 0, 1, 1, 2, 3, 5 and on.
The specification also has eWagon2, which keeps its values in a deque. It is a different language and not this one.
Patterns it teaches
- Stack machines: one store read as a stack or as a queue.
Further
See also
Deque-based
Write your own in Run Convert a program from eWagon
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: ewagon.
Command line
shib run ewagon -e '&^[{%$'\''1'\''^}]'\''0'\''^$. ' --input '0'shib manual ewagonSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/ewagon.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org