szos / advisor

A defun replacement that allows for advising functions.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Advisor

ADVISOR HAS BEEN REPLACED WITH CL-ADVICE, AVAILABLE HERE: https://github.com/szos/cl-advice

Advisor is a project to define functions that can be advised. Advice can be designated for before, after, and around the main function.

Usage

To use this system seamlessly, youll need to import several symbols, and shadow-import defun, from the :advisor package. Here is an example defpackage form:

(defpackage #:example
  (:shadowing-import-from #:advisor #:defun)
  (:import-from #:advisor #:defadvice #:remove-advice
                #:call-main-function #:call-main-function-with-args
                #:activate-advice #:deactivate-advice
                #:delete-advice #:advice-documentation)
  (:use #:cl))

It is absolutely neccessary to import either call-main-function or call-main-function-with-args, as without it one or the other you will be unable to write advice :around a function, only :before and :after.

DEFUN

defun function-name lambda-list [​[declaration* | documentation]] form*

The defun macro replaces cl:defun, but is used in the same way. It generates a dispatch function alongside the main function, and sets the symbol-value of the provided function name to the main function. It additionally defines an advisable-function object which contains the main function and the dispatch function.

While the dispatch function will call the before/after functions, it will always return the main function. If one wants to modify what is returned, one should define around advice instead, as that will be returned instead of the main function.

Unfortunately, the dispatch function will always have a signature of function &rest arguments, as it is infeasible to account for &optional, &key, and &rest manually.

DEFADVICE

defadvice qualifier function-name lambda-list [​[declaration* | documentation]] form*

The defadvice macro will add advice to the advisable-function object. lambda-list must have the same signature as the function being advised, or must be of the form (&rest arg) to allow the function to apply advice functions to the arguments.

REMOVE-ADVICE

remove-advice qualifier name

The remove-advice function removes the advice for name specified by qualifier, or if qualifier is :all or :everything removes all advice for name.

DELETE-ADVICE

delete-advice symbol &optional fmakunbound

The delete-advice function deletes an advisable-function object. If fmakunbound is nil, the symbol-function of symbol is set to the main function of the advisable-function object before deletion. If fmakunbound is t, then the symbol-function of symbol is unbound. If symbol does not denote an advisable-function object nothing is done.

DE/ACTIVATE-ADVICE

deactivate-advice symbol

activate-advice symbol

These functions activate or deactivate advice for a function without deleting that advice.

ADVICE-DOCUMENTATION

advice-documentation symbol

The advice-documentation function returns an alist with the documentation of the main function as well as all advice. The alist keys are :before :around :main and :after.

About

A defun replacement that allows for advising functions.


Languages

Language:Common Lisp 100.0%