Appendix: Quick reference

The bare bones

Comments:

From %% to end of line.

Special characters:

#, $, @, ~, *, |, \, parentheses, brackets, and braces. Prefix by \ to print.

Rule definitions:

Statements:

Value syntax:

#abc

Object name.

@abc

Dictionary word. The @ is optional inside list expressions.

$abc

Variable.

123

Number (the valid range is 0–16383).

[]

Empty list.

[ element1 element2 element3 ... ]

Complete list.

[ element1 element2 element3 ... | tail ]

Partial list.

{ ... }

Closure.

*

Current topic.

The current topic is set with an object name in the leftmost column.

Unification:

Special syntax

{ ... }

Conjunction.

~{ ... }

Negated conjunction.

... (or) ... (or) ...

Disjunction.

(if) ... (then) ... (elseif) ... (then) ... (else) ... (endif)

Conditions are evaluated at most once. Missing else-clause is assumed to be empty, i.e. succeeds.

(select) ... (or) ... (or) ... (stopping)

Branches entered one at a time, then the final branch repeats.

(select) ... (or) ... (or) ... (cycling)

Branches entered one at a time, then the cycle repeats.

(select) ... (or) ... (or) ... (at random)

Branches entered at random, avoiding repetition.

(select) ... (or) ... (or) ... (purely at random)

Branches entered at random, allowing repetition.

(select) ... (or) ... (or) ... (then at random)

First like (select) ... (stopping), then like (select) ... (at random).

(select) ... (or) ... (or) ... (then purely at random)

First like (select) ... (stopping), then like (select) ... (purely at random).

(exhaust) statement

Backtracks over all solutions to the statement (typically a block).

(collect $Element) ... (into $List)

Backtracks over all solutions to the inner expression. Values bound to $Element are collected in order and unified with $List.

(collect words) ... (into $List)

Backtracks over all solutions to the inner expression, grabbing all output. Printed words are diverted into $List, possibly out of order.

(determine object $Obj) ... (from words) ... (matching all of $List)

Backtracks over every object $Obj that makes the first inner expression succeed, and for which the second expression (when exhausted) emits at least every word in $List.

(stoppable) statement

The inner statement executes, succeeding at most once. The (stop) built-in breaks out of the innermost stoppable environment. The stoppable environment itself always succeeds.

(div $Class) statement

The inner statement executes, succeeding at most once. All output is rendered into a rectangular area according to the given style class.

(status bar $Class) statement

Like (div $), but the output is rendered into the status bar area, which is created if necessary.

(now) pseudo-query

Updates a dynamic predicate.

(just)

Removes choice-points created since the current predicate was queried.

(global variable (name of predicate $))

Declares a global variable for holding simple values.

(generate $N (name of predicate $))

Creates $N anonymous objects, for which the predicate will succeed.

Built-in predicates

The list is sorted alphabetically, considering just the non-parameter words.

($X = $Y)

Unifies $X with $Y.

($X < $Y)

Succeeds if $X and $Y are numbers, and $X is strictly less than $Y.

($X > $Y)

Succeeds if $X and $Y are numbers, and $X is strictly greater than $Y.

(bold)

Enables bold text.

(bound $X)

Succeeds if $X is bound to a value.

(breakpoint)

Suspends execution (if running in the debugger).

(clear)

Clears the main window, but not the status bar area.

(clear all)

Clears the screen and disables the status bar.

(compiler version)

Prints the name and version of the compiler.

(display memory statistics)

Displays a backend-specific line of memory usage statistics.

($X divided by $Y into $Z)

Unifies $Z with the quotient after dividing $X by $Y.

(empty $X)

Succeeds if $X is bound to an empty list.

(fail)

Fails. Equivalent in functionality to e.g. (1 = 2).

(fixed pitch)

Enables fixed-pitch text.

(get input $)

Reads a line of input from the player. Returns a list of words.

(get key $)

Waits for the player to press a key. Returns a single-character word.

($X has parent $Y)

Dynamic predicate that succeeds when $X is a direct child of $Y in the object tree. Either parameter can be unbound.

(interpreter supports undo)

Succeeds if the current interpreter claims to support undo.

($X is one of $Y)

Unifies $X with each element of $Y in turn.

(italic)

Enables italic text.

(line)

Requests a line break.

(list $X)

Succeeds if $X is bound to a list (empty or non-empty).

($X minus $Y into $Z)

Unifies $Z with the difference between $X and $Y.

($X modulo $Y into $Z)

Unifies $Z with the remainder after dividing $X by $Y.

(non-empty $X)

Succeeds if $X is bound to an non-empty list.

(no space)

Inhibits automatic whitespace before the next word or punctuation mark.

(number $X)

Succeeds if $X is bound to a number.

(object $X)

Checks if $X is an object, or—in a multi-query—backtracks over every object.

(par)

Requests a paragraph break.

(progress bar $ of $)

Draws a progress bar scaled to fit the width of the current div.

($X plus $Y into $Z)

Unifies $Z with the sum of $X and $Y.

(quit)

Immediately terminates the interpreter.

(random from $X to $Y into $Z)

Unifies $Z with a random number in the range $X to $Y inclusive.

(repeat forever)

Provides an infinite supply of choice points. Generally invoked with a multi-query.

(restart)

Restarts the program.

(restore)

Restores a saved game (the interpreter asks for a filename).

(reverse)

Enables reverse-video text.

(roman)

Disables all text styles (bold, italic, reverse, and fixed pitch).

(save $ComingBack)

Saves the current game (the interpreter asks for a filename). Unifies $ComingBack with 0 after a successful save, 1 after a successful restore.

(save undo $ComingBack)

Saves the current program state in memory. Unifies $ComingBack with 0 after a successful save, 1 after a successful restore.

(script off)

Disables transcription.

(script on)

Enables transcription (the interpreter asks for a filename).

(serial number)

Prints the serial number (compilation date) of the current program.

(space)

Forces whitespace before the next word or punctuation mark.

(space $N)

Prints $N space characters.

(split $X by $Y into $Left and $Right)

Splits $X into two halves around each occurrence of a keyword from $Y.

(stop)

Breaks out of the innermost (stoppable) environment.

($X times $Y into $Z)

Unifies $Z with the product of $X and $Y.

(trace off)

Disables query tracing.

(trace on)

Enables query tracing.

(undo)

Restores the program state at the time of the latest (save undo 0).

(unstyle)

Select the default text style for the current division.

(uppercase)

Convert the next printed character to uppercase.

(word $X)

Succeeds if $X is bound to a dictionary word.

(word representing backspace $Char)

Unifies $Char with the single-character word that represents the backspace key.

(word representing down $Char)

Unifies $Char with the single-character word that represents the down arrow key.

(word representing left $Char)

Unifies $Char with the single-character word that represents the left arrow key.

(word representing return $Char)

Unifies $Char with the single-character word that represents the return key.

(word representing right $Char)

Unifies $Char with the single-character word that represents the right arrow key.

(word representing space $Char)

Unifies $Char with the single-character word that represents the space key.

(word representing up $Char)

Unifies $Char with the single-character word that represents the up arrow key.

Entry points and metadata predicates

(error $ErrorCode entry point)

Execution restarts here when a fatal error has occurred.

(program entry point)

Normal execution starts here.

(story author)

Metadata: Defines the author of the story.

(story blurb)

Metadata: Defines the blurb for the story.

(story ifid)

Metadata: Defines the IFID of the story.

(story noun)

Metadata: Defines the noun (also known as the headline) of the story.

(story release $N)

Metadata: Defines the release number of the story.

(story title)

Metadata: Defines the title of the story.

(removable word endings)

Defines one or more word endings that can be removed when parsing user input.

(style class $Name)

Associates one or more style attributes with the given class name.