@Eleas, I’m quite familiar with this problem, having written a bug report about this issue years ago. (I’d cite it on Mantis, but it’s still down.)
The Understand
line from @mirality very much seems like it should work, but the way that it is translated at the I6 level has an order of operations problem, such that the value of parsed_number
(which will hold the color understood) is being checked prior to the attempt to parse the color word (which will set parsed_number
to the desired value).
There’s no way to change the compiler behavior, but you can insert a short I6-level workaround:
"Undertest"
Color is a kind of value. The colors are red, green, blue.
Hue relates a thing to a color. The verb to like means the hue relation.
Adam, Betty, Claire, David and Edith are people. Understand "fan" as a person.
Adam and David like red.
Betty likes blue.
Claire likes green.
Include
(-
Global dct_wn_tmp;
[ DummyColorTest ;
dct_wn_tmp = wn;
ParseTokenStopped(GPR_TT, Kind_GPR_53);
wn = dct_wn_tmp;
];
-).
To decide whether the next word is a color word: [force "early" parsing of next word to set parsed_number]
(-
(DummyColorTest())
-).
Understand "[color]" as a person when the next word is a color word and the item described likes the color understood.
There is a room. All persons are here. Test me with "x blue fan / x green fan / x red fan / david".
which yields:
room
You can see Adam, Betty, Claire, David and Edith here.
>X BLUE FAN
You see nothing special about Betty.
>X GREEN FAN
You see nothing special about Claire.
>X RED FAN
Who do you mean, Adam or David?
>DAVID
You see nothing special about David.
and seems to work reliably in my brief tests.
EDIT: I should add that this is a bit brittle because it uses the generated name for the routine (Kind_GPR_53
) which could change if the source code is modified. There should be a way to use an I7-level insertion, though.
EDIT: This is slightly more resilient to changes in source code:
Include
(-
Global dct_wn_tmp;
[ DummyColorTest ;
dct_wn_tmp = wn;
ParseTokenStopped(GPR_TT, DCTSetParsedNumber);
wn = dct_wn_tmp;
];
[ DCTSetParsedNumber
original_wn ! internal use only
group_wn ! internal use only
v ! internal use only
w ! internal use only
rv ! internal use only
;
original_wn = wn;
wn = original_wn;if (NextWordStopped() ~= 'red') jump Failed_1;
parsed_number = (+ red +); return GPR_NUMBER;
.Failed_1;
wn = original_wn;if (NextWordStopped() ~= 'green') jump Failed_2;
parsed_number = (+ green +); return GPR_NUMBER;
.Failed_2;
wn = original_wn;if (NextWordStopped() ~= 'blue') jump Failed_3;
parsed_number = (+ blue +); return GPR_NUMBER;
.Failed_3;
return GPR_FAIL;
];
-).
At least, changing the order of declaration of kinds of value doesn’t break it.
Note that changes to the list of colors would require tinkering with the DCTSetParsedNumber()
routine (which is a modified copy of the generated Kind_GPR_53()
routine) to update the dictionary words and the I7 includes for color values. Not pleasant, but I couldn’t find any kind of linkage between the color KOV and the GPR routine to get around this. (Maybe the only such linkages that exist are temporarily stored in a compiler table during I6 code generation?)