All Manuals > LispWorks® User Guide and Reference Manual > 38 The LISPWORKS Package

call-next-advice Function

Summary

Calls the next piece of advice associated with a function.

Package

lispworks

Signature

call-next-advice &rest args => value*

Arguments
args
Arguments to be given to the next piece of advice to be called.
Values
value*
Values produced by the call to the next piece of advice or the original definition.
Description

The function call-next-advice is the local function used to invoke the next item in the ordering of pieces of advice associated with a function. It can only be called from within the scope of the around advice. Advice may be attached to a function by defadvice and this allows the behavior of a function to be modified. Extra code to be performed before or after the function may be simply added by creating before or after advice for it. Around advice is more powerful and replaces the original definition. All the advice for a function is ordered with the around advice coming first.

The first piece of around advice receives the arguments to the function and may return any values at all. It has access to the rest of the advice, and to the original definition, by means of call-next-advice. A call to call-next-advice from within the body of the around advice invokes the next piece of around advice with the arguments args. Any number of arguments may be given in this way, including keyword arguments, and there is no requirement for pieces of around advice to receive the same number of arguments as the original definition expected. The last piece of around advice in the ordering invokes the sequence of before advice, the original definition, and after advice if it calls call-next-advice. Around advice may contain any number of calls to call-next-advice, including no calls.

Notes
  1. call-next-advice is an extension to Common Lisp. See 6 The Advice Facility for a broader discussion of advice.
  2. call-next-advice is not like cl:call-next-method, where passing no arguments has a special meaning. To pass the same arguments to the next advice, you need something like:
    (lw:defadvice (my-func my-func-advice :around)
        (a b c &rest other-args)
      (format t "my-func advice~%")
      (apply #'lw:call-next-advice a b c other-args)
      )
    

    or:

    (lw:defadvice (my-func my-func-advice :around)
        (&rest args)
      (format t "my-func advice~%")
      (apply #'lw:call-next-advice args)
      )
    
See also

defadvice
6 The Advice Facility


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:41