OK, here’s a further kick. I decided to try to make a more general routine, because the one I had was pretty ugly–it depends on the fact that the first thing after the article for a block will always be the color, and requires some nitpicky workarounds there. That wouldn’t do if, for instance, we wanted to be able to describe containers as “an empty bottle” or “an open chest,” when we wouldn’t necessarily be sure which adjective would come first.
So I thought I’d try to write something generic that runs the routine for printing the name of the item, grabs its text, and runs the a-an routine on that. Here’s what I came up with–the first half is just the a-an business from a few posts ago, which is still working as expected; the good stuff starts at “An object is already printed with the article.”
[spoiler][code]Use the serial comma.
Lab is a room.
To decide what text is a-an (T - sayable value):
let string be the substituted form of “[T]”;
if string starts with a vowel sound:
decide on “an [string]”;
otherwise:
decide on “a [string]”.
To decide what text is uppercase (T - sayable value):
let string be the substituted form of “[T]”;
replace character number 1 in string with character number 1 in string in upper case;
decide on string.
To decide what text is upper case (T - sayable value):
decide on uppercase T.
To decide whether (string - a text) starts with a vowel sound:
let the first word be word number 1 in string;
if the first word is a word listed in the Table of Words That Start With Vowel Sounds, yes;
if the first word is a word listed in the Table of Words That Don’t Start With Vowel Sounds, no;
if character number 1 in the first word is a vowel, yes;
no.
To decide whether (letter - a text) is a vowel:
if letter exactly matches the regular expression “a|e|i|o|u|A|E|I|O|U”, yes;
no.
Table of Words That Start With Vowel Sounds
word
“hour”
“hourglass”
“honest”
“yttrium”
Table of Words That Don’t Start With Vowel Sounds
word
“uniform”
“unicorn”
“united”
“United”
“one”
Color is a kind of value. The colors are red, orange, yellow, green, blue, indigo, and violet.
A block is a kind of thing. A block has a color. Understand the color property as describing a block.
Before printing the name of a block (called cube):
say "[color of the cube] ".
An object can be already printed with the article. The indefinite article of a block is usually “[adaptive article of the item described]”.
To say adaptive article of (item - an object):
if item is not already printed with the article:
let T be the substituted form of “[item]”;
now the item is already printed with the article; [if the previous two lines are switched, this doesn’t work at all]
say “[a-an T]”.
First before printing the name of an object (called item) that is already printed with the article:
do nothing instead.
First for printing the name of an object that is already printed with the article:
do nothing.
First after printing the name of an object (called item) that is already printed with the article:
now the item is not already printed with the article instead.
One red block and one orange block are in Lab.
A fancier is a person in the lab. The indefinite article of the fancier is “[adaptive article of the item described]”. [if we write "[adaptive article of the fancier] " instead, the name prints blank!]
Before printing the name of the fancier:
say "[one of]cat[or]dog[or]aardvark[cycling] ".[/code][/spoiler]
Output:
Note that there’s an extra space after “a red block” but not after “an orange block.” Some experiment with debugging text confirms that this is where the rules before/for/after printing the name of an object that is already printed with the article are running. Not sure why they don’t run for the orange block.
If I switch the two lines that I mention in the “To say adaptive article of” phrase, then we get “a red block, a orange block”–with an extra space going before “red” and “orange,” and the test for whether the word starts with a vowel failing for “orange.” The debugging text confirms that the extra space is where the rules before/for/after printing the name of an object that is already printed with the article are running.
Also, for the cat/dog/aardvark fancier, note that the indefinite article you get depends on whether the next thing it’s planning to print starts with a vowel, not whether the one it’s about to print does. I think this may be an inescapable side-effect of the way Inform now preloads its text substitutions, which is too bad, because it makes this approach pretty useless.
Also! If I change the indefinite article of the fancier from “[adaptive article of the item described]” to “[adaptive article of the fancier]”, then the fancier’s name goes completely blank, thus:
Why is that happening? They’re two calls to the same object.
There is something strange going on here, some of it partly in my code, but I also think that the adaptation of indefinite articles is wobbly and tends to fall over when pushed. Which is too bad, because I’d really like to be able to do this smoothly without special-casing it every time I add a new way to vary my text.