All Manuals > LispWorks® User Guide and Reference Manual

6 The Advice Facility

The advice facility provides a mechanism for altering the behavior of existing functions. As a simple application of this, you may supplement the original function definition by supplying additional actions to be performed before or after the function is called. Alternatively, you may replace the function with a new piece of code that has access to the original definition, but which is free to ignore it altogether and to process the arguments to the function and return the results from the function in any way you decide. The advice facility allows you to alter the behavior of functions in a very flexible manner, and may be used to engineer anything from a minor addition of a message, to a major modification of the interface to a function, to a complete change in the behavior of a function. This facility can be helpful when debugging, or when experimenting with new versions of functions, or when you wish to locally change some functionality without affecting the original definition.

Note: It can be dangerous to put advice on system functions or functions used at low-level by the system In general, advising a basic Common Lisp function (that is, a simple function for manipulating simple objects such as reverse) is dangerous, because the implementation may use it.

6.1 Defining advice

6.2 Combining the advice

6.3 Removing advice

6.4 Advice for macros and methods

6.5 Advising subfunctions

6.6 Examples

6.7 Advice functions and macros

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