As I understand it, setf can not only set a variable, it can also set a "place", in this case, a position in a list. So I can create a simple class:
Code: Select all
(new class 'Node)
(setq n (Node "test" '(5 3)))
If want to inspect or change the Node's coordinates, I can do this:
Code: Select all
(println "location: " (n 2))
(setf (n 2) '(9 9))
(println "new location: " (n 2))
However, if I want to encapsulate the list access into the class, it doesn't work for setting:
Code: Select all
(define (Node:where) ((self) 2))
(println "location: " (:where n))
(setf (:where n) '(14 3))
(println "same old location: " (:where n))
Is there any way to do anything like the above without having to define a separate getter and setter?
Thanks!
Testing can show the presence of bugs, but not their absence.