File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 2
2
" Provides a pretty document serializer and pprint fn for Clojure/EDN forms.
3
3
See fipp.clojure for pretty printing Clojure code."
4
4
(:require [clojure.string :as str]
5
- [fipp.ednize :refer [edn record->tagged]]
5
+ [fipp.ednize :refer [edn record->tagged IOverride ]]
6
6
[fipp.visit :refer [visit visit*]]
7
7
[fipp.engine :refer (pprint-document )]))
8
8
19
19
[:span sep " ..." ])]
20
20
[:group open [:align ys ellipsis] close]))
21
21
22
- (defrecord EdnPrinter [symbols print-meta print-length print-level]
22
+ (defn- cache-satisfies
23
+ ([prot]
24
+ (let [cache (volatile! {})]
25
+ (fn [x]
26
+ (cache-satisfies prot cache x))))
27
+ ([prot cache x]
28
+ (let [clazz (type x)
29
+ ret (get @cache clazz ::not-found )]
30
+ (if (identical? ::not-found ret)
31
+ (let [ret (satisfies? prot x)]
32
+ (vswap! cache assoc clazz ret)
33
+ ret)
34
+ ret))))
35
+
36
+ (defrecord EdnPrinter [symbols print-meta print-length print-level cache]
23
37
24
38
fipp.visit /IVisitor
25
39
40
+ (visit-ovrride? [_ x]
41
+ (cache-satisfies IOverride cache x))
26
42
27
43
(visit-unknown [this x]
28
44
(visit this (edn x)))
96
112
([x] (pretty x {}))
97
113
([x options]
98
114
(let [defaults {:symbols {}
115
+ :cache (volatile! {})
99
116
:print-length *print-length*
100
117
:print-level *print-level*
101
118
:print-meta *print-meta*}
Original file line number Diff line number Diff line change 27
27
(visit-var [this x])
28
28
(visit-pattern [this x])
29
29
(visit-record [this x])
30
+
31
+ (visit-ovrride? [this x])
30
32
)
31
33
32
34
(defn visit*
33
35
" Visits objects, ignoring metadata."
34
36
[visitor x]
35
37
(cond
36
38
(nil? x) (visit-nil visitor)
37
- (override? x) (visit-unknown visitor x)
39
+ (visit-ovrride? visitor x) (visit-unknown visitor x)
38
40
(util/boolean? x) (visit-boolean visitor x)
39
41
(string? x) (visit-string visitor x)
40
42
(util/char? x) (visit-character visitor x)
You can’t perform that action at this time.
0 commit comments