esolang

MechaniQue

A language for text adventures with no variables. A line runs only while the program holds the keys to its locks.

Gabor de Mooij, 2006 · Turing complete: unknown · ●○○ easy · esolangs.org

Tested with 12 known programs · Test method

Run it

Expected: there are 3 left... oops I broke one! there are 2 left... oops I broke one! there are 1 left... oops I broke one!

The idea

Gabor de Mooij designed MechaniQue in 2006 for writing interactive fiction. It has no variables and no IF. Every line carries locks instead, and the program holds keys, like the inventory in an adventure. +lantern adds the key lantern, and a line marked {lantern} runs only while the program has it. When the player answers a question, the answer becomes a key too. Typing a gives the key _a.

Read the story

Version 2.0 added counts. +lamp*10 adds ten lamps, {lamp*2} opens with two or more, and %%lamp%% prints how many there are. With a jump, that is enough for a loop.

The machine

A program is a book of lines, each @[label]{lock}^action, and it ends at @fin. A line can hold more than one action, joined by |.

PartDoes
{key} {key*3}Opens with the key, or with 3 of it
{!key}Opens without the key
{$key}A slot. Opens with the key, and takes it when the line runs
{OR}Opens if one of the locks before it opens
{a}<< and >>Lock every line from here down to the line marked >>
^:textPrint the text; ^:;text prints it only the first time
^+key ^-key*5Add a key, drop five
^->label ^<-Jump to a label, jump back
^?Ask; the answer without its spaces becomes the key _answer
^#textA comment

Each question also gives the system keys ZERO, which the first line with locks that opens takes away, so {ZERO} works as an else, and ROT1 to ROT6 in turn. Answering #exit ends the book. This implementation leaves out the keys that need chance or the date (DICE, TWIST, OCC), PATH, and TIME, whose rule and example in the specification disagree.

Example

The loop, with 3 lamps in place of 10.

The loop, with 3 lamps in place of 10.

The vending machine. The coin sits in a slot, so the first a takes it and the second finds none left.

Expected: a. insert coin into vending machine OK you got yourself a coke. a. insert coin into vending machine no more coins! a. insert coin into vending machine

ZERO as an else.

Expected: you entered something ELSE..

The extended locks, with only the key a. The first << locks the lines below it on a, the second adds b, and each >> lifts one again.

Expected: this line needs a this line needs a as well this line needs a

Patterns it teaches

Further

Also in Camouflage

Write your own in Run Convert a program from MechaniQue

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: mechanique.

Command line

shib run mechanique -e '@[start]^:;this text will dissappear..	
@^?
@^->start' --input 'look
look
#exit
'
shib manual mechanique

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/mechanique.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org