Indefinite Article Substitution Fix by Matt Weiner


Indefinite Article Substitution Fix (for Glulx only, at present) is intended to fix a bug in the interaction of indefinite articles with text substitutions.

When an improper-named object does not have a defined indefinite article, Inform by default supplies the article "a" or "an." In order to figure out whether "a" or "an" is needed, Inform carries out the printing the name of activity for the object, redirecting the output to the buffer StorageForShortName rather than the screen. It then checks whether the first character in StorageForShortName is a vowel, prints the appropriate article; and carries out the printing the name of activity for the object again, this time with the output directed to the screen.

The problem is that this runs the printing the name of activity twice, which can have undesirable side effects. For instance, if any of the rules before/for/after printing the name of the object involve a cycling or random subsitution, the substitution will be evaluated once when deciding what article to print and again when printing the name of the object. This will cause cycling substitutions to cycle twice rather than once, and can cause mismatches between the article chosen and the text that winds up getting printed.

Indefinite Article Substitution Fix addresses this problem by caching the text that is printed to StorageForShortName to the cached_name buffer when the I6 routine PrefaceByArticle carries out the printing the name of activity in order to determine which article to use. PSN__, the routine that prints the name of the object, then checks to see whether the name has been cached. If so, PSN__ prints the contents of the cached_name buffer rather than carrying out the printing the name of activity again.

You don't need to worry about any of those internals, though; Indefinite Article Substitution Fix is a plug-and-play extension. Simply including it should repair the interaction of indefinite articles with substitutions.

Known limitations (as of Nov. 26, 2016):

This extension is incompatible with Print Stage Detection by Taryn Michelle, and any other extension that directly modifies Object Names II or Object Names I in "Printing.i6t".

This extension is currently Glulx only. It may be possible to do the work to make it work with the z-machine as well, although working with StorageForShortName seems to be trickier in the z-machine than in Glulx.

Since the name that is printed first gets shuffled through StorageForShortName, and StorageForShortName is a byte array rather than a word array, this extension will not be able to print any characters that cannot be used outside quoted text in the source code, per Writing with Inform 5.10. Those who want to have a book with printed name "[unicode 339]nology text" will have to look elsewhere.

As with the standard Inform template, the algorithm for checking which form of the indefinite article should be used is simply "Does it start with a vowel?" So if we do not directly specify articles, we will get "a hourglass" and "an one-hour photo booth." If you are interested in my code for trying to address this, or in anything else about the extension, contact me at myfirstname@myfirstnamemylastname.net.

Thanks to Taryn Michelle, whose Print Stage Detection extension was a very helpful gude; Hugo Labrande, for reminding me of Print Stage Detection; and Daniel Fremont, for invaluable I6 assistance.

Example A demonstrates that the traffic signal's name properly cycles through "a green traffic signal" /"an amber traffic signal"/"a red traffic signal". Without the extension it would be "a amber traffic signal" /"an red traffic signal"/"a green traffic signal". Various other things are included to demonstrate that nested indefinite articles, proper-named things, plural-named things, and things with custom indefinite articles still appear to print properly.

Example: * Although My Name's Not Bamber - Demonstrating use of an indefinite article with a cycling substitution.

Include Indefinite Article Substitution Fix by Matt Weiner.

Crossroads is a room.

A traffic signal is in the Crossroads.

Before printing the name of the traffic signal, say "[one of]green[or]amber[or]red[cycling] ".

An Opel is a vehicle in Crossroads. A dashboard is in the Opel. A book is on the dashboard.

The book can be open. The book is open. Before printing the name of the open book: say "open ".

Some sand is in Crossroads. A lollipop lady is a woman in the crossroads. The indefinite article of the lollipop lady is "that old reliable". Mr Gascoigne is a man in the crossroads.

Test me with "l/l/l/l/l".