
6.3 The Advice Facility
Syntax:advice-continue&rest args
Syntax:apply-advice-continue args&rest more-args
advice-continue andapply-advice-continue call an advised function from within the body ofdefadvice.
advice-continue applies the continuation to the specified arguments.
apply-advice-continue applies the continuation to a specified list of arguments.
apply-advice-continue is toadvice-continue as the Common Lisp functionapply is tofuncall.
defadvice (function-to-advise name-of-advice&optional place) (lambda-list) {form}*
defadvice defines a piece of advice for a specified function.
string-equal.
:outside name), (:before name):outside keyword option puts the piece of advice that is being defined outside the advice with the specified name; the:before keyword option is synonymous.
:inside name), (:after name):inside keyword option puts the piece of advice that is being defined inside the advice with the specified name; the:after keyword option is synonymous.
defadvice, which is any normal function body.
defadvice appears in a compiled file, the advice is compiled.
defadvice advises the expansion function for the macro, not the macro itself. For information about expansion functions for macros, see the chapter on macros in CLtL2.
;; Define a macro that creates a cons of an object with itself. > (defmacro two (x) '(cons ,x ,x)) TWOdescribe-advice Function> (macroexpand '(two 3)) ; It expands into consing code. (CONS 3 3) T
> (two 3) ; It returns a cons cell. (3 . 3)
;; Now advise the expansion function. The advice first takes ;; apart the form it is given and then creates a new form for the ;; macro to expand. In this case, if the FORM argument is (TWO 3), ;; the NAME argument is TWO and the ARG argument is 3. You call ;; the continuation with the form (TWO (1+ 3)) for it to expand. ;; The continuation expands this form into (CONS (1+ 3) (1+ 3)), ;; as shown. > (defadvice (two add-one-first) (form &optional env) (destructuring-bind (name arg) form (advice-continue '(,name (1+ ,arg)) env))) #<ADVICE ADD-ONE-FIRST B52087>
> (macroexpand '(two 3)) (CONS (1+ 3) (1+ 3)) T
> (two 3) (4 . 4)
Syntax:describe-advice function
describe-advice describes all levels of advice for a specified function.
defadvice
Syntax:remove-advice function&optional advice-name
remove-advice removes some or all of the advice from a specified function.
string-equal. If you do not specify this argument, all advice is removed from the function.
defadvice

Generated with Harlequin WebMaker