comparing text substitutions

I think this is it. (I find that I’m happy I made extensive comments on the code, while I understood it!)
It’s pretty much bound not to be the most efficient way of doing the thing, so I’d be grateful for any suggestions for improvements.

[spoiler][code]

[We want the game to understand the printed name of an object as that object, since normally the printed name of an object will contain the definite inflection of the object’s name. It’s probably good if this can be overriden, though.]

An object can be understood by its printed name or not understood by its printed name.
An object is usually understood by its printed name.
The understood by its printed name property translates into I6 as “short_name_understood”.

Include (-
Attribute short_name_understood; ! flags objects to be understood by their printed name
-) after “Template Attributes” in “Definitions.i6t”

[These variables are used only in the phrases to decide if the printed name is understood and to decide if the indexed name is understood, called by the custom I6 routine LanguageRefers in the process of determining the reference of input nouns. The The LR-formal-supposition holds the object whose printed name we are matching against the input noun. The LR-material-supposition holds the input noun we are trying to match against. (In scholastic logic, the formal supposition of a word is what the word normally refers to in “use”; the material supposition is the word itself in “mention”.)]

The LR-formal-supposition is an object that varies. The LR-formal-supposition variable translates into I6 as “LR_object”.
The LR-material-supposition is indexed text that varies. The LR-material-supposition variable translates into I6 as “parameter_object”.

[These phrases are called by the I6 LanguageRefers() routine. They match the printed name of a given object in scope (the LR-formal-supposition – LR_object in I6) against a would-be noun in the player’s command (the LR-material-supposition, which is yet another I7 name for the I6 parameter_object variable).]

To decide if the printed name is understood:
let numbawords be the number of words in the printed name of LR-formal-supposition;
repeat with wordnumba running from 1 to numbawords:
if word number wordnumba in the printed name of the LR-formal-supposition exactly matches the text LR-material-supposition, case insensitively:
decide yes.

[We define a LanguageRefers routine to make sure that the Swedish translation understands the short_name (printed name) of objects, as the author normally will give the definite forms of object names there. This mirrors the standard I6 Refers routine but adds an else block that tries to match the input word (the value of parameter_object) against each word in the printed name of a given object in scope (the value of LR_object), using both the definite and the indefinite forms of the printed name (that’s why we change the indef_mode global at the end of the routine). The routine relies on an I7 phrase matching indexed texts against each other.]

Include (-
Global LR_object = nothing;

[ LanguageRefers obj wnum wd k po spec_mode;
if (obj == 0) rfalse;

!# if parser_inflection is set to a routine, run it
k = wn; wn = wnum; wd = NextWordStopped(); wn = k;
if (parser_inflection >= 256) {
k = indirect(parser_inflection, obj, wd);
if (k >= 0) return k;
}

!# if parser_inflection is set to a property (by default it’s set to the name property), look in it for our word
k = WordInProperty(wd, obj, parser_inflection);
if (k>0) rtrue;

!# and if we don’t find the word we look for in that property, check the object’s short_name (i.e. the I7 printed name)
else if (obj has short_name_understood) {
LR_object = obj; po = parameter_object; spec_mode = indef_mode;
parameter_object = INDEXED_TEXT_TY_Create();
INDEXED_TEXT_TY_Cast(wnum*100+1, SNIPPET_TY, parameter_object);
k = (+ whether or not the printed name is understood +);
if (k>0) {
parameter_object = po;
rtrue;
}
if (indef_mode == false) indef_mode = true;
else indef_mode = false;
k = (+ whether or not the printed name is understood +);
indef_mode = spec_mode; parameter_object = po;
if (k>0) rtrue;
else rfalse;
}

else rfalse;
];
-) before “Refers” in “Parser.i6t”.

[/code][/spoiler]