Is this type of decide phrase possible?

I’m trying to figure out a way to write a “decide on” phrase to return:

  1. a number N
  2. that is the property of an object of kind X1
  3. which is one of several distinct but related objects with varying kinds (X1, X2, X3, etc.)
    a) each of said kinds being a subkind of a parent X kind
    b) and each of said objects being the only instance of that subkind in the related group
  4. the whole group of which are related to a thing (call it Z)

and I would like the phrase to be expressible with something like: “intensity of X1 for Z”

That’s a bit complicated in the abstract, so, as an example:
A) rock kind is the equivalent of kind X, and all rocks have a numeric beauty property (which is the N value)
B) slate, marble, and flint are the equivalents of kinds X1, X2, X3
C) Z might be a person named Bob
D) a collection of a slate and a marble and a flint might all be desired by Bob using a new “desires” relation

I want to be able to say something like:

   say "[beauty of flint* wanted by Bob*]"

where I can substitute the asterisked items with any combination of a subkind of rock and a person.

Is this possible? It seems like it should be, but I can’t quite seem to make it work. If I’m reading the documentation correctly, this would be along the lines of a phrase (description of things, person)->number but I’m having trouble translating that back into a working phrase.

Note that a construction like “list of rocks that are flints that are desired by Bob” works OK… I just can’t figure out how to get a parameterized equivalent. I assumed it would be along the lines of:

To decide which number is the beauty of (rocktype - description of rocks) for (X - a person): ... decide on N.

In the middle part, it seems OK to write something like:

   let possibilities be the list of rocktype; [sets it to a list of all flints, marbles, etc. as specified]

or

let possibilities be the list of rocks desired by X; [sets it to a list of all rocks desired by person specified]

but I want to be able to combine the two filters to get it down to just the one rock of the right type desired by the right person, and I can’t figure out a phrase acceptable to the compiler along the lines of:

   let possibilities be the list of rocks that are rocktype that are desired by X;

Note that I realize I could use the working bits above to create the two short lists and then iterate through one of them looking for the item listed in the other, but that doesn’t seem very elegant.

Does “the beauty of a random rock which is flint which is desired by Bob” work? (Often “a random…” is used when there’s only one of something, though it should be possible to create some sort of “the first…” construction which breaks out of the loop once it finds something. May help performance if you have thousands of rocks.)

Can a person desire more than one rock of the same kind? If there are multiple flints and Bob can desire more than one of them, then you can’t just return “the beauty value of the flint desired by Bob,” because there might be more than one flint involved.

If a person can only desire one rock of any given kind, then you just get the list of rocks desired by that person, iterate through the list until you find a rock that matches the specified kind, and return its sparkliness value. (Note, I’m using “sparkliness” to refer to the rock property, because in your original example you use “beauty” to mean two different things: the name of the rock property and the temporary variable in which your phrase stores its return value. That will probably cause problems in your code.)

To decide which number is the beauty of (rocktype - description of rocks) for (X - a person): let possibilities be the list of rocks desired by (X); repeat with testrock running through possibilities: if testrock matches rocktype, decide on the sparkliness of the testrock; decide on 0.

The phrase returns 0 if the specified person does not desire any rocks of the specified type.

(Edited for zarf’s correction.)

You want “if testrock matches rocktype”, not “if testrock is rocktype”.

Mike,

Yes, in the analogy a given person will only want one of a given subtype of rock. You have the idea of what I am trying to do, but is that the only way it can be done? I specifically noted at the tail end that I was trying to figure out a way to do this that didn’t iterate through one list from another (though that is how I’m doing it now, as a placeholder).

zarf,

I was hoping that I could figure out something that uses matches, but that means I have to construct a description that will simultaneously filter on both at once? (Constructed by phrase returning a phrase??) It seems like maybe I’m trying to convince the compiler to accept two descriptions (one based on kind and one based on relations) at the same time… which is more complicated than I originally considered in the general case, probably, so I can see why it wouldn’t be allowed, though it seems as if certain specific cases can be done (e.g. “list of open containers in Cave,” which simultaneously qualifies on an adjective and a relation).

Oh, you sure did – my bad.

What about:

To decide which number is the beauty of (rocktype - description of rocks) for (X - a person): let possibilities be the list of rocks desired by X; let remaining be filter to rocktype of possibilities; if the number of entries in remaining is 1, decide on the sparkliness of entry 1 of remaining; if the number of entries in remaining is 0, decide on 0; if the number of entries in remaining is greater than 1, decide on 9999.

I’ve not done very much with the material in the Advanced Phrases chapter of the documentation, but that seems like it should work.

If you set up the relation like “desirability relates various people to various rocks,” where flints and agates and quartzes are sub-kinds of rocks, then you should also account for the possibility that Joe likes more than one flint, even though it’s not supposed to happen.

If you don’t mind a couple of temporary global variables, you can say

Current-rocktype is a description of rocks that varies.
Current-person is a person that varies.

Definition: a rock is selectable if it matches current-rocktype and it is desired by current-person.

Once you set current-rocktype and current-person, you can talk about “all selectable rocks”, “a random selectable rock”, etc.

Add in

Definition: a rock is pretty if its sparkliness is 5 or more.

…and you can talk about “the prettiest selectable rock”. (Which might be nothing, of course.)

zarf,

This is interesting, but there’s a part I don’t get: How can one construct a description to use for setting the current-rocktype variable?

In my test code I wrote:

A rock is a kind of thing.
A rock has a number called the sparkliness.

A rock can be mafic.

To decide which number is the beauty of (rocktype - description of rocks) for (X - a person):
[...]

Every turn:
	showme the beauty of mafic rocks for the player;