How an agent could save a file on the machine running Cyc, while running remotely. For example, I might want to save the output of a runtime agent to the session directory.

Cyc has a full API for writing to the server-local file system. However, it is mostly designed for writing SubL objects. That said, strings are SubL objects, for example.

The following SubL fragment could be used to save a set of strings via the Java API.

Call #1: open the stream to a file in Cyc's installation directory, (i.e. cyc-sys10.133610-kb7148)

;; assign a global variable for a sample stream
(csetq *sample-stream* (open-text "sample-file.text" :output))

;; pass each string down as needed, where STRING is some string 
;; TERPRI appends a newline character
(progn
  (write-string STRING *sample-stream*)
  (terpri *sample-stream*))

;; Alternatively, pass down groups of strings as a list
(cdolist (string '("There was a king who ruled the land"
     "his majesty was in command"
     "flying flags from every steeple"
     "showering silver on the people."
     "--Pink Floyd, Piper at the Gates of Dawn"))
  (write-string string *sample-stream*)
  (terpri *sample-stream*))

;; final Call close the stream
(progn
  (close *sample-stream*)
  (csetq *sample-stream* NIL))

If you do have all the strings, then you can use the SubL macro facility to leave the stream a local variable and ensure that cleanup happens on error.

  (with-private-text-file (stream "sample-file.text" :output)
    (cdolist (string '("There was a king who ruled the land"
      "his majesty was in command"
      "flying flags from every steeple"
      "showering silver on the people."
      "--Pink Floyd, Piper at the Gates of Dawn"))
    (write-string string stream)
     (terpri stream))

Finally, if you want to write the strings in chunks, you can use the :append flag instead of the :output flag to do the usual UN*X file appending instead of overwriting in the subsequent calls.

(cdolist (string '("There was a king who ruled the land"
     "his majesty was in command"))
 (with-private-text-file (stream "sample-string.text" :output)
   (write-string string stream)
   (terpri stream)))

(cdolist (string '("flying flags from every steeple"
     "showering silver on the people."
     "--Pink Floyd, Piper at the Gates of Dawn"))
 (with-private-text-file (stream "sample-string.text" :append)
   (write-string string stream)
   (terpri stream)))

 

 

FAQ Category: