In aspect and functional programming, advice describes a class of functions which modify other functions when the latter are run; it is a certain function, method or procedure that is to be applied at a given join point of a program.

The following is taken from a discussion at the mailing list aosd-discuss. Pascal Costanza contributed the following:

The term advice goes back to the term advising as introduced by Warren Teitelman in his PhD thesis in 1966. Here is a quote from Chapter 3 of his thesis:

"Advising" found its way into BBN Lisp and later into Xerox PARC's Interlisp.

It also found its way to Flavors, the first object-oriented extension to Lisp developed at MIT. They were subsumed under the notion of method combination. See, for example, AIM-602 at http://www.ai.mit.edu/research/publications/browse/0600browse.shtml 1

Since method combination and macros are closely related, it's also interesting to note that the first macro system was described in 1963, three years before Warren Teitelman's PhD thesis. See AIM-57 at http://www.ai.mit.edu/research/publications/browse/0000browse.shtml 2

Use

The practical use of advice functions is generally to modify or otherwise extend the behavior of functions which cannot be easily modified or extended. The Emacspeak Emacs-addon makes extensive use of advice: it must modify thousands of existing Emacs modules and functions such that it can produce audio output for the blind corresponding to the visual presentation, but it would obviously be infeasible to copy all of them and redefine them to produce audio output in addition to their normal outputs; so, the Emacspeak programmers define advice functions which run before and after.

Another Emacs example; suppose after one corrected a misspelled word through ispell, one wanted to re-spellcheck the entire buffer. M-$ offers no such functionality, even if the spellchecked word is used a thousand times. One could track down the definition of ispell-word , copy it into one's .emacs, and write the additional functionality, but this is tedious, prone to broken-ness (the .emacs version will get out of sync with the actual Ispell Elisp module, if it even works out of its home). What one wants is fairly simple: just to run another command after ispell-word runs. Using advice functions, it can be done as simply as this:

                        
                          (defadvice ispell (after advice) (flyspell-buffer))(ad-activate 'ispell t)
                        
                      

Notes

Gregor Kiczales comments the above as follows:

  1. Advice appeared separately from Flavors in Maclisp and the Lisp Machine. You could advise any function, just like in Interlisp at the time. The before/after ontology appeared separately in Flavors methods.
  2. Method combination and macros were only marginally related until much later, in New Flavors and CLOS, when a macro-like mechanism was provided to allow people to define their own rules for combining methods. Prior to that the rules governing combination of before/after methods and so-called whoppers methods (around) was fixed, and the compiler just generated the code for that. There were things called wrappers, which had macro-like behavior, but I forget when they came around. Traipsing through the various versions of MacLisp and Lispm manual to get this part of the history exactly right could interesting. Or it could be that Howard Cannon or David Moon or someone could actually remember it all exactly.

See also

  • Function decorator

External links

  • Teitelman's PhD thesis (AITR-221)
  • InterLisp reference manual
  • "Origin of Advice"

    Computer Repairs in Reading, Computer Support, Computer help. Computer ...

    Computer Advice Centre in Reading, provides Computer support, Computer help and Computer repairs. We are a local team of friendly, mature and qualified computer specialists, who ...

    ...

    Computer Advice

    General computer advice ... Scan Your Computer for viruses! Call for help. When all else fails ? call in an expert from Computer Troubleshooters.

    ...

    computer advice « Questions Answered

    Latest Updates: computer advice RSS. Is it really possible to shred unwanted files on your computer so that they are truly unrecoverable? asked by putipato 5:38 am on July 12, 2009 ...

    ...

    Computer Advice and Repair Solutions

    Computer advice, repair, tech support, inhome repair, home repair, network, anti virus, antispam, kansas city area.

    ...

    Computer Advice and Support in Leicester, Loughborough, Melton Mowbray ...

    Whether you are adding bits, new programs or updating - we will make sure everything runs smoothly. Very affordable hourly rate or fixed project fee.

    ...

    computer advice | Latest Tech News, Tips & Advice

    Just like today’s automobile, the average home computer user usually doesn’t have the time or inclination to conduct their own maintenance of the computer.

    ...

    Free Computer Advice Forums

    Free resources to help you with your computer problems. Tutorials, Forums and a Ask a question section.

    ...

    Computer Advice

    IP address. It should only show your internet connection IP even if you are on a LAN (well it does here in me office). This is very useful if you are opening any ports for any ...

    ...

    Computer Advice and Repair Solutions--Extended Options

    Call: (816) 820-7863 Call: (913) 485-8890 Extended Options: We have unlimited Advice or Service plans: Contract with us for Advice Weekly for:

    ...

    Comments for Computer Advice

    Also checkout http://www.gigstreams.com for more p2p software. Comment on Download pplive Free by Live Football

    ...