blob: d16e5ed006f259eba03e53e5ae233a58ce869d6b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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)
|