CLIPS - 如何从 IF/READ 语句的异常中排除字符?

CLIPS - How can I exclude characters from IF/READ statement's exceptions?

代码向用户提出 y/n 问题并进行更改 - 很简单。该语句似乎只接受整数和浮点类型,我只需要两个答案,所以我使用 1 和 0,并排除其余部分,但它只读取数字,所以只排除数字,不排除字符。

(defrule rule01
    =>
    (printout t "Question (yes=1/no=0)?" crlf)
    (bind ?x (read))
    (if (!= ?x 1)
        then
        (if (= ?x 0)
            then
            (assert (rule01 no))
        else (printout t "Use ONLY 0 OR 1 for your answers!" crlf))
    else (assert (rule01 yes))))

目前,当您尝试输入一个字符时,它 returns 如下:

CLIPS> (run)
Question (yes=1/no=0)?
g
[ARGACCES5] Function <> expected argument #1 to be of type integer or float
[PRCCODE4] Execution halted during the actions of defrule rule01.

如何为字符设置例外?

使用 eq 和 neq 代替 = 和 <>。

         CLIPS (6.31 6/12/19)
CLIPS> 
(defrule rule01
    =>
    (printout t "Question (yes=1/no=0)?" crlf)
    (bind ?x (read))
    (if (neq ?x 1)
        then
        (if (eq ?x 0)
            then
            (assert (rule01 no))
        else (printout t "Use ONLY 0 OR 1 for your answers!" crlf))
    else (assert (rule01 yes))))
CLIPS> (reset)
CLIPS> (run)
Question (yes=1/no=0)?
g
Use ONLY 0 OR 1 for your answers!
CLIPS>