2917
2917
(rf result input))))))))
2918
2918
([n coll]
2919
2919
(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
+ ())
2921
2925
(let [step (fn [n coll]
2922
2926
(let [s (seq coll)]
2923
2927
(if (and (pos? n) s)
3005
3009
[n x] (take n (repeat x)))
3006
3010
3007
3011
(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"
3009
3014
{:added "1.0"
3010
3015
:static true}
3011
3016
[f x] (glojure.lang.Iterate/create f x) )
3020
3025
([]
3021
3026
(iterate inc' 0))
3022
3027
([end]
3023
- (if (instance? go/int64 end)
3028
+ (if (int? end)
3024
3029
(github.com$glojurelang$glojure$pkg$lang.NewLongRange 0 end 1)
3025
3030
(github.com$glojurelang$glojure$pkg$lang.NewRange 0 end 1)))
3026
3031
([start end]
3027
- (if (and (instance? go/int64 start) (instance? go/int64 end))
3032
+ (if (and (int? start) (int? end))
3028
3033
(github.com$glojurelang$glojure$pkg$lang.NewLongRange start end 1)
3029
3034
(github.com$glojurelang$glojure$pkg$lang.NewRange start end 1)))
3030
3035
([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))
3032
3037
(github.com$glojurelang$glojure$pkg$lang.NewLongRange start end step)
3033
3038
(github.com$glojurelang$glojure$pkg$lang.NewRange start end step))))
3034
3039
3145
3150
:static true}
3146
3151
[coll n]
3147
3152
(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))
3149
3156
(loop [n n xs (seq coll)]
3150
3157
(if (and xs (pos? n))
3151
3158
(recur (dec n) (next xs))
3156
3163
{:added "1.3"
3157
3164
:static true}
3158
3165
[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))
3165
3176
3166
3177
(defn partition
3167
3178
"Returns a lazy sequence of lists of n items each, at offsets step
3322
3333
3323
3334
;;;;;;;;;;;;;;;;;;;;; editable collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3324
3335
(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."
3326
3345
{:added "1.1"
3327
3346
:static true}
3328
3347
[^github.com$glojurelang$glojure$pkg$lang.IEditableCollection coll]
3827
3846
(try
3828
3847
(with-open ~(subvec bindings 2) ~@body)
3829
3848
(finally
3830
- (. ~(bindings 0) close))))
3849
+ (. ~(bindings 0) ~' close))))
3831
3850
:else (throw (github.com$glojurelang$glojure$pkg$lang.NewIllegalArgumentError
3832
3851
"with-open only allows Symbols in bindings"))))
3833
3852
4816
4835
(.getCause ^github.com$glojurelang$glojure$pkg$lang.Throwable ex)))
4817
4836
4818
4837
(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."
4821
4843
{:added "1.0"}
4822
4844
([x]
4823
4845
(when *assert*
@@ -6306,6 +6328,11 @@ fails, attempts to require sym's namespace and retries."
6306
6328
:added "1.0"}
6307
6329
*e)
6308
6330
6331
+ (def ^:dynamic
6332
+ ^{:doc "Bound to true in a repl thread"
6333
+ :added "1.12"}
6334
+ *repl* false)
6335
+
6309
6336
(defn trampoline
6310
6337
"trampoline can be used to convert algorithms requiring mutual
6311
6338
recursion without stack consumption. Calls f with supplied args, if
@@ -6540,6 +6567,11 @@ fails, attempts to require sym's namespace and retries."
6540
6567
"
6541
6568
{:added "1.0"})
6542
6569
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
+
6543
6575
(defn future?
6544
6576
"Returns true if x is a future"
6545
6577
{:added "1.1"
@@ -6783,8 +6815,6 @@ fails, attempts to require sym's namespace and retries."
6783
6815
`(let [~ge ~e] (case* ~ge ~shift ~mask ~default ~imap ~switch-type :hash-identity ~skip-check))))))))
6784
6816
6785
6817
6786
- ;; redefine reduce with internal-reduce
6787
-
6788
6818
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; helper files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6789
6819
(alter-meta! (find-ns 'glojure.core) assoc :doc "Fundamental library of the Clojure language")
6790
6820
(do)
@@ -6794,6 +6824,45 @@ fails, attempts to require sym's namespace and retries."
6794
6824
(load "protocols")
6795
6825
(do)
6796
6826
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
+
6797
6866
(do)
6798
6867
6799
6868
(do)
@@ -6830,6 +6899,7 @@ fails, attempts to require sym's namespace and retries."
6830
6899
:added "1.11"}
6831
6900
^java.util.UUID [] (java.util.UUID/randomUUID))
6832
6901
6902
+ ;; redefine reduce with internal-reduce
6833
6903
(defn reduce
6834
6904
"f should be a function of 2 arguments. If val is not supplied,
6835
6905
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."
6893
6963
(f ret))))
6894
6964
6895
6965
(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 []."
6898
6969
{:added "1.0"
6899
6970
:static true}
6900
6971
([] [])
@@ -7252,7 +7323,7 @@ fails, attempts to require sym's namespace and retries."
7252
7323
(let [p (into [] (take n) s)]
7253
7324
(if (= n (count p))
7254
7325
(cons p (partitionv n step pad (nthrest s step)))
7255
- (into [] (take n) (concat p pad))))))))
7326
+ (list ( into [] (take n) (concat p pad) ))))))))
7256
7327
7257
7328
(defn partitionv-all
7258
7329
"Returns a lazy sequence of vector partitions, but may include
0 commit comments