esolang

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

Expected: Hello, World!

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

CodeDoes
x = 5 local x = 5Set a variable here or in the scope that already has it
x++ x += 2Change 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 writebytePrint with a newline, without, a character code
read readlineAll of the input, or its next line
ord chr eval destroyCharacter 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.
Expected: three
Expected: now later
Expected: 9
Expected: 0

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

  1. Print the numbers 1 to 5 with one when and one assignment.
  2. Print tick three times, a second apart.
  3. Hard: the specification's truth machine prints 1 forever on input 1. Work out why it never stops.

Further

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 maybelater

Source

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