有我的困境:
(defrule A15_test
?list <- (accumulate (bind ?ll (new java.util.ArrayList)) ;; initializer
(?ll add ?id) ;; action
?ll ;; result
(P (ID_Jess ?id) (m ?ref&:(neq ?ref nil)))
) ;; CE
(foreach ?l ?list
(printout t "l:" ?l " " crlf)
)
=>
(printout t "FIRE ! c:" (?list toString) " end. " crlf)
出现以下错误:
Jess reported an error in routine Jesp.parsePattern.
Message: Bad slot value at token '('.
Program text: ( defrule A15_test ?list <- ( accumulate ( bind ?ll ( new java.util.ArrayList ) ) ( ?ll add ?id ) ?ll ( P ( ID_Jess ?id ) ( m ?ref & : ( neq ?ref nil ) ) ) ) ( foreach ?l ?list ( at line 80 in file <eval pipe>.
at jess.Jesp.error(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.a(Unknown Source)
at jess.Jesp.if(Unknown Source)
at jess.Jesp.parseDefrule(Unknown Source)
at jess.Jesp.parseExpression(Unknown Source)
at jess.Jesp.promptAndParseOneExpression(Unknown Source)
at jess.Jesp.parse(Unknown Source)
at jess.Rete.eval(Unknown Source)
at jess.Rete.eval(Unknown Source)
at jesslanguage.JessExecutor.executeJess(JessExecutor.java:30)
at Main.testJessRules(Main.java:293)
at Main.main(Main.java:62)
显然,foreach并不喜欢我的列表。 请注意,如果我删除它(foreach XXX),它一切正常并给出:
FIRE ! c:[p1, p3, p4]
FIRE ! c:[p1, p3, p4]
(我试图在一个火灾中分组累积或指望列表中的元素)
有人知道如何直接从Jess迭代Java ArrayList吗?
答案 0 :(得分:0)
您的迭代代码很好。问题是你将它包含在只允许模式(条件元素)的地方,而不是函数调用。你需要移动&#34; foreach&#34;在规则的右边。