I was wondering whether it is possible to create rules from within rules? For example, the program below tries to create a rule from within its RHS.

(defrule create-rule-on-rhs
        "This is a test to see if you can create a rule"
        ;LHS
        (some-fact)
        =>
        ;RHS
        ;call to the function defrule
        (defrule child-rule
                "This is the rule that will be created"
                (another-fact)
                =>
                (printout t "Hello world - i'm a new rule and i am alive!" crlf)
        )
)

(deffacts ben-facts
        "Some test data"
        (some-fact)
)

(reset)
(rules)
(run)
(rules)

However, this code generates the exception below:

MAIN::create-rule-on-rhs
For a total of 1 rules.
Jess reported an error in routine Funcall.execute
        while executing (defrule child-rule "This is the rule that will be creat
ed" (another-fact) "=" > (printout t "Hello world - i'm a new rule and i am aliv
e!" crlf))
        while executing defrule MAIN::create-rule-on-rhs
        while executing (run).
  Message: Unimplemented function defrule.
  Program text: ( run )  at line 35.
        at jess.Funcall.execute(Funcall.java:258)
        at jess.Defrule.fire(Defrule.java:215)
        at jess.Activation.fire(Activation.java:84)
        at jess.Agenda.run(Agenda.java:203)
        at jess.Agenda.run(Agenda.java:183)
        at jess.Rete.run(Rete.java:1098)
        at jess.HaltEtc.call(Funcall.java:1487)
        at jess.FunctionHolder.call(FunctionHolder.java:30)
        at jess.Funcall.execute(Funcall.java:266)
        at jess.Jesp.parseAndExecuteFuncall(Jesp.java:1590)
        at jess.Jesp.parseSexp(Jesp.java:173)
        at jess.Jesp.parse(Jesp.java:69)
        at jess.Jesp.parse(Jesp.java:54)
        at jess.Main.execute(Main.java:126)
        at jess.Main.main(Main.java:24)

Can anyone help? This may turn out to be a crazy thing to do but that is an equally good response to the problem.

Ben Allen -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------

Reply via email to