AFTL
Every command destroys itself once it has run, and then the program runs again on what is left.
Vriskanon, 2015 · Turing complete: unknown · ●●● hard · esolangs.org
Tested with 3 known programs · Test method
Run it
The idea
Vriskanon made AFTL in 2015. The name is short for Another Fucking Time Loop. A command runs once and is gone from the source. When the run reaches the end it starts over on what is left, so the second pass sees only what the first one left behind. After that pass, or as soon as it meets ., the program ends.
Read the story
There is no command that prints a character. ^ turns itself into the character whose code is on top of the stack, and . prints the whole program as it then stands. So a program writes its output into itself and then prints itself.
The machine
| Command | Does |
|---|---|
" | Duplicate the top of the stack |
+ * | Add or multiply the top two |
- / | The top minus, or divided by, the item below it |
, | Push one byte of input |
( ) | Destroy the cell to the left or right and push its code |
< > | Destroy the cell to the left or right |
^ | Pop a number and become that character |
. | Print the program without this . and stop |
@ | Go back to the start |
[ ] | ] goes back to its [ and destroys both |
~ | Skip the next cell, which stays |
Every character that is not a command is removed before the run starts. Every command except [ and ^ is destroyed once it has run.
Example
The Hello world from the specification.
The Hello world from the specification. )@ pushes 64, the code of @, and destroys the @ without running it. "/ divides 64 by itself, and that 1 stays at the bottom of the stack. Each line builds one code from it and ends in ^, which becomes the character. ~, skips the comma, so it stays in the program as the comma of the greeting. At the end . prints the 13 characters that are left.
The cat reads one byte, turns into it and prints the program, which is now that one character. It copies only the first character of its input.
The time loop. On the first pass each ^ becomes a character of the input, in this case . and x. On the second pass the new . runs and prints what is left.
Patterns it teaches
- Self-modifying code: the program consumes itself and writes new commands for its second pass.
- Code as data: output is whatever text the program has turned itself into.
- Stack machines: every number is built on one stack from the code of a single cell.
Further
See also
Self-modifying
Stack-based
Write your own in Run Convert a program from AFTL
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: aftl.
Command line
shib run aftl -e ',^.' --input 'a'shib manual aftlSource
- Module
langs/wiki/ports.js- Interpreter
langs/wiki/aftl.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org