From: Joost Diepenmaat
Subject: using 2 or more arguments in a setf method
Date: 
Message-ID: <87myrrx0ww.fsf@zeekat.nl>
I'm beginning to suspect that I'm missing something about setf methods
in CLOS, or maybe I'm just overlooking something simple:

I've got a simple method that retrieves a buffer from an object by a key

(defmethod input-buffer ((patch my-class) key)
  (getf (input-buffers patch) key))

and I would like this method to be setf-able:

(setf (input-buffer patch 'my-key) new-buffer)

I tried the following in SBCL:

(defmethod (setf input-buffer) (buffer (patch my-class) key)
  (setf (getf (input-buffers patch) key) buffer))

But that gives me an error:

    The generic function
    #<STANDARD-GENERIC-FUNCTION (SETF INPUT-BUFFER) (2)> takes 2
    required arguments; was asked to find a method with specializers
    (#1=#<BUILT-IN-CLASS T> #<STANDARD-CLASS LADSPA-PATCH> #1#)
       [Condition of type SB-PCL::FIND-METHOD-LENGTH-MISMATCH]
       See also:
         Common Lisp Hyperspec, FIND-METHOD [:function]

As far as I can make out, that seems to indicate that you can't setf
on a method that takes more than one argument.

It does work if I use a normal method instead of a setf method but I
don't think it's as nice to look at when I can use setf in other places:

(defmethod set-input-buffer ((patch my-class) key buffer)
  (setf (getf (input-buffers patch) key) buffer))

Is there any way I can get the setf version to work?

Joost.

From: Drew Crampsie
Subject: Re: using 2 or more arguments in a setf method
Date: 
Message-ID: <297b2b06-6c62-49f7-a357-6306f58e7b34@i29g2000prf.googlegroups.com>
On Dec 30, 2:39 pm, Joost Diepenmaat <·····@zeekat.nl> wrote:
[snip]
>
> I tried the following in SBCL:
>
> (defmethod (setf input-buffer) (buffer (patch my-class) key)
>   (setf (getf (input-buffers patch) key) buffer))
>
> But that gives me an error:
>
>     The generic function
>     #<STANDARD-GENERIC-FUNCTION (SETF INPUT-BUFFER) (2)> takes 2
>     required arguments; was asked to find a method with specializers
>     (#1=#<BUILT-IN-CLASS T> #<STANDARD-CLASS LADSPA-PATCH> #1#)
>        [Condition of type SB-PCL::FIND-METHOD-LENGTH-MISMATCH]
>        See also:
>          Common Lisp Hyperspec, FIND-METHOD [:function]
>
> As far as I can make out, that seems to indicate that you can't setf
> on a method that takes more than one argument.

You didn't make out far enough. This error indicates that the generic
function (SETF INPUT-BUFFER) is already defined with less arguments
than in your method definition. You've probably defined an accessor
somewhere, like in the definition of one of your class's slots.

* (defmethod (setf input-buffer) (val (class t) thing otherthing &rest
things)
    (declare (ignore thing otherthing things))
    t)
#<STANDARD-METHOD (SETF INPUT-BUFFER) (T T T T) {9493EA9}>


hth,

drewc


>
> It does work if I use a normal method instead of a setf method but I
> don't think it's as nice to look at when I can use setf in other places:
>
> (defmethod set-input-buffer ((patch my-class) key buffer)
>   (setf (getf (input-buffers patch) key) buffer))
>
> Is there any way I can get the setf version to work?
>
> Joost.
From: Joost Diepenmaat
Subject: SOLVED - Re: using 2 or more arguments in a setf method
Date: 
Message-ID: <87ejd3wz86.fsf_-_@zeekat.nl>
Drew Crampsie <·············@gmail.com> writes:
> You didn't make out far enough. This error indicates that the generic
> function (SETF INPUT-BUFFER) is already defined with less arguments
> than in your method definition. You've probably defined an accessor
> somewhere, like in the definition of one of your class's slots.

Ah yes. I couldn't find any other definition in my code, but some of my 
experimenting may have introduced one anyway. After restarting my lisp
it works - or at least it compiles :-)

Thanks,

Joost.