DavidKinder / Inform6

The latest version of the Inform 6 compiler, used for generating interactive fiction games.
http://inform-fiction.org/
Other
199 stars 32 forks source link

Feature: singular flag for dict words #267

Closed erkyrath closed 4 months ago

erkyrath commented 4 months ago

From I7 discussion:

The example Claims Adjustment is the neatest demonstration of this. It defines the kind "photograph". This causes code to be generated which puts both PHOTOGRAPH and PHOTOGRAPHS//p into the Z/Glulx dictionary. The previous truncation behaviour caused these words to be same entry in the virtual machine dictionary, PHOTOG on Z, PHOTOGRAP on Glulx, and that common word did not have the plural bit set because //p was never read. But with the new behaviour, the definitions still become a single word in the dictionary, but now that word has the plural bit set: thus PHOTOG//p, PHOTOGRAP//p.

It would be good for the parser to know that this dict word PHOTOGRAP has been used in both singular and plural mode in the source (PHOTOGRAPH and PHOTOGRAPHS//p). Then it could make more sensible decisions. But the I6 dictionary cannot currently represent this fact.

(Footnote from Graham: "It is arguably time to increase the Glulx dictionary word length from 9 to something much more generous (31, say), but this only makes the issue rarer in practice, rather than fixing it in a principled way." This would be just a matter of setting $DICT_WORD_SIZE, which I7 can do, but we're looking at the underlying issue here.)


The proposal is to reserve one of the unused dict flag bits (say bit 4) to mean SINGULAR. I6 would set SINGULAR for any dict word usage which has NOUN but not PLURAL. So in the typical I6 definition

Class coin
  with name 'coin' 'coins//p';

...'coin' would have NOUN and SINGULAR; 'coins' would have NOUN and PLURAL.

If you then wrote 'coin//p' elsewhere in the code, that word would have NOUN and SINGULAR and PLURAL (because of the dual usage). And this would also occur in the 'photograph', 'photographs//p' case due to truncation.

Following the pattern of https://github.com/DavidKinder/Inform6/issues/259 , you could write 'word//s' to explicitly set the flag, or 'word//~s' to skip implicitly setting it.

The SINGULAR feature would be opt-in, to maintain backwards compatibility. Say $DICT_IMPLICIT_SINGULAR=1. Without this flag, bit 4 would never be implicitly set. (But you could still do 'word//s' to set it.)

ganelson commented 4 months ago

If bit 4 has not previously been used, and the notation //s is new, do we need this to be an opt-in feature? It seems to me that it doesn't change previous behaviour except to specify the contents of a bit which was previously unspecified - is there code out there which relies on that bit being always zero?

erkyrath commented 4 months ago

Maybe? We don't know for sure. It's also possible (I concede unlikely) that some author started setting bit 4 for their own purposes, via the Dictionary directive.

But also, it's easier for testing if old source compiles to exactly the same game file as before. (Modulo Inform version flag and serial number.) I don't always succeed at maintaining this guarantee, but I do whenever possible.