esolang

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

Expected: Hi

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

InstructionDoes
push nStore n in a new cell, push a poisoned pointer to it
cleanse cleanse 0xAMake the current pointer, or the one at address A, safe
popTake the top pointer as the current one
out dumpPrint the current cell as a character; print and pop everything
read 0xAMake address A current
in hasinRead a byte; loop while input is waiting
while 0xA ... endLoop while the cell at A is above 0
add x y sub x yAdd or subtract numbers or cells, pushing a pointer to the result
const 0xA nA 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.
Expected: *
Expected: cat

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

Further

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 forget

Source

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