当接收到用户的输入时,片段爆炸$无法正常工作

时间:2019-03-29 10:13:12

标签: rules clips

您好,我写过一个可以模拟命题定律的小问题,但是如果我给它正确的输入,该小问题就不会触发。

我相信explode $可能会添加一些空格,但是我不确定如何删除它们

     CLIPS (Cypher Beta 8/21/18)
CLIPS> (batch "AI taak.txt")
TRUE
CLIPS> (deftemplate andprop (slot symbol1)(slot symbol2))
CLIPS> (deftemplate orprop (slot symbol1)(slot symbol2))
CLIPS> (deftemplate implies (multislot premise)(multislot implication))
CLIPS> (deftemplate sentence (multislot sent))
CLIPS> 
(defrule read-from-user
=>
(printout t "Please enter a sentence: Use ~ for not and => for implies 
please " crlf)
 (bind ?response (explode$ (readline)))
(assert (sentence (sent ?response))))
CLIPS> 
(defrule negative
(sentence (sent "~" "(" "~" ?symbol ")"))
 =>
   (printout t "HI " ?symbol crlf))
CLIPS> (run)
Please enter a sentence: Use ~ for not and => for implies please 
~(~P)
CLIPS> (facts)
f-1     (sentence (sent ~ ( ~ P )))
For a total of 1 fact.

因此,从理论上讲,否定规则应该触发,但它不是#t。找出原因的帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

在6.4中,针对通常用作分隔符的令牌将explode $函数的行为进行了调整,以将其转换为符号而不是字符串。这样做是为了先分解一个字符串,然后再分解结果,从而生成一个没有附加引号的字符串。

这是6.3版曾经发生的事情:

         CLIPS (6.31 2/3/18)
CLIPS> (implode$ (explode$ "~(~P)"))
""~" "(" "~" P ")""
CLIPS> 

这就是6.4的情况:

         CLIPS (Cypher Beta 8/21/18)
CLIPS> (implode$ (explode$ "~(~P)"))
"~ ( ~ P )"
CLIPS> 

通过从用户读取规则中使用replace-member $函数将符号替换为字符串,可以获得以前的结果:

         CLIPS (Cypher Beta 8/21/18)
CLIPS> (deftemplate sentence (multislot sent))
CLIPS> 
(defrule read-from-user
   =>
   (printout t "Please enter a sentence: Use ~ for not and => for implies please " crlf)
   (bind ?response (explode$ (readline)))
   (bind ?response (replace-member$ ?response "(" (sym-cat "(")))
   (bind ?response (replace-member$ ?response ")" (sym-cat ")")))
   (bind ?response (replace-member$ ?response "~" (sym-cat "~")))
   (assert (sentence (sent ?response))))
CLIPS> (run)
Please enter a sentence: Use ~ for not and => for implies please 
~(~P)
CLIPS> (facts)
f-1     (sentence (sent "~" "(" "~" P ")"))
For a total of 1 fact.
CLIPS>