[I7] Phrases involving kinds

Hi all, I’m trying to pass in a kind to a phrase, but I can’t get anything to work. Any ideas?

[code]When play begins:
try1 person;
try2 person;

To try1 (kind - name of kind of object):
(- print {kind}, “^”; -).
To try2 (kind - name of kind of value):
(- print {kind}, “^”; -).
[/code]

This results in nothing being substituted, rather than the class.

[ R_744 ; ! phrase 1 ! [1: try1 person] print nothing, "^"; ! phrase 2 ! [2: try2 person] print nothing, "^"; rfalse; ];

Could you set the name of a kind as a text belonging to the kind?

Like:

[code]A thing has a name called kind-name.
A dog is a kind of animal.
The kind-name of a dog is “dog”.

To try1 (T - a thing):
say “[kind-name of T]”;[/code]

Thanks, but I don’t want the name of the kind, I want the kind itself. In the standard rules there are a few phrases which use arguments something like “name of kind of value”, but I can’t get them to work.

The answer appears to be “no, you can’t do that.”

The only library phrases that accept naked kinds look like this:

To decide what K is the (name of kind K) produced by (RL - rule producing a value of kind K):
(- ResultOfRule({RL}, 0, false, {-strong-kind:K}) -).

I can’t tell what the “-strong-kind” qualifier is doing there; in my tests it always compiles to 9, no matter what kind is used. :slight_smile: In further tests I managed to make the I7 compiler assert, but since I’m misusing an undocumented notation, I’m not surprised.

In any case this sort of phrase requires a second argument – a value whose type involves K in some way. So it’s not what you want.

Aha – it appears that -strong-kind:K generates the I6 constant OBJECT_TY, NUMBER_TY, etc (as appropriate for K). All kinds-of-thing generate 9 because that’s OBJECT_TY.

I presume that’s not what you want either.

Well it’s a little messy, but I got it working:

[code]There is a room.

A scroll is a kind of thing.
A default scroll is a scroll.

A scroll of invisibility is a kind of scroll.
My scroll of invisibility is a scroll of invisibility.

A scroll of torment is a kind of scroll.
My scroll of torment is a scroll of torment.

Include (-
[ KindOfObj obj;
return KindHierarchy–>( ( obj.KD_Count ) * 2 );
];

[ TestSubkind subclass superclass i;
! These classes are outside the kind heirarchy and must be dealt with first
if ( subclass == Class or Object or Routine or String or VPH_Class )
rfalse;
while (1)
{
if ( KindHierarchy–>i == subclass )
return KindHierarchy–>( KindHierarchy–>(i + 1) * 2 ) == superclass;
i = i + 2;
}
];
-).

To repeat with (loopvar - nonexisting K variable) running through the/-- kinds of (kind - name of kind of value of kind K) begin – end:
(- objectloop( {loopvar} && metaclass({loopvar}) == Class && TestSubkind({loopvar}, KindOfObj({-default-value-for:kind})) ) -).

When play begins:
repeat with A running through the kinds of scroll:
say “Kind: [A][line break]”;[/code]

Things I’d like to clean up if possible:

  1. A better way to eliminate non-kind classes than manually listing them all, or some way to find out the number of kinds.
  2. Some way to get access to the class of a kind other than through it’s default value (which necessitates creating an instance of each kind which you want to iterate through.)

My goal is making kinds mutable at run-time. :slight_smile:

Regarding 1 and 2, my earlier reply to Victor somewhat addresses both points, at the cost of introducing dead code. I’m not quite sure if it’s what you want.