【发布时间】:2017-04-07 13:49:01
【问题描述】:
如何在 Jess 中正确使用运算符“and”?
我的(错误)代码示例:
(test (and (>= ?x ?minx) (and (<= ?x ?maxx) (and (>= (+ ?x (- ?y1 ?y)) ?minx) (and (<= (+ ?x (- ?y1 ?y)) ?maxx) ...
另外,在 if 子句中,如何使用呢?
谢谢。
【问题讨论】:
如何在 Jess 中正确使用运算符“and”?
我的(错误)代码示例:
(test (and (>= ?x ?minx) (and (<= ?x ?maxx) (and (>= (+ ?x (- ?y1 ?y)) ?minx) (and (<= (+ ?x (- ?y1 ?y)) ?maxx) ...
另外,在 if 子句中,如何使用呢?
谢谢。
【问题讨论】:
我在您的代码中添加了一些缩进以试图了解您在做什么:
(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))
【讨论】: