CLIPS如何将从文件读取的数据绑定到一个变量

时间:2018-05-22 12:30:36

标签: clips

(deftemplate startup-rule
   (multislot output)
   (slot state))   

 (defrule end-state
        =>
        (open "output.dat" theFile "r")
        (bind ?data (readline theFile))
        (while (neq ?data EOF)
        (bind ?data (?data readline theFile)))
        (assert (startup-rule (output ?data)(state final))) 
        (close theFile) )

在这个默认情况下,我试图将从文件中读取的所有行绑定到?data变量中,然后将其声明为deftemplate启动规则,但这似乎不起作用。

1 个答案:

答案 0 :(得分:0)

(defrule end-state
   =>
   (open "output.dat" theFile "r")
   (bind ?str "")
   (bind ?data (readline theFile))
   (while (neq ?data EOF)
      (bind ?str (str-cat ?str ?data))
      (bind ?data (readline theFile)))
   (assert (startup-rule (output ?str) (state final))) 
   (close theFile))