[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Extending Defstruct
I am glad to see the revival of the discussion of defstruct. I brought
up this issue more than a year ago. At that time it got only one reply.
The defstruct facility would be much more useful to layered systems
builders if information about the defstruct definition was available.
In addition, you should be able to access and update a slot in a
structure via the slot name. Most implementations keep the necessary
information around anyway.
Simply being able to get the names of the accessor functions is not
sufficient. This will enable you to access the value of a slot by using
FUNCALL, but won't allow you to update the value of the slot because
funcall is not a valid place form.
I would like to see several functions added to the language:
STRUCTURE-SLOT structure slot [Function]
Returns the value of the slot in STRUCTURE specified by SLOT. STRUCTURE
is a defstruct instance and SLOT is a symbol. SETF may be used with
STRUCTURE-SLOT to modify a slot in a structure.
STRUCTURE-SLOT-NAMES structure-type [Function]
STRUCTURE-TYPE must be a type defined by DEFSTRUCT. This function
returns a list of slot names for structures of that type.
MAKE-STRUCTURE structure-type keyword-1 value-1 ... [Function]
Creates an instance of a structure. STRUCTURE-TYPE is the type of
structure to create. The rest of the arguments are the same as for the
default constructor function. If a slot is not initialised by a
slot-keyword, then the slot will be initialized with the default init
form specified in the defstruct.
STRUCTURE-OPTION structure-type option [Function]
STRUCTURE-TYPE must be a type defined by defstruct. OPTION must be a
defstruct option (e.g., :conc-name). This function returns the argument
that was given to that option if an argument was given in the call to
defstruct. Otherwise it returns the default value of that option.
For example, after the defstruct on page 312,
(structure-option 'astronaut :conc-name) ==> astro-
STRUCTURE-SLOT-OPTION structure-type slot option [Function]
STRUCTURE-TYPE must be a type defined by defstruct. SLOT is the name of
a slot in that defstruct. OPTION must be a defstruct slot option (:type
or :read-only). This function returns the argument that was given to
that option if an argument was given in the call to defstruct. Otherwise
it returns the default value of that option.
DEFSTRUCTP symbol [Function]
This function returns true if SYMBOL is the name of a defstruct type.
Kevin Gallagher
Gallagher@CS.UMass.EDU