You are looking at historical revision 23964 of this page. It may differ significantly from its current revision.
The advice extensions allows modifying the behaviour of existing procedures by specifying code that should run before, after or instead of the original procedure.
Usage[procedure] (advise MODE PROCEDURE ADVISOR [ID])
Adds a "piece of advice" to PROCEDURE. Depending on MODE, do any of the following:
- if MODE is the symbol before, every call to PROCEDURE will invoke the procedure ADVISOR with a list of the arguments passed to PROCEDURE before the original procedure is executed.
- if MODE is the symbol after, every call to PROCEDURE will invoke the procedure ADVISOR with a list of the arguments passed to PROCEDURE after the original procedure is executed.
- if MODE is the symbol around, every call to PROCEDURE will invoke the procedure ADVISOR with the next "inner" around advisor procedure (or the original procedure, if no other around advice is defined or remaining) and a list of the arguments passed to PROCEDURE.
before advice-procedures are invoked in the reverse order: the most recently added advisor runs first. after advice-procedures are invoked in the order in which they are added, the most recent one running last. The most recently added around advice-procedures is called with the next "inner" advice procedure passed as argument.
The procedure passed as first argument to around advisors takes its arguments in the same manner as the original procedure.
advise returns an ID that can be used to identify a particular piece of advice. If no ID was given, one will be generated.[procedure] (unadvise PROCEDURE [ID [MODE]])
Removes advice from an advised procedure. Advice can be removed completely (no ID or mode given). Specific pieces of advice can be removed by passing the advice-ID (as returned by advice). Alternatively advice for a given mode (before, after or around) can be removed (by passing #f as the ID argument).
- ported to CHICKEN 4
- Initial version
Copyright (c) 2007, Felix L. Winkelmann All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.