当从用户接收输入时,剪辑会爆炸$无法正常运行

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

嗨,我已经写了一个应该模拟命题法的规则,但是当我给它正确的输入时,规则不会触发。

我相信爆炸$可能会增加ome空间,但我不知道如何删除它们

     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。帮助找出为什么会受到赞赏。谢谢

rules clips
1个回答
0
投票

爆炸$ function的行为在6.4中被调整为令牌,通常作为分隔符将它们转换为符号而不是字符串。这样做是为了爆炸一个字符串然后破坏结果产生一个字符串而没有额外的引用。

这是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> 

通过在read-from-user规则中使用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> 
© www.soinside.com 2019 - 2024. All rights reserved.