I've define a class and created an instance. I'd like to use
incf in conjunction with a slot accessor, but it does not seem to
work.
(defclass row-col nil
( rows :initarg :rows
:accessor rows)
( cols :initarg :cols
:accessor cols))
(setf obj (make-instance 'row-col :rows 1 :cols 10))
(incf (rows obj))
(incf (cols obj))
But the rows and the cols remain at their initial values.
Is there something wrong with what i'm doing?
-jim
Jim Newton wrote:
> I've define a class and created an instance. I'd like to use
> incf in conjunction with a slot accessor, but it does not seem to
> work.
>
> (defclass row-col nil
> ( rows :initarg :rows
> :accessor rows)
> ( cols :initarg :cols
> :accessor cols))
There is a pair of parentheses missing in the defclass form. And while
we're at it, I think it's more idiomatic to use () instead of nil to
denote empty lists. And you're using too many spaces. ;)
(defclass row-col ()
((rows :accessor rows
:initarg :rows)
(cols :accessor cols
:initarg :cols)))
(I also prefer to mention the accessors before the initarg and initform
options. I don't know why, or whether this is idiomatic. But I believe I
have seen this more often.)
> (setf obj (make-instance 'row-col :rows 1 :cols 10))
> (incf (rows obj))
> (incf (cols obj))
>
> But the rows and the cols remain at their initial values.
> Is there something wrong with what i'm doing?
With the above changes, the code works over here. However, your defclass
form should generate an error before you can even run the rest, so maybe
there's something else going on.
Pascal
--
Tyler: "How's that working out for you?"
Jack: "Great."
Tyler: "Keep it up, then."