§17.21. 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.

Finally, there are a few grammars where the number of values produced is different in different lines. For example, the Standard Rules include these among the possible "put" commands:

Understand "put [something preferably held] on" as wearing.
Understand "put [other things] on/onto [something]" as putting it on.

One produces a single object, the other produces two. Inform gives precedence to the first of these, that is, it tries the one with fewer values first. This is important when reading commands like "PUT MARCH ON WASHINGTON SHIRT ON", and also prevents bogus auto-completions, in which PUT HAT ON might wrongly be auto-completed as if it were PUT HAT ON THE TABLE.


arrow-up.pngStart of Chapter 17: Understanding
arrow-left.pngBack to §17.20. Understanding mistakes
arrow-right.pngOnward to Chapter 18: Activities: §18.1. What are activities?

We now have the mechanisms in place to do some fairly sophisticated renaming of objects. For instance:

paste.png "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:
        reassess item.

To reassess (item - a torso):
    if the number of things which are part of the item is 0:
        now garment type of the item is vest;
        rule succeeds;
    if exactly two short sleeves are part of the item:
        if a collar is part of the item,
            now garment type of the item is polo shirt;
        otherwise now garment type of the item is t-shirt;
        rule succeeds;
    if exactly two long sleeves are part of the item:
        if a collar is part of the item,
            now garment type of the item is button-down;
        otherwise now garment type of the item is mandarin blouse;
        rule succeeds;
    if a collar is part of the item and the number of sleeves which are part of the item is 0, now garment type of the item is shell;
    otherwise now garment type of the item is 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".

*ExampleSome 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:

paste.png "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:
        reassess item.

To reassess (item - a torso):
    if the number of things which are part of the item is 0:
        now garment type of the item is vest;
        rule succeeds;
    if exactly two short sleeves are part of the item:
        if a collar is part of the item,
            now garment type of the item is polo shirt;
        otherwise now garment type of the item is t-shirt;
        rule succeeds;
    if exactly two long sleeves are part of the item:
        if a collar is part of the item,
            now garment type of the item is button-down;
        otherwise now garment type of the item is mandarin blouse;
        rule succeeds;
    if a collar is part of the item and the number of sleeves which are part of the item is 0, now garment type of the item is shell;
    otherwise now garment type of the item is 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".

We now have the mechanisms in place to do some fairly sophisticated renaming of objects. For instance:

paste.png "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:
        reassess item.

To reassess (item - a torso):
    if the number of things which are part of the item is 0:
        now garment type of the item is vest;
        rule succeeds;
    if exactly two short sleeves are part of the item:
        if a collar is part of the item,
            now garment type of the item is polo shirt;
        otherwise now garment type of the item is t-shirt;
        rule succeeds;
    if exactly two long sleeves are part of the item:
        if a collar is part of the item,
            now garment type of the item is button-down;
        otherwise now garment type of the item is mandarin blouse;
        rule succeeds;
    if a collar is part of the item and the number of sleeves which are part of the item is 0, now garment type of the item is shell;
    otherwise now garment type of the item is 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".

***ExampleLakeside 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.