If statement 剪辑-如何从IF/READ语句中排除字符';什么是例外?

If statement 剪辑-如何从IF/READ语句中排除字符';什么是例外?,if-statement,exception,clips,If Statement,Exception,Clips,代码向用户询问一个y/n问题,并进行简单的更改。该语句似乎只接受整数和浮点类型,我只需要两个答案,所以我使用了1和0,并排除了其余的,但它只读取数字,所以只排除数字,而不排除字符 (defrule rule01 => (printout t "Question (yes=1/no=0)?" crlf) (bind ?x (read)) (if (!= ?x 1) then (if (= ?x 0) th

代码向用户询问一个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))))
当前,当您尝试键入字符时,它将返回以下内容:

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.
CLIPS>(运行)
问题(是=1/否=0)?
G
[ARGACCES5]函数要求参数#1的类型为integer或float
[PRCCODE4]在defrule rule01的操作过程中停止执行。

如何为字符设置异常?

使用eq和neq代替=和


使用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>