diff options
author | Konrad Hinsen <konrad.hinsen@laposte.net> | 2009-03-19 12:52:35 +0000 |
---|---|---|
committer | Konrad Hinsen <konrad.hinsen@laposte.net> | 2009-03-19 12:52:35 +0000 |
commit | 1cc9c2d456f26142c577fca7d233870d2f3586ea (patch) | |
tree | 2bbe9b6aeaa61ba6d326c5a094f750134cd9cabd /src/clojure/contrib/generic.clj | |
parent | 3ea2f7c795b79f0f9d59938ff16770c0d2627a37 (diff) |
generic: new module comparison plus general support code
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) + |