jan tolenaar / kiezellisp / index-of-everything

Name

defmulti

Usage

special-form

Syntax

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

Description

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

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

make-html > (m 'blue "berry")
blue string: berry

make-html > (m 'red 123)
red number: 123

make-html > (m 'blue 456)
blue number: 456
a: blue number: 456
a: blue b: 456

See also

call-next-method defmethod