| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Sometimes it is useful to extend a Festival function in some way. Standard Festival functions don't provide easy to use means for it. This module tries to fill the gap.
The following macro allows you to wrap a defined function:
define-wrapper (function arg ...) wrapper-name . body)
Wrap function with arguments arg ... by the code
body. Given function arguments must match the arguments of the
wrapped function. wrapper-name is a symbol uniquely identifying
the wrapper, it allows redefinition of the wrapper. One function can
be wrapped by any number of wrappers. None of the define-wrapper
arguments is evaluated.
Within body, a function named next-func is automatically
defined. It returns the next wrapper or the original function.
Please note next-func is a function, not a variable, so its
typical invocation looks as follows: ((next-func) arg ...).
oo-ensure-function-wrapped function-name
If a wrapped function gets redefined, its wrapper is lost. If you want to ensure the function is still wrapped before its use, you may call this function, with its symbol name as the argument.
oo-unwrapped function-name
Return the original definition of a wrapped function.
Example use:
festival> (define (foo x) (+ x 42)) #<CLOSURE (x) (+ x 42)> festival> (foo 1) 43 festival> (define-wrapper (foo x) my-foo-wrapper (print "Foo called.") ((next-func) x)) nil festival> (foo 1) "Foo called." 43 |
You can also wrap parameters, set by Param.set:
Param.wrap name wrapper-name . body
Wrap access to parameter name by code body. If the given
parameter is accessed, its wrapper is invoked instead of just
returning the parameter value. wrapper-name is the same as in
define-wrapper.
Macro next-value is automatically defined within body.
It returns the parameter value, either plain or modified by another
wrapper.
Example use of parameter wrapping:
festival> (Param.set 'foo 42) #<feats 0x8169950> festival> (Param.wrap foo foo-w (+ (next-value) 1)) nil festival> (Param.get 'foo) 43 |
And finally, the glet* macro allows you to dynamically bind a
global variable value:
glet* bindings . body
Similar to let* (see section util.scm) except that the variables in
bindings are bound dynamically instead of lexically. All
variables in bindings must be global variables.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by Milan Zamazal on August, 11 2009 using texi2html 1.78.