6L02 / Inform 6 / -default-value-for

Okay, this is a bit technical and verbose, so I thought I’d put it in its own topic. Kerkerkruip has some code that allows us to do fun things with kinds. But apparently, something has changed in Inform 6L02 that makes this fail compilation.

I don’t understand this code very well, since it dives into the I6 layer rather deeply. If anyone can help me, that would be much appreciated.

Here is a sample game:

[code]“Species” by Victor Gijsbers

The lab is a room. “Let’s count kinds.” The player is here.

A vegetable is a kind of thing.
A cucumber is a kind of vegetable.
A tomato is a kind of vegetable.
A cabbage is a kind of vegetable.

Include (-

! Find the kind of an object
[ KindOfObj obj;
return KindHierarchy–>( ( obj.KD_Count ) * 2 );
];

! Test if a kind is a subkind of another kind
[ 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 decide which K is kind of/-- (kind - name of kind of value of kind K):
(- KindOfObj( {-default-value-for:kind} ) -).

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 (this is the count kinds of vegetables rule):
let n be 0;
repeat with S running through the kinds of vegetable:
increase n by 1;
say “There are [n in words] kinds of vegetable.”.[/code]
This now fails with:

It did work previously, though. Has something changed that has to do with “default-value-for”?

Yes.

The “kind of…” phrase should now look like:

To decide which K is kind of/-- (kind - name of kind of value of kind K):
	(- KindOfObj( {-new:K} ) -).

However, making the same substitution in the objectloop doesn’t produce a correct count. Will look further.

Oh, okay, it does work – as long as there’s at least one instance of every class. (6G60 had the same requirement, it’s not new.)

The Kitchen is a room.

A vegetable is a kind of thing.
A cucumber is a kind of vegetable.
A tomato is a kind of vegetable.
A cabbage is a kind of vegetable.

The veg is a vegetable.
The tom is a tomato.
The cuke is a cucumber.
The cab is a cabbage.

Include (-

! Find the kind of an object
[ KindOfObj obj;
	return KindHierarchy-->( ( obj.KD_Count ) * 2 );
];

! Test if a kind is a subkind of another kind
[ 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 decide which K is kind of/-- (kind - name of kind of value of kind K):
	(- KindOfObj( {-new:K} ) -).

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({-new:K})) ) -).
	
When play begins (this is the count kinds of vegetables rule):
	let n be 0;
	repeat with S running through the kinds of vegetable:
		increase n by 1;
	say "There are [n in words] kinds of vegetable.".

Thanks zarf, that’s very helpful!