Skip to content

next-method call in method*

A (next-method) call in a method* will pass on all required, optional and rest arguments in the list of formals to the next less specialized method in the list of applicable methods, as well as any actual keyword arguments passed in the call to the method*.

This has the following consequences for default values:

  1. A an optional argument will shadow default values for optional arguments in the same position in less specialized methods. For example if <B> is a subclass of <A> and b an instance of <B>,

    emacs-lisp
    (define-method* (foo (obj <A>) #:optional (c 1)) c)
    (define-method* (foo (obj <B>) #:optional c)) (next-method))
    (foo b) ⇒ #f

    The reason for this is that c will obtain the value #f already in the call to the second (most specialized, called first) method, and this value will be passed on by the (next-method) call.

  2. A keyword argument will not shadow a default value for the same keyword argument in less specialized methods. Example:

    emacs-lisp
    (define-method* (foo (obj <A>) #:key (c 1)) c)
    (define-method* (foo (obj <B>) #:key c)) (next-method))
    (foo b) ⇒ 1

    The reason for this is that the first (less specialized, called last) method will not be passed any keyword arguments from the call. In particular, it won’t be passed #:c VAL, and it will therefore use its default value.

The user can pass arguments to next-method to customize the behavior. In particular, if the current method uses advanced argument handling in such a way that it has keywords in its list of formals and the next, less specialized, method is an ordinary method, it will be necessary to pass arguments explicitly to next-method to “filter out” any keywords.