| 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.

218
| 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.

> "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 begin; 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", change quip entry to copied quip; if copied discussion is not "blank", change discussion entry to copied discussion; if copied subtopics is not second table, change subtopics entry to copied subtopics; end repeat. 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: change interlocutor to noun; change current conversation table to the conversation of the second noun; if the number of filled rows in the current conversation table is 1 begin; repeat through current conversation table begin; change label entry to 1; end repeat; change number understood to 1; try selecting 1 instead; end if; if the number of filled rows in the current conversation table is 0 begin; 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 begin; change index to index + 1; change label entry to 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 ", "; end repeat; end if. 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 begin; copy subtopics entry to current conversation table; end if; 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".

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

Previous | Contents | Next