Advice (computer science)

Advice (computer science)

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 [http://aosd.net/pipermail/discuss_aosd.net/2004-November/001173.html 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 is the basic innovation in the model, and in the PILOT system. Advising consists of inserting new procedures at any or all of the entry or exit points to a particular procedure (or class of procedures). The procedures inserted are called "advice procedures" or simply "advice"."

:"Since each piece of advice is itself a procedure, it has its own entries and exits. In particular, this means that the execution of advice can cause the procedure that it modifies to be bypassed completely, e.g., by specifying as an exit from the advice one of the exits from the original procedure; or the advice may change essential variables and continue with the computation so that the original procedure is executed, but with modified variables. Finally, the advice may not alter the execution or affect the original procedure at all, e.g., it may merely perform some additional computation such as printing a message or recording history. Since advice can be conditional, the decision as to what is to be done can depend on the results of the computation up to that point."

:"The principal advantage of advising is that the user need not be concerned about the details of the actual changes in his program, nor the internal representation of advice. He can treat the procedure to be advised _as a unit_, a single block, and make changes to it without concern for the particulars of this block. This may be contrasted with editing in which the programmer must be cognizant of the internal structure of the procedure."

"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:
# "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."
# "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."

External links

* [http://www.ai.mit.edu/research/publications/browse/0200browse.shtml Teitelman's PhD thesis] (AITR-221)
* [http://www.classiccmp.org/bitsavers/pdf/xerox/interlisp/1974_InterlispRefMan.pdf InterLisp reference manual]
* [http://p-cos.blogspot.com/2007/12/origin-of-advice.html "Origin of Advice"]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • computer science — computer scientist. the science that deals with the theory and methods of processing information in digital computers, the design of computer hardware and software, and the applications of computers. [1970 75] * * * Study of computers, their… …   Universalium

  • On the Cruelty of Really Teaching Computer Science — “On the Cruelty of Really Teaching Computing Science” is a 1988 paper by E. W. Dijkstra[1] which argues that computer programming should be understood as a branch of mathematics, and that the formal provability of a program is a major criterion… …   Wikipedia

  • The Cruelty of Really Teaching Computer Science — “The Cruelty of Really Teaching Computing Science” is a 1988 paper by E. W. Dijkstra, which argues that computer programming should be understood as a branch of mathematics, and that the formal provability of a program is a major criterion for… …   Wikipedia

  • Computer Society of India — Established 1965 Type Professional Society President Mr. M D Agrawal Location …   Wikipedia

  • Computer Music Center — For the 1961 album, see Columbia–Princeton Electronic Music Center (album). For other uses, see CMC (disambiguation). The Computer Music Center (CMC) at Columbia University is the oldest center for electronic and computer music research in the… …   Wikipedia

  • science — noun ADJECTIVE ▪ modern ▪ bad, junk (informal) ▪ This rule is based on bad science. ▪ good, hard, real …   Collocations dictionary

  • Computer recycling — Computer monitors are typically packed into low stacks on wooden pallets for recycling and then shrink wrapped.[1] Computer recycling or electronic recycling is the recycling or reuse of computers or other electronics. It includes both finding… …   Wikipedia

  • United States President's Council of Advisors on Science and Technology — President s Council of Advisors on Science and Technology Agency overview Formed September 30, 2001 Preceding agency President s Science Advisory Committee Headquarte …   Wikipedia

  • History of science — History of science …   Wikipedia

  • History of science and technology in the People's Republic of China — For more than a century China s leaders have called for rapid development of science and technology, and science policy has played a greater role in national politics in China than in many other countries. China s scientific and technical… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”