开发者

Access a slot from multifield in deffunction

I have开发者_JAVA技巧 this function which calculates some value based on multiple slots of multiple multifield facts.

Because quite some slots are involved and all of them are needed in the function I was thinking if I could pass a whole fact to a function and access its slots in it, like so:

(deftemplate a-fact
    (slot id)
    (slot name)
    (slot ...)
    ...
)

(deffunction a-funciton (?factadr)
    (switch ?factadr:name
        (case bla then ...)
    )

    (return ?calculated-value)
)

(defrule a-rule
    ?factadr <- (a-fact (id ?i))
    =>
    (if (> **(a-function ?factadr) 20) then ... )
)

I saw this ?fact-adrres:slot-name in this example and thought it will work but it doesn't. So, is it possible and how to do it?

(bind ?facts (find-all-facts ((?f attribute))
                               (and (eq ?f:name wine)
                                    (>= ?f:certainty 20))))

Clips 6.3 is used.


Use the fact-slot-value function.

CLIPS> 
(deftemplate a-fact
   (slot id)
   (slot name))
CLIPS>  
(defrule a-rule
   ?f <- (a-fact)
   =>
   (printout t (fact-slot-value ?f id) " " (fact-slot-value ?f name) crlf))
CLIPS> (assert (a-fact (id 3) (name x)))
<Fact-1>
CLIPS> (assert (a-fact (id  7) (name y)))
<Fact-2>
CLIPS> (run)
7 y
3 x
CLIPS>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜