Deconstructing and reconstructing structures
Hi,
I'm looking for a way to automatically save and load structures.
(Yes, I know about the problems with equality and cloning and
that it's very difficult to do this in a completely general way.)
As far as I know, there's no portable way to find out the 'slot
names', 'slot values' and type of a structure. I didn't find
any documentation about a Lispworks-specific way either.
So I've done some APROPOSing. (I found a typo while doing that,
by the way. You might want to fix the names of the functions
STRUCTURE::UNKNWON-STRUCTURE-SET-SLOT-VALUE and
STRUCTURE::UNKNWON-STRUCTURE-SLOT-VALUE, if you didn't fix them
already in version 4.3.)
I've included some documentation below on what I found out about
'generic' structure functions. I have three questions about this:
1. Could you tell me if this documentation is correct?
2. Can I rely on these functions to continue to work in future
versions of Lispworks?
3. Is there some function like MAKE-STRUCTURE that can construct
a structure from a list of slot-names and a list of slot-values
without having to cons up a plist?
Thanks a lot,
Arthur Lemmens
--
The following functions are available (i.e. exported) in the STRUCTURE
package:
- STRUCTURE-NAMES-AND-VALUES struct
Returns two values: a list with the names of the structure slots, and
a list with the corresponding values. The slot names are not keywords,
but 'normal' symbols (from the package in which the DEFSTRUCT-form was
evaluated, I suppose).
Example: (STRUCTURE-NAMES-AND-VALUES #S(TEST FOO 1 BAR 2))
-> (FOO BAR)
(1 2)
- MAKE-STRUCTURE type &rest args
Creates a new structure of the given structure-type.
ARGS is just like the arguments for the structure constructor function.
Example: (MAKE-STRUCTURE 'TEST :FOO 1 :BAR 2) -> #S(TEST FOO 1 BAR 2)
- STRUCTURE-CLASS-SLOT-NAMES structure-class
Returns a list with the slot names of the structure-class.
Example: (STRUCTURE-CLASS-SLOT-NAMES (CLASS-OF #S(TEST FOO 1 BAR 2)))
-> (FOO BAR)
- STRUCTURE-TYPE struct
Returns the 'type' of the struct.
Example: (STRUCTURE-TYPE #S(TEST FOO 1 BAR 2)) -> TEST
- STRUCTURE-SLOT-DETAILS structure-class structure-slot-name
Returns four values:
1. ???
2. The type of the slot.
3. The name of the reader function for the slot.
4. The (unevaluated) initform for the slot.