2017-04-07 75 views
0

如何在Jess中正确使用操作符'和'?我的(错误的)代码使用操作符'和'Jess

例子:

(test (and (>= ?x ?minx) (and (<= ?x ?maxx) (and (>= (+ ?x (- ?y1 ?y)) ?minx) (and (<= (+ ?x (- ?y1 ?y)) ?maxx) ... 

此外,在if语句,如何使用?

谢谢。

回答

0

我加了一些缩进你的代码,试图了解你在做什么:

(test 
    (and (>= ?x ?minx) 
     (and (<= ?x ?maxx) 
       (and (>= (+ ?x (- ?y1 ?y)) ?minx) 
        (and (<= (+ ?x (- ?y1 ?y)) ?maxx) 

存在缺少“)” s的结束,但我认为这不是问题。基本上,如果你想表达一系列条件的联合,你只需要一个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)) 
+0

谢谢你,非常有帮助! –