I have a class for which I'd like an output function to write the slot
values to a stream. The class has about 250 slots. Since I would
prefer not to solve the problem with the cut-and-paste technique, I am
wondering if it is possible (and if so, how) to get access to the slot
names of a class so that I can iterate over them. I have not stumbled
on the solution yet.
I have CLISP, CMU Lisp and Allegro Common Lisp available to me. I
have done something similar using the tiny-CLOS-like STklos in the
past. I am thinking about something like the following:
(defclass foo () ; only 4 slots here, for brevity
((a)
(b)
(c)
(d)))
(defgeneric dump-object (obj))
(defmethod dump-object ((obj foo))
(let ((slot-defs (slots-of (class-of obj))))
(loop for slot in slot-defs
do (format t "~A ~A~%"
(symbol-name (slot-name slot))
(slot-value obj (slot-name slot))))))
where `slots-of' returns a list of slot definitions, and `slot-name'
extracts the name of the slot from the slot definition. I am having
trouble finding a function to fill-in for my `slots-of' function. Is
there anything?
Thanks!
--
Russell Senior
·······@teleport.com
In article <··············@coulee.tdb.com>, Russell Senior
<·······@teleport.com> wrote:
> I have a class for which I'd like an output function to write the slot
> values to a stream. The class has about 250 slots.
Wasn't there a save-object.lisp somewhere?
File: save-object.lisp. (version 3A)
SAVE-OBJECT by K.V. Koitzsch: Effective Date 5-31-91.
Copyright (c) 1990, 1991 Advanced Decision Systems
Maybe there is a newer version.
--
http://www.lavielle.com/~joswig/