@dircategory Emacs lisp libraries
@direntry
-* CL: (cl). Partial Common Lisp support for Emacs Lisp.
+* CL-Lib: (cl). Partial Common Lisp support for Emacs Lisp.
@end direntry
@finalout
is a Lisp form that is evaluated any time an instance of the
structure type is created without specifying that slot's value.
-Common Lisp defines several slot options, but the only one
-implemented in this package is @code{:read-only}. A non-@code{nil}
-value for this option means the slot should not be @code{setf}-able;
-the slot's value is determined when the object is created and does
-not change afterward.
-
@example
(cl-defstruct person
(name nil :read-only t)
(sex 'unknown))
@end example
-Any slot options other than @code{:read-only} are ignored.
+@var{slot-options} is a list of keyword-value pairs, where the
+following keywords can be used:
+
+@table @code
+@item :read-only
+A non-nil value means the slot should not be @code{setf}-able;
+the slot's value is determined when the object is created and does
+not change afterward.
+
+@item :type
+The expected type of the values held in this slot.
+
+@item :documentation
+A documentation string describing the slot.
+@end table
+
+Other slot options are currently ignored.
For obscure historical reasons, structure options take a different
form than slot options. A structure option is either a keyword
Each SLOT may instead take the form (SNAME SDEFAULT SOPTIONS...), where
SDEFAULT is the default value of that slot and SOPTIONS are keyword-value
pairs for that slot.
-Currently, only one keyword is supported, `:read-only'. If this has a
-non-nil value, that slot cannot be set via `setf'.
+Supported keywords for slots are:
+- `:read-only': If this has a non-nil value, that slot cannot be set via `setf'.
+- `:documentation': this is a docstring describing the slot.
+- `:type': the type of the field; currently unused.
\(fn NAME &optional DOCSTRING &rest SLOTS)"
(declare (doc-string 2) (indent 1)
defaults))
(if (assq slot descp)
(error "Duplicate slots named %s in %s" slot name))
- (let ((accessor (intern (format "%s%s" conc-name slot))))
+ (let ((accessor (intern (format "%s%s" conc-name slot)))
+ (default-value (pop desc))
+ (doc (plist-get desc :documentation)))
(push slot slots)
- (push (pop desc) defaults)
+ (push default-value defaults)
;; The arg "cl-x" is referenced by name in eg pred-form
;; and pred-check, so changing it is not straightforward.
(push `(,defsym ,accessor (cl-x)
- ,(format "Access slot \"%s\" of `%s' struct CL-X."
- slot name)
+ ,(format "Access slot \"%s\" of `%s' struct CL-X.%s"
+ slot name
+ (if doc (concat "\n" doc) ""))
(declare (side-effect-free t))
,@(and pred-check
(list `(or ,pred-check