Next: Class Options, Previous: Inheritance, Up: Building Classes [Contents][Index]
The slot-list argument to defclass is a list of elements
where each element defines one slot. Each slot is a list of the form
(SLOT-NAME :TAG1 ATTRIB-VALUE1
:TAG2 ATTRIB-VALUE2
:TAGN ATTRIB-VALUEN)
where SLOT-NAME is a symbol that will be used to refer to the slot. :TAG is a symbol that describes a feature to be set on the slot. ATTRIB-VALUE is a lisp expression that will be used for :TAG.
Valid tags are:
:initargA symbol that can be used in the argument list of the constructor to specify a value for this slot of the new instance being created.
A good symbol to use for initarg is one that starts with a colon :.
The slot specified like this:
(myslot :initarg :myslot)
could then be initialized to the number 1 like this:
(myobject :myslot 1)
See Making New Objects.
:initformAn expression used as the default value for this slot.
If :initform is left out, that slot defaults to being unbound.
It is an error to reference an unbound slot, so if you need
slots to always be in a bound state, you should always use an
:initform specifier.
Use slot-boundp to test if a slot is unbound
(see Predicates). Use slot-makeunbound to set a slot to
being unbound after giving it a value (see Accessing Slots).
The value passed to initform used to be automatically quoted. Thus,
:initform (1 2 3)
will use the list as a value. This is incompatible with CLOS (which would signal an error since 1 is not a valid function) and will likely change in the future, so better quote your initforms if they’re just values.
:typeAn unquoted type specifier used to validate data set into this slot. See Type Predicates in Common Lisp Extensions. Here are some examples:
symbolA symbol.
numberA number type
my-class-nameAn object of your class type.
(or null symbol)A symbol, or nil.
:allocationEither :class or :instance (defaults to :instance) used to specify how data is stored. Slots stored per instance have unique values for each object. Slots stored per class have shared values for each object. If one object changes a :class allocated slot, then all objects for that class gain the new value.
:documentationDocumentation detailing the use of this slot. This documentation is exposed when the user describes a class, and during customization of an object.
:accessorName of a generic function which can be used to fetch the value of this slot. You can call this function later on your object and retrieve the value of the slot.
This options is in the CLOS spec, but is not fully compliant in EIEIO.
:writerName of a generic function which will write this slot.
This options is in the CLOS spec, but is not fully compliant in EIEIO.
:readerName of a generic function which will read this slot.
This options is in the CLOS spec, but is not fully compliant in EIEIO.
:customA custom :type specifier used when editing an object of this type.
See documentation for defcustom for details. This specifier is
equivalent to the :type spec of a defcustom call.
This options is specific to Emacs, and is not in the CLOS spec.
:labelWhen customizing an object, the value of :label will be used instead of the slot name. This enables better descriptions of the data than would usually be afforded.
This options is specific to Emacs, and is not in the CLOS spec.
:groupSimilar to defcustom’s :group command, this organizes different
slots in an object into groups. When customizing an object, only the
slots belonging to a specific group need be worked with, simplifying the
size of the display.
This options is specific to Emacs, and is not in the CLOS spec.
:printerThis routine takes a symbol which is a function name. The function
should accept one argument. The argument is the value from the slot
to be printed. The function in object-write will write the
slot value out to a printable form on standard-output.
The output format MUST be something that could in turn be interpreted
with read such that the object can be brought back in from the
output stream. Thus, if you wanted to output a symbol, you would need
to quote the symbol. If you wanted to run a function on load, you
can output the code to do the construction of the value.
:protectionThis is an old option that is not supported any more.
When using a slot referencing function such as slot-value, and
the value behind slot is private or protected, then the current
scope of operation must be within a method of the calling object.
This protection is not enforced by the code any more, so it’s only useful as documentation.
Valid values are:
:publicAccess this slot from any scope.
:protectedAccess this slot only from methods of the same class or a child class.
:privateAccess this slot only from methods of the same class.
This options is specific to Emacs, and is not in the CLOS spec.
Next: Class Options, Previous: Inheritance, Up: Building Classes [Contents][Index]