# 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?]
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:

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