Lisp HUG Maillist Archive

I don't understand define-method-combination

Lispworks appears to treat what I think should be a "short form"
define-method-combination as a "long form".

The Hyperspec says, regarding d-m-c short form:

  The short form syntax of define-method-combination is recognized
  when the second subform is a non-nil symbol or is not present.

But this code gives me an error:

  (defun combine (&rest args)
    (format t "combine: ~S~%" args)
    args)
  (define-method-combination combine)
  (defgeneric foo (l) (:method-combination combine))
  (defmethod foo combine ((l list))
    (format t "l is ~S~%" l)
    l)
  (foo '(a list)) =>

  Error: invalid-method-error in #<STANDARD-METHOD FOO (COMBINE) (LIST) 21D56ED3>,
  called with arguments ((A LIST)):
  This method has qualifiers which are invalid for method-combination-type COMBINE.
    1 (abort) Return to level 0.
    2 Return to top loop level 0.

  Type :b for backtrace, :c <option number> to proceed,  or :? for other options

  CL-USER 2 : 1 > 

If I macroexpand the d-m-c call I get what looks like a "long form"
expansion; note the COND with a single T clause that throws the error
I got:

(DSPEC:DEF (METHOD-COMBINATION COMBINE)
  (CLOS::LOAD-METHOD-COMBINATION 'COMBINE
                                 'NIL
                                 #'(LAMBDA ()
                                     (DECLARE)
                                     #'(LAMBDA (#:G5594 #:|methods-5593|)
                                         (LET ()
                                           (LOOP CLOS::FOR #:|method-5592| CLOS::IN
                                                           #:|methods-5593|
                                                 CLOS::FOR #:|qualifiers-5591| =
                                                           (METHOD-QUALIFIERS
                                                            #:|method-5592|)
                                                 DO (COND
                                                     (T
                                                      (INVALID-METHOD-ERROR
                                                       #:|method-5592|
                                                       "This method has qualifiers which are invalid for ~
                          method-combination-type ~S."
                                                       'COMBINE))))
                                           (PROGN))))
                                 :LOCATION
                                 (DSPEC:LOCATION)))

By comparison if I macroexpand

  (define-method-combination combine :operator combine)

I get what looks like a "short form" expansion:

(DSPEC:DEF (DEFINE-METHOD-COMBINATION COMBINE)
  (CLOS::LOAD-SIMPLE-METHOD-COMBINATION 'COMBINE 'COMBINE 'NIL 'NIL (DSPEC:LOCATION)))

(And, of course, if I *use* that code, then my example code above
works.)

Have I misunderstood the Hyperspec, or is something else going on?

-- Larry Clapp


Re: I don't understand define-method-combination

Unable to parse email body. Email id is 7281

Updated at: 2020-12-10 08:44 UTC