如何在Jess中正确使用运算符'和'
我的(错误)代码示例:
(test (and (>= ?x ?minx) (and (<= ?x ?maxx) (and (>= (+ ?x (- ?y1 ?y)) ?minx) (and (<= (+ ?x (- ?y1 ?y)) ?maxx) ...
另外,在if子句中,如何使用它?
感谢。
答案 0 :(得分:0)
我在您的代码中添加了一些缩进,以尝试了解您正在做的事情:
(test
(and (>= ?x ?minx)
(and (<= ?x ?maxx)
(and (>= (+ ?x (- ?y1 ?y)) ?minx)
(and (<= (+ ?x (- ?y1 ?y)) ?maxx)
最后缺少“)”但我认为这不是问题。基本上,如果你试图表达一系列条件的结合,你只需要一个and
,并根据需要给它提供多个参数。所以,例如,像
(test
(and (>= ?x ?minx)
(<= ?x ?maxx)
(>= (+ ?x (- ?y1 ?y)) ?minx)
(<= (+ ?x (- ?y1 ?y)) ?maxx)))
就if
而言,the manual中已明确记录了这些内容:
(if (> ?x 100) then
(printout t "X is big" crlf)
elif (> ?x 50) then
(printout t "X is average" crlf)
else
(printout t "X is small" crlf))