Understanding things via their number-based properties

I submitted a uservoice request (inform7.uservoice.com/forums/57 … d#comments) about an issue I ran into last year, which I traced to some subtleties in the way the related I6 code was being generated. Some simple example code illustrating the type of issue would be:

[code]“Spot the Difference”

A tribble is a kind of thing. A tribble has a number called spot count. The description of a tribble is usually “It has [spot count] spot[s].”

Understand “with [number] spots” as a tribble when the spot count of the item described is the number understood.

Cargo Hold is a room.

A tribble called a red tribble is in Cargo Hold. The spot count of the red tribble is 3.

A tribble called a blue tribble is in Cargo Hold. The spot count of the blue tribble is 4.

test me with “get tribble with 3 spots / trace 5 / get tribble with 3 spots”[/code]

Basically, “tribble with 3 spots” seems like should be understood as referring to the red tribble. I don’t recall every bit of the details of what’s going on at the I6 layer, but I remember thinking that it wouldn’t take much for it to work as naively expected. I think maybe it came down to the order in which the relevant I6 clauses were being evaluated – perhaps parsed_number wasn’t being set early enough?

At any rate, I just noticed that curiousdanii implied in a comment this might count as a real bug, and it seems that this issue still exists as of 6M62.

Am I correct to think that the above example code should work? If not, can anyone explain what I’m missing? In short, should I report this as a bug?

I think the problem is that you’re referring to “the number understood” while still in the process of understanding.

From §17.17. (Context: understanding when):

However, see §17.15. (Understanding things by their properties). You can get somewhere with:

Understand the spot count property as describing a tribble.

If you want to keep the “with N spots” phrase as a phrase, this works:

Definition: a number (called X) is self-spot-matching if the item described is a tribble and X is the spot count of the item described.
Understand "with [self-spot-matching number] spots" as a tribble.

At the time the grammar token is evaluated, the “item described” variable is set. So we define an adjective on numbers which peeks at it.

Yes, I think so. I dimly remember that it seemed like rearranging the generated I6 snippets would result in parsed_number (the number understood’s I6 variable) being set early enough that it would work as expected. I may have also run across the documentation you mentioned, which is why I logged it as a suggestion instead of a bug report.

Cool workaround, zarf. I didn’t know you could apply adjectives to numbers in understanding rules like that. Thank you.

That would be one of the uses of “item described” I think it’d be OK not to include in the documentation.

matt w, “the item described” confused me for a long time, too, but mostly because of the way it’s been named. It’s really just the object-oriented “self” at the I6 layer, as can be seen in the Standard Rules:

The item described is an object that varies. ... The item described variable translates into I6 as "self".

Maybe it would have been better to call it “the item in question” or “the item being evaluated” or something along those lines to make this slightly clearer. I do agree that it’s under-documented in WWI.

Or even “this”. That would make for some much nicer phrasings.

Well, honestly, “the item described” as used in I7 didn’t confuse me much as such–pretty early on someone tipped me off that it was like “the noun,” except for descriptions and things like that, and then some other time I realized that you could use it in Understand statements as well. I only wound up reporting that because when I was reporting the weird bug with my article-printing code I looked to see what WwI said about “the item described” and was surprised to discover it didn’t say anything.

Not knowing any I6, the “self” thing doesn’t really mean much to me–why is this the same thing for properties and Understand statements? And the subtleties like the way zarf is using it go right over my head. I figure it’s called “the item described” because it started out as something you talk about for, well, descriptions and Understand statements where you really are describing something, and then it spread out from there. Kind of like how “the person asked” has mutated from persuasion statements to a catchall for talking about the I6 actor variable (zarf, I know this is undocumented).

It’s an object oriented programming thing, not just an I6 thing. It allows code to be shared among all members of a class (kind) and yet still refer to the individual property values of a specific instance of that class.

For example, let’s say that we create a tribble class with a color property and declare two instances of tribble: a red tribble with color = red and a blue tribble with color = blue. Then, we can write code attached to the tribble class that refers to self.color. When the red tribble runs this code, ‘self’ will refer to the red tribble and self.color will be red. When the blue tribble runs the same code, ‘self’ will refer to the blue tribble instead and self.color will be blue.

It’s used in the when clauses of understand statements, because those kinds of understand statements translate into parse_name routines attached as properties to I6 objects. These are called during parsing when the objects in scope are being matched against a grammar token. If multiple objects share a parse_name routine, self can be used within it to refer to the specific object under consideration when the routine is called.

I’ll also take this opportunity to recommend the DM4 (PDF). It’s a very entertaining read, and I6 knowledge helps one get the most out of I7, especially when things aren’t working as expected.

The name was apparently chosen to try to prevent people from using “the item described” too liberally. Since I7 is not object-oriented (unlike I6), ‘self’ doesn’t make sense most of the time, and so “the item described” is only meant to be used in very specific circumstances (although I agree that the documentation does not at all adequately explain this). From the Standard Rules (A/sr2.4):

And that causes a fair bit of trouble, because I7 is not an object-oriented language – in this technical sense. The use of “self” / “item described” stems from some old, old low-level I6 parser structure which fits awkwardly with the modern language.

I’m not saying you shouldn’t use it. It’s solidly entrenched and it’s the only way to do all the things we’ve been discussing. I’m just saying it’s… messy.

(Cross-posted with dfremont, I see)