So If I have a defclass object and I make an instance of it and place it inside an array. How do I get the value of its slots inside the array?
I've tried:
(slot-value (aref *array* 0) :name)
I guess I am just not understanding how to access an object that is inside an array.
I can print the object in an unreadable form using (format t) but is there a way to print an object and all the slots in a form I can actually understand?
(defun generate-object (name)
(let ((a (make-instance 'person
:name name)))
(setf (aref *array* 0) a)))
it places the object inside the array but it seems that the slot is not being created?
This causes the problem:
(defclass person ()
((name :accessor name
:reader read-name
:initarg :name)))
(defvar *array* 0)
(setf *array* (make-array 20))
(defun generate-object (name)
(let ((a (make-instance 'person
:name name)))
(setf (aref *array* 0) a)))
The slot name needs to be a symbol that is syntactically valid as a variable name. Try 'name instead of :name .
(slot-value (aref *array* 0) 'name)
Look at the examples here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With