Inform 7 Home Page / Documentation
§13.13. Relations involving values
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:
"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
(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
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) relates ... value
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 (name of kind) to which/whom (relation of values to values) relates ... value
list of (name of kind) that/which/whom (relation of values to values) relates to ... value
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
For efficiency reasons, there are no guarantees about what order these lists have - but they can of course always be sorted when found.
Start of Chapter 13: Relations | |
Back to §13.12. Relations which express conditions | |
Onward to §13.14. Relations as values in their own right |
Meet Market |
For Demonstration Purposes |