【发布时间】:2020-07-21 16:27:16
【问题描述】:
我有一个模板
(deftemplate Product
(slot productId (type INTEGER))
(slot uom (default EA))
(slot quantity (type INTEGER))
(slot amount))
我正在使用代码
(defrule sum_of_quantity
(exists (Product (productId 1 | 2 | 3)(amount ?amount)))
=>
(bind ?totalQuantity 0)
(do-for-all-facts ((?p Product))
(or (eq ?p:productNumber 1)
(eq ?p:productNumber 2)
(eq ?p:productNumber 3))
(bind ?totalQuantity (+ ?totalQuantity ?p:quantity)))
(if (>= ?amount 5000) then
(printout t "TotalQuantity is " ?totalQuantity crlf)))
在这里我收到一条错误消息: defrule的RHS中引用了未定义的变量。
我要检查每个产品的数量是否大于5000。我们怎么做。
【问题讨论】:
-
您发布的代码不会产生上述错误。您得到的错误是因为 Product deftemplate 不包含规则引用的 productNumber 插槽。
-
抱歉,我发布的代码发生了变化。现在我得到了同样的错误。我该如何解决这个问题
标签: rules rule-engine clips