Reflective Operations on Functions
The following functions don't need to be called in routine programming, but are useful for implementation of the language and in the construction of the programming environment.
generic-function-methods generic-function [Function] => sequence
generic-function-methods returns a sequence of all of the methods in generic-function. The order of the methods in the sequence is not significant.[21]The sequence returned should never be destructively modified. Doing so may cause unpredictable behavior.
If generic-function is sealed, an implementation may choose not to return a sequence of methods, but instead signal an error of type <sealed-object-error>.
add-method generic-function method [Function] => new-method old-method
add-method adds method to generic-function. This operation modifies the generic function object.In general, you do not need to call add-method directly. It is called by define method.
If you add a method to a generic function, and the generic function already has a method with the exact same specializers, then the old method is replaced with the new one.
A single method may be added to any number of generic functions.
add-method returns two values. The first is the new method. The second will be either the method in generic-function which is being replaced by method, or it will be #f, if no method is being replaced.
generic-function-mandatory-keywords generic-function [Function]
If generic-function accepts keyword arguments, returns a collection of the mandatory keywords for generic-function. Returns #f if generic-function does not accept keyword arguments.
The collection returned should never be destructively modified. Doing so may cause unpredictable behavior.
function-specializers function => sequence [Function]
function-specializers returns a sequence of the specializers for function. The length of the sequence will equal the number of required arguments of function. The first element of the sequence will be the specializer of the first argument of function, the second will be the specializer of the second argument, etc.The sequence returned should never be destructively modified. Doing so may cause unpredictable behavior.
function-arguments function [Function] => required-number rest-boolean kwd-sequence
function-arguments returns three values:
1. The number of required arguments accepted by the function.
2. A boolean that indicates whether the function accepts a variable number of arguments.
3. If the value is #f then the function does not accept keyword arguments. Otherwise, the function does accept keyword arguments, and the value is either a collection of the keywords which are permissible for any call to the function, or the symbol all if all keywords are permitted by the function.
Note that particular calls to a generic function may accept additional keywords not included in the third value returned by function-arguments, by virtue of their being recognized by applicable methods.
applicable-method? function #rest sample-arguments [Function] => boolean
applicable-method? returns true if function is a method or contains a method that would be applicable for sample-arguments.
sorted-applicable-methods [Function] generic-function #rest sample-arguments => sequence1 sequence2
sorted-applicable-methods returns two sequences that, taken together, contain the methods in generic-function that are applicable for the sample-arguments. sequence1 contains methods that are more specific than every method that follows them. sequence2 (which cannot be sorted itself) begins at the first point of ambiguity; there are at least two methods that could equally well go first in sequence2.The sequences returned should never be destructively modified. Doing so may cause unpredictable behavior.
find-method generic-function specializer-list [Function] => {method or #f}
find-method returns the method in generic-function that has the specializers in specializer-list as its specializers. The specializers must match exactly for a method to be returned. If generic-function is sealed, an implementation may choose to signal an error of type <sealed-object-error> (instead of returning any value at all) .
remove-method generic-function method => method [Function]
remove-method removes method from generic-function and returns method. remove-method will signal an error if method is not in generic-function. If generic-function is sealed, or if method is a sealed method of generic-function , then an error of type <sealed-object-error> is signaled.Next section: The classes <function>, <generic-function>, and <method>