diff --git a/Makefile b/Makefile index 279747aa..6edc7b0b 100644 --- a/Makefile +++ b/Makefile @@ -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/%=%) @@ -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) diff --git a/pkg/stdlib/glojure/core.glj b/pkg/stdlib/glojure/core.glj index dbf53637..0f362c13 100644 --- a/pkg/stdlib/glojure/core.glj +++ b/pkg/stdlib/glojure/core.glj @@ -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) @@ -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) ) @@ -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)))) @@ -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)) @@ -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 @@ -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] @@ -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")))) @@ -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* @@ -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 @@ -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" @@ -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) @@ -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) @@ -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 @@ -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} ([] []) @@ -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 diff --git a/pkg/stdlib/glojure/core_print.glj b/pkg/stdlib/glojure/core_print.glj index cfef554f..fc677038 100644 --- a/pkg/stdlib/glojure/core_print.glj +++ b/pkg/stdlib/glojure/core_print.glj @@ -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)) @@ -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?))))) diff --git a/pkg/stdlib/glojure/uuid.glj b/pkg/stdlib/glojure/uuid.glj index ca29bfdb..f4d2d7fb 100644 --- a/pkg/stdlib/glojure/uuid.glj +++ b/pkg/stdlib/glojure/uuid.glj @@ -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) "\""))) diff --git a/pkg/stdlib/glojure/walk.glj b/pkg/stdlib/glojure/walk.glj index 91a9f68c..4886535e 100644 --- a/pkg/stdlib/glojure/walk.glj +++ b/pkg/stdlib/glojure/walk.glj @@ -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))) diff --git a/scripts/rewrite-core/originals/core.clj b/scripts/rewrite-core/originals/core.clj index 1e48fcc9..be8e61c9 100644 --- a/scripts/rewrite-core/originals/core.clj +++ b/scripts/rewrite-core/originals/core.clj @@ -2942,7 +2942,11 @@ (rf result input)))))))) ([n coll] (if (instance? clojure.lang.IDrop coll) - (or (.drop ^clojure.lang.IDrop coll n) ()) + (or + (if (pos? n) + (.drop ^clojure.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) @@ -3030,7 +3034,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] (clojure.lang.Iterate/create f x) ) @@ -3045,15 +3050,15 @@ ([] (iterate inc' 0)) ([end] - (if (instance? Long end) + (if (int? end) (clojure.lang.LongRange/create end) (clojure.lang.Range/create end))) ([start end] - (if (and (instance? Long start) (instance? Long end)) + (if (and (int? start) (int? end)) (clojure.lang.LongRange/create start end) (clojure.lang.Range/create start end))) ([start end step] - (if (and (instance? Long start) (instance? Long end) (instance? Long step)) + (if (and (int? start) (int? end) (int? step)) (clojure.lang.LongRange/create start end step) (clojure.lang.Range/create start end step)))) @@ -3170,7 +3175,9 @@ :static true} [coll n] (if (instance? clojure.lang.IDrop coll) - (.drop ^clojure.lang.IDrop coll n) + (if (pos? n) + (.drop ^clojure.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)) @@ -3181,12 +3188,16 @@ {:added "1.3" :static true} [coll n] - (if (instance? clojure.lang.IDrop coll) - (or (.drop ^clojure.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? clojure.lang.IDrop coll) + (.drop ^clojure.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 @@ -3347,7 +3358,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} [^clojure.lang.IEditableCollection coll] @@ -3852,7 +3871,7 @@ (try (with-open ~(subvec bindings 2) ~@body) (finally - (. ~(bindings 0) close)))) + (. ~(bindings 0) ~'close)))) :else (throw (IllegalArgumentException. "with-open only allows Symbols in bindings")))) @@ -4845,8 +4864,11 @@ (.getCause ^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* @@ -6340,6 +6362,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 @@ -6574,6 +6601,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" @@ -6817,8 +6849,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 'clojure.core) assoc :doc "Fundamental library of the Clojure language") (load "core_proxy") @@ -6828,6 +6858,45 @@ fails, attempts to require sym's namespace and retries." (load "core/protocols") (load "gvec") +(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] + (clojure.core.protocols/iterator-reduce! (.iterator s) f)) + ([f init ^java.util.stream.BaseStream s] + (clojure.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? clojure.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? clojure.lang.IEditableCollection to) + (with-meta (persistent! (stream-transduce! xform conj! (transient to) stream)) (meta to)) + (stream-transduce! xform conj to stream)))) + (defmacro ^:private when-class [class-name & body] `(try (Class/forName ^String ~class-name) @@ -6874,6 +6943,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 @@ -6957,8 +7027,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} ([] []) @@ -7375,7 +7446,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 diff --git a/scripts/rewrite-core/originals/core_print.clj b/scripts/rewrite-core/originals/core_print.clj index 18c5101c..7e59c9c8 100644 --- a/scripts/rewrite-core/originals/core_print.clj +++ b/scripts/rewrite-core/originals/core_print.clj @@ -380,7 +380,9 @@ Short/TYPE "Short/TYPE"}) (defmethod print-method Class [^Class c, ^Writer w] - (.write w (.getName c))) + (if (.isArray c) + (print-method (clojure.lang.Util/arrayTypeToSymbol c) w) + (.write w (.getName c)))) (defmethod print-dup Class [^Class c, ^Writer w] (cond @@ -559,10 +561,13 @@ (defn ^java.io.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)) @@ -578,4 +583,4 @@ (.append sb ^String str-cbuf ^int off ^int len) (.append sb ^chars str-cbuf ^int off ^int len))))) java.io.BufferedWriter. - java.io.PrintWriter.))) + (java.io.PrintWriter. ^boolean autoflush?))))) diff --git a/scripts/rewrite-core/originals/uuid.clj b/scripts/rewrite-core/originals/uuid.clj index dbaa9d14..4ffbdf60 100644 --- a/scripts/rewrite-core/originals/uuid.clj +++ b/scripts/rewrite-core/originals/uuid.clj @@ -9,8 +9,9 @@ (ns clojure.uuid) (defn- default-uuid-reader [form] - {:pre [(string? form)]} - (java.util.UUID/fromString form)) + (if (string? form) + (java.util.UUID/fromString form) + (throw (IllegalArgumentException. "#uuid data reader expected string")))) (defmethod print-method java.util.UUID [uuid ^java.io.Writer w] (.write w (str "#uuid \"" (str uuid) "\""))) diff --git a/scripts/rewrite-core/originals/walk.clj b/scripts/rewrite-core/originals/walk.clj index fe8fb631..0f027e7a 100644 --- a/scripts/rewrite-core/originals/walk.clj +++ b/scripts/rewrite-core/originals/walk.clj @@ -41,10 +41,10 @@ the sorting function."} {: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? clojure.lang.IMapEntry form) (outer (clojure.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? clojure.lang.IRecord form) (outer (reduce (fn [r x] (conj r (inner x))) form form)) (coll? form) (outer (into (empty form) (map inner form))) diff --git a/scripts/rewrite-core/update-clojure-sources.sh b/scripts/rewrite-core/update-clojure-sources.sh new file mode 100755 index 00000000..c52dbb9c --- /dev/null +++ b/scripts/rewrite-core/update-clojure-sources.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +# Script to update Clojure source files from a specific GitHub tag +# Usage: ./update-clojure-sources.sh +# Example: ./update-clojure-sources.sh clojure-1.12.1 + +set -euo pipefail + +# Check if tag argument is provided +if [ $# -eq 0 ]; then + echo "Error: Please provide a Clojure tag as an argument" + echo "Usage: $0 " + echo "Example: $0 clojure-1.12.1" + exit 1 +fi + +TAG=$1 +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ORIGINALS_DIR="${SCRIPT_DIR}/originals" +BASE_URL="https://raw.githubusercontent.com/clojure/clojure/${TAG}/src/clj/clojure" + +# List of files to download (based on current files in originals/) +FILES=( + "core.clj" + "core_print.clj" + "template.clj" + "test.clj" + "uuid.clj" + "walk.clj" +) + +echo "Updating Clojure source files from tag: ${TAG}" +echo "Destination: ${ORIGINALS_DIR}" +echo + +# Ensure originals directory exists +mkdir -p "${ORIGINALS_DIR}" + +# Download each file +for file in "${FILES[@]}"; do + url="${BASE_URL}/${file}" + dest="${ORIGINALS_DIR}/${file}" + + echo -n "Downloading ${file}... " + + if curl -fsSL "${url}" -o "${dest}"; then + echo "✓" + else + echo "✗" + echo "Error: Failed to download ${file} from ${url}" + exit 1 + fi +done + +echo +echo "Successfully updated ${#FILES[@]} files from Clojure ${TAG}" \ No newline at end of file