Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

CLOJURE_STDLIB_VERSION := clojure-1.12.1
STDLIB_ORIGINALS_DIR := scripts/rewrite-core/originals
STDLIB_ORIGINALS := $(shell find $(STDLIB_ORIGINALS_DIR) -name '*.clj')
STDLIB := $(STDLIB_ORIGINALS:scripts/rewrite-core/originals/%=%)
Expand Down Expand Up @@ -67,3 +68,7 @@ format:
echo "Files were formatted. Please commit the changes."; \
exit 1; \
fi

.PHONY: update-clojure-sources
update-clojure-sources:
@scripts/rewrite-core/update-clojure-sources.sh $(CLOJURE_STDLIB_VERSION)
113 changes: 92 additions & 21 deletions pkg/stdlib/glojure/core.glj
Original file line number Diff line number Diff line change
Expand Up @@ -2917,7 +2917,11 @@
(rf result input))))))))
([n coll]
(if (instance? github.com$glojurelang$glojure$pkg$lang.IDrop coll)
(or (.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll n) ())
(or
(if (pos? n)
(.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll (if (int? n) n (Math/ceil n)))
(seq coll))
())
(let [step (fn [n coll]
(let [s (seq coll)]
(if (and (pos? n) s)
Expand Down Expand Up @@ -3005,7 +3009,8 @@
[n x] (take n (repeat x)))

(defn iterate
"Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects"
"Returns a lazy (infinite!) sequence of x, (f x), (f (f x)) etc.
f must be free of side-effects"
{:added "1.0"
:static true}
[f x] (glojure.lang.Iterate/create f x) )
Expand All @@ -3020,15 +3025,15 @@
([]
(iterate inc' 0))
([end]
(if (instance? go/int64 end)
(if (int? end)
(github.com$glojurelang$glojure$pkg$lang.NewLongRange 0 end 1)
(github.com$glojurelang$glojure$pkg$lang.NewRange 0 end 1)))
([start end]
(if (and (instance? go/int64 start) (instance? go/int64 end))
(if (and (int? start) (int? end))
(github.com$glojurelang$glojure$pkg$lang.NewLongRange start end 1)
(github.com$glojurelang$glojure$pkg$lang.NewRange start end 1)))
([start end step]
(if (and (instance? go/int64 start) (instance? go/int64 end) (instance? go/int64 step))
(if (and (int? start) (int? end) (int? step))
(github.com$glojurelang$glojure$pkg$lang.NewLongRange start end step)
(github.com$glojurelang$glojure$pkg$lang.NewRange start end step))))

Expand Down Expand Up @@ -3145,7 +3150,9 @@
:static true}
[coll n]
(if (instance? github.com$glojurelang$glojure$pkg$lang.IDrop coll)
(.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll n)
(if (pos? n)
(.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll (if (int? n) n (Math/ceil n)))
(seq coll))
(loop [n n xs (seq coll)]
(if (and xs (pos? n))
(recur (dec n) (next xs))
Expand All @@ -3156,12 +3163,16 @@
{:added "1.3"
:static true}
[coll n]
(if (instance? github.com$glojurelang$glojure$pkg$lang.IDrop coll)
(or (.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll n) ())
(loop [n n xs coll]
(if-let [xs (and (pos? n) (seq xs))]
(recur (dec n) (rest xs))
xs))))
(if (pos? n)
(or
(if (instance? github.com$glojurelang$glojure$pkg$lang.IDrop coll)
(.drop ^github.com$glojurelang$glojure$pkg$lang.IDrop coll (if (int? n) n (Math/ceil n)))
(loop [n n xs coll]
(if-let [xs (and (pos? n) (seq xs))]
(recur (dec n) (rest xs))
(seq xs))))
())
coll))

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

;;;;;;;;;;;;;;;;;;;;; editable collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn transient
"Returns a new, transient version of the collection, in constant time."
"Returns a new, transient version of the collection, in constant time.

Transients support a parallel set of 'changing' operations, with similar names
followed by ! - assoc!, conj! etc. These do the same things as their persistent
counterparts except the return values are themselves transient.

Note in particular that transients are not designed to be bashed in-place. You
must capture and use the return value in the next call. In this way, they support
the same code structure as the functional persistent code they replace."
{:added "1.1"
:static true}
[^github.com$glojurelang$glojure$pkg$lang.IEditableCollection coll]
Expand Down Expand Up @@ -3827,7 +3846,7 @@
(try
(with-open ~(subvec bindings 2) ~@body)
(finally
(. ~(bindings 0) close))))
(. ~(bindings 0) ~'close))))
:else (throw (github.com$glojurelang$glojure$pkg$lang.NewIllegalArgumentError
"with-open only allows Symbols in bindings"))))

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

(defmacro assert
"Evaluates expr and throws an exception if it does not evaluate to
logical true."
"Evaluates expression x and throws an AssertionError with optional
message if x does not evaluate to logical true.

Assertion checks are omitted from compiled code if '*assert*' is
false."
{:added "1.0"}
([x]
(when *assert*
Expand Down Expand Up @@ -6306,6 +6328,11 @@ fails, attempts to require sym's namespace and retries."
:added "1.0"}
*e)

(def ^:dynamic
^{:doc "Bound to true in a repl thread"
:added "1.12"}
*repl* false)

(defn trampoline
"trampoline can be used to convert algorithms requiring mutual
recursion without stack consumption. Calls f with supplied args, if
Expand Down Expand Up @@ -6540,6 +6567,11 @@ fails, attempts to require sym's namespace and retries."
"
{:added "1.0"})

(add-doc-and-meta *assert*
"When set to logical false, 'assert' will omit assertion checks in
compiled code. Defaults to true."
{:added "1.0"})

(defn future?
"Returns true if x is a future"
{:added "1.1"
Expand Down Expand Up @@ -6783,8 +6815,6 @@ fails, attempts to require sym's namespace and retries."
`(let [~ge ~e] (case* ~ge ~shift ~mask ~default ~imap ~switch-type :hash-identity ~skip-check))))))))


;; redefine reduce with internal-reduce

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; helper files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(alter-meta! (find-ns 'glojure.core) assoc :doc "Fundamental library of the Clojure language")
(do)
Expand All @@ -6794,6 +6824,45 @@ fails, attempts to require sym's namespace and retries."
(load "protocols")
(do)

(defn stream-reduce!
"Works like reduce but takes a java.util.stream.BaseStream as its source.
Honors 'reduced', is a terminal operation on the stream"
{:added "1.12"}
([f ^java.util.stream.BaseStream s]
(glojure.core.protocols/iterator-reduce! (.iterator s) f))
([f init ^java.util.stream.BaseStream s]
(glojure.core.protocols/iterator-reduce! (.iterator s) f init)))

(defn stream-seq!
"Takes a java.util.stream.BaseStream instance s and returns a seq of its
contents. This is a terminal operation on the stream."
{:added "1.12"}
[^java.util.stream.BaseStream stream]
(iterator-seq (.iterator stream)))

(defn stream-transduce!
"Works like transduce but takes a java.util.stream.BaseStream as its source.
This is a terminal operation on the stream."
{:added "1.12"}
([xform f ^java.util.stream.BaseStream stream] (stream-transduce! xform f (f) stream))
([xform f init ^java.util.stream.BaseStream stream]
(let [f (xform f)
ret (stream-reduce! f init stream)]
(f ret))))

(defn stream-into!
"Returns a new coll consisting of coll with all of the items of the
stream conjoined. This is a terminal operation on the stream."
{:added "1.12"}
([to ^java.util.stream.BaseStream stream]
(if (instance? github.com$glojurelang$glojure$pkg$lang.IEditableCollection to)
(with-meta (persistent! (stream-reduce! conj! (transient to) stream)) (meta to))
(stream-reduce! conj to stream)))
([to xform ^java.util.stream.BaseStream stream]
(if (instance? github.com$glojurelang$glojure$pkg$lang.IEditableCollection to)
(with-meta (persistent! (stream-transduce! xform conj! (transient to) stream)) (meta to))
(stream-transduce! xform conj to stream))))

(do)

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

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

(defn into
"Returns a new coll consisting of to-coll with all of the items of
from-coll conjoined. A transducer may be supplied."
"Returns a new coll consisting of to with all of the items of
from conjoined. A transducer may be supplied.
(into x) returns x. (into) returns []."
{:added "1.0"
:static true}
([] [])
Expand Down Expand Up @@ -7252,7 +7323,7 @@ fails, attempts to require sym's namespace and retries."
(let [p (into [] (take n) s)]
(if (= n (count p))
(cons p (partitionv n step pad (nthrest s step)))
(into [] (take n) (concat p pad))))))))
(list (into [] (take n) (concat p pad)))))))))

(defn partitionv-all
"Returns a lazy sequence of vector partitions, but may include
Expand Down
11 changes: 7 additions & 4 deletions pkg/stdlib/glojure/core_print.glj
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,13 @@
(defn ^github.com$glojurelang$glojure$pkg$lang.PrintWriter PrintWriter-on
"implements java.io.PrintWriter given flush-fn, which will be called
when .flush() is called, with a string built up since the last call to .flush().
if not nil, close-fn will be called with no arguments when .close is called"
if not nil, close-fn will be called with no arguments when .close is called.
autoflush? determines if the PrintWriter will autoflush, false by default."
{:added "1.10"}
[flush-fn close-fn]
(let [sb (StringBuilder.)]
([flush-fn close-fn]
(PrintWriter-on flush-fn close-fn false))
([flush-fn close-fn autoflush?]
(let [sb (StringBuilder.)]
(-> (proxy [Writer] []
(flush []
(when (pos? (.length sb))
Expand All @@ -541,4 +544,4 @@
(github.com$glojurelang$glojure$pkg$lang.AppendWriter sb ^go/string str-cbuf ^int off ^int len)
(github.com$glojurelang$glojure$pkg$lang.AppendWriter sb ^chars str-cbuf ^int off ^int len)))))
java.io.BufferedWriter.
java.io.PrintWriter.)))
(java.io.PrintWriter. ^boolean autoflush?)))))
5 changes: 3 additions & 2 deletions pkg/stdlib/glojure/uuid.glj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
(ns glojure.uuid)

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

(defmethod print-method java.util.UUID [uuid ^io.Writer w]
(github.com$glojurelang$glojure$pkg$lang.WriteWriter w (str "#uuid \"" (str uuid) "\"")))
Expand Down
4 changes: 2 additions & 2 deletions pkg/stdlib/glojure/walk.glj
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
{:added "1.1"}
[inner outer form]
(cond
(list? form) (outer (apply list (map inner form)))
(list? form) (outer (with-meta (apply list (map inner form)) (meta form)))
(instance? github.com$glojurelang$glojure$pkg$lang.IMapEntry form)
(outer (glojure.lang.MapEntry/create (inner (key form)) (inner (val form))))
(seq? form) (outer (doall (map inner form)))
(seq? form) (outer (with-meta (doall (map inner form)) (meta form)))
(instance? github.com$glojurelang$glojure$pkg$lang.IRecord form)
(outer (reduce (fn [r x] (conj r (inner x))) form form))
(coll? form) (outer (into (empty form) (map inner form)))
Expand Down
Loading