With the defgeneric and defmethod constructs, new generic functions may be written directly in CLIPS. Generic functions are similar to deffunctions because they can be used to define new procedural code directly in CLIPS, and they can be called like any other function (see sections 2.3.2 and 7). However, generic functions are much more powerful because they can do different things depending on the types (or classes) and number of their arguments. For example, a ì+î operator could be defined which performs concatenation for strings but still performs arithmetic addition for numbers. Generic functions are comprised of multiple components called methods, where each method handles different cases of arguments for the generic function. A generic function which has more than one method is said to be overloaded.
Generic functions can have system functions and userdefined external functions as implicit methods. For example, an overloading of the "+" operator to handle strings consists of two methods: 1) an implicit one which is the system function handling numerical addition, and 2) an explicit (user-defined) one handling string concatenation. Deffunctions, however, may not be methods of generic functions because they are subsumed by generic functions anyway. Deffunctions are only provided so that basic new functions can be added directly in CLIPS without the concerns of overloading. For example, a generic function which has only one method that restricts only the number of arguments is equivalent to a deffunction.
In most cases, generic function methods are not called directly
(the function call-specific-method
described in section 12.15.8 can be used to do so, however). CLIPS
recognizes that a function call is generic and uses the generic
functionís arguments to find and execute the appropriate
method. This process is termed the generic dispatch.
8.1 NOTE ON THE USE OF THE TERM METHOD
8.2 PERFORMANCE PENALTY OF GENERIC FUNCTIONS
8.3 ORDER DEPENDENCE OF GENERIC FUNCTION DEFINITIONS
8.4 DEFINING A NEW GENERIC FUNCTION
8.5 GENERIC DISPATCH