Go to the first, previous, next, last section, table of contents.

Generic Functions

CommonLisp introduced the very nice concept of generic functions, which look (and in fact really are) just like normal functions to the caller, but which internally dispatch to the appropriate method based on the parameter values.

This allows message-passing to be used anywhere a function is permitted, and to take advantage of all system facilities constructed to support use of functions, which is much more elegant than having a special distinguished syntax used for sending messages.

Muq implements message-passing functionality by having folks do

:: + ; --> obj/:/plus

in order to establish a method, and having the system automatically create a corresponding generic function plus if one does not already exist: The generic function has the same arity as the method, and future plus methods that can "see" this generic (due to being in a package in which the generic is accessable) are required to have the same arity.

Internally, these generic functions would look like something like

: generic { ... $ -> ... ! } -> recipient
    recipient findMethod -> method
    method call

where findMethod is a function which implements inheritance of methods by searching up the parent chain (or tree) of the first argument to the function.

Go to the first, previous, next, last section, table of contents.