【问题标题】:Use of operator 'and' Jess使用运算符“和”Jess
【发布时间】: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 子句中,如何使用呢?

谢谢。

【问题讨论】:

    标签: operators jess


    【解决方案1】:

    我在您的代码中添加了一些缩进以试图了解您在做什么:

    (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))
    

    【讨论】:

    • 谢谢,很有帮助!
    猜你喜欢
    • 2011-07-09
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 1970-01-01
    • 2021-07-14
    • 2012-11-26
    • 2013-05-03
    相关资源
    最近更新 更多