15.16. Defining things with tables

| Chapter 15: Tables |

| 15.16. Defining things with tables

Suppose we need to create a collection of items which differ in their properties, but are basically part of a larger pattern. For instance, here we set up what we need to make a collection of coloured shirts:

> A jersey is a kind of thing. A jersey is wearable. A jersey has a number called year established. A jersey has a text called citation. The description of a jersey is "Since [year established], the Tour de France has awarded this jersey to the [citation]."

Now we have the pattern, but making the actual shirts is tedious and repetitive:

> The yellow jersey is a jersey. The year established of the yellow jersey is 1919. The citation of the yellow jersey is "race leader". The polkadot jersey...

And so on. Instead, we can use a table to abbreviate all of this:

> "Tour des Maillots"

> The Staging Area is a room. A jersey is a kind of thing. A jersey is wearable. Some jerseys in the Staging Area are defined by the Table of Honorary Jerseys. The description of a jersey is "Since [year established], the Tour de France has awarded this jersey to the [citation]."

> Table of Honorary Jerseys

> jersey | year established | citation
> a yellow jersey | 1919 | "race leader"
> a polkadot jersey | 1933 | "King of the Mountains"
> a green jersey | 1953 | "highest point scorer on sprints"
> a white jersey | 1975 | "best cyclist aged 25 or less"

The first column provides names for the new things to be created. Subsequent columns provide property values. Note that we did not need to say that jerseys have a number called "year established" because Inform is able to infer this from the column heading and the presence of numbers in the column; similarly for "citation". Lastly, note that if any entry is blank (written "--") then that particular property is simply not set for that particular item.

Note that Inform reads articles such as "the" or "a" in the first column just as it would when something is created with any other sentence.

It's even possible to define kinds this way, though it's rare to need to create many kinds at once. (See the worked example "Reliques of Tolti-Aph" at the Inform website. There's no special syntax needed: rather than saying "Some jerseys are defined by..." we would say "Some kinds of jersey are defined by...")

271
| Example Sweeney A conversation where each topic may have multiple questions and answers associated with it, and where a given exchange can lead to new additions to the list. |
RB

> "Sweeney" A subject is a kind of thing. Some subjects are defined by the Table of Conversation Subjects. Table of Conversation Subjects
> subject | conversation
> pies | Table of Pie Queries
> employment | Table of Job Queries
> Understand "job" as employment. Understand "meat" or "food" as pies. Table of Job Queries
> quip | discussion | label | subtopics
> "whether there is a job available here" | "'Say, are you hiring?' you ask, as casually as you can manage. [The interlocutor] looks you over dubiously. 'I might be hiring someone, but I can't say it would necessarily be you.'" | 0 | --
> "what happened to that boy that worked here" | "'Tell me, didn't you used to have a young assistant working here?' She shrugs. 'Young men these days are so unstable. He left-- who knows where he's gone? I haven't seen hair or fingernail of him for weeks.'" | 0 | --
> with 3 blank rows.
> Table of Pie Queries
> quip | discussion | label | subtopics
> "what pie fillings are available" | "'What pies do you have in today, Mrs Lovett?' you ask. She starts, then smiles. 'Meat pies, of course.'" | 0 | Table of Pie Flavor Queries
> with 3 blank rows.
> Table of Pie Flavor Queries
> quip | discussion | label | subtopics
> "what kind of meat" | "'What kind of meat goes into these pies, Mrs Lovett?' you ask pressingly. She looks shifty. 'Whatever the butcher brings this week,' she says. 'With the price of meat what it is, when you get it, you have to be glad of what you can get. If you get it.'" | 0 | --
To copy (first table - a table name) to (second table - a table name): repeat through first table: if there is a quip entry, let copied quip be quip entry; otherwise let copied quip be "blank"; if there is a discussion entry, let copied discussion be discussion entry; otherwise let copied discussion be "blank"; if there is a subtopics entry, let copied subtopics be subtopics entry; otherwise let copied subtopics be second table; choose a blank row in the second table; if copied quip is not "blank", now quip entry is copied quip; if copied discussion is not "blank", now discussion entry is copied discussion; if copied subtopics is not second table, now subtopics entry is copied subtopics. Current conversation table is a table name that varies. Current conversation table is Table of Job Queries. Interlocutor is a person that varies. Understand "ask [someone] about [any subject]" as asking it about the subject. Asking it about the subject is an action applying to two visible things. Carry out asking it about the subject: say "You can't think of anything to say." Instead of asking someone about the subject a subject listed in the Table of Conversation Subjects: now interlocutor is noun; now current conversation table is the conversation of the second noun; if the number of filled rows in the current conversation table is 1: repeat through current conversation table: now label entry is 1; now number understood is 1; try selecting 1 instead; if the number of filled rows in the current conversation table is 0: say "You can think of nothing further to say on that topic."; stop the action; otherwise: let index be 0; let total be the number of filled rows in the current conversation table; say "Do you mean "; repeat through current conversation table: now index is index + 1; now label entry is index; say "([index]) [quip entry]"; if index is total, say "?"; if index is total - 1, say ", or "; if index is less than total - 1, say ", ". Understand "[number]" as selecting. Selecting is an action applying to one number. Carry out selecting: say "No such option is available." Instead of selecting a label listed in the current conversation table: say "[discussion entry][paragraph break]"; if there is a subtopics entry: copy subtopics entry to current conversation table; choose row with label of number understood in the current conversation table; blank out the whole row. Mrs Lovett's Meat Pies is a room. Mrs Lovett is a woman in Meat Pies. Test me with "ask lovett about pies / ask lovett about employment / 1 / 2 / ask lovett about pies".

272
| Example Introduction to Juggling Assortment of equipment defined with price and description, in a table. |
RB

Previous | Contents | Next