This repository has been archived by the owner on Jan 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
detritus.clj
93 lines (77 loc) · 1.76 KB
/
detritus.clj
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
(ns detritus
(:refer-clojure :exclude [namespace name]))
(defn zip
"Zips the argument collections together, returning striped sequences
of the nth element from each sequence.
```
user> (zip [1 2 3]
[4 5 6])
([1 4]
[2 5]
[3 6])
```"
[& colls]
(map vector colls))
(defprotocol Named
(name [obj])
(namespace [obj]))
(extend-protocol Named
nil
(name [_] nil)
(namespace [_] nil)
clojure.lang.Named
(name [^clojure.lang.Named obj]
(.getName obj))
(namespace [^clojure.lang.Named obj]
(name (.getNamespace obj)))
clojure.lang.Namespace
(name [^clojure.lang.Namespace ns]
(name (.name ns)))
(namespace [^clojure.lang.Namespace ns]
nil)
clojure.lang.Var
(name [^clojure.lang.Var v]
(name (.sym v)))
(namespace [^clojure.lang.Var v]
(name (.ns v)))
java.lang.String
(name [^String str]
str)
(namespace [_] nil)
java.lang.Class
(name [^Class c]
(.getSimpleName c))
(namespace [^Class c]
(.getName (.getPackage c))))
(defn eprintf
"`#'printf` but to `*err*`."
[& args]
(binding [*out* *err*]
(apply printf args)))
(defn eprint
"`#'print` but to `*err*`."
[& args]
(binding [*out* *err*]
(apply print args)))
(defn eprintln
"`#'println` but to `*err*`."
[& args]
(binding [*out* *err*]
(apply println args)))
(defn epr
"`#'pr` but to `*err*`."
[& args]
(binding [*out* *err*]
(apply pr args)))
(defn eprn
"`#'prn` but to `*err*`."
[& args]
(binding [*out* *err*]
(apply prn args)))
(defmacro none [& forms]
`(and ~@(map #(list `not %) forms)))
(defmacro xor [& forms]
`(or ~@(for [[f forms] (map vector forms (repeat forms))]
(cons `and
(for [f* forms]
(if (= f f*) f (list `not f*)))))))