LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Common Lisp: CLOS and with-slots (https://www.linuxquestions.org/questions/programming-9/common-lisp-clos-and-with-slots-4175465455/)

hydraMax 06-10-2013 01:02 PM

Common Lisp: CLOS and with-slots
 
Hi. I'm a newbie to Common Lisp, and I'm using GNU Clisp. In working through a tutorial on CLOS, I set up a simple class and an instance:

Code:

(defclass rect () (l w))

(setf rect-a (make-instance 'rect))

One of the exercises challenged me to create a setter function, using with-slots. So, I wrote this:

Code:

(defun set-rect-values (rect l w)
  (with-slots ((l-old l) (w-old w))
              rect
              (setf 'l-old l)
              (setf 'w-old w)))

But I get this error when trying to use it:

Code:

> (set-rect-values rect-a 2 2)

*** - SLOT-VALUE: The slot L of #<RECT #x0003348AC408> has no value

Please advise.

ntubski 06-10-2013 08:59 PM

Code:

(setf 'l-old l)
(setf l-old l)

Don't quote the first argument to setf.


All times are GMT -5. The time now is 07:10 PM.