Search code examples
assertlogical-operatorsclips

Logical OR in CLIPS - simple defrule


I've just started working in CLIPS. I'm trying to do this simple rule, but i've got no idea how to use logical OR here. I know I could define two rules (one for relative-brother and other one for relative-sister) but I think it's not a point. The rule is: You are a relative of someone, if you are his brother or sister.

(defrule MAIN::siblings-relatives
       (is-brother ?x ?y)
      (test (or (is-sister ?x ?y))
       =>
       (assert (is-relative ?x ?y))
       (printout t ?x " is relative of " ?y crlf))

Solution

  • CLIPS> (clear)
    CLIPS>
    (defrule siblings-relatives
       (or (is-brother ?x ?y)
           (is-sister ?x ?y))
       =>
       (assert (is-relative ?x ?y))
       (printout t ?x " is relative of " ?y crlf))
    CLIPS> (assert (is-brother Dave Jim))
    <Fact-1>
    CLIPS> (assert (is-sister Jane Frank))
    <Fact-2>
    CLIPS> (run)
    Jane is relative of Frank
    Dave is relative of Jim
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (is-brother Dave Jim)
    f-2     (is-sister Jane Frank)
    f-3     (is-relative Jane Frank)
    f-4     (is-relative Dave Jim)
    For a total of 5 facts.
    CLIPS>