Dispatch

The term and topic of a programming language's method of choosing a definition to use to evaluate some expression. This notion generalizes over several more commonly-known methods that are often not distinguished from evaluation itself. In this sense, dispatch is complementary to rewrite.

A function definition is a fairly common part of many programming languages. However, the rules for how definitions are composed into a whole vary widely. The following spectrum is arrayed in increasing range of expressiveness:

  1. Lexically-scoped procedural languages in general will require exactly one definition per name of a function, possibly allowing for lexically-scoped overriding of the definition.
  2. Object-oriented programming languages have a variety of arranged schemes for polymorphic dispatch, depending on the object model:
    • Single-dispatch versus multiple-dispatch: whether the first argument or all the arguments are consulted for dispatch.
    • Single inheritance versus multiple inheritance or mixin-based overrides.
    • Dispatch on classes versus instances.
    • Predicate dispatch (only really deployed in Cecil).
    • Various forms of combination options for functions, whether termed inner calls, super calls, resends, before/after-calls, or around calls.
  3. Functional programming languages use pattern-matching to identify the applicable evaluation result. The advantage is that the expression value defined recursively is fully-available for inspection. Such languages can usually dispatch on types, structure, and value of their arguments.
  4. Logical programming languages generally specify a set of rules in an arbitrary sense which apply, and often define a strategy for traversing these rules which hopefully results in a terminating or at least manageable program. This process is often known as unification as distinguished from pattern-matchers.

Each of these can generally express the previous one without emulation, but also requires a more sophisticated algorithm to manage efficiently.

Of final note is that the specification of the traversal order of the functions is also included within this concept, through a meta-level protocol concerning the function definitions or the context within which the function definitions are entered.


This page is linked from: C++   MultiJava   Needle