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

问题描述 投票:1回答:1

代码向用户询问是/否问题并进行更改-很简单。该语句似乎只接受整数和浮点类型,我只需要两个答案,因此我使用了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.

如何为字符添加例外?

if-statement exception clips
1个回答
0
投票

使用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> 
© www.soinside.com 2019 - 2024. All rights reserved.