| Chapter 15: Tables |

| 15.5. Choosing rows

The following would be one way to print out a list of recent Kings and Queens:

> To list the succession:
> say "The Succession List runs as follows...";
> repeat with N running from 1 to the number of rows in the Table of Recent Monarchs begin;
> say "[accession in row N of the Table of Recent Monarchs]: [name in row N of the Table of Recent Monarchs] ([family in row N of the Table of Recent Monarchs]).";
> end repeat.

This works, but is repetitive. We often want to work on a single row for a while, either to change things or think about the contents, and it is tiresome to keep specifying the row over and over again. The following shorthand provides some relief:

> choose row N in the Table of Recent Monarchs;
> say "[accession entry]: [name entry] ([family entry]).";

That is, if "accession" is a column name then "accession entry" will mean the entry in that column of the currently chosen row. This notation can only be used if a "choose" has certainly already happened, and it is a good idea to make that choice somewhere close by in the source code (and certainly in the same rule or phrase definition) for the sake of avoiding errors. We can also choose rows by specifying something about them, like so:

> choose row with a name of "Victoria" in the Table of Recent Monarchs;
> change name entry to "Clytemnestra Honeytongue III";

This will choose the first row with the given entry: an error will result if there are no rows which qualify. We can also choose a row quite at random:

> choose a random row in the Table of Recent Monarchs;
> say "Your eye falls upon the reign of [name entry]."

Sometimes it will happen that a column's name clashes with the name of something else: for instance, if we call a column "apples" but we also have a kind called "apple", so that the word "apples" could mean either some fruit or the column. Inform will generally prefer the former meaning as more likely. In case of such trouble, we can simply refer to "the apples column" rather than just "the apples": for instance, "choose row with an apples column of..." rather than "choose row with an apples of..."

Previous | Contents | Next