views:

10

answers:

1

How do you dereference a slot in a fact matched in the LHS of a rule? If a variable matches a fact, I can't find how to create further conditions that match slots within that fact.

For example, in the code below, I want to print some text if there's a fact of the form "(do (action ?action))". However, ?action is itself a fact, and I only want the rule to trigger if that fact's "name" slot is "run". How would I accomplish this?

(deftemplate do 
        (slot action) 
) 
(deftemplate action 
        (slot name) 
) 
(defrule find-do "" 
        ?do <- (do (action ?action)) 
        (test (eq ?action.name "run")) ; This causes a syntax error. 
        => 
        (printout t "doing " ?action crlf) 
) 
(deffacts startup (do (action (action (name "running")))))
+1  A: 

Searching through the Clips Reference manual, I finally found the function "fact-slot-value" that seems to do what I want.

(deftemplate do 
        (slot action) 
) 
(deftemplate action 
        (slot name) 
) 
(defrule find-do "" 
        ?do <- (do (action ?action)) 
        (test (eq (fact-slot-value ?action name) "run"))
        => 
        (printout t "doing " ?action crlf) 
) 
(deffacts startup (do (action (action (name "running")))))
Chris S