I wanted to get the value of an attribute from a pointer, inside another object, but accessing it without evaluating the reference got me the error
When attempting to read the slot's value (slot-value), the slot
POS is missing from the object *NODE-1*.
Here is a piece of code to simulate the error:
(defclass node ()
((pos
:initarg :pos
:initform '(0 0)
:accessor pos)))
(defclass edge ()
((vertices
:initarg :vertices
:accessor vertices)))
(defparameter *node-1* (make-instance 'node))
(defparameter *node-2* (make-instance 'node :pos '(100 100)))
(defparameter *edge-1* (make-instance 'edge :vertices '(*node-1* *node-2*)))
After that, evaluating this expression throws an error
(slot-value (car (slot-value *edge-1* 'vertices)) 'pos)
But this one has the desired behavior
(slot-value (eval (car (slot-value *edge-1* 'vertices))) 'pos)
I already know that eval
is used for ugly hacks, that's why I'm trying to find a clever way to do what I need.