21.1. A review of kinds

| Chapter 21: Advanced Phrases |

| 21.1. A review of kinds

Most, if not quite all, Inform constructions are values - sometimes openly so, sometimes not. In this book, we haven't gone out of our way to make that point, because there was no real need to do so. It's possible to make heavy use of rulebooks and write large-scale Inform projects without ever needing to use a rulebook's name as a value in its own right, for example. But if we want to create sophisticated extensions to Inform, or to use modern techniques such as functional and generic programming, we need to be fluent in the language of kinds.

Inform's language of kinds has four ingredients: base kinds, constructions, kind variables and kinds of kinds.

1. Base kinds. Inform provides the following base kinds for values:

> object, number, time, truth state, text, indexed text, snippet, Unicode character, stored action, scene, table name, equation name, use option, action name, figure name, sound name, external file

And Inform allows us to create new base kinds either by making more specialised kinds of object:

> A geographical layout is a kind of object.
> A marmoset is a kind of animal.

Or by making new enumerations or arithmetical kinds:

> Distance is a kind of value. 10km specifies a distance.
> Colour is a kind of value. Red, green and blue are colours.

2. Constructions. These are ways to make new kinds from existing ones. The construction most often used is "list of...". For any kind K, there is a kind called list of K. So the range of possible kinds in Inform is actually infinite, because:

> number
> list of numbers
> list of lists of numbers
> list of lists of lists of numbers
> ...

are all different from each other. Inform currently has nine constructions, and does not (yet) provide a way for us to create new ones. Here they are:

> list of K
> description of K
> relation of K to L
> K based rule producing L
> K based rulebook producing L
> activity on K
> phrase K -> L
> K valued property
> K valued table column

Some of these have appeared in previous chapters, but in abbreviated form. For example, "rulebook" abbreviates "action based rulebook producing nothing", and "either/or property" is a synonym for "truth state valued property". The kinds of descriptions and phrases haven't been covered yet, but are coming up in the sections following.

These constructions can of course be combined:

> phrase (relation of numbers to colours, number) -> list of colours

Brackets can be used to clarify matters:

> phrase (phrase number -> (phrase number -> number)) -> nothing

Nothing will make that a simple idea, but it's unambiguous and can be puzzled out with practice.

3. Variables. In a way, that's everything: there are just base kinds and constructions on them, and those construct every possible kind in Inform. But the language we use to describe kinds is larger than that, because it allows us to describe many kinds at once, in the same way that Inform reads the word "something" as applying to many objects at once, not as a single object.

Kind variables will be covered later in the chapter, but the idea is that:

> To hunt for (needle - value of kind K) in (haystack - list of Ks): ...

allows us to describe the kinds acceptable in a phrase so that a wide range of possibilities are allowed. The above matches both:

> hunt for 4 in { 2, 3, 4, 5 };
> hunt for "fish" in { "lemon sauce", "fish", "garden peas" };

The letter K in the definition stood for any kind; in the first use of "hunt" here, K turned out to be "number", and in the second it was "text". On the other hand Inform would reject:

> hunt for 4 in { containment relation, support relation };

because there is no kind K which can make this match the definition.

There are potentially 26 kind variables, A to Z, though it's customary to use them in the order K, L, M, ..., and it's very rare to need more than two at a time.

4. Kinds of kind. Inform understands several names which look as if they are kinds, but actually aren't:

> value, arithmetic value, enumerated value, sayable value

(Again, these are built in to Inform.) They are not kinds because they're just too loose and vague. Instead, they can be used in phrase definitions to match against multiple possibilities:

> To announce (X - sayable value): say "I declare that [X] has arrived."

This makes "announce X" work for any value X which can be said. All the same, "sayable value" is not a kind. It could never be safe for this to be the kind of a variable, because Inform would never know what could be done with the contents (except that it could be printed out).

5. Secret inner workings. There isn't a fifth ingredient, but if there were, it would be a handful of names used in matching some of the core built-in phrases of Inform which have so-called inline I6 definitions. These are not intended for anyone else to use, and are just an internal convenience; they aren't publically documented and might change without notice. They don't describe kinds at all, because they tell the matcher to look for something else instead. For instance, there's one called "condition", which means "match a condition rather than a value". They appear in red ink in the Phrasebook index.

Previous | Contents | Next