Search code examples
clips

trying to retract facts when using clips


I am new to clips, I found that my retract not really delete the facts.

(defrule test
(select ?select~indoor&~outdoor)
=>
(retract ?select)
)

After the clips run this code, I try to check by using (facts),but I still found that the facts select is still there


Solution

  • You need to bind a variable to the fact matching the pattern. You can't retract the fact by binding a variable to a value inside the fact.

             CLIPS (6.31 2/3/18)
    CLIPS> 
    (defrule test
       ?f <- (select ...)
       =>
       (retract ?f))
    CLIPS> (assert (select ...))
    <Fact-1>
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (select ...)
    For a total of 2 facts.
    CLIPS> (run)
    CLIPS> (facts)
    f-0     (initial-fact)
    For a total of 1 fact.
    CLIPS>