How do I get the number of columns in a given table? Section 16.2 gives the syntax for the number of rows of a given table (and switching ‘rows’ with ‘columns’ doesn’t compile), but my luck with guessing-the-verb for the corresponding syntax for columns, if it exists, has not been successful.
I don’t think it exists? ‘number of columns’ is a phrase that doesn’t exist in the docs.
Since you have to specify what kind of data goes in each column, it’s probably considered impossible that you wouldn’t know how many columns there are, and there are generally few columns but possibly very many rows.
You may have trouble counting the number of columns in source if the table is super-wide, but the total is never going to change, and tables are scanned downwards by Inform (if you use a ‘repeat through’) not horizontally.
I figure the system’s set up in a way where you shouldn’t need to ask this question (How many columns are there in table X?) during runtime, and it being easy enough to collect the unchanging answer, if you need it, before compiling the source.
EDIT - Looks like the answer can change. And it looks like you can use a spot of I6 to get a count. So, once again, I’ve typed too many words in vain
-Wade
To decide which number is the column count of (T - table name):
(- ({T}-->0) -).
When play begins:
say "Table of Locale Priorities has [column count of Table of Locale Priorities] columns."
It’s been a while, but I thought that table continuations could add columns. So checking how a table is defined wouldn’t necessarily tell you how many columns it actually has.
I’ve never tried continuing horizontally, but I defer to you, since you got me all cleared up about being able to leave the rightmost columns empty when I made my menus extensions.
-Wade
Ah, thanks. On that subject, what exactly is an I7 table under the hood? From that bit of code, it looks like a standard one-dimensional I6 array with each entry pointing to a column. (That would explain the weird syntax for tables and the awkwardness of looping over them, at least. I was expecting something more like a block of dynamically-allocated memory with a bunch of hash tables for lookups.)
There’s no phrase in the standard library which uses a column by column number or repeats through columns. So there’s nothing you can do with this information.
You could write a second I6 phrase “the entry number (N - number)” to look up a column by number. But you’d have to manually ensure that every column had the same type.
That’s what it is. Each column is another I6 array with the entries, plus some overhead for type info and noting which entries are blanked.
No, the syntax came first. The implementation was built to do what Graham wanted tables to do.
It’s worth remembering that the first releases of I7 were meant to run on either Z-machine or Glulx, so they had to stick to simple algorithms. Tables were designed to avoid dynamic memory (lists came later). Hashing code was probably also too heavyweight to consider.
Those are relations. (At least, various-to-various ones.)
Hm, now I feel silly. Were v-v relations in the first Inform release with Z-code support? Must have been.
They appear in Reliques of Tolti Aph, so I guess so (although that’s too big a project to compile to Z-machine)