1 % Inform in four minutes
2 % Roger Firth <roger@firthworks.com>
4 A quick reference to the Inform programming language.
6 Copyright © 2002 Roger Firth <roger@firthworks.com>. Copying and
7 distribution, with or without modification, are permitted in any
8 medium without royalty provided the copyright notice and this notice
11 <http://www.firthworks.com/roger/>
13 Version 1.3 (March 2002)
15 The road to brevity is via imprecision and through solecism.
20 A Z-code **word** literal uses sixteen bits (whereas a Glulx word has
21 thirty-two bits). A **byte** literal is always eight bits.
23 - Decimal: `-32768` to `32767`\
24 Hexadecimal: `$0` to `$FFFF`\
25 Binary: `$$0` to `$$1111111111111111`
28 - Dictionary word: `'aardvark'` (up to nine characters significant);
29 use circumflex "`^`" to denote apostrophe.\
30 Plural word: `'aardvarks//p'`\
31 Single-character word: `"a"` (`name` property only) or `'a//'`
32 - String: `"aardvark's adventure"` (maximum around 4000 characters);
33 can include special values including:
35 ------------- ------------------------------------
42 @\`a a with a grave accent "`à`", et al
43 @LL pound sign "£", et al
44 @00 ... @31 low string 0..31
45 ------------- ------------------------------------
50 The identifier of an Inform *constant*, *variable*, *array*, *class*,
51 *object*, *property*, *attribute*, *routine* or *label*. Up to 32
52 characters: alphabetic (case not significant), numeric and underscore,
53 with the first character not a digit.
55 Expressions and Operators
56 -------------------------
58 Use parentheses (...) to control the order of evaluation.
59 Arithmetic/logical expressions support these operators:
61 ---------- ---------------------------------------------
64 *p * q\* multiplication
65 *p / q* integer division
67 *p++* increments *p*, evaluates to original value
68 *++p* increments *p*, evaluates to new value
69 *p--* decrements *p*, evaluates to original value
70 *--p* decrements *p*, evaluates to new value
73 *\~p* bitwise NOT (inversion)
74 ---------- ---------------------------------------------
76 Conditional expressions return `true` (1) or `false` (0); *q* may be a
77 list of alternatives *q1* `or` *q2* `or` ... *qN*:
79 ---------------- ----------------------------------------
80 *p == q* *p* is equal to *q*
81 *p \~= q* *p* isn't equal to *q*
82 *p* > *q* *p* is greater than *q*
83 *p < q* *p* is less than *q*
84 *p >= q* *p* is greater than or equal to *q*
85 *p <= q* *p* is less than or equal to *q*
86 *p ofclass q* object *p* is of class *q*
87 *p in q* object *p* is a child of object *q*
88 *p notin q* object *p* isn't a child of object *q*
89 *p provides q* object *p* provides property *q*
90 *p has q* object *p* has attribute *q*
91 *p hasnt q* object *p* hasn't attribute *q*
92 ---------------- ----------------------------------------
94 Boolean expressions return `true` (1) or `false` (0):
96 -------- ----------------------------------
97 p && q both p and q are true (non-zero)
98 p || q either p or q is true (non-zero)
99 \~\~p p is false (zero)
100 -------- ----------------------------------
102 To return -1, 0 or 1 based on unsigned comparison:
106 To return `true` if object *q* is a child or grand-child or... of *p*:
108 IndirectlyContains(p,q)
110 To return a random number 1..*N*, or one from a list of constant
114 random(value,value, ... value )
119 Named word values, unchanging at run-time, which are by default
123 Constant constant = expr;
125 Standard constants are `true` (1), `false` (0) and `nothing` (0), also
128 To define a constant (unless it already exists):
130 Default constant expr ;
135 Named word/byte values which can change at run-time and are by default
138 A **global** variable is a single word:
141 Global variable = expr;
143 A **word array** is a set of global words accessed using `array-->0`,
144 `array-->1`, ... `array-->(N-1)`:
147 Array array --> expr1 expr2 ... exprN;
148 Array array --> "string";
150 A **table array** is a set of global words accessed using
151 *array-->1*, *array-->2*, ... *array-->N*, with
152 *array-->0* initialized to *N*:
154 Array array table N ;
155 Array array table expr1 expr2 ... exprN
156 Array array table "string";
158 A **byte array** is a set of global bytes accessed using
159 *array->0*, *array->1*, ... *array->(N-1)*:
162 Array array -> expr1 expr2 ... exprN;
163 Array array -> "string";
165 A **string array** is a set of global bytes accessed using
166 *array->1*, *array->2*, ... *array->N*, with *array->0*
169 Array array string N;
170 Array array string expr1 expr2 ... exprN;
171 Array array string "string";
173 In all these cases, the characters of the initializing *string* are
174 unpacked to the individual word/byte elements of the array. See also
175 Objects (for **property** variables) and Routines (for **local**
178 ## Classes and Objects
180 To declare a *class* - a template for a family of objects -
181 where the optional (*N*) limits instances created at run-time:
184 class class class ... class
185 has attr_def attr_def ... attr_def
190 To declare an *object*; "`Object`" can instead be a *class*, the
191 remaining four header items are all optional, and *arrows*
192 (`->`, `->` `->`, ...) and *parent_object* are incompatible:
194 Object arrows object "ext_name " parent_object
195 class class class ... class
196 has attr_def attr_def ... attr_def
201 The `class`, `has` and `with` (and also the rarely-used `private`)
202 segments are all optional, and can appear in any order.
204 To determine an object's class as one of `Class`, `Object`,
205 `Routine`, `String` (or `nothing`):
209 **has segment**: Each *attr_def* is either of:
214 To change attributes at run-time:
216 give object attr_def attr_def ... attr_def;
218 **with/private segments**: Each *prop_def* declares a variable
219 (or word array) and can take any of these forms (where a
220 *value* is an expression, a string or an embedded routine):
224 property value value ... value
226 A property variable is addressed by *object.property* (or
227 within the object's declaration as *self.property*).
229 Multiple values create a property array; in this case
230 *object.#property* is the number of **bytes** occupied by the
231 array, the entries can be accessed using
232 *object.&property-->0*, *object.&property-->1*, ... , and
233 *object.property* refers to the value of the first entry.
235 A property variable inherited from an object's class is
236 addressed by *object.class::property*; this gives the
237 original value prior to any changes within the object.