Skip to content

tgk/kaleidoscope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kaleidoscope

Odili Donald Odita: Kaleidoscope "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.

Usage

Download the plugin (Clojure and ClojureScript compatible) from Clojars.

Clojars Project

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.

License

Copyright © 2014 Thomas G. Kristensen

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

Predicate dispatch for Clojure

Resources

License

Stars

Watchers

Forks

Packages

No packages published