Structural Informatics Group (SIG) logo
Home | Projects | Demos | Downloads | Publications | Local Info | About Us | New site
Go to the first, previous, next, last section, table of contents.

Lisp file format

Suppose we create an array and save it to "myfile.lsp" using XFIL-SAVE-GRAPHICS-FILE:

(send class-graphic-file :new "myfile.lsp")
(setq my-array (send class-int32-array :new 3 :initial-contents '(1 0 1)))
(setq fd (xfil-save-graphics-file "myfile.lsp"))

(format fd "~%(setq my-array ")
(xfil-write-sexp-to-file my-array fd)
(format fd ")~%")

(close fd)

The resulting file will look like:

;;; Skandha4 XFIL-SAVE-GRAPHICS-FILE filepair
;;;   (myfile.lsp myfile.bin)
;;; Read by (XFIL-LOAD-GRAPHICS-FILE "myfile.lsp")

;;; Create all our objects ;;;
(setq xfil-this (send CLASS-INT32-ARRAY :new '(3) :initial-element 0
  :initialize-from-file XFIL-FD-BINARY))
(send xfil-this :set-file-info "myfile.lsp/0")

;;; Restore our LVALS ;;;
(setq xfil-this (xfil-ref "myfile.lsp/0"))
(send xfil-this :set-instance-variable 'PROPERTY-LIST

;;; Application-specific code ;;;

(setq my-array (xfil-ref "myfile.lsp/0"))

In general, there should be no particular need to understand how this file works, other than that it can be loaded via


but if you're curious, the basic strategy is:

The "Create all our objects" section does exactly that by sending :NEW messages to the appropriate class objects. Objects with internal binary data are instructed to load it via the :INITIALIZE-FROM-FILE keyword. (XFIL-FD-BINARY will be opened on "myfile.bin" by XFIL-LOAD-GRAPHICS-FILE)

By creating all objects before we restore links between them, we eliminate the problem of figuring out how to restore a link to an object which we haven't created yet.

The "Restore our LVALS" section restores the values of all lisp variables in our objects. In general, it does this by calling XFIL-EXPAND, which substitutes the correct lisp value in for all lists of the form (XFIL-REF "myfile.lsp/12").

It uses a couple of secret undocumented messages like the :set-instance-variable message illustrated above. One of these messages will be sent for each lisp variable in the object.

The "Application-specific code" section is just whatever code you yourself appended to the file.

Go to the first, previous, next, last section, table of contents.