X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=informqr%2Finformqr.md;h=9e3f72d7f641b03eb5f1bbd52536376707d83a04;hb=842cdcf6dea5feaeeb6db4b6c3ef014785cc1f09;hp=eea256baa78e9c8df3aab8b3c611da1b1405a515;hpb=b4e6f6f6d6289dc48db053be2149be75050cbc2e;p=inform-resources.git diff --git a/informqr/informqr.md b/informqr/informqr.md index eea256b..9e3f72d 100644 --- a/informqr/informqr.md +++ b/informqr/informqr.md @@ -1,4 +1,4 @@ -o% Inform in four minutes +% Inform in four minutes % Roger Firth A quick reference to the Inform programming language. @@ -302,4 +302,222 @@ A common statement is the assignment: There are two forms of multiple assignment: variable = variable = ... = expr ; - variable = expr, variable = expr, ... ; \ No newline at end of file + variable = expr, variable = expr, ... ; + +Routines +-------- + +A routine can have up to 15 local variables: word values which are +private to the routine and which by default are set to zero on each +call. Recursion is permitted. + +A **standalone** routine: + +- has a name, by which it is called using `routine();` can also be + called indirectly using + + indirect(routine,a1,a2, ... a7) + +- can take arguments, using `routine(a1,a2, ... a7)`, whose values + initialise the equivalent local variables + +- returns true at the final "]" + + [ routine + local_var local_var ... local_var ; + statement; + statement; + ... + statement; + ] + +A routine **embedded** as the value of an object property: + +- has no name, and is called when the property is invoked; can also + be called explicitly using object.property() + +- accepts arguments only when called explicitly + +- returns false at the final "]" + + property [ + local_var local_var ... local_var; + statement; + statement; + ... + statement; + ] + +Routines return a single value, when execution reaches the final "\]" +or an explicit return statement: + + return expr; + return; + rtrue; + rfalse; + +To define a dummy standalone routine with N local variables (unless it +already exists): + + Stub routine N; + +Flow control +------------ + +To execute statements if *expr* is true; optionally, to execute other +statements if *expr* is false: + + if (expr) + statement_block + if (expr) + statement_block + else + statement_block + +To execute statements depending on the value of *expr*: + + switch (expr) { + value: statement; ... statement; + value: statement; ... statement; + ... + default: statement; ... statement; + } + +where each *value* can be given as: + + constant + lo_constant to hi_constant + constant,constant, ... constant + +Loop control +------------ + +To execute statements while *expr* is true: + + while (expr) + statement_block + +To execute statements until *expr* is true: + + do + statement_block + until (expr) + +To execute statements while a variable changes: + + for (set_var : loop_while_expr : update_var ) + statement_block + +To execute statements for all defined objects: + + objectloop (variable) + statement_block + +To execute statements for all objects selected by *expr*: + + objectloop (expr_starting_with_variable) + statement_block + +To jump out of the current innermost loop or switch: + + break; + +To immediately start the next iteration of the current loop: + + continue; + +Displaying information +---------------------- + +To output a list of values: + + print value,value, ... value; + +To output a list of values followed by a newline, then return `true` +from the current routine: + + print_ret value,value, ... value; + +If the first (or only) *value* is a string, "`print_ret`" can be +omitted: + + "string",value, ... value ; + +Each *value* can be an expression, a string or a rule. + +An **expression** is output as a signed decimal value. + +A **string** in quotes "..." is output as text. + +A **rule** is one of: + + -------------------- ------------------------------------------------ + `(number)` *expr* the *expr* in words + `(char)` *expr* the *expr* as a single character + `(string)` *addr* the string at the *addr* + `(address)` *addr* the dictionary word at the *addr* + `(name)` *object* the external (short) name of the object + `(a)` *object* the short name preceded by "a/an" + `(the)` *object* the short name preceded by "the" + `(The)` *object* the short name preceded by "The" + `(routine)` value the output when calling `routine(value)` + -------------------- ------------------------------------------------ + +To output a newline character: + + new_line; + +To output multiple spaces: + + spaces expr; + +To output text in a display box: + + box "string " "string " ... "string "; + +To change from regular to fixed-pitch font: + + font off; + ... + font on; + +To change the font attributes: + + style bold; ! use one or more of these + style underline ; ! + style reverse ; ! + ... + style roman; + +Uncommon and deprecated statements +---------------------------------- + +To jump to a labelled statement: + + jump label; + ... + .label; statement; + +To terminate the program: + + quit + +To save and restore the program state: + + save label; + ... + restore label; + +To output the Inform compiler version number: + +inversion; + +To accept data from the current input stream: + + read text_array parse_array routine; + +To assign to one of 32 'low string' variables: + + string N "string"; + Lowstring string_var "string"; + string N string_var; \ No newline at end of file