| Chapter 16: Understanding |

| 16.18. Precedence

When several different lines of grammar are supplied to meet the same circumstances, it makes a big difference what order they are tried in. For instance, suppose we have:

> Understand "photograph [a door]" as photographing.

> Understand "photograph [an open door]" as photographing.

The second line is more specific than the first, so Inform takes these grammar lines the other way around: it checks for "open door" before it checks for "door". That didn't matter here, since both lines came out with the same result (the action of photographing), but it matters very much in the next example:

> Understand "employ [a door]" as opening.

> Understand "employ [an open door]" as entering.

More subtle is a line already seen:

> Understand "on/in/inside" or "on top of" as "[within]".

Here Inform puts "on top of" before "on/in/inside", since otherwise only the "on" of "on top of" will be recognised.

Mistakes always take precedence over non-mistakes: this is intended to make sure that

> Understand "take umbrage" as a mistake ("Nobody takes umbrage in this game, mister.").

will take precedence over

> Understand "take [something]" as taking.

even if there is, in fact, a character called Mr Nimbus Umbrage so that the command could conceivably make sense.

247
| Example Some Assembly Required Building different styles of shirt from component sleeves and collars.

We now have the mechanisms in place to do some fairly sophisticated renaming of objects. For instance: "Some Assembly Required" Garment type is a kind of value. The garment types are vest, t-shirt, polo shirt, mandarin blouse, button-down, shell, experiment. Every turn: assign identities. When play begins: assign identities. To assign identities: repeat with item running through torsos begin; reassess item; end repeat. To reassess (item - a torso): if the number of things which are part of the item is 0 begin; change garment type of the item to vest; rule succeeds; end if; if exactly two short sleeves are part of the item begin; if a collar is part of the item, change garment type of the item to polo shirt; otherwise change garment type of the item to t-shirt; rule succeeds; end if; if exactly two long sleeves are part of the item begin; if a collar is part of the item, change garment type of the item to button-down; otherwise change garment type of the item to mandarin blouse; rule succeeds; end if; if a collar is part of the item and the number of sleeves which are part of the item is 0, change garment type of the item to shell; otherwise change garment type of the item to experiment. Before cutting something which is worn by the player: try taking off the noun. Instead of cutting something when something is part of the noun: say "You cut up [the noun], snipping off [a list of things which are part of the noun]."; now every thing which is part of the noun is in the holder of the noun. Instead of cutting something which is part of something: say "You carefully snip [the noun] free."; now the player carries the noun. Rule for printing the name of a torso: say "[garment type]". A torso is a kind of thing. A torso is always wearable. Understand "shirt" or "blouse" as a torso. A torso has a garment type. Understand the garment type property as describing a torso. A sleeve is a kind of thing. A short sleeve is a kind of sleeve. A long sleeve is a kind of sleeve. A collar is a kind of thing. Understand "sew [something] to [something]" as affixing it to. Affixing it to is an action applying to two things. Carry out affixing something to something: now the noun is part of the second noun. Report affixing something to something: assign identities; say "You sew [the noun] on, creating [a second noun]." Understand the command "stitch" as "sew". Instead of affixing something to something when the second noun is worn: say "You're wearing [the second noun]!" Instead of affixing a torso to something: if the second noun is a torso, say "Couture for Siamese twins is a daring field, but a bit of a niche market."; otherwise try affixing the second noun to the noun. Instead of affixing a sleeve to something when at least two sleeves are part of the second noun: say "[The second noun] already sports [a list of sleeves that are part of the second noun]." Instead of affixing a collar to something when a collar is part of the second noun: say "[The second noun] already sports [a list of collars that are part of the second noun]." Instead of examining something when something is part of the noun: say "Stitched to [the noun] [is-are a list of things which are part of the noun]." Here is where the issue of precedence arises. We want to encourage Inform to select a cuttable object that is part of something else, rather than one of the spares: Definition: a thing is removable if it is part of something. Understand "cut [removable thing]" as cutting. The Boutique is a room. "Still festively strewn with the confetti and streamers of the Grand Opening party, and still almost totally customer-free." The player carries a torso. The player carries three short sleeves. The player carries two long sleeves. The player carries two collars. Test me with "sew collar to shirt / i / sew short sleeve to shirt / g / i / x polo shirt / cut collar / i / cut shirt / sew long sleeve to shirt / i / sew long sleeve to shirt / i / sew collar to shirt / g / i / wear button-down".

248
| Example Lakeside Living Similar to "Lemonade", but with bodies of liquid that can never be depleted, and some adjustments to the "fill" command so that it will automatically attempt to fill from a large liquid source if possible.

Previous | Contents | Next