Maybe Later
No loops and no functions. Code runs when something happens, when a variable is set to a value or when enough time has passed.
TehFlaminTaco, 2017 · Turing complete: yes · ●●○ moderate · esolangs.org
Tested with 6 known programs · Hello World on Try It Online: identical except the line end · Test method
Run it
The idea
Maybe Later looks like a small scripting language, with variables, strings, tables and if. The flow of control is the odd part. Besides if, the only way to make code run is when. when x is 3 { … } hangs a block on the variable x, and the block runs every time x is set to 3, in the middle of the assignment that set it. when 2 second pass { … } runs a block later. The plural seconds does not work, because the grammar tries second first and then finds an s where it wants pass.
Read the story
An assignment gives back the variable's value after its events have run. That is how the Fibonacci program recurses. Setting fib to 0 starts the calculation, the event sets fib to the answer, and print fib = 0 prints it.
The machine
| Code | Does |
|---|---|
x = 5 local x = 5 | Set a variable here or in the scope that already has it |
x++ x += 2 | Change a number, which also fires events |
when x is 5 {…} when x is * {…} | Run the block whenever x is set to 5, or to anything |
when 3 s pass {…} | Run the block after three seconds |
if x > 3 {…} else {…} | Run one of two blocks |
print write writebyte | Print with a newline, without, a character code |
read readline | All of the input, or its next line |
ord chr eval destroy | Character codes, run a string, stop an event |
This implementation follows interpreter.js, the JavaScript interpreter Try It Online runs, and parses with the same grammar in the same way. Its quirks stay. Arithmetic is worked out right to left, so 10 - 4 - 3 is 9. ^ is exclusive or. Names run together, so printa prints a. A month is one day long, and a year is a tenth of a real one. Time is a clock that only moves when a timer fires, so the waits cost nothing and every run replays.
Example
The second program prints once, at the moment x becomes 3.
The second program prints once, at the moment x becomes 3. The third prints now first, because the timer only fires after the program's last line. The last is the start of a truth machine, which reads the input into n.
Patterns it teaches
- Turing completeness: events that set the variables they wait on are enough for recursion, as the Fibonacci program on the specification shows.
Try this
- Print the numbers 1 to 5 with one
whenand one assignment. - Print
tickthree times, a second apart. - Hard: the specification's truth machine prints 1 forever on input 1. Work out why it never stops.
See also
Also in Strange time
Write your own in Run Convert a program from Maybe Later
Implementation
JavaScript interpreter, source and command line
A JavaScript interpreter, used in the browser and on the command line. Id: maybelater.
Command line
shib run maybelater -e 'print readall a' --input 'cat food'shib manual maybelaterSource
- Module
langs/tio/ports.js- Interpreter
langs/tio/maybelater.js
Docs: Kernel instructions · The .shib format · Command line · Adding a language
Source esolangs.org (CC0) · Edit on esolangs.org