Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining custom setf for class in lisp

Suppose I have a class called board:

(defclass board ()
 ((blocker    :accessor blocker    :initarg :blocker    :initform  0))

According to this book I can define a custom setf for blocker by:

(defmethod (setf blocker) (new-blocker (b board))
  (setf (slot-value b 'blocker) new-blocker))

However, steel bank common lisp will say function not defined, even though I have evaluated it. Does anyone know what's wrong here?

like image 662
Mark Avatar asked Nov 17 '25 21:11

Mark


1 Answers

That looks correct. Note that you are redefining the already existing setf method that you created by specifying :accessor blocker. SBCL will give you a style-warning about that.

Your mistake is somewhere else. Are you in a different package, perhaps? Try to show the steps you have taken in your IDE to compile and load those forms, and to attempt to run that method invocation.

like image 120
Svante Avatar answered Nov 19 '25 14:11

Svante