Search code examples
clips

CLIPS How can I bind data read from a file to one variable


(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) )

In this defrule I am trying to bind all the lines being read from the file into the ?data variable to be asserted into the deftemplate startup-rule afterwards, however that does not seem to be working.


Solution

  • (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))