next up previous

8.4 DEFINING A NEW GENERIC FUNCTION

A generic function is comprised of a header (similar to a forward declaration) and zero or more methods. A generic function header can either be explicitly declared by the user or implicitly declared by the definition of at least one method. A method is comprised of six elements: 1) a name (which identifies to which generic function the method belongs), 2) an optional index, 3) an optional comment , 4) a set of parameter restrictions, 5) an optional wildcard parameter restriction to handle a variable number of arguments and 6) a sequence of actions, or expressions, which will be executed in order when the method is called. The parameter restrictions are used by the generic dispatch to determine a method's applicability to a set of arguments when the generic function is actually called. The defgeneric construct is used to specify the generic function header, and the defmethod construct is used for each of the generic function's methods.

Syntax

(defgeneric <name> [<comment>])
(defmethod <name> [<index>] [<comment>]
    (<parameter-restriction>* [<wildcard-parameter-restriction>])
    <action>*)
<parameter-restriction>   ::=
                <single-field-variable> |
                (<single-field-variable> <type>* [<query>])
<wildcard-parameter-restriction>      ::=
                <multifield-variable> |
                (<multifield-variable> <type>* [<query>])
<type>        ::= <class-name>
<query>   ::= <global-variable> |
                <function-call>

A generic function must be declared, either by a header or a method, prior to being called from another generic function method, deffunction, object message-handler, rule, or the top level. The only exception is a self recursive generic function.

8.4.1 Generic Function Headers

8.4.2 Method Indices

8.4.3 Method Parameter Restrictions

8.4.4 Method Wildcard Parameter



next up previous