-
Notifications
You must be signed in to change notification settings - Fork 7
/
write.clj
66 lines (37 loc) · 1.25 KB
/
write.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
(ns convex.write
"Writing CVX cells as UTF-8 text.
Also see [[convex.read]] for the opposite idea."
{:author "Adam Helinski"}
(:import (convex.core.data ACell
AString
Strings)
(java.io Writer)))
(set! *warn-on-reflection*
true)
;;;;;;;;;;
(defn stream
"Writes the given `cell` to the given `java.io.Writer` (parent class of text streams).
By default, standard `str` is used for stringifying `cell`. See [[string]] for implications."
(^Writer [writer cell]
(stream writer
str
cell))
(^Writer [^Writer writer stringify ^ACell cell]
(.write writer
(if (nil? cell)
"nil"
^String (stringify cell)))
writer))
(defn string
"Prints the given `cell` as a string cell which can be read back with the [[convex.read]] namespace.
A default limit of 10000 bytes is applied relative to the output, beyond which \"<<Print limit exceeded>>\"
is appended. Pass `Long/MAX_VALUE` for the maximum limit."
(^AString [cell]
(string nil
cell))
(^AString [limit ^ACell cell]
(if (nil? cell)
(Strings/create "nil")
(.print cell
(or limit
10000)))))