问题
Updated code:
where to add the check for ?f<-(practice-is-on-off OFF)
(defrule no-practice "Rules for when practice cannot be held"
(or ?f <- (practice (number-of-paddlers ?p&:(< ?p 6)))
?f <- (practice (number-of-coaches ?c&:(< ?c 1))))
=>
(modify ?f (practice-is-on-off OFF)))
;end
I am defining a template in CLIPS and I am using logical operator OR. However, when I load the template, it is throwing an error saying
[TMPLTDEF1] Invalid slot or not defined in corresponding deftemplate practice.
ERROR:
(defrule MAIN::no-practice "Rules for when practice cannot be held"
?f <- (practice (or
Here's what I have: Thanks in advance for any insight. Thanks
(deftemplate practice "structure of a practice"
(slot number-of-paddlers (type NUMBER))
(slot number-of-coaches (type NUMBER))
(slot practice-is-on-off (type SYMBOL) (default ON))
(slot practice-id (type NUMBER))
)
(defrule no-practice "Rules for when practice cannot be held"
?f <- (practice
(or
(number-of-paddlers
?v_number-of-paddlers&:(
< ?v_number-of-paddlers 6))
(number-of-coaches
?v_number-of-coaches&:(
< ?v_number-of-coaches 1))
)
)
=>
(modify ?f (practice-is-on-off OFF)
)
)
回答1:
The error is telling you that you are attempting to match a slot named "or" in the practice
deftemplate and that slot does not exist. Here are two alternate versions of the "no-practice" rule that will accomplish what you are trying to do.:
Version 1:
(defrule no-practice "Rules for when practice cannot be held"
(or ?f <- (practice (practice-is-on-off ON)
(number-of-paddlers ?p&:(< ?p 6)))
?f <- (practice (practice-is-on-off ON)
(number-of-coaches ?c&:(< ?c 6))))
=>
(modify ?f (practice-is-on-off OFF)))
Note that the rule above may fire twice for a practice
unless you also check that practice-is-on-off
is "ON" in the CE's.
Version 2:
(defrule no-practice "Rules for when practice cannot be held"
?f <- (practice (practice-is-on-off ON)
(number-of-paddlers ?p) (number-of-coaches ?c))
(test (or (< ?p 6) (< ?c 6)))
=>
(modify ?f (practice-is-on-off OFF)))
来源:https://stackoverflow.com/questions/16223702/how-to-do-a-logical-or-in-clips