I realize that this is quite old, but I think that the most important point to be made here is:
Don't use slot-value
like that!
In order to get an accessor, use the :accessor
or :reader
slot options, and for passing values to the constructor, use :initarg
:
(defclass foo ()
((bar :accessor foo-bar :initarg :bar)))
This means: create a getter method and a setf expander named foo-bar
, and use a keyword argument named :bar
to make-instance
to initialize this slot's value.
Now you can instantiate such an object like this:
(make-instance 'foo :bar "quux")
or, if you get a property list of initargs (as Rainer had already shown):
(let ((initargs (list :bar "quux"))) ; getting this from somewhere
(apply #'make-instance 'foo initargs))
You can then get the value like this:
(foo-bar some-foo)
And set it with setf
as usual:
(setf (foo-bar some-foo) "wobble")
If you use :reader
instead of :accessor
, setting is not allowed. This is often useful to communicate intent of immutability.
Slot-value
is really for special situations in the lifetime of an object, such as when playing around with methods for initialize-instance
. That is an advanced topic.