diff options
Diffstat (limited to 'src/clojure/contrib/generic.clj')
-rw-r--r-- | src/clojure/contrib/generic.clj | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/clojure/contrib/generic.clj b/src/clojure/contrib/generic.clj new file mode 100644 index 00000000..d16e5ed0 --- /dev/null +++ b/src/clojure/contrib/generic.clj @@ -0,0 +1,36 @@ +;; Support code for generic interfaces + +(ns clojure.contrib.generic + "Generic interface support code + + NOTE: This library is VERY experimental. It WILL change significantly + with future release." + (:use [clojure.contrib.types :only (defadt)])) + +; +; A dispatch function that separates nulary, unary, binary, and +; higher arity calls and also selects on type for unary and binary +; calls. +; +(defn nary-dispatch + ([] ::nulary) + ([x] (type x)) + ([x y] + [(type x) (type y)]) + ([x y & more] ::nary)) + +; +; We can't use [::binary :default], so we need to define a root type +; of the type hierarcy. The derivation for Object covers all classes, +; but all non-class types will need an explicit derive clause. +; Ultimately, a macro might take care of this. +; +(def root-type ::any) +(derive Object root-type) + +; +; Symbols referring to ::nulary and ::n-ary +; +(def nulary-type ::nulary) +(def nary-type ::nary) + |