reversing relations

I have a relation “sitting” that maps multiple customers to a single table in the Inn.

Sitting relates various customers to one inn-table. 
The verb to sit at means the sitting relation. 

And this works fine for randomly distributing multiple customers to various tables. However, down the road I need to find which table a particular customer is sitting.
I have not found how to declare relations as reversible or not, not can I find how I know if they are reversible.
When I enter RELATIONS, I get a strange symbol:
Roberta >=> Table 1
Tyrone >=> Table 2

Are these reversible relations? Doesn’t seem so since the arrows (>=>) go in the same direction. If not, how can I make the relation reversible?

Sitting relates one inn-table to various customers. 

doesn’t work: compiler complains of redundancy.

EDIT: OK, I found that reversible relations are designated by this symbol:
<=>.
So now, how to make this relation reversible?

Except for conditional relations, relations are automatically reversible. Defining another verb to mean the reversed relation can make it easier to access the info in the other direction…

The Inn is a room.

An inn-table is a kind of thing.
The table is an inn-table in the Inn.

A customer is a kind of person.
Bob is a customer in the Inn.

Sitting relates various customers to one inn-table.

The verb to sit at means the sitting relation.
The verb to seat means the reversed sitting relation.

The table seats Bob.

If the verb you associate with a relation is single-word, Inform automatically creates a to be <verb>ed by verb meaning the reversed relation (as well as a to be <verb>ing alias for the regular relation).

Ownership relates one person to various things.
The verb to own means the ownership relation.

Bob owns the wristwatch.

when play begins:
  if the wristwatch is owned by Bob, say "tick tock.";
  if Bob is owning the wristwatch, say "tock tick.";

<=> is just something the relations debugging command uses in output. It’s not Inform code.

2 Likes

This is great! I was not focusing on the verb used.
However, when I add that extra line

Sitting relates various customers to one inn-table.
The verb to sit at means the sitting relation. 
The verb to seat means the reversed sitting relation.

I still get the single directional arrows; I just get the list of customers twice; as in

Sitting relates various customers to one inn-table:
Ahaz >=> Table 1
Boaz >=> Table 2
. . .
Sitting relates various customers to one inn-table:
Ahaz >=> Table 1
Boaz >=> Table 2
. . .

I would like to build this rule:

find inn-table of noun;
	
To find inn-table of (P - customer): 
	say "[P] is seated at [inn-table]";

doesn’t compile. What’s wrong?

<=> is relations’ output for symmetric/reciprocal relations; it doesn’t have to do with reversibility.

That relations’ output gives the results twice when you explicitly define a verb for the reversed relation is a bug. It didn’t happen in 9.3/6M62.

Inform doesn’t base anything about what To find inn-table of does on the text of the string “To find inn-table of”. It had might as well be:

To bloop (P - customer): 
  say "[P] is seated at [inn-table]";

…which perhaps makes more obvious that the compiler would have no idea what inn-table is supposed to mean in that code block.

Check out WI Chapter 6: Descriptions [of values] again, especially Which and who?, and then reread WI Chapter 13: Relations. It’s not great that they’re presented as different topics and separated by several chapters. They’re very substantially two halves of one whole about relations and sentences and understanding either requires understanding both.

Two existing ways to get at the info are:

  • a random inn-table which seats Bob
  • the inn-table that Bob relates to by the sitting relation
2 Likes

Great! Thanks very much. It worked.
I understood about the compiler being ignorant of “inn-table”; that was merely to link the rule with its caller.

	find inn-table of noun;
	
To find inn-table of (P - customer): 
	let T be a random inn-table which seats P;
	say "[P] is seated at [T]";

One last thing though. I want all the customers sitting at that table, and this doesn’t work, even though it is taken verbatim from the index. Can you explain it?

To find inn-table of (P - customer): 
	let T be a random inn-table which seats P;
	say "[P] is seated at [T]";
	let L be a list of customers which T relates to by the sitting relation;
	say "[L]";

I’ve tried all the (indistinguishable) phrasing in the index about “list of [name of kind]” and none of them compile.
And also (more intuitive but not compiling)

...
let L be a list of customers which are seated by T;
say [L];
let t be a random inn-table that seats Bob;
say the list of customers which relate to t by the sitting relation;

You could also use, e.g., the list of inn-tables which Bob relates to by the sitting relation.

When you create a relation like

Sitting relates various customers to one inn-table.

What’s on the left-hand side – customers relates to what’s on the right-hand side – inn-tables. What’s on the right-hand side is related to by what’s on the left-hand side.

So these work:

  if Bob relates to an inn-table by the sitting relation, say "bob-table: [the inn-table to which bob relates by the sitting relation]!";
  if a customer relates to the banquet-table by the sitting relation, say "[the customer that relates to the banquet-table by the sitting relation].";
  say the list of inn-tables which Bob relates to by the sitting relation;
  say the list of customers which relate to t by the sitting relation;

but if you get the direction of relates to and related to by backwards, they won’t.

I have to look up the exact phrasing every time and still usually get it wrong multiple times before getting it right.

1 Like

This should work, but it doesn’t compile. First, the quotes are missing for a say statement; second, the compile error

Problem. You wrote ‘let L be a list of customers which relates to T by the sitting relation’ but the ingredients in this phrase do not fit it, and I am confused enough by this that I can’t give a very helpful problem message. Sorry about that.

There are 6 different forms of “list of (name of kind)” and I can’t tell one from the other. I’ve tried them all, and all give compile errors.

EDIT: I’m sorry. I should have been more specific.

To find inn-table of (P - customer): 
	let T be a random inn-table that seats P;
	say "[P] is seated at [T]";
>>	leet L be list of customers which relate to T by the sitting relation;
	say "[L]";

The fourth line (marked with >>) fails with the compile error shown above.

PS. Based on example 238, the following line seems the most intuitive (it also doesn’t compile):

let L be a list of customers that sit at T;

I had changed “the table” to “the banquet-table” in my sample code, sorry, but otherwise what I gave above compiles (and works) as given, in combination with the code I gave above.

Yes, that worked! What worries me is that all I did was close down Inform and reopen it. I think perhaps that cleared something up, some partial compile note perhaps?