![]() | Chapter 11: Phrases | ![]() ![]() |
11.18. The value after and the value before |
A point which has come up several times in recent chapters is that enumerated kinds of value have a natural ordering. For example, if we write:
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
...then we not only have seven possible values, we have put them into a sequence, in order of their naming. We can't perform arithmetic on colours, of course, but we can perform comparisons on them. Thus "red < yellow" is true, while "green >= violet" is not. (More on comparisons in the chapter on units, which also covers arithmetic.)
It's also sometimes useful to get at the sequence directly. First, the two ends:
first value of (name of kind) ... value
This phrase produces the first-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "first value of colour" is red.
|
last value of (name of kind) ... value
This phrase produces the last-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "last value of colour" is violet.
|
And now how to step forward and back:
(name of kind) after (enumerated value) ... value
This phrase produces the next-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "colour after orange" is yellow.
|
(name of kind) before (enumerated value) ... value
This phrase produces the previous-created value of the given kind, which should be an enumeration. Example: if we have
Colour is a kind of value. The colours are red, orange, yellow, green, blue, indigo and violet.
then "colour before blue" is green.
|
| ![]() All objects in the game have a heat, but if not kept insulated they will tend toward room temperature (and at a somewhat exaggerated rate). |
|
| ![]() ![]() ![]() Turns take a quarter day each, and the game rotates through the days of the week. |
|
Previous | Contents | Next |