"Kaleidoscope" by Odili Donald Odita
kaleidoscope is a library offering predicate dispatch operators to Clojure programmers.
kaleidoscope offers:
- Extensible operators, which is effectively a generalisation of multimethods.
- Recursion within the same operator matching predicate defined downstream.
- Run-time creation of generic operators.
- Unlike muiltimethods, kaleidoscope operators are not bound to namespaces.
The price is that predicate logic is stored as meta-data on the generic operator. For a further discussion of the tradeoffs selected in this implementation, please see this blog post.
Download the plugin (Clojure and ClojureScript compatible) from Clojars.
There are no macros, so the following example works out of the box in both Clojure and ClojureScript.
(require '[kaleidoscope :refer (generic-operator assign-operation)])
(let [plus (generic-operator +)]
(doto plus
(assign-operation concat vector? vector?))
[(plus 1 2)
(plus [1 2 3] [4 5])])
;; => [3 (1 2 3 4 5)]
For a more advanced example, please see example.clj
.
Copyright © 2014 Thomas G. Kristensen
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.