Repeat Through a Rulebook

version 4 by Ron Newcomb

  • Home page
  • Beginning
  • Previous
  • Next



  • Section - Rule Loops, modified

    To repeat with (loopvar - nonexisting rule variable) running through/thru the/a/an/-- modified/-- (ar - a rulebook) begin -- end:
    (- {-allocate-storage:LoopingThruRulebooks} ! {-advance-counter:LoopingThruRulebooks} ! don't delete this comment; it actually still advances the counter, which is important because -->0 means something way different than -->1 or -->2
        I7_ST_LoopingThruRulebooks-->{-counter:LoopingThruRulebooks} = 0;
        for ( {loopvar} = NextRuleAfterRule({ar},{ar})
            : {loopvar} ~= NULL
            : {loopvar} = NextRuleAfterRule({loopvar}, {ar})
            ) -).

    To repeat with (loopvar - nonexisting rule variable) running through/thru the/a/an/-- modified/-- (ar - a rulebook variable) begin -- end:
    (- {-allocate-storage:LoopingThruRulebooks} ! {-advance-counter:LoopingThruRulebooks} ! don't delete this comment; it actually still advances the counter, which is important because -->0 means something way different than -->1 or -->2
        I7_ST_LoopingThruRulebooks-->{-counter:LoopingThruRulebooks} = 0;
        for ( {loopvar} = NextRuleAfterRule({ar},{ar})
            : {loopvar} ~= NULL
            : {loopvar} = NextRuleAfterRule({loopvar}, {ar})
            ) -).

    To decide if (R - a rule) is/are currently/-- listed in/for the/a/an/-- modified/-- (rb - a rulebook):
        (-IsRuleInRulebook({R}, {rb})-).

    To decide if (R - a rule) is/are currently/-- not currently/-- listed in/for the/a/an/-- modified/-- (rb - a rulebook):
        if R is listed in rb, decide no; otherwise decide yes.

    To decide which number is number of rules of/in/for/from the/a/an/-- modified/-- (rb - a rulebook):
        (- (NumberOfRulesInRulebook({rb})) -).

    Include (-
    Global LookingForRuleInRulebook = NULL; ! set to a Rule when looking for a rule in a modified rulebook; if found, set to NULL; if not found, leave as-is; initialized back to NULL before returning
    Global CountRulesInRulebook = 0;
    Global DoneSearchingRulebooks = 0;
    Global ReasonForIterating; ! 1 = NextRuleAfterRule; 2 = NumberOfRules; 3 = IsRuleIn

    [ IsRuleInRulebook r ar i; ! also nicknamed case (3)
        DoneSearchingRulebooks = 0;
        CountRulesInRulebook = 0;
        ReasonForIterating = 3;
        LookingForRuleInRulebook = r;
        PseudoProcessRulebook(ar,0,0,(+directly invoked+));
        if (LookingForRuleInRulebook == NULL) rtrue; ! being found is indicated by this variable having been set back to NULL
        rfalse;
    ];

    [ NumberOfRulesInRulebook ar; ! also nicknamed case (2)
        DoneSearchingRulebooks = 0;
        CountRulesInRulebook = 0;
        ReasonForIterating = 2;
        LookingForRuleInRulebook = LITTLE_USED_DO_NOTHING_R;
        PseudoProcessRulebook(ar,0,0,(+directly invoked+));
        return CountRulesInRulebook;
    ];

    [ NextRuleAfterRule r ar; ! also nicknamed case (1)
        DoneSearchingRulebooks = 0;
        CountRulesInRulebook = 0;
        ReasonForIterating = 1;
        LookingForRuleInRulebook = r;
    #ifdef LOOP_THRU_RULEBOOKS_F;
        print "[SEARCHING for the rule that comes after ~", (RulePrintingRule) r, "~]^";
    #endif;
        PseudoProcessRulebook(ar,0,0,(+directly invoked+));
        if (LookingForRuleInRulebook == r) return NULL; ! meaning there isn't a Next Rule after the one we entered
        return LookingForRuleInRulebook;
    ];
    -).