"Overload" of CLOS multimethods with various parameter lists

I am trying to do an β€œebull overload call” in Common Lisp. Here is a simplified summary of the case:

(defclass foo ()
  ((slotty :accessor slotty :initarg :slotty)))

(defclass bar ()
  ((slotty :accessor slotty :initarg :slotty)))

(defparameter *foo* (make-instance 'foo :slotty "defnoodle"))
(defparameter *bar* (make-instance 'bar :slotty "Chocolate"))

(defmethod contrived ((f foo) (b bar))
  (format t "i pity the foo ~A, who has a bar ~A ~%" (slotty f) (slotty b)))

(contrived *foo* *bar*)

outputs: i pity the foo defnoodle, who has a bar Chocolate

But as soon as I try to define the following method:

 (defmethod contrived ((f foo))
    (format  t "i just pity the foo ~A ~%" (slotty f)))

CL is angry:

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

Does anyone know what I'm doing wrong here? I know that initialize-instance has similar flexibility, because you need to be able to identify the n number of initialize-instance methods for each class and for any number of arguments.

(defmethod initialize-instance :after ((f foo) &key)
  ())

but I don’t understand how I can translate this into the example of vanilla, which I gave above. And I feel that I can bark the wrong tree, as it is part of the SS.

+3
source share
2 answers

: - , ?

: CLOS . . . Lisp "".

INITIALIZE-INSTANCE :

initialize-instance instance &rest initargs &key &allow-other-keys => instance

- . . - .

, , , .

. CL Hyperspec : - .

+6

. , , &rest &key .

, , &optional, &rest &key.

+3

All Articles