【发布时间】:2019-12-10 16:40:27
【问题描述】:
我希望以前没有人问过这个问题,因为我试图搜索已经问过的问题。我正在尝试编写一个规则,该规则将检查一个 deftemplate 中定义的两个不同插槽是否都存在于不同 deftemplate 的多插槽中。例如:
(deftemplate manifest
(slot origin (type SYMBOL))
(slot destination (type SYMBOL))
(slot pkgsize (type INTEGER))
(slot priority (type INTEGER))
(slot zone (type SYMBOL) (default UNKNOWN))
)
(deftemplate shipzone
(slot zonename (type SYMBOL))
(multislot cities (type SYMBOL))
)
(deffacts load-data
(manifest (origin CHI) (destination DET) (pkgsize 10) (priority 1))
(manifest (origin ATL) (destination WAS) (pkgsize 8) (priority 2))
(manifest (origin CHI) (destination WAS) (pkgsize 15) (priority 1))
(shipzone (zonename ZONEA) (cities CHI DET NYC BOS))
(shipzone (zonename ZONEB) (cities ATL WAS NYC))
(shipzone (zonename ZONEC) (cities CHI WAS BOS))
)
(defrule city-group
?f <- (manifest (origin ?x1) (destination ?x2) (zone UNKNOWN))
(shipzone (zonename ?zname) (cities $?x1 $?x2))
=>
(modify ?f (zone ?zname))
)
给出以下错误:
CLIPS> (clear)
CLIPS> (load testgroup.clp)
[ANALYSIS3] testgroup.clp, Line 29: Variable ?x1 is used as both a single and multifield variable in the LHS.
ERROR:
(defrule MAIN::city-group
?f <- (manifest (origin ?x1) (destination ?x2))
(shipzone (zonename ?zname) (cities $?x1 $?x2))
=>
(modify ?f (zone ?zname)))
%%$*
FALSE
CLIPS>
我做错了什么,或者有更好的方法来解决这个问题?
【问题讨论】:
标签: clips