How to access the slots in a fact

1,508 views
Skip to first unread message

daniels

unread,
Apr 9, 2010, 11:35:40 AM4/9/10
to CLIPSESG
Hi,

I have the following template:
(deftemplate person (slot name) (slot age))

and the following facts
(assert (person (name X) (age 30)))
(assert (person (name Y) (age 31)))

I use (find-fact) to get the fact that has name X

(bind ?f (find-fact ((?p person)) (eq ?p:name X)))

Now ?f is a list of one element containing the fact address of the
one with the name X

Then i do
(bind ?x (nth$ 1 ?f))
So now ?x is the address of the fact with the name X

At this point how can i access the age slot of this fact?
?x:age does not work
Any idea how can i do this?

CLIPS Support

unread,
Apr 11, 2010, 6:52:06 PM4/11/10
to CLIPSESG
CLIPS> (deftemplate person (slot name) (slot age))
CLIPS> (assert (person (name X) (age 30)))
<Fact-0>
CLIPS> (assert (person (name Y) (age 31)))
<Fact-1>
CLIPS> (find-fact ((?p person)) (eq ?p:name X))
(<Fact-0>)
CLIPS> (nth$ 1 (find-fact ((?p person)) (eq ?p:name X)))
<Fact-0>
CLIPS> (fact-slot-value (nth$ 1 (find-fact ((?p person)) (eq ?p:name
X))) name)
X
CLIPS> (fact-slot-value (nth$ 1 (find-fact ((?p person)) (eq ?p:name
X))) age)
30
CLIPS>

daniels

unread,
Apr 12, 2010, 3:37:05 AM4/12/10
to CLIPSESG
Thank you
Reply all
Reply to author
Forward
0 new messages