Search code examples
clips

How to retrive facts asserted by a rule having particular name?


I have certain template defined as follows:

(deftemplate action
    (slot name)
    (slot field)
    (slot value))

I have other rules which will use other facts to assert the action fact.

Now I want to retrieve only the fact with template action.

For now, I am using find-fact to retrieve, but here I have to use query which I do not want to provide.

(find-fact ((?fact action)) (= (str-compare ?fact:name 'Action1') 0))

I want all facts with template action and do not want to write a loop over all names with Action1, Action2 etc..

Thank you in advance.


Solution

  •          CLIPS (6.31 4/1/19)
    CLIPS> 
    (deftemplate action
        (slot name)
        (slot field)
        (slot value))
    CLIPS> 
    (deffacts actions
       (action (name Action1) (field x) (value 3))
       (action (name Action2) (field y) (value 4))
       (action (name Action3) (field z) (value 5)))
    CLIPS>        
    (defrule find-Action1
       (action (name Action1))
       =>)
    CLIPS> (reset)
    CLIPS> (agenda)
    0      find-Action1: f-1
    For a total of 1 activation.
    CLIPS> (facts)
    f-0     (initial-fact)
    f-1     (action (name Action1) (field x) (value 3))
    f-2     (action (name Action2) (field y) (value 4))
    f-3     (action (name Action3) (field z) (value 5))
    For a total of 4 facts.
    CLIPS>