Rules producing numbers vs. rulebooks producing numbers

I have this code that works if I define a rulebook. But I would like to be able to access the rule.

r1 is a room. r2 is west of r1. r3 is south of r2. r4 is east of r3. r1 is north of r4.

the cluelength rules are a rulebook producing a number.

a cluelength rule (this is the jake-g-length rule):
	if the player is in r1, rule succeeds with result 37;
	if the player is in r2, rule succeeds with result 23;
	if the player is in r3, rule succeeds with result 49;
	
every turn: [the commented code doesn't work. What am I doing wrong?]
	[follow the jake-g-length rule;
	let X be the number produced by the rulebook;
	let Y be the number produced by the jake-g-length rule;]
	let Y be the number produced by the cluelength rules;
	say "[Y].";

The numeric details of the code aren’t important, but I want to be able to use a rule to find a number, instead of a rulebook. Is this possible or desirable? If so, how?

I’ve had success using “the outcome produced by the rulebook” when I’ve defined outcomes, but I’m having trouble with numbers.

Code that works for outcomes
the goodrhyme rules are a rulebook. the goodrhyme rules have outcomes unavailable, not-yet, already-done and ready.

a goodrhyme rule (this is the vc-big-bag rule) :
	if player has big bag:
		vcal "You already made the big bag.";
		already-done;
	ready;

every turn:
    consider the vc-big-bag rule;
    let X be the outcome of the rulebook;
    if X is the ready outcome, say "You can make the big bag now.";

I’m using 6g60. Thanks!

I think this is not possible without digging into the I6 level.

I’m not sure whether it counts as a bug or a hole in the type system. A rulebook can have a a “producing” type. Rules in such a rulebook do in fact produce values. Rulebooks are type-convertible to rules. The compiler understands “rule producing a value of type T” as a type declaration. So all the pieces are in place. But you can’t define a concrete rule as producing a number.

In practice I use functions (phrases) for singleton cases like this, and rulebooks for when I want several rules.

2 Likes