conditional patterns

19 views
Skip to first unread message

agascon

unread,
Jun 5, 2012, 2:06:46 PM6/5/12
to CLIPSESG
Hi all,

I have a fact A whose fields are all instances of a template T with
slots a, b and I want to non-deterministically extract a field from A.
This can be done as (A $? ?T $?). I also want to extract the values of
T since I want to add conditions on them.
I tried something like (A $? (T (a ?a) (b ?b)) $?) but it didn't work.
I can also do (A $? ?T $?) and then add constraints on the variable T
but I don't know how to do it. I've been looking at the section in the
clips reference about conditional patterns with no success.
Any guidelines would be appreciated.

I just joined the group. I hope to be useful soon ;)

Adria

CLIPS Support

unread,
Jun 5, 2012, 2:20:14 PM6/5/12
to CLIPSESG
CLIPS> (deftemplate A (multislot A))
CLIPS> (deftemplate T (slot a) (slot b))
CLIPS>
(defrule example
(A (A $? ?T $?))
(test (and (eq (fact-slot-value ?T a) 3) (eq (fact-slot-value ?T b)
4)))
=>)
CLIPS> (assert (A (A (assert (T (a 3) (b 4))) (assert (T (a 2) (b
3))))))
<Fact-3>
CLIPS> (agenda)
0 example: f-3
For a total of 1 activation.
CLIPS> (facts)
f-0 (initial-fact)
f-1 (T (a 3) (b 4))
f-2 (T (a 2) (b 3))
f-3 (A (A <Fact-1> <Fact-2>))
For a total of 4 facts.
CLIPS>

agascon

unread,
Jun 5, 2012, 4:35:57 PM6/5/12
to CLIPSESG
This is it!

I do not know how does clips work internally but looks like this two
conditions:

(A (A $? ?T $?))
(test (and (eq (fact-slot-value ?T a) 3) (eq (fact-slot-value ?T
b)
4)))

correspond to traverse all the fields in A and then check the
condition for each of them whereas
encoding the conditions in the pattern matching instance could be
faster. Intuitively,
I was expecting something like (A $? (T (a 3) (b 4)) $?).

Thanks a lot!

Adria
Reply all
Reply to author
Forward
0 new messages