Name

defmulti

Usage

special-form

Syntax

(defmulti name (arg*) [doc-string])

Description

Defines a multi-method (same as generic function in CommonLisp).

user > (defmulti m (a b) "The m multimethod.")
it: #<Kiezel.MultiMethod>
user > (defmethod m ((a (eql 'red)) (b string))
           (print-line "red string: " b))
it: #<Lambda Name="m">
user > (defmethod m ((a (eql 'blue)) (b string))
           (print-line "blue string: " b))
it: #<Lambda Name="m">
user > (defmethod m ((a (eql 'red)) (b number))
           (print-line "red number: " b))
it: #<Lambda Name="m">
user > (defmethod m ((a (eql 'blue)) (b number))
           (print-line "blue number: " b)
           (call-next-method))
it: #<Lambda Name="m">
user > (defmethod m (a (b number))
           (print-line "a: " a  " number: " b)
           (call-next-method))
it: #<Lambda Name="m">
user > (defmethod m (a b)
           (print-line "a: " a  " b: " b))
it: #<Lambda Name="m">
user > (m 'red "cherry")
red string: cherry
it: null
user > (m 'blue "berry")
blue string: berry
it: null
user > (m 'red 123)
red number: 123
it: null
user > (m 'blue 456)
blue number: 456
a: blue number: 456
a: blue b: 456
it: null

See also

call-next-method defmethod