25.14. Defining phrases in Inform 6

| Chapter 25: Extensions |

| 25.14. Defining phrases in Inform 6

The phrases described in this documentation, such as "end the story", are all defined in the Standard Rules, and are for the most part defined not in terms of other I7 phrases but instead reduced to equivalents in I6. For instance:

> To end the game in death: (- deadflag=3; story_complete=false; -).

The notation "(-" and "-)" indicates that what comes in between is I6 code. The minus sign is supposed to be a mnemonic for the decrease from 7 to 6: later we shall use "(+" and "+)" to go back up the other way, from 6 to 7.

When a phrase is defined as containing only a single command, and that command is defined using I6 - as here - it is compiled in-line. This means that the phrase "end the game in death" will always be translated as "deadflag=1;", rather than being translated into a call to a suitable function whose only statement is "deadflag=1;".

This is an easy case since the wording never varies. More typical examples would be:

> To say (something - number): (- print {something}; -).
> To sort (T - table name) in (TC - table column) order:
> (- TableSort({T}, {TC}, 1); -).

When the braced name of one of the variables in the phrase preamble appears, this is compiled to the corresponding I6 expression at the relevant position in the I6 code. So, for instance,

> say the capacity of the basket

might be compiled to

> print O17_basket.capacity;

because "{something}" is expanded to "capacity of the basket" (I7 code) and then translated to "O17_basket.capacity" (I6 code), which is then spliced into the original I6 definition "print {something};".

Braces "{" are of course significant in I6. A real brace can be obtained by making the character following it a space, and then I7 will not attempt to read it as a request for substitution.

Finally, note that while a normal I7 phrase definition can give a kind as what must be matched, e.g.,

> To release wild tigers into (arena - a room): ...

it is in general a bad idea, and will result in inefficient code, for an phrase defined using I6 to do this. Instead, if possible, match against "object", where any room, region, thing or direction will be a valid match:

> To release wild tigers into (arena - an object): ...

440
| Example Odins Making [is-are] and [it-they] say tokens that will choose appropriately based on the last object mentioned. |
RB

The faithful reader may recall this example from the previous chapter. It was always a bit flawed, though, because it didn't account very well for the possibility that our game might contain some intrinsically plural items. Here we define a "to say is-are" ability, checking the appropriate either/or property - "plural-named". "Odins" The House of a Mortal Farmer is a room. "Having two separate rooms, this house testifies to considerable wealth and success at agriculture." The Bedroom is inside from the House. A chair is a kind of supporter. A chair is always enterable. In the House are a table, two chairs, a basket, and a hearth. On the table is a loaf of bread. Some shoes are on the table. The description of a thing is usually "You give [the noun] a glance, but [it-they] [is-are] plainly beneath your attention." The infant is a man in the basket. The description of the infant is "So strong and fat that you wonder whether one of your fellow gods is acquainted with the mistress of the house-- but it's no concern of yours, of course." The last mentioned thing is a thing that varies. After printing the name of something (called the target): now the last mentioned thing is the target. To say is-are: if the last mentioned thing is plural-named, say "are"; otherwise say "is". To say it-they: if the last mentioned thing is plural-named, say "they"; otherwise say "it". Test me with "x chair / x basket / x infant / x shoes".

441
| Example Pink or Blue Asking the player to select a gender to begin play. |
RB

Previous | Contents | Next