I have the following program (using CLIPS)
Facts:
(deffacts family
(father tom nicholas)
(mother clair nicholas)
(father tom john)
(father brad tom)
(father mark clair))
then I use (reset)
rule1:
(defrule parent
(or (father ?x ?y) (mother ?x ?y))
=> (assert (parent ?x ?y)))
rule2:
(defrule gp
(and (parent ?x ?y) (parent ?y ?z))
=> (assert (gp ?x ?z)))
If I wrote (agenda) I am getting only
0 parent: f-5
0 parent: f-4
0 parent: f-3
0 parent: f-2
0 parent: f-1
and for matches (matches parent):
Matches for Pattern 1
f-1
f-3
f-4
f-5
Matches for Pattern 1
f-2
Activations
f-5
f-4
f-3
f-2
f-1
but for gp: (matches gp)
Matches for Pattern 1
None
Matches for Pattern 2
None
Partial matches for CEs 1 - 2
None
Activations
None
(0 0 0)
Why id the rule is based on another rule doesn't appear neither in agenda nor in matches ? or is there anything wrong ?
Update: is it because when we execute (agenda), CLIPS evaluates all the rules in the rule base to determine which ones have conditions (patterns) that match the current state of the working memory, which consists of asserted facts. If a rule's conditions match the facts, an activation for that rule is placed on the agenda. so it is only meant for facts ?
A fact has to exist in order to match a pattern in a rule. When a (reset) command is issued, the facts in the deffacts family will be asserted and these will match the patterns in the parent rule. When a (run) command is issued, the parent rule will be able to execute and this will cause the parent facts to be asserted that can match and activate the gp rule.
CLIPS (6.4.1 4/8/23)
CLIPS>
(deffacts family
(father tom nicholas)
(mother clair nicholas)
(father tom john)
(father brad tom)
(father mark clair))
CLIPS>
(defrule parent
(or (father ?x ?y) (mother ?x ?y))
=>
(assert (parent ?x ?y)))
CLIPS>
(defrule gp
(and (parent ?x ?y) (parent ?y ?z))
=>
(assert (gp ?x ?z)))
CLIPS> (agenda)
CLIPS> (matches parent)
Matches for Pattern 1
None
Matches for Pattern 1
None
Activations
None
(0 0 0)
CLIPS> (matches gp)
Matches for Pattern 1
None
Matches for Pattern 2
None
Partial matches for CEs 1 - 2
None
Activations
None
(0 0 0)
CLIPS> (reset)
CLIPS> (agenda)
0 parent: f-5
0 parent: f-4
0 parent: f-3
0 parent: f-2
0 parent: f-1
For a total of 5 activations.
CLIPS> (matches gp)
Matches for Pattern 1
None
Matches for Pattern 2
None
Partial matches for CEs 1 - 2
None
Activations
None
(0 0 0)
CLIPS> (matches parent)
Matches for Pattern 1
f-1
f-3
f-4
f-5
Matches for Pattern 1
f-2
Activations
f-5
f-4
f-3
f-2
f-1
(5 0 5)
CLIPS> (run 1)
CLIPS> (facts)
f-1 (father tom nicholas)
f-2 (mother clair nicholas)
f-3 (father tom john)
f-4 (father brad tom)
f-5 (father mark clair)
f-6 (parent mark clair)
For a total of 6 facts.
CLIPS> (matches gp)
Matches for Pattern 1
f-6
Matches for Pattern 2
f-6
Partial matches for CEs 1 - 2
None
Activations
None
(2 0 0)
CLIPS> (agenda)
0 parent: f-4
0 parent: f-3
0 parent: f-2
0 parent: f-1
For a total of 4 activations.
CLIPS> (run 4)
CLIPS> (facts)
f-1 (father tom nicholas)
f-2 (mother clair nicholas)
f-3 (father tom john)
f-4 (father brad tom)
f-5 (father mark clair)
f-6 (parent mark clair)
f-7 (parent brad tom)
f-8 (parent tom john)
f-9 (gp brad john)
f-10 (parent clair nicholas)
For a total of 10 facts.
CLIPS> (agenda)
0 gp: f-6,f-10
0 parent: f-1
For a total of 2 activations.
CLIPS>