*** Welcome to piglix ***

Generic function


In computer programming, a generic function is a function defined for polymorphism.

In statically typed languages (such as C++ and Java), the term generic functions refers to a mechanism for compile-time polymorphism (static dispatch), specifically parametric polymorphism. These are functions defined with TypeParameters, intended to be resolved with compile time type information. The compiler uses these types to instantiate suitable versions, resolving any function overloading appropriately.

In some systems for object-oriented programming such as the Common Lisp Object System (CLOS) and Dylan, a generic function is an entity made up of all methods having the same name. Typically a generic function is an instance of a class that inherits both from function and standard-object. Thus generic functions are both functions (that can be called with and applied to arguments) and ordinary objects. The book explains the implementation and use of CLOS generic functions in detail.

One of the early object-oriented programming extensions to Lisp is Flavors. It used the usual message sending paradigm influenced by Smalltalk. The Flavors syntax to send a message is:

With New Flavors, it was decided the message should be a real function and the usual function calling syntax should be used:

message now is a generic function, an object and function in its own right. Individual implementations of the message are called methods.

The same idea was implemented in CommonLoops. New Flavors and CommonLoops were the main influence for the Common Lisp Object System.


...
Wikipedia

...