13. Relations

Writing with Inform

WI §13.1 Sentence verbs

Descriptions of things – "open door", "people in the Drawing Room" – have already had a whole chapter to themselves. But descriptions are only half of the story of Inform's highly flexible language for talking about places, things and circumstances: this chapter is the other half, and is about the "sentence". Of course all text is made up of sentences, but Inform has a more specific meaning than that. Consider the following pieces of source text:

The mouse is in the teapot.
Every turn when the mouse is in the teapot, say "A tail hangs out of the spout."
Instead of taking the mouse:
   say "The mouse slips from your hand and disappears into the teapot!";
   now the mouse is in the teapot.

What these three extracts have in common is the sentence "the mouse is in the teapot". Such a sentence can be used in three different ways: to declare the original state of the world, to ask during play if the world currently has that state, or to change things during play so that it does.

Actually, though, only definite sentences about the present can be used in all three ways. A vague instruction like

now Mr Darcy can see the mouse;

will fail, because there are so many ways in which Darcy might be able to see the mouse that Inform has no way to know how to arrange matters. And this by contrast is not merely difficult but impossible:

now Mr Darcy has never seen the mouse;

Which cannot be arranged because the past cannot be changed.

Verbs also turn up inside the more complicated descriptions. For instance,

things which are in the teapot
people who can see the mouse

are both descriptions, not sentences, but they contain "to be" and "to be able to see" respectively.

This chapter is about the verbs which can be used in sentences and descriptions. Inform involves many other features which use verbs – the action "taking the mouse" and the phrase "end the story" both use forms of verbs (to take and to end) – but this chapter has nothing to do with them: so for the sake of clarity, we will call verbs that occur in sentences "sentence verbs".

WI §13.2 What sentences are made up from

A sentence consists of two nouns with a verb between them. Usually, the two nouns are descriptions, as in:

Mr Collins is in a lighted room.

Here "Mr Collins" and "a lighted room" are descriptions. But there are sentences where one or both of the nouns is a value of some other kind. For instance, in

if the score is greater than 10, ...

the sentence "the score is greater than 10" consists of two number values ("the score" and "10") connected by a verb part ("is greater than").

This chapter is about getting the most out of sentences by defining new verbs to express ideas not already built in to Inform. Before we can define a new sentence verb, however, we must first look at the meanings of verbs: which Inform calls "relations".

Example

A more formal description of the sentence grammar used by Inform for both assertions and conditions.

WI §13.3 What are relations?

Relations are what sentences express. They are yes/no questions about pairs of things: for example, to say that the coin is in the purse is to say that a particular relation ("being in") is true about a specific pair of things (the coin, the purse). It is neither a fact about the coin nor about the purse, but about the two together.

Inform comes with a number of relations built in, almost all of which have been used in previous chapters already. The following table names some of the more useful ones, giving examples of sentences to bring them about:

containment relation - The coin is in the purse.
support relation - The coin is on the table.
incorporation relation - The coin is part of the sculpture.
carrying relation - The coin is carried by Peter.
wearing relation - The jacket is worn by Peter.
possession relation - if Mr Darcy has a rapier...
adjacency relation - The Study is east of the Hallway.
visibility relation - if Darcy can see Elizabeth...
touchability relation - if Darcy can touch Elizabeth...

These relation names do not trip off the tongue, but they relatively seldom need to be referred to.

The same meaning can often be expressed by using several different verbs, or using the same verb in several different ways, as in the following examples:

The coin is in the purse.
The purse contains the coin.
The coin is contained by the purse.

all of which boil down to saying that the coin and purse satisfy the containment relation. Because of that, relations are not the same as verbs. To create a new idea, we will need first to create a new relation, and only then can we set up a verb which allows us to talk about that relation.

WI §13.4 To carry, to wear, to have

Inform has altogether five mutually exclusive ways in which one thing can be physically joined to another one:

containment relation - The coin is in the purse.
support relation - The coin is on the table.
incorporation relation - The coin is part of the sculpture.
carrying relation - The coin is carried by Peter.
wearing relation - The jacket is worn by Peter.

This is why we cannot have

The coin is on the table.
The coin is part of the table.

simultaneously, and it is a rare exception to the general rule that having one relation does not affect having another.

We have discussed how the holding relation applies if any one of those relations does. Another relation, similarly, is the union of two of them.

The possession relation is the meaning of the verb "to have". At first sight this seems the same as the carrying relation, but in fact it is a convenient shorthand for carrying or wearing, provided for conditions rather than assertions:

if Mr Darcy has a wet shirt ...

will be true during play if he is either carrying or wearing the shirt.

"to have" *can* be used in now phrase sentences, but in now phrases it always means carrying, only.

Still another relation exists which can be tested, but not declared to be true or false: the concealment relation, which is the meaning of the verb "to conceal". So we can ask:

if Mr Darcy conceals a fob watch ...

Examples

224.
Using the enclosure relation to let the player drop things which he only indirectly carries.
A wand which, when waved, reveals the concealed items carried by people the player can see.

WI §13.5 Making new relations

We can create new relations like so:

Loving relates various people to one person.

Every relation has a name which ends with the word "relation", and in this case the name is "loving relation". While the name is often just two words long, as here, it doesn't have to be:

Adept sensitivity relates one person to one vehicle.

makes the "adept sensitivity relation". (The limit is 32 words.)

In such a definition, we have to say what kind of thing appears on the left and right of any relation, and also whether "one" or "various" possibilities can exist. In the example

Loving relates various people to one person.

what we are saying is that only people love, that they only love people, and that each person loves only one other person (at any given moment).

The "various" part comes in because, for instance, it might be the case that Verenka loves Stankevich *and* Liubov loves Stankevich. So, various people (Verenka and Liubov, to name but two) love one person (Stankevich). But we are forbidding anyone to love two other people at the same time: Stankevich must decide which of them to love, or pick someone else, or no-one at all.

Similarly, because loving relates various people to *one person*, if it had been asserted that Liubov loves Stankevich, a further assertion that Liubov loved Belinsky would result in a compiler error. Note the important difference between assertions and now phrases here. Assertions are what Inform uses to build the initial state of the game world, so it insists on consistency. All the compiler wants is to create the world you intended and any contradiction leaves it unsure what that is.

But relations are subject to change. The assertion that Liubov loves Stankevich only establishes what's true of the game world initially. Assuming we've established that the verb "to love" means the loving relation (more on which soon), any of your rules or phrases could include:

now Liubov loves Belinsky;

If Liubov already loved someone else, this would automatically cause Liubov to *cease* loving that person. With a one-to-one relation, a single now phrase creating a relation between two values could potentially break *two* other previously existing relations.

It is sometimes convenient to give a name to the other side of a relationship, so to speak. We might imagine:

Pet-ownership relates various animals to one person (called the owner).

It would then make sense to talk about "the owner of Loulou", and we could have phrases like "now Flaubert is the owner of Loulou" or "if the owner of Loulou is a woman…" and so forth. This, however, would not be allowed:

Pet-ownership relates various animals (called the pet) to one person.

because "the pet of Flaubert" would be ambiguous: he might have owned dozens.

WI §13.6 Making reciprocal relations

The relationships described in this chapter so far are by no means always reciprocated. For instance, if a stone is on a table, then it is never true that the table is also on the stone. And the question may not even be meaningful to ask. If Peter wears a jacket, the jacket does not even have the possibility of wearing Peter.

But sometimes we do want a relation which works both ways equally well. These are simple to set up:

Meeting relates people to each other.

The effect is that various people know various other people, and this is always reciprocated. If Daisy knows Sophie then, automatically, Sophie knows Daisy. This even-handedness is maintained throughout play, so that whatever changes are made it is always true that if A knows B then B knows A.

And similarly for a reciprocal relation between one and another:

Marriage relates one person to another.

In this case, we can again give a name to the partner under a relation:

Marriage relates one person to another (called the spouse).

and now, for instance, we may have that the spouse of John is Yoko and the spouse of Yoko is John.

Since many of these examples have involved people, it might be worth mentioning again that any kind can be involved, not just the "person" kind.

Example

226.
Four Cheeses ★★★
A system of telephones on which the player can call distant persons and have conversations.

WI §13.7 Relations in groups

Finally, there is a kind of relation which binds even more strongly.

Nationality relates people to each other in groups.

This is a kind of relation which divides people up: we might wish to have all the Icelandic people related to each other, all the Peruvians to each other, and so on. If there were a Pacific island called Informia with one inhabitant, then that person would be related only to himself. As time goes by, we could imagine people emigrating, and so on, so that these groupings would switch: perhaps everyone would leave Belgium and, for a while, there would be no Belgian nationals at all.

The testing command RELATIONS prints out the current state of all the relations created in the source code. For instance:

>relations
Overlooking relates various rooms to various rooms:
   The Pub >=> the Garden
   The Garden >=> the Shrubbery
   The Shrubbery >=> the Sundial Plot
Friendship relates people to each other:
   Mr Wickham <=> Sophie
   Charlotte <=> Sophie
Marriage relates one person to another:
   Mr Wickham == Sophie

That can produce a lot of output. To see only a single relation, or to see it at some intermediate point in a calculation, there's also a testing phrase:

show relation (relation of values to values)

This phrase is for testing purposes only. It shows the current state of the named relation, that is, it shows which values relate to which other ones, where it's possible to do this in any sensible way.

But this is a phrase – not a typed command.

Examples

A machine that turns objects into other, similar objects.
228.
Otranto ★★★
A kind of rope which can be tied to objects and used to anchor the player or drag items from room to room.

WI §13.8 The built-in verbs and their meanings

It is all very well to define new relations, but a verb makes it useful. In fact, a relation is nothing more than what Inform uses as the "meaning" of a verb. The assertion verbs built in to Inform have the following built-in relations as their meanings:

[TODO – more verbs, more discussion of exceptions ]

Verb - Relation
to be - equality relation
to have - possession relation
to contain - containment relation
to support - support relation
to carry - carrying relation
to wear - wearing relation
to incorporate - incorporation relation

Some of Inform's built-in relations are expressed using prepositions:

Preposition - Relation
to be part of - (reversed) incorporation relation
to be adjacent to - adjacency relation

to be in – (reversed) containment relation

to be on – (reversed) support relation

It would be easy to make verbs for these if we wanted ("to adjoin", say) using the techniques of the next section.

The verb to be is grammatically different from any other, and its meaning is too complicated to be fully expressed by any one relation. A great deal of the Inform program is given over to its "meaning", which we are not allowed to change or imitate. The "equality relation" is simple enough, and is the one implied by conditions like

if the score is 20, ...

but to be can have more complicated implications – "if Mr Wickham is hungry" clearly doesn't test whether two quantities are equal. Likewise, to have, to hold, and to contain/to be in have different meanings in different contexts.

There are a few other built-in verbs, as can be seen in the Index, but these are mostly for experts only. For example:

Verb - Relation
to mean - meaning relation
to provide - provision relation

"To mean" can be used to make new verbs, as we'll soon see. Provision is to do with whether something can have a given property: for example, "if R provides the property lighted" tests whether R is able to have this property, not whether it actually has it at the moment.

WI §13.9 Defining new assertion verbs

Here is an example definition of a new verb:

The verb to sport means the wearing relation.

Once this is done, we can write the assertion

Mr Wickham sports a Tory rosette.

which will do the the same thing as

Mr Wickham wears a Tory rosette.

because both verbs have the same relation as their meaning.

[ TODO contradicts the description in 3.20 of these being participles ]

One can also use the present progressive (but not with "to be" or other verbs beginning "to be"):

Mr Wickham is sporting a Tory rosette.

Earlier versions of Inform needed to be told how to make other parts of the verb, but that's rarely true now. Just writing:

The verb to sport means the wearing relation.

is enough for Inform to understand "he sports", "they sport", "he sported", "it is sported", "he is sporting", "he had sported" and so on. It works with irregular verbs, too; it has a very comprehensive dictionary. But it's legal to spell out the conjugation if need be:

The verb to sport (he sports, they sport, he sported, it is sported) implies the knowledge relation.

Occasionally it's convenient to have the relation the other way around. For instance:

The verb to grace means the reversed wearing relation.

With that defined, these two sentences have identical meanings:

Mr Wickham sports a Tory rosette.
A Tory rosette graces Mr Wickham.

Reversed in this sense means that the things related – the subject and object of the verb – are the other way round.

This is so convenient that when you define a verb meaning a relation, Inform automatically creates a "to be (verbed) by" verb that means that relation reversed. So the following are *also* equivalent to the above:

A Tory rosette is sported by Mr Wickham.

Mr Wickham is graced by a Tory rosette.

Possible conditionals include:

if Mr Wickham is sporting a Tory rosette:
if a Tory rosette graces Mr Wickham:
if a Tory rosette is gracing Mr Wickham:

Or, in the negative:

if Mr Wickham does not sport a Tory rosette:
if a Tory rosette does not grace Mr Wickham:
if a Mr Wickham is not graced by a Tory rosette:

While "does *not*" can be used in negatives, "does" or "do" cannot be used in a positive: one cannot say "if Mr Wickham does sport a Tory rosette".

[TODO – not in 10.1 it doesn't. ]

The Phrasebook index contains all the verbs associated with assertions, in the Verbs section. When we add new verbs to our source, those will appear in the Phrasebook as well.

The verbs above are short ones, but we're free to make them longer than that. For example:

The verb to cover oneself with means the wearing relation.
Peter is covering himself with a tent-like raincoat.

Here we have "to cover oneself with", four words long; the limit is 29.

Examples

People are to be grouped into alliances. To kiss someone is to join his or her faction, which may make a grand alliance; to strike them is to give notice of quitting, and to become a lone wolf.
230.
An adaptive hint system that tracks what the player needs to have seen or to possess in order to solve a given puzzle, and doles out suggestions accordingly. Handles changes in the game state with remarkable flexibility, and allows the player to decide how explicit a nudge he wants at any given moment.

WI §13.10 Defining new prepositions

The term preposition is used here, a little loosely, to mean anything which we add to the verb to be in order to talk about some relation or other. We have seen many examples already, such as:

To be in - The ball is in the box.
To be part of - The lever is part of the slot machine.

These are defined just the way verbs are. Compare the following:

Suspicion relates various people to one person.
The verb to suspect means the suspicion relation.
The verb to be suspicious of means the suspicion relation.

The result of this is that

Hercule Poirot suspects Colonel Hotchkiss.
Hercule Poirot is suspicious of Colonel Hotchkiss.

are exactly equivalent, and so are these two descriptions:

somebody who suspects Colonel Hotchkiss
somebody suspicious of Colonel Hotchkiss

While most prepositions are short ("in", "part of", "suspicious of"), they're free to be longer if need be ("inordinately far away from"): the limit is 30 words, which should be ample.

We can also define verbs as auxiliaries, like so:

The verb to be able to approach means the approachability relation.

Now we can ask if Poirot "can approach" Hotchkiss, and so on.

[TODO] not all verbs are created equal.

Examples

A thorough exploration of all the kinds of relations established so far, with the syntax to set and unset them.
Building a marble chute track in which a dropped marble will automatically roll downhill.
An "underlying" relation which adds to the world model the idea of objects hidden under other objects.
234.
Bogart ★★★
Clothing for the player that layers, so that items cannot be taken off in the wrong order, and the player's inventory lists only the clothing that is currently visible.

WI §13.11 Indirect relations

We have already seen, in the chapter on Descriptions which is a forerunner of this one, that Inform provides not only "adjacent" as a way of seeing if one room is directly connected to another, but also "the best route from A to B", which allows us to see if any sequence of moves connects them.

Something similar – in fact, simpler – is allowed for any relation between objects. Suppose we would like to go sledging: we can go downhill, but not up. Some quite distant places may be reachable, while others close by may not be, even if lower than us, because they would involve climbing again at some point. The following would implement this:

Overlooking relates various rooms to various rooms.
The verb to overlook means the overlooking relation.
The Garden overlooks the Shrubbery. The Folly overlooks the Garden. The Shrubbery overlooks the Sundial Plot. The Old Ice House overlooks the Garden.
After looking:
   say "This wintry vantage point overlooks [the list of rooms overlooked by the location].";
   let the way be the next step via the overlooking relation from the location to the Sundial Plot;
   if the way is a room, say "To sledge downhill to the Sundial, aim for [the way].";
   otherwise say "It is not possible to sledge downhill to the Sundial."

Here we're making use of:

next step via (relation of values to values) from (object) to (object)object

This phrase tries to find a shortest route between the two given endpoints, using the given relation of objects to determine single steps. Example:

next step via the overlooking relation from the Folly to the Chinese Lake

The result is the special object value "nothing" if the two endpoints are the same or if no route exists.

number of steps via (relation of values to values) from (object) to (object)number

This phrase tries to find the length of a shortest route between the two given endpoints, using the given relation of objects to determine single steps. Example:

number of steps via the overlooking relation from the Folly to the Chinese Lake

The result is 0 if the two endpoints are the same, or -1 if no route exists.

Another example would be the "six degrees of separation" game, where it is claimed that any two people on Earth are connected by a sequence of up to six acquaintances. In an Inform implementation, we might talk about "the next step via the friendship relation from George Bush to Saddam Hussein", for instance, a phrase likely to evaluate to Donald Rumsfeld, and then

the number of steps via the friendship relation from George Bush to Saddam Hussein

would be… but that would be telling.

As with route-finding through the map, finding "the next step via" a relation can be slow. For instance, suppose we have dozens of articles of clothing all partially revealing each other, connected by two relations – overlying and underlying. Then "the next step via" these relations allows us to establish what can be worn on top of what else. If we need to calculate this often, and there are enormous wardrobes of clothes to choose from, speed starts to matter.

Once again there is a choice of algorithms: "fast" and "slow", where "fast" needs much more memory. To make route-finding for a given relation "fast", we have to declare it that way:

Overlying relates various garments to various garments with fast route-finding.
Overlapping relates various garments to each other with fast route-finding.

Otherwise, the "slow" method will be used.

This "with fast route-finding" note can only be added to various-to-various relations. (Although route-finding through various-to-one and one-to-various relations is fully supported, it exploits the relative simplicity of these problems to use a more efficient algorithm than either "fast" or "slow".)

See Also

Adjacent rooms and routes through the map for route-finding through the map rather than a relation.

Example

235.
A conversation in which the main character tries to build logical connections between what the player is saying now and what went immediately before.

WI §13.12 Relations which express conditions

One last way to create a new relation and, in many ways, the easiest of all. If we write:

Contact relates a thing (called X) to a thing (called Y) when X is part of Y or Y is part of X. The verb to be joined to means the contact relation.

then we would be able to talk about a handle being joined to a door, and a door being joined to a handle, and so on. We are not allowed to declare:

The hook is joined to the line.

because the question of whether they are joined is not for us to decide: that will be for the condition to determine, whenever we test it. Similarly, we cannot meaningfully write

now the hook is joined to the line;

(and Inform will not let us) because this relation is not something we can force either way: we can make it come true by other means, maybe, but we cannot simply make it true by saying so. Lastly, this kind of relation is restricted in that we are not allowed to find paths or calculate numbers of steps through it.

So this way to define relations is, on the face of it, just a sort of verbal trick to write conditions in a more attractive way. The more flexible, changeable relations in previous sections have much greater expressive power. All the same, it is nice to be able to write -

Nearness relates a room (called A) to a room (called B) when the number of moves from B to A is less than 3. The verb to be near means the nearness relation.

and then to be able to write rules like:

Instead of listening when the location is near the Sundial: say "You hear a splashing of water."

As with other relations, there's no reason why we have to use objects. For example:

Material is a kind of value. The materials are wood and metal. A thing has a material.
Materiality relates a thing (called X) to a material (called Y) when Y is the material of X. The verb to be made of means the materiality relation.

which enables us to write:

if the cube is made of wood, ...
say "The carpenter looks at [the list of things which are made of wood].";

And here is a mathematical one:

Divisibility relates a number (called N) to a number (called M) when the remainder after dividing M by N is 0. The verb to divide means the divisibility relation. The verb to be a factor of means the divisibility relation.

We now find that "2 divides 12", "5 is not a factor of 12" and "12 is divisible by 3" are all true. Again, we are only really gaining a nice form of words, but improving the clarity of the source text is never a bad thing.

Examples

A technical note about checking the location of door objects when characters other than the player are interacting with them.
Relations track the relationships between one character and another. Whenever the player meets a relative of someone he already knows, he receives a brief introduction.

WI §13.13 Relations involving values

[ TODO verb equivalents ]

Although most of the examples in this chapter have involved objects, relations can connect almost any values together. We can create relations in groups, one to various relations, various to one relations, one to one relations, and various to various relations for any combination of kinds. For example:

Partnership relates various texts to various texts.
The verb to belong with means the
partnership relation.
"cheese" belongs with "crackers".
"clam" belongs with "chowder".

How might we make use of this? Clearly it would be impractical to keep trying:

if "caviar" belongs with "aardvarks", ...
if "caviar" belongs with "abacuses", ...
...

to find out what "caviar" belongs with. It's still harder to find out if it belongs with anything at all – in theory we would have to try every possibility, which of course is impossible. Instead we have these phrases:

if (value) relates to (name of kind) by (relation of values to values):

This condition is true if the value V is such that V relates to something by the given relation. Example: suppose partnership relates various texts to various texts. Then we can test

if "chalk" relates to a text by the partnership relation, ...
if (name of kind) relates to (value) by (relation of values to values):

This condition is true if the value V is such that something relates to V by the given relation. Example: suppose partnership relates various texts to various texts. Then we can test

if a text relates to "cheese" by the partnership relation, ...

If a partner does exist, then we can find it with:

(name of kind) to which/whom (value) relates by (relation of values to values)value
or…
(name of kind) that/which/whom (value) relates to by (relation of values to values)value

This phrase produces an Y such that the given value V relates to Y by the given relation. Example: suppose partnership relates various texts to various texts. Then we can obtain

the text to which "chalk" relates by the partnership relation

which might be, say, "cheese". It's a run-time problem to use this if no such Y exists.

(name of kind) that/which/who relates to (value) by (relation of values to values)value

This phrase produces an X such that X relates to the given value V by the given relation. Example: suppose partnership relates various texts to various texts. Then we can obtain

the text which relates to "cheese" by the partnership relation

which might be, say, "chalk". It's a run-time problem to use this if no such X exists.

Of course, there might be many answers to this question, so perhaps these are neater:

list of (name of kind) that/which/who relate to (value) by (relation of values to values)value

This phrase produces a list of all the X such that X relates to the given value V by the given relation. Example: suppose partnership relates various texts to various texts. Then we can obtain

list of texts which relate to "cheese" by the partnership relation

which might be, say, { "chalk", "grapes", "macaroni" }. The answer might be the empty set, but that's not a problem.

list of (name of kind) to which/whom (value) relates by (relation of values to values)value
or…
list of (name of kind) that/which/whom (value) relates to by (relation of values to values)value

This phrase produces a list of all Y such that the given value V relates to Y by the given relation. Example: suppose partnership relates various texts to various texts. Then we can obtain

list of texts to which "chalk" relates by the partnership relation

which might be, say, { "cheese", "blackboard", "cliffs" }. The answer might be the empty set, but that's not a problem.

Finally, it's sometimes useful to get at the list of all values which can appear on the left or right hand side of a relation. We need tongue-twister like wording to do it, but:

list of (name of kind) that/which/whom (relation of values to values) relatesvalue

This phrase produces a list of all X which relate to anything under the given relation. Example: suppose partnership relates various texts to various texts. Then we can obtain

list of texts which the partnership relation relates
list of (name of kind) to which/whom (relation of values to values) relatesvalue
or…
list of (name of kind) that/which/whom (relation of values to values) relates tovalue

This phrase produces a list of all Y which anything relates to under the given relation. Example: suppose partnership relates various texts to various texts. Then we can obtain

list of texts which the partnership relation relates to

For efficiency reasons, there are no guarantees about what order these lists have – but they can of course always be sorted when found.

Examples

238.
A case in which relations give characters multiple values of the same kind.
A character who learns new actions by watching the player performing them.

WI §13.14 Relations as values in their own right

As we've seen, most relations have names – "containment relation", for instance. These are themselves values in Inform, though there are a few restrictions on how they are used. (Relations can contain a colossal amount of data, so we don't want to have to copy them casually.)

Consider these two examples:

Parity relates a number (called N) to a number (called M) when N minus M is even.
Joint magnitude relates a number (called N) to a number (called M) when N plus M is greater than 7.

Here "parity relation" and "joint magnitude relation" are both values of the same kind: "relation of numbers to numbers". In general, every relation is a value of kind "relation of K to L", for the appropriate kinds K and L. So the parity relation doesn't have the same kind as the containment relation, for example. Because it often happens that K and L are the same, we can just say "relation of K" in this case, so we could equally say that the kind of the parity relation is "relation of numbers".

This is useful to know when writing phrases like so:

To chart (R - a relation of numbers):
   repeat with N running from 1 to 5:
      repeat with M running from 1 to 5:
         if R relates N to M, say "[N] <=> [M] ";
      say "[line break]";

and now "chart parity relation" will work nicely, but "chart visibility relation" will be rejected (as it should be, because it relates things, not numbers). In general, if R is any relation, we can write

if R relates X to Y, ...
now R relates X to Y;
now R does not relate X to Y;

to test, set and unset a relation R between two values. (Inform checks that the values X and Y have the right kind and produces a problem message if not.)

Several useful adjectives can be applied to relations:

"empty" - nothing relates to anything else
"symmetric" - by definition X relates to Y if and only if Y relates to X
"equivalence" - this is a relation "in groups", or an "equivalence relation"
"one-to-one" - it relates one K to one L
"one-to-various" - similarly
"various-to-one" - similarly
"various-to-various" - similarly

So for example it's possible to ask

if R is a symmetric one-to-one relation of texts, ...

With some relations, it's possible to clear them out by writing:

now R is empty;

and with temporary relations (see the next section), it's even possible to change their valencies (one-to-one vs. one-to-various, etc.) using "now", but only when they are empty. The exceptions where "empty" can't be used are those which can't be changed at all, like the parity relation above, and a few built-in cases such as the support, containment and incorporation relations, where emptying would dissolve the model world in a disastrous way.

Example

240.
The parity and joint magnitude relations explored.

WI §13.15 Temporary relations

So far in this chapter, we've only seen relations which exist permanently during play. The relationships might change – sometimes Red Riding Hood would be in the Woodcutter's Cottage, sometimes not – but the relations themselves were eternal.

In fact, though, we can also create relations to be dynamic data structures, like lists:

let (a name not so far used) be (description of relations of values to values)

This phrase creates a new temporary variable, and sets its value to the identity of a newly created and equally temporary relation. These last only for the present block of phrases, which certainly means that they exist only in the current rule. Example:

let the password dictionary be a relation of texts;

This makes a purely temporary various-to-various relation between texts, which lasts as long as the temporary value "password dictionary" lasts. By default, relations are various-to-various, but we could instead write, say:

let the nicknames catalogue be a various-to-one relation of texts;

Such a relation exists only in the current phrase, and is destroyed when the phrase finishes, like any other "let". Of course there's no verb whose meaning is this relation, but that's no obstacle, because we can manipulate it using "relates":

now the nicknames catalogue relates "Trudy" to "Snake-eyes";

(At present such a relation cannot be used outside its own phrase.)

WI §13.16 What are relations for?

It is easy to say what verbs are for: they are to express relations. But what are relations for?

Inform 7's focus on relations between objects is unusual as an approach to interactive fiction; the concept does not exist in most design systems, or rather, it does but is submerged. Traditional design systems do, after all, have the spatial relations of being inside, on top of, and so on. It could well be said that these are the only relationships that inanimate objects ever have. A stone can be on top of a table, and if so then that expresses their entire association.

This is because the stone, and the table, have no opinions, emotions, knowledge or memory. If the stone is taken away and then put back, nothing has changed. People, on the other hand, tend to remember having met each other before; they like being in some places, but not others; their behaviour depends on who, or what, is nearby. Being conscious, they have internal states, unlike the stone. Relations are a simple but powerful way to express and talk about such connections, and although they have numerous uses in physical contexts too, they are at their most powerful when helping to make the characters of interactive fiction come alive.

A note of caution: perfectly innocent conditionals involving relations can prove to be woefully inefficient in practice: testing a relationship among things may end up comparing a thing to every other thing. If that's occurring in multiple Every Turn rules and your things number in the hundreds, you may find your game slowing to a crawl. There can be dramatic differences that are impossible to anticipate. "If the first thing held by the box is nothing" is fast; "if there is nothing in the box" isn't terrible; "if nothing is in the box", however, can be very slow if there are a lot of objects in the game. In an ideal world, this would be beneath an author's concerns. In this world, it's a problem you could encounter in a large game. [TODO some statement of what to do about it? ]

See Also

Which and who for a review of things that can be done with relations, along with the remainder of the chapter on Descriptions.

Examples

A number of sleuths (the player among them) find themselves aboard the Orient Express, where a murder has taken place, and one of them is apparently the culprit. Naturally they do not agree on whom, but there is physical evidence which may change their minds…
242.
A general-purpose clothing system that handles a variety of different clothing items layered in different combinations over different areas of the body.
Some notes on relations from a mathematical point of view, provided only to clarify some technicalities for those who are interested.
Some notes on relations from the point of view of graph theory.