[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Common-Lisp@su-ai.ARPA
- Subject: Defstruct Extensions
- From: Kevin Gallagher <gallagher%umass-cs.csnet@CSNET-RELAY.ARPA>
- Date: Mon, 3 Feb 86 13:15 EST
I think it is a deficiency in the language that you can't access a slot in a
structure via the slot name. Every implementation keeps this information
around and anyone who is writing a layered system eventually needs that
ability and writes a non-portable slot getter. Structure definition
information should be available also.
I propose the addition of several functions to the language:
GET-STRUCTURE-SLOT structure slot [Function]
Returns the value of the slot in STRUCTURE specified by SLOT. SETF may be
used with GET-STRUCTURE-SLOT to modify a slot in a structure.
STRUCTURE-SLOT-NAMES name [Function]
NAME must be a type defined by DEFSTRUCT. This function returns a list of
slot names for structures of that type.
Also nice but not quite so important would be:
MAKE-STRUCTURE name slot-keyword-1 form1 ... [Function]
Creates an instance of a structure. NAME 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
STRUCTURE-OPTION name option [Function]
NAME 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 name slot option [Function]
(This function is included mostly for completeness.)
NAME 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.