Generic function

from Wikipedia, the free encyclopedia

Generic functions (not to be confused with functions in generic programming ) are within object-oriented programming a concept of certain programming languages such as Common Lisp that implement multi- methods. Since multi- methods can not be assigned to a class due to their nature , they are assigned to a generic function instead. The totality of the methods assigned to a generic function in this way then forms its functional scope.

Generic functions in Common Lisp

definition

Generic functions are defgenericdefined with the macro . The formal parameter list only consists of the parameter types, since no parameter names are required. Generic functions do not have their own function body.

(defgeneric meine-funktion (typ1 typ2 typ3))

use

The generic functions only form the entry point into a hierarchy of methods. You can omit the definition, as it occurs automatically as soon as a first method of the same name is defined. If, however, optional, keyword or rest parameters are provided, the exact specification of the parameter list can only take place via an explicit definition of the generic functions.

See also

Individual evidence

  1. Generic Function. In: Wiki Wiki Web. Portland Pattern Repository , Ward Cunningham , July 15, 2003, accessed November 3, 2013 .
  2. Kent Pitman: 7.6.1 Introduction to Generic Functions. In: Common Lisp HyperSpec. LispWorks Ltd., accessed November 3, 2013 .