Inform 7 Home Page / Documentation


§22.4. Default values for phrase kinds

The default value for "phrase K -> nothing" is a phrase which does nothing. For example, if we write:

let S be a phrase numbers -> nothing;

then S is created holding the default phrase numbers -> nothing, and if we then try it out with:

apply S to 17;

we will indeed find that nothing happens.

The default value for "phrase K -> L" is a phrase which, no matter what value of K it applies to, always produces the default value of L. (It's a sort of equivalent of the zero function in mathematics - indeed that's exactly what it is, if L is "number".) So:

let Q be a phrase numbers -> times;
showme Q;
showme Q applied to 4;
showme Q applied to -7;

produces:

"q" = phrase number -> time: default value of phrase number -> time
"q applied to 4" = time: 9:00 am
"q applied to -7" = time: 9:00 am

Here Q is set to the default phrase because we didn't give it any other value; it has the name we might expect ("default value of phrase number -> time") and it works as advertised, producing 9:00 am no matter what number is fed in.

More ambitiously, and supposing that we have a kind called "colour" whose first possible value is "red":

let R be a phrase numbers -> (phrase numbers -> colours);
showme R;
showme R applied to 3;
showme (R applied to 3) applied to 2;

produces:

"r" = phrase number -> (phrase number -> colour): default value of phrase
number -> (phrase number -> colour)
"r applied to 3" = phrase number -> colour: default value of phrase number
-> colour
"( r applied to 3 ) applied to 2" = colour: red


arrow-up.png Start of Chapter 22: Advanced Phrases
arrow-left.png Back to §22.3. Phrases as values
arrow-right.png Onward to §22.5. Map, filter and reduce