Get the thing another thing is part of

I’m new to inform and this problem is driving me nuts.

I have something (let’s say a drawer) that is part of something else (let’s say a desk). What I want to be able to do in a function is for a given drawer, get the desk (a kind) it is part of. This seems like it should be trivial, but maybe there’s some subtlety to the incorporation relationship that I don’t get. For example:

if the drawer is part of a desk

This works (where “the drawer” is a value and “a desk” is a kind).

However, Inform chokes on:

Let p be the desk that incorporates the drawer
Let p be the desk that the drawer is part of
Let p be the desk to which the drawer relates to by incorporation

And any number of other combinations I’ve tried. Inform complains that “I was expecting to read a value”, but this seems to be the syntax suggested in section 13.13. of the manual. Any ideas? What am I missing here?

Not sure whether this will work, but have you tried “a random thing which incorporates the drawer”? If the only thing that the drawer is part of is the desk, then this might do it, since it will (I think) start by essentially generating the list of things that incorporate the drawer, and then choosing something from that list at random; since there is only one such thing, it automatically gets picked.

Robert Rothman

Thanks Robert. That does seem to work. Although I’m still at a loss as to why the other things I tried didn’t work.

There are a couple of ways to approach this. Robert’s suggestion is one.

Another way: when you specify an object via an “if” statement, you can always name it. So this works:

	if the noun is part of a desk (called D):
		say "[The noun] is part of [a D].";

What you can’t do is expect the compiler to presume that there must be exactly one such desk. Even if the incorporation relation were one-to-one (which it isn’t), Inform isn’t good at picking exactly one described item. You have to tell it to pick a random one, either explicitly or with this sort of “if” clause.

Ahh…thanks zarf. That makes sense.

Actually, thinking about this some more (it’ll have to wait until tonight before I can try it), this ought to be more efficient than the previous suggest (depending on how smart inform is).

In the first case of “a random thing which incorporates the drawer”, Inform would presumably have to go through the entire list of things (of course, it could be restricted to a random desk) and test to see if they incorporate the drawer, but since it doesn’t know if there is more than one, it must test all things. On the other hand, with the if test, it can quit as soon as it finds the first thing that satisfies the condition since I didn’t ask it to find all of them.

Thanks for this, I’ve meant to ask the same thing. It feels like there ought to be some kind of “the first thing that” rather than “a random thing that”… but I guess it’s just not a list like that?

Inform7 is really cool, but when it comes to handling collections (lists, sets, dictionaries, maps, arrays, stacks, queues, what have you) I 'd really much rather be doing stuff in Java or some other type of language. Maybe I ought to write an extension for this. :slight_smile:

There is a canonical list of each kind, but it’s not up to you – it’s the order the compiler puts things in. (Which is not always the same as source-code order.) Since it’s an implementation detail, exposing it would be more confusing than not; it would effectively be “a random thing that mostly doesn’t change between runs”…

The good news is that the “a random DESC” routine is quite efficient, particularly for the case where there’s exactly one thing that matches. It doesn’t need to create a dynamic list and measure it.

(However, a property lookup or one-to-one relation is more efficient.)

I know this is already solved, but I noticed this in the OP

Let p be the desk that incorporates the drawer Let p be the desk that the drawer is part of Let p be the desk to which the drawer relates to by incorporation
Any time you say “the [kind]”, you’re asking for trouble since Inform does not distinguish between that and “a [kind]”, so as far as Inform was concerned, you saidLet p be a desk that incorporates the drawer Let p be a desk that the drawer is part of Let p be a desk to which the drawer relates to by incorporation
And of course, Inform complains that you’re not being specific enough!