Skip to content

Commit 01d8a0a

Browse files
authored
Update source stdlib clj files to clojure 1.12.1 (#81)
Signed-off-by: James Hamlin <[email protected]>
1 parent a3eb1b6 commit 01d8a0a

File tree

10 files changed

+272
-59
lines changed

10 files changed

+272
-59
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
CLOJURE_STDLIB_VERSION := clojure-1.12.1
23
STDLIB_ORIGINALS_DIR := scripts/rewrite-core/originals
34
STDLIB_ORIGINALS := $(shell find $(STDLIB_ORIGINALS_DIR) -name '*.clj')
45
STDLIB := $(STDLIB_ORIGINALS:scripts/rewrite-core/originals/%=%)
@@ -67,3 +68,7 @@ format:
6768
echo "Files were formatted. Please commit the changes."; \
6869
exit 1; \
6970
fi
71+
72+
.PHONY: update-clojure-sources
73+
update-clojure-sources:
74+
@scripts/rewrite-core/update-clojure-sources.sh $(CLOJURE_STDLIB_VERSION)

pkg/stdlib/glojure/core.glj

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2917,7 +2917,11 @@
29172917
(rf result input))))))))
29182918
([n coll]
29192919
(if (instance? github.com$glojurelang$glojure$pkg$lang.IDrop coll)
2920-
(or (.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll n) ())
2920+
(or
2921+
(if (pos? n)
2922+
(.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll (if (int? n) n (Math/ceil n)))
2923+
(seq coll))
2924+
())
29212925
(let [step (fn [n coll]
29222926
(let [s (seq coll)]
29232927
(if (and (pos? n) s)
@@ -3005,7 +3009,8 @@
30053009
[n x] (take n (repeat x)))
30063010

30073011
(defn iterate
3008-
"Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects"
3012+
"Returns a lazy (infinite!) sequence of x, (f x), (f (f x)) etc.
3013+
f must be free of side-effects"
30093014
{:added "1.0"
30103015
:static true}
30113016
[f x] (glojure.lang.Iterate/create f x) )
@@ -3020,15 +3025,15 @@
30203025
([]
30213026
(iterate inc' 0))
30223027
([end]
3023-
(if (instance? go/int64 end)
3028+
(if (int? end)
30243029
(github.com$glojurelang$glojure$pkg$lang.NewLongRange 0 end 1)
30253030
(github.com$glojurelang$glojure$pkg$lang.NewRange 0 end 1)))
30263031
([start end]
3027-
(if (and (instance? go/int64 start) (instance? go/int64 end))
3032+
(if (and (int? start) (int? end))
30283033
(github.com$glojurelang$glojure$pkg$lang.NewLongRange start end 1)
30293034
(github.com$glojurelang$glojure$pkg$lang.NewRange start end 1)))
30303035
([start end step]
3031-
(if (and (instance? go/int64 start) (instance? go/int64 end) (instance? go/int64 step))
3036+
(if (and (int? start) (int? end) (int? step))
30323037
(github.com$glojurelang$glojure$pkg$lang.NewLongRange start end step)
30333038
(github.com$glojurelang$glojure$pkg$lang.NewRange start end step))))
30343039

@@ -3145,7 +3150,9 @@
31453150
:static true}
31463151
[coll n]
31473152
(if (instance? github.com$glojurelang$glojure$pkg$lang.IDrop coll)
3148-
(.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll n)
3153+
(if (pos? n)
3154+
(.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll (if (int? n) n (Math/ceil n)))
3155+
(seq coll))
31493156
(loop [n n xs (seq coll)]
31503157
(if (and xs (pos? n))
31513158
(recur (dec n) (next xs))
@@ -3156,12 +3163,16 @@
31563163
{:added "1.3"
31573164
:static true}
31583165
[coll n]
3159-
(if (instance? github.com$glojurelang$glojure$pkg$lang.IDrop coll)
3160-
(or (.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll n) ())
3161-
(loop [n n xs coll]
3162-
(if-let [xs (and (pos? n) (seq xs))]
3163-
(recur (dec n) (rest xs))
3164-
xs))))
3166+
(if (pos? n)
3167+
(or
3168+
(if (instance? github.com$glojurelang$glojure$pkg$lang.IDrop coll)
3169+
(.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll (if (int? n) n (Math/ceil n)))
3170+
(loop [n n xs coll]
3171+
(if-let [xs (and (pos? n) (seq xs))]
3172+
(recur (dec n) (rest xs))
3173+
(seq xs))))
3174+
())
3175+
coll))
31653176

31663177
(defn partition
31673178
"Returns a lazy sequence of lists of n items each, at offsets step
@@ -3322,7 +3333,15 @@
33223333

33233334
;;;;;;;;;;;;;;;;;;;;; editable collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33243335
(defn transient
3325-
"Returns a new, transient version of the collection, in constant time."
3336+
"Returns a new, transient version of the collection, in constant time.
3337+
3338+
Transients support a parallel set of 'changing' operations, with similar names
3339+
followed by ! - assoc!, conj! etc. These do the same things as their persistent
3340+
counterparts except the return values are themselves transient.
3341+
3342+
Note in particular that transients are not designed to be bashed in-place. You
3343+
must capture and use the return value in the next call. In this way, they support
3344+
the same code structure as the functional persistent code they replace."
33263345
{:added "1.1"
33273346
:static true}
33283347
[^github.com$glojurelang$glojure$pkg$lang.IEditableCollection coll]
@@ -3827,7 +3846,7 @@
38273846
(try
38283847
(with-open ~(subvec bindings 2) ~@body)
38293848
(finally
3830-
(. ~(bindings 0) close))))
3849+
(. ~(bindings 0) ~'close))))
38313850
:else (throw (github.com$glojurelang$glojure$pkg$lang.NewIllegalArgumentError
38323851
"with-open only allows Symbols in bindings"))))
38333852

@@ -4816,8 +4835,11 @@
48164835
(.getCause ^github.com$glojurelang$glojure$pkg$lang.Throwable ex)))
48174836

48184837
(defmacro assert
4819-
"Evaluates expr and throws an exception if it does not evaluate to
4820-
logical true."
4838+
"Evaluates expression x and throws an AssertionError with optional
4839+
message if x does not evaluate to logical true.
4840+
4841+
Assertion checks are omitted from compiled code if '*assert*' is
4842+
false."
48214843
{:added "1.0"}
48224844
([x]
48234845
(when *assert*
@@ -6306,6 +6328,11 @@ fails, attempts to require sym's namespace and retries."
63066328
:added "1.0"}
63076329
*e)
63086330

6331+
(def ^:dynamic
6332+
^{:doc "Bound to true in a repl thread"
6333+
:added "1.12"}
6334+
*repl* false)
6335+
63096336
(defn trampoline
63106337
"trampoline can be used to convert algorithms requiring mutual
63116338
recursion without stack consumption. Calls f with supplied args, if
@@ -6540,6 +6567,11 @@ fails, attempts to require sym's namespace and retries."
65406567
"
65416568
{:added "1.0"})
65426569

6570+
(add-doc-and-meta *assert*
6571+
"When set to logical false, 'assert' will omit assertion checks in
6572+
compiled code. Defaults to true."
6573+
{:added "1.0"})
6574+
65436575
(defn future?
65446576
"Returns true if x is a future"
65456577
{:added "1.1"
@@ -6783,8 +6815,6 @@ fails, attempts to require sym's namespace and retries."
67836815
`(let [~ge ~e] (case* ~ge ~shift ~mask ~default ~imap ~switch-type :hash-identity ~skip-check))))))))
67846816

67856817

6786-
;; redefine reduce with internal-reduce
6787-
67886818
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; helper files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
67896819
(alter-meta! (find-ns 'glojure.core) assoc :doc "Fundamental library of the Clojure language")
67906820
(do)
@@ -6794,6 +6824,45 @@ fails, attempts to require sym's namespace and retries."
67946824
(load "protocols")
67956825
(do)
67966826

6827+
(defn stream-reduce!
6828+
"Works like reduce but takes a java.util.stream.BaseStream as its source.
6829+
Honors 'reduced', is a terminal operation on the stream"
6830+
{:added "1.12"}
6831+
([f ^java.util.stream.BaseStream s]
6832+
(glojure.core.protocols/iterator-reduce! (.iterator s) f))
6833+
([f init ^java.util.stream.BaseStream s]
6834+
(glojure.core.protocols/iterator-reduce! (.iterator s) f init)))
6835+
6836+
(defn stream-seq!
6837+
"Takes a java.util.stream.BaseStream instance s and returns a seq of its
6838+
contents. This is a terminal operation on the stream."
6839+
{:added "1.12"}
6840+
[^java.util.stream.BaseStream stream]
6841+
(iterator-seq (.iterator stream)))
6842+
6843+
(defn stream-transduce!
6844+
"Works like transduce but takes a java.util.stream.BaseStream as its source.
6845+
This is a terminal operation on the stream."
6846+
{:added "1.12"}
6847+
([xform f ^java.util.stream.BaseStream stream] (stream-transduce! xform f (f) stream))
6848+
([xform f init ^java.util.stream.BaseStream stream]
6849+
(let [f (xform f)
6850+
ret (stream-reduce! f init stream)]
6851+
(f ret))))
6852+
6853+
(defn stream-into!
6854+
"Returns a new coll consisting of coll with all of the items of the
6855+
stream conjoined. This is a terminal operation on the stream."
6856+
{:added "1.12"}
6857+
([to ^java.util.stream.BaseStream stream]
6858+
(if (instance? github.com$glojurelang$glojure$pkg$lang.IEditableCollection to)
6859+
(with-meta (persistent! (stream-reduce! conj! (transient to) stream)) (meta to))
6860+
(stream-reduce! conj to stream)))
6861+
([to xform ^java.util.stream.BaseStream stream]
6862+
(if (instance? github.com$glojurelang$glojure$pkg$lang.IEditableCollection to)
6863+
(with-meta (persistent! (stream-transduce! xform conj! (transient to) stream)) (meta to))
6864+
(stream-transduce! xform conj to stream))))
6865+
67976866
(do)
67986867

67996868
(do)
@@ -6830,6 +6899,7 @@ fails, attempts to require sym's namespace and retries."
68306899
:added "1.11"}
68316900
^java.util.UUID [] (java.util.UUID/randomUUID))
68326901

6902+
;; redefine reduce with internal-reduce
68336903
(defn reduce
68346904
"f should be a function of 2 arguments. If val is not supplied,
68356905
returns the result of applying f to the first 2 items in coll, then
@@ -6893,8 +6963,9 @@ fails, attempts to require sym's namespace and retries."
68936963
(f ret))))
68946964

68956965
(defn into
6896-
"Returns a new coll consisting of to-coll with all of the items of
6897-
from-coll conjoined. A transducer may be supplied."
6966+
"Returns a new coll consisting of to with all of the items of
6967+
from conjoined. A transducer may be supplied.
6968+
(into x) returns x. (into) returns []."
68986969
{:added "1.0"
68996970
:static true}
69006971
([] [])
@@ -7252,7 +7323,7 @@ fails, attempts to require sym's namespace and retries."
72527323
(let [p (into [] (take n) s)]
72537324
(if (= n (count p))
72547325
(cons p (partitionv n step pad (nthrest s step)))
7255-
(into [] (take n) (concat p pad))))))))
7326+
(list (into [] (take n) (concat p pad)))))))))
72567327

72577328
(defn partitionv-all
72587329
"Returns a lazy sequence of vector partitions, but may include

pkg/stdlib/glojure/core_print.glj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,13 @@
522522
(defn ^github.com$glojurelang$glojure$pkg$lang.PrintWriter PrintWriter-on
523523
"implements java.io.PrintWriter given flush-fn, which will be called
524524
when .flush() is called, with a string built up since the last call to .flush().
525-
if not nil, close-fn will be called with no arguments when .close is called"
525+
if not nil, close-fn will be called with no arguments when .close is called.
526+
autoflush? determines if the PrintWriter will autoflush, false by default."
526527
{:added "1.10"}
527-
[flush-fn close-fn]
528-
(let [sb (StringBuilder.)]
528+
([flush-fn close-fn]
529+
(PrintWriter-on flush-fn close-fn false))
530+
([flush-fn close-fn autoflush?]
531+
(let [sb (StringBuilder.)]
529532
(-> (proxy [Writer] []
530533
(flush []
531534
(when (pos? (.length sb))
@@ -541,4 +544,4 @@
541544
(github.com$glojurelang$glojure$pkg$lang.AppendWriter sb ^go/string str-cbuf ^int off ^int len)
542545
(github.com$glojurelang$glojure$pkg$lang.AppendWriter sb ^chars str-cbuf ^int off ^int len)))))
543546
java.io.BufferedWriter.
544-
java.io.PrintWriter.)))
547+
(java.io.PrintWriter. ^boolean autoflush?)))))

pkg/stdlib/glojure/uuid.glj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
(ns glojure.uuid)
1010

1111
(defn- default-uuid-reader [form]
12-
{:pre [(string? form)]}
13-
(java.util.UUID/fromString form))
12+
(if (string? form)
13+
(java.util.UUID/fromString form)
14+
(throw (github.com$glojurelang$glojure$pkg$lang.NewIllegalArgumentError "#uuid data reader expected string"))))
1415

1516
(defmethod print-method java.util.UUID [uuid ^io.Writer w]
1617
(github.com$glojurelang$glojure$pkg$lang.WriteWriter w (str "#uuid \"" (str uuid) "\"")))

pkg/stdlib/glojure/walk.glj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@
3030
{:added "1.1"}
3131
[inner outer form]
3232
(cond
33-
(list? form) (outer (apply list (map inner form)))
33+
(list? form) (outer (with-meta (apply list (map inner form)) (meta form)))
3434
(instance? github.com$glojurelang$glojure$pkg$lang.IMapEntry form)
3535
(outer (glojure.lang.MapEntry/create (inner (key form)) (inner (val form))))
36-
(seq? form) (outer (doall (map inner form)))
36+
(seq? form) (outer (with-meta (doall (map inner form)) (meta form)))
3737
(instance? github.com$glojurelang$glojure$pkg$lang.IRecord form)
3838
(outer (reduce (fn [r x] (conj r (inner x))) form form))
3939
(coll? form) (outer (into (empty form) (map inner form)))

0 commit comments

Comments
 (0)