Are quantitative relations possible? Or relations between three objects and values?

I would like to be able to relate various objects and values by a number, however reading through the relations section I assume this isn’t possible as all of the examples are between two objects or values. It seemed to me trying to accomplish this by relations would be the most intuitive way but if it’s not possible I’m curious what other ways to accomplish this would be that can be more generalized.

Here is an example of what I would ideally like, which does not work:

lab is a room. Here is a person called Gwen. Here is a person called Bob.

Friendship relates various people to various people by a number.

Gwen Friendship relations Bob by 10.

The other way that came to mind was much more brute force which I’d like to avoid, of having each person having their own values representing their relation to others. For example:

lab is a room. Here is a person called Gwen. Here is a person called Bob.

Every person has a number called friendship to Bob.

Every person has a number called friendship to Gwen

The friendship to Bob of Gwen is 10.

The friendship to Gwen of Bob is 10.
1 Like

A month ago the answer would have basically been “no.” But @Dannii has been rocking the I7 universe with new extensions like Collections and so…

Include Collections by Dannii Willis.

Friendship-map is a collection reference that varies.

To set the friendship of (p1 - a person) to (p2 - a person) to (n - a number):
  (friendship-map => p1) => p2 = n;

To decide what number is the friendship of (p1 - a person) to (p2 - a person):
  unless (friendship-map has key p1) and ((friendship-map => p1) has key p2), decide on 0;
  decide on (friendship-map => p1) => p2 as a number;

Alice is a person.
Bob is a person.
Char is a person.

First when play begins:
  now friendship-map is a new map;
  repeat with p running through persons begin;
    set key p of friendship-map to a new map;
  end repeat;
  set the friendship of alice to bob to 5;
  set the friendship of alice to char to 9;
  set the friendship of bob to alice to 4;
  set the friendship of bob to char to 7;
  set the friendship of char to alice to 8;
  set the friendship of char to bob to 2;

every turn:
  set the friendship of char to alice to 1;
  repeat with p1 running through people begin;
    repeat with p2 running through people begin;
      if p1 is p2, next;
      say "[p1] to [p2] is [friendship of p1 to p2].";
    end repeat;
  end repeat;

test me with "z".

produces

yourself to Alice is 0.
yourself to Bob is 0.
yourself to Char is 0.
Alice to yourself is 0.
Alice to Bob is 5.
Alice to Char is 9.
Bob to yourself is 0.
Bob to Alice is 4.
Bob to Char is 7.
Char to yourself is 0.
Char to Alice is 1.
Char to Bob is 2.

People already used to hashes/associative arrays from other languages will feel at home with this; it might feel somewhat foreign to people new to them.

5 Likes

I know Collections is the latest craze :wink: but couldn’t we do the same with plain old tables?

Table of Friendship
p1   	p2   	value
alice	bob  	5
alice	char  	9
bob  	alice	4
bob  	char 	7
char 	alice	8
char 	bob  	2

To set the friendship of (p1 - a person) to (p2 - a person) to (n - a number):
	repeat through table of Friendship:
		if the p1 entry is p1 and the p2 entry is p2:
			now the value entry is n;
			stop;

To decide what number is the friendship of (p1 - a person) to (p2 - a person):
	repeat through table of Friendship:
		if the p1 entry is p1 and the p2 entry is p2:
			decide on the value entry;
	decide on 0;

Alice is a person.
Bob is a person.
Char is a person.

Every turn:
	set the friendship of char to alice to 1;
	repeat with p1 running through people:
		repeat with p2 running through people:
			if p1 is p2, next;
			say "[p1] to [p2] is [friendship of p1 to p2].";

test me with "z".
1 Like

For many things tables will be a better solution. The main downside of tables is that they have a fixed size. You can put in blank rows, but you have to predict carefully how much space to preserve. And if you predict wrong there’s nothing you can do at run time to add more rows.

5 Likes

This works in v10:

a person has a relation of a person to a number called the friendship level.

To set the friendship of (p1 - a person) to (p2 - a person) to (n - a number):
  now the friendship level of p1 relates p2 to n;

To decide what number is the friendship of (p1 - a person) to (p2 - a person):
  if p2 relates to a number by the friendship level of p1, decide on the number to which p2 relates by the friendship level of p1;
  decide on 0.

This changes some things.

It compiles in 6M62 but along with the other code in my example above (with the friendship-map bits removed) blows up on a runtime error in all of git, glulxe, quixe.

6 Likes