eieio: Making New Objects
4 Making New Objects
********************
Suppose we have a simple class is defined, such as:
(defclass record ()
( ) "Doc String")
It is now possible to create objects of that class type.
Calling ‘defclass’ has defined two new functions. One is the
constructor RECORD, and the other is the predicate, RECORD-p.
-- Function: record object-name &rest slots
This creates and returns a new object. This object is not assigned
to anything, and will be garbage collected if not saved. This
object will be given the string name OBJECT-NAME. There can be
multiple objects of the same name, but the name slot provides a
handy way to keep track of your objects. SLOTS is just all the
slots you wish to preset. Any slot set as such _will not_ get its
default value, and any side effects from a slot’s ‘:initform’ that
may be a function will not occur.
An example pair would appear simply as ‘:value 1’. Of course you
can do any valid Lispy thing you want with it, such as ‘:value (if
(boundp 'special-symbol) special-symbol nil)’
Example of creating an object from a class:
(record :value 3 :reference nil)
To create an object from a class symbol, use ‘make-instance’.
-- Function: make-instance class &rest initargs
Make a new instance of CLASS based on INITARGS. CLASS is a class
symbol. For example:
(make-instance 'foo)
INITARGS is a property list with keywords based on the ‘:initarg’
for each slot. For example:
(make-instance 'foo :slot1 value1 :slotN valueN)