2013-12-30 14:32:36 +01:00
|
|
|
========
|
|
|
|
defmulti
|
|
|
|
========
|
|
|
|
|
2014-04-10 20:21:32 +02:00
|
|
|
.. versionadded:: 0.10.0
|
2013-12-30 14:32:36 +01:00
|
|
|
|
2014-12-07 07:05:52 +01:00
|
|
|
``defmulti`` lets you arity-overload a function by the given number of
|
|
|
|
args and/or kwargs. Inspired by Clojure's take on ``defn``.
|
2013-12-30 14:32:36 +01:00
|
|
|
|
|
|
|
.. code-block:: clj
|
|
|
|
|
|
|
|
=> (require hy.contrib.multi)
|
|
|
|
=> (defmulti fun
|
2014-09-08 16:57:52 +02:00
|
|
|
... ([a] "a")
|
2013-12-30 14:32:36 +01:00
|
|
|
... ([a b] "a b")
|
|
|
|
... ([a b c] "a b c"))
|
|
|
|
=> (fun 1)
|
2014-09-08 16:57:52 +02:00
|
|
|
"a"
|
|
|
|
=> (fun 1 2)
|
|
|
|
"a b"
|
|
|
|
=> (fun 1 2 3)
|
|
|
|
"a b c"
|
2013-12-30 14:32:36 +01:00
|
|
|
|