Generic Functions

A generic or polymorphic function is one that performs a given operation for a variety of argument data types.

Example: + in Lisp:

(defun + (x y)
  (if (and (integerp x) (integerp y))
      (iplus x y)
      (if (and (floatp x) (floatp y))
          (fplus x y)
          ...) ) )
The + function in Lisp will also perform type coercion as needed. The CLOS implementation of object-oriented programming in Lisp combines the ideas of messages and generic functions. In effect, the programmer is allowed to overload functions -- even system functions such as + -- to specialize them for user data types.

Contents    Page-10    Prev    Next    Page+10    Index