Fob
A stack of strings and one accumulator. The only loop is "start the whole program again", so useful programs are quines.
Tslil Clingman, 2010 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Tslil Clingman (Hiato on the wiki) made Fob in 2010 by, in the author's words, gluing together several abandoned ideas. It mixes a stack with an accumulator, like a tiny assembly language, and it has two modes. In execution mode each character is a command. In accumulator mode each character is appended to the accumulator, which is a string.
Read the story
No command takes an argument, so everything goes through the accumulator and the stack. The trick is =: it runs the accumulator as code. A program builds text, then runs that text as a program, which may build more text.
There is one control structure, @, which restarts the current program while keeping the stack and the accumulator. To loop, a program must rebuild itself or be a careful state machine. The author believes Fob can simulate a tag system, but it has not been shown.
The machine
A stack of strings (it starts with one empty string) and a string accumulator.
| Char | Does |
|---|---|
$ | Switch to accumulator mode |
# | Switch back to execution mode |
: | In accumulator mode, append the next character as is |
< | Push the accumulator |
> | Pop and print |
. | Swap the top two |
/ | Move the top to the bottom |
& | Clear the accumulator |
% | Pop and append to the accumulator |
? | If the accumulator is empty, pop and discard |
= | Run the accumulator as code, on the same stack and accumulator |
@ | Restart the current program |
Any other character in execution mode is a comment. There is no input. Printing, swapping or popping with too few strings is an error, as in the Python reference.
Example
$ enters accumulator mode and :# puts a literal # in the accumulator, so the accumulator ends up holding…
$ enters accumulator mode and :# puts a literal # in the accumulator, so the accumulator ends up holding the program #&$Hello, World!#<>. The final #= returns to execution mode and runs it. That inner program clears the accumulator, collects Hello, World!, pushes it and prints it.
Patterns it teaches
- Stack machines: a stack of strings instead of numbers.
- Code as data: the accumulator is both a string and a program.
- Quine: with restart as the only loop, self-reproduction is how you repeat.
Try this
- Print
aband thencd, using two pushes and two prints. - Run the tally program
$:#&$1:#<<>&#<.&$:#.%&%<%<<>&#<.&%?<.&%=@with a step limit and explain why the output doubles. - Hard: work out how the 135-character quine copies itself.
Further
- esolangs.org/wiki/Fob, with the Python reference implementation.
See also
Stack-based
Write your own in Run Convert a program from Fob
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: fob.
Command line
shib run fob -e '$Hello, World#<>'shib manual fobSource
- Module
langs/stack/ports.js- Interpreter
langs/stack/fob.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org