如何取消引用规则LHS中匹配事实的插槽?如果是变量 匹配一个事实,我找不到如何创造进一步的条件 在那个事实中匹配槽。
例如,在下面的代码中,如果存在“(do(action?action))”形式的事实,我想打印一些文本。但是,?action本身就是一个事实,我只希望规则触发,如果该事实的“名称”槽是“运行”。我该如何做到这一点?
(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")))))
答案 0 :(得分:1)
通过剪辑参考手册搜索,我终于找到了似乎做我想要的功能“fact-slot-value”。
(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")))))