'One of' by kind

In an attempt to get around the no nested ifs limitation for text replacements, I tried to create a new “one of” construction that compares an object to a description of a kind. If the object is of that kind, then the phrase is selected for display. I got it to kinda work, but it feels awfully hacky and has a number of problems. Here is the code:

To say one of for (X - an object) when kind (V - name of kind of value of kind K) -- beginning say_when_kind: (- {-allocate-storage:say_when_kind}I7_ST_say_when_kind-->{-counter:say_when_kind} = {X}; if ( (((I7_ST_say_when_kind-->{-counter:say_when_kind}).KD_Count)*2) == (({-default-value-for:V}.KD_Count)*2) ) {-open-brace} -). To say when kind (V - name of kind of value of kind K) -- continuing say_when_kind: (- {-close-brace} if ( (((I7_ST_say_when_kind-->{-counter:say_when_kind}).KD_Count)*2) == (({-default-value-for:V}.KD_Count)*2) ) {-open-brace} -). To say end when kind -- ending say_when_kind: (- {-close-brace} ! {-advance-counter:say_when_kind} -).
It uses the old KD_Count method of comparing types by obtaining the default value of a kind and then comparing the KD_Count values for it.

The above will work for my purposes, but it has obvious problems (and probably a few I’m not aware of yet). If you have a kind of animal called a cat and you’re trying to compare it to the default value of animal, which may not be a kind of cat at all. Could be a kind of dog! The way it is now makes it impossible to reliably compare things by parent kinds.

There is also the possibility that a kind will have the default value of nothing, which usually occurs when the developer has not created an object of that kind in their story. This is less of an issue, as if you have no animals in your story, why would you be creating a text replacement for the kind ‘animal’… But, it still should be possible to compare something to an animal even if your world is devoid of animals.

What I really wanted to do was use the “ofclass” operator to compare the two which will fix the previously mentioned problems, but I could not for the life of me get Inform 7 to expand a description of a kind with the resolved static kind (as in- a description of an animal -> K12_animal) to perform the ofclass operation on.

I’m not familiar with Inform 6, nor am I much familiar with all the undocumented features of Inform 7 that would likely have the answer I’m looking for. Does anybody have any suggestions on how to make this construction a bit more robust?

You could writeTo say one of for (X - an object) when kind (D - a description of a value of kind K) -- beginning say_when_kind: (- {-allocate-storage:say_when_kind} I7_ST_say_when_kind-->0={X}; if({D}({X})){-open-brace} -). To say when kind (D - a description of a value of kind K) -- continuing say_when_kind: (- {-close-brace} if({D}(I7_ST_say_when_kind-->0)){-open-brace} -). To say end when kind -- ending say_when_kind: (- {-close-brace} -). and have Inform generate the ofclass tests in Prop_* routines.