从多字段访问插槽中的插槽

Arm*_*lak 2 expert-system clips

我有这个函数,它根据多个多场事实的多个槽来计算一些值.

因为涉及相当多的插槽并且在函数中需要所有插槽,我在想是否可以将整个事实传递给函数并访问其中的插槽,如下所示:

(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 ... )
)
Run Code Online (Sandbox Code Playgroud)

我看到了这个?fact-adrres:这个例子中的slot-name并认为它可以工作,但事实并非如此.那么,它是否可能以及如何做到这一点?

(bind ?facts (find-all-facts ((?f attribute))
                               (and (eq ?f:name wine)
                                    (>= ?f:certainty 20))))
Run Code Online (Sandbox Code Playgroud)

使用剪辑6.3.

Gar*_*ley 7

使用fact-slot-value函数.

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>
Run Code Online (Sandbox Code Playgroud)