| Chapter 11: Phrases |

| 11.13. Let and temporary variables

A variable, as we have seen, is a name for a value which changes, though always remaining of the same kind. For instance, if "target" is a number variable (or "number that varies") then it may change value from 2 to 4, but not from 2 to "fishknife".

To make complicated decisions, phrases often need to remember values on a temporary basis. We have already seen this for the counter in a "repeat" loop, which exists only inside that loop, and then is no longer needed. Now we define named values which exist only inside the current phrase. For instance:

> let outer bull be 25;
> let the current appearance be "reddish brown";
> let the special room be Marley Wood;

creates temporary variables "outer bull", "current appearance" and "special room". The kinds of these are deduced from the values given, so that, for instance,

> say "The outer bull scores [the outer bull in words] when you practice archery in [special room]."

produces

> The outer bull scores twenty-five when you practice archery in Marley Wood.

Temporary variables made by "let" are only temporarily in existence while a phrase is being carried out. Their values often change: we could say

> let x be 10;
> change x to 11;

for instance, or indeed we could "let x be 10" and then "let x be 11". But although we are allowed to change the value, we are not allowed to change the kind of value. The name "x" must always have the same kind of value throughout the phrase to which it belongs, so the following will not be allowed:

> let x be 45;
> change x to "Norway";

(The difference between "let" and "change" is that "let" can create a new temporary variable, whereas "change" can only alter one which already exists: on the other hand, "change" can change many other things as well, whereas "let" applies only to temporary variables.)

145
| Example A pushable box More on using kinds of value inside phrases, this time to simulate something new: a box which, although it cannot be picked up, can be pushed around between three different places on the floor.

146
| Example Tinted wallpaper A worked example using a new kind of value, "colour", within phrases to talk about tinted wallpaper.

Kinds of value come into their own inside phrases, as the following worked example may suggest. Suppose we have declared that: Colour is a kind of value. The colours are green, aquamarine and darkish purple. The effect is that "colour" is now a kind of value on a par with, for instance, "number". We are allowed, for instance, in a phrase to write let the tint be aquamarine; to create a temporary quantity called "tint", which always holds a colour, initially aquamarine. (If, later in the same phrase, we were to try "let the tint be 15", we would be rebuffed because a colour can't be a number or vice versa. The tint may change colour, but must always be a colour.) We can also say "The wallpaper has a distinctly [tint] wash."; which results in The wallpaper has a distinctly green wash. The wallpaper has a distinctly aquamarine wash. The wallpaper has a distinctly darkish purple wash. as may be. (Oscar Wilde's last words: "Either that wallpaper goes or I do.") As might be expected, we can also test conditions: if the tint is darkish purple then ... When a property is created that has the same name as a kind of value, like so: A door has a colour. it becomes a property whose value is required at all times to fit that quality. Thus The colour of a door is usually green. The colour of the lounge door is aquamarine. ... say "The lounge door is [colour of lounge door]."; if the colour of the lounge door is green then ... However, this is obviously rather cumbersome in English, so we can also more naturally write any of these: A door is usually green. The lounge door is aquamarine. if the lounge door is green then ... Before putting something into an aquamarine container: ... which are unambiguous since "green" is a colour and in the context of an object must imply the colour of that object.

Previous | Contents | Next