(defrule R1
?f <‐ (lista $?x ?a $?y)
(lista1 $?p ?a $?q ?a $?r)
=>
(retract ?f)
(assert (lista $?x $?y)))
A. {(lista e b a c d f g) (lista1 a c a d e e f g)}
B. {(lista b) (lista1 a c a d e e f g) }
C. {(lista b c d) (lista1 a c a d e e f g)}
D. {(lista e b a c d) (lista1)}
I understand that lista1 remains unchanged, but why only b,c,d remain in lista?
Variables that occur more than once in patterns must have the same value in order for the rule to be matched. The variable ?a occurs once in the first pattern and twice in the second pattern. The multifield variables $?x, $?y, $?p, $?q, and $?r all occur once each so because of their positioning these will just bind to any remaining values in the patterns not matched by ?a. The actions of the rule will then remove any value that was found at least twice in lista1 and also in lista.
CLIPS (6.4 2/9/21)
CLIPS>
(defrule R1
?f <- (lista $?x ?a $?y)
(lista1 $?p ?a $?q ?a $?r)
=>
(retract ?f)
(assert (lista $?x $?y)))
CLIPS> (watch facts)
CLIPS> (assert (lista e b a c d e a) (lista1 a c a d e e f g))
==> f-1 (lista e b a c d e a)
==> f-2 (lista1 a c a d e e f g)
<Fact-2>
CLIPS> (run)
<== f-1 (lista e b a c d e a)
==> f-3 (lista e b a c d e)
<== f-3 (lista e b a c d e)
==> f-4 (lista b a c d e)
<== f-4 (lista b a c d e)
==> f-5 (lista b c d e)
<== f-5 (lista b c d e)
==> f-6 (lista b c d)
CLIPS>