Skip to content

clojure.core/defmulti

View this page on ClojureDocs

Type: macro Added: Clojure 1.0 Examples: 16 Runnable: 7
([name docstring? attr-map? dispatch-fn & options])

Creates a new multimethod with the associated dispatch function. The docstring and attr-map are optional.

Options are key-value pairs and may be one of:

:default

The default dispatch value, defaults to :default

:hierarchy

The value used for hierarchical dispatch (e.g. ::square is-a ::shape)

Hierarchies are type-like relationships that do not depend upon type inheritance. By default Clojure's multimethods dispatch off of a global hierarchy map. However, a hierarchy relationship can be created with the derive function used to augment the root ancestor created with make-hierarchy.

Multimethods expect the value of the hierarchy option to be supplied as a reference type e.g. a var (i.e. via the Var-quote dispatch macro #' or the var special form).

Examples

by Victor on . May have evaluation errors.
by Victor on . May have evaluation errors.
by OnesimusUnbound on
by phreed on . May have evaluation errors.
by kgann on
by hura on . May have evaluation errors.
by metasoarous on . May have evaluation errors.
by peter on
by rauhs on . May have evaluation errors.
by timgilbert on
by ibercode on
by ibercode on
by the-frey on
by Gavlooth on . May have evaluation errors.
by jimka2001 on . May have evaluation errors.
by kroncatti on . May have evaluation errors.

Note by Victor

See also

http://clojure.org/runtime_polymorphism

http://clojure.org/multimethods

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.