This was one of those triggering situations where it seemed as though the compiler should take a simple phrase in its stride, but it was rejected in disgust with an error message that was itself a little misleading:
Problem. You wrote ‘Understand the colour-range property as describing a swatch’ : but that property is of a kind which I can’t recognise in typed commands, so that it cannot be understood as describing or referring to something. I can understand either/or properties, properties with a limited list of named possible values, numbers, times of day, or units; but certain built-into-Inform kinds of value (like snippet or rulebook, for instance) I can’t use.
See the manual: 17.15 > 17.15. Understanding things by their properties
‘that property is of a kind which I can’t recognise in typed commands’ was something of a surprise, since a topic is very much something one might expect the parser to recognise in typed commands.
To elaborate, the word ‘topic’ has a confusing usage in Inform, as it refers to two entirely different entities. The more commonly encountered one is found in action definitions such as:
Conversing is an action applying to one thing and one topic.
Here, ‘topic’ refers to a sequence of unparsed words, a part of a typed command that could be any text at all and which the parser is not expected to process. Seasoned Informers will realise that part of a typed command is usually now referred to as a ‘snippet’, not a ‘topic’- but the use of the latter term here has historic roots in actions using snippets to represent topics of conversation. e.g.
Understand "converse with [someone] about [text]" as conversing.
Here, just to add to the confusion, the ‘topic’ or (more properly) ‘snippet’ referred to in the action definition is in Understand...
phrases represented by a [text]
token- which again really represents not a text as in Inform’s text kind, but part of a typed command (here, the part coming after “converse with [someone] about”), in other words a snippet.
However, after parsing, just to add insult to injury, the snippet the parser matched to the [text] token must be referred to as ‘the topic understood’- e.g.
Instead of conversing with Mr Darcy:
say "Mr Darcy clearly has no interest in [the topic understood].".
Having got this other historic meaning of ‘topic’==‘snippet’ out of the way, what is a topic in the sense of Inform’s topic kind? It is neither a text or a snippet but a routine to match one or more words against a snippet. What does that mean? Recall that a snippet is a sequence of words in the player’s command. A snippet has no textual meaning separate to the typed command because in itself a snippet consists simply of an encoding of two numbers- a starting point and a number of words. The encoding is (start-word)*100+(number of words). So a snippet encoded as 204 means the second to fifth words (inclusive) of the typed command. The snippet representing the full typed command is 100+(length of command in words) and this snippet has the special name ‘the player’s command’.
Topics are usually represented in Inform in a way that at first sight looks confusingly like a text- i.e. something within double quotes. e.g.
If the player's command includes "red", replace the matched text with "green".
Here, the player's command
is a snippet, in this case the full typed command; the innocuous-looking “red” is actually a word(s)-> snippet matching routine (a topic); ‘the matched text’ is a snippet representing the position and word(s) where the “red” word(s)-> snippet matching routine made a match in the typed command, and “green” is a text, which will be inserted into the typed command in place of the snippet represented by ‘the matched text’.
So, if we type ‘open the red book’, the player’s command starts as a snippet encoded as 104, the routine compiled by the (topic) “red” searches through the player’s command and matches the third word, so ‘the matched text’ becomes the snippet encoded as 301; this snippet, i.e. the third word in the typed command is then replaced by the text “green” and the typed command ends as ‘open the green book’.
Although a topic like “red” really does look like a common-or-garden text, despite being compiled to an I6 routine, more commonly a topic will embody a more complex search routine than just 'find the word “red” '. e.g.
After reading a command:
If the player's command includes "red/yellow/blue", replace the matched text with "green".
means that the i6 routine compiled by “red/yellow/blue” will match any one of the words ‘red’, ‘yellow’, or ‘blue’.
And we can go further, by including in topics the same kinds of token that are used in Understand… phrases.
A colour is a kind of value. Some colours are red, orange, yellow, green, blue, indigo, violet.
After reading a command:
If the player's command includes "[colour]", replace the matched text with "green".
means that the I6 routine compiled by “[colour]” will match the name of any one of the colour values we have defined and replace it with “green”.
And we can even find the word(s) matched by the [colour] token by ‘the colour understood’:
After reading a command:
If the player's command includes "[colour]", replace the matched text with "green".
say "I replaced '[the colour understood]' with 'green' and the command is now [the player's command]."
So, it seems plain that a topic held by a property ought to be the sort of thing that the parser can use to match against words in a typed command and it’s a surprise and a disappointment that the compiler is not set up to generate a suitable routine to do this.
However, one thing the compiler is coy about in the error message given at the start of this post is that the text kind is one of the kinds that can be ‘understood as describing or referring to something’ when held in a property. (Another, perhaps unexpected and at the same time less useful kind that can be used in this way is the scene kind).
So I realised this gave a backdoor to allow an ‘After reading a command’ routine to apply a topic grabbed from a topic property of a certain object to the player’s command, then, if there was a match, to put the matched text into a text property of the same object- a property that had been set up to be ‘understood as describing or referring to something’. In parsing the command, now whatever had been matched by the topic property would be matched by the text property, and thereby be recognised as describing or referring to the object.
This partially overcomes the limitation of using a text property to be understood as describing or referring to something, which is that such a property can only match a single literal plain word or sequence of words, not one of alternative words, or tokens. So in a text property, “red/blue/green” will match only the actual text ‘red/blue/green’ rather than ‘red’ or ‘blue’ or ‘green’ and “[colour]” will match only the actual text ‘[colour]’ rather than ‘(any sequence of words that is the name of a defined colour)’.
I have done some more work on the technique to allow more than one word in the command to be matched (as published to date, it will match for example ‘take red handkerchief’ or ‘take all green’ but not ‘take red green handkerchief’ (which requires two separate text properties to hold both “red” and “green” in order that the command can be matched) or ‘take red and green handkerchief’ (which the parser wants to interpret as take '(something) red' AND 'the green handkerchief'
) rather than ‘take the handkerchief that is both red and green’- to resolve this latter ambiguity requires some rather more substantial hacking of the command).
I have also almost finished working up an alternative approach- as suggested by Otis- whereby a relation is used in place of a property to be ‘understood as describing or referring to something’. To simplify setup by use of a table, as required by the original OP, the colours of things are defined as lists:
Table of Haberdashery
name colour-range (list of things)
handkerchief {red,yellow,green}
necktie {blue,red,white}
and the initial relations swatch<=>colour are created from those lists when play begins. Watch this space!
PS I have submitted an improvement request for topic properties to be ‘understood as describing or referring to something’, hopefully in due course making my efforts redundant…