Forget
A stack language where pointers are poisonous and the interpreter does not do a good job of remembering anything.
Benjamin Urquhart · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 4 known programs · Hello World on Try It Online: identical · Test method
Run it
The idea
Benjamin Urquhart wrote Forget as a joke on manual memory management. push 72 does not push 72. It puts 72 in a fresh memory cell somewhere and pushes a pointer to it, and that pointer is poisoned. Any attempt to read through it is a segfault until cleanse makes it safe. So printing one character takes four instructions, push 72;cleanse;pop;out.
Read the story
Then the memory forgets. Every cell made while the program runs has a random lifetime of up to 999 instructions, renewed each time it is read. A cell that goes unread too long is freed, and reading a freed or unknown address is a coin toss between random garbage and a segfault. Only cells declared with const before the program starts are safe for good. TIO's Hello World can fail for exactly this reason, since each of its 13 cells has to last four instructions.
The machine
| Instruction | Does |
|---|---|
push n | Store n in a new cell, push a poisoned pointer to it |
cleanse cleanse 0xA | Make the current pointer, or the one at address A, safe |
pop | Take the top pointer as the current one |
out dump | Print the current cell as a character; print and pop everything |
read 0xA | Make address A current |
in hasin | Read a byte; loop while input is waiting |
while 0xA ... end | Loop while the cell at A is above 0 |
add x y sub x y | Add or subtract numbers or cells, pushing a pointer to the result |
const 0xA n | A cell that never fades, allowed only at the start |
Instructions are separated by ;. The interpreter has quirks of its own. A cleanse without an address remembers the first pointer it was given, so in a loop it keeps cleansing that one, and a loop that ends skips one more instruction after its end.
Example
The second program adds 2 to 40 and prints character 42.
The second program adds 2 to 40 and prints character 42. The result of add gets a new poisoned pointer, hence the second cleanse. This implementation draws its random lifetimes from a fixed seed, so each program does the same thing every time it runs.
Patterns it teaches
- Hostile design: the language works against you on purpose.
- Nondeterminism: the same program can print, print garbage or crash.
- Stack machines: a stack of pointers rather than of values.
Further
See also
Stack-based
Write your own in Run Convert a program from Forget
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: forget.
Command line
shib run forget -e 'push 40;cleanse;add 2;cleanse;out'shib manual forgetSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/forget.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org