Skip to content

Instantly share code, notes, and snippets.

@shaunlebron
Created December 15, 2018 03:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaunlebron/bcaa2b6c5a2b5cc01a99b8a0d4deeed0 to your computer and use it in GitHub Desktop.
Save shaunlebron/bcaa2b6c5a2b5cc01a99b8a0d4deeed0 to your computer and use it in GitHub Desktop.
parindent on clojure core
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj
index 8e98e072..b3174e14 100644
--- a/src/clj/clojure/core.clj
+++ b/src/clj/clojure/core.clj
@@ -7,26 +7,26 @@
; You must not remove this notice, or any other, from this software.
(ns ^{:doc "The core Clojure language."
- :author "Rich Hickey"}
+ :author "Rich Hickey"}
clojure.core)
(def unquote)
(def unquote-splicing)
(def
- ^{:arglists '([& items])
- :doc "Creates a new list containing the items."
- :added "1.0"}
+ ^{:arglists '([& items])
+ :doc "Creates a new list containing the items."
+ :added "1.0"}
list (. clojure.lang.PersistentList creator))
(def
- ^{:arglists '([x seq])
+ ^{:arglists '([x seq])
:doc "Returns a new seq where x is the first element and seq is
the rest."
- :added "1.0"
- :static true}
+ :added "1.0"
+ :static true}
- cons (fn* ^:static cons [x seq] (. clojure.lang.RT (cons x seq))))
+ cons (fn* ^:static cons [x seq] (. clojure.lang.RT (cons x seq))))
;during bootstrap we don't have destructuring let, loop or fn, will redefine later
(def
@@ -35,210 +35,210 @@
let (fn* let [&form &env & decl] (cons 'let* decl)))
(def
- ^{:macro true
- :added "1.0"}
- loop (fn* loop [&form &env & decl] (cons 'loop* decl)))
+ ^{:macro true
+ :added "1.0"}
+ loop (fn* loop [&form &env & decl] (cons 'loop* decl)))
(def
- ^{:macro true
- :added "1.0"}
- fn (fn* fn [&form &env & decl]
- (.withMeta ^clojure.lang.IObj (cons 'fn* decl)
- (.meta ^clojure.lang.IMeta &form))))
+ ^{:macro true
+ :added "1.0"}
+ fn (fn* fn [&form &env & decl]
+ (.withMeta ^clojure.lang.IObj (cons 'fn* decl)
+ (.meta ^clojure.lang.IMeta &form))))
(def
- ^{:arglists '([coll])
- :doc "Returns the first item in the collection. Calls seq on its
+ ^{:arglists '([coll])
+ :doc "Returns the first item in the collection. Calls seq on its
argument. If coll is nil, returns nil."
- :added "1.0"
- :static true}
- first (fn ^:static first [coll] (. clojure.lang.RT (first coll))))
+ :added "1.0"
+ :static true}
+ first (fn ^:static first [coll] (. clojure.lang.RT (first coll))))
(def
- ^{:arglists '([coll])
- :tag clojure.lang.ISeq
- :doc "Returns a seq of the items after the first. Calls seq on its
+ ^{:arglists '([coll])
+ :tag clojure.lang.ISeq
+ :doc "Returns a seq of the items after the first. Calls seq on its
argument. If there are no more items, returns nil."
- :added "1.0"
- :static true}
- next (fn ^:static next [x] (. clojure.lang.RT (next x))))
+ :added "1.0"
+ :static true}
+ next (fn ^:static next [x] (. clojure.lang.RT (next x))))
(def
- ^{:arglists '([coll])
- :tag clojure.lang.ISeq
- :doc "Returns a possibly empty seq of the items after the first. Calls seq on its
+ ^{:arglists '([coll])
+ :tag clojure.lang.ISeq
+ :doc "Returns a possibly empty seq of the items after the first. Calls seq on its
argument."
- :added "1.0"
- :static true}
- rest (fn ^:static rest [x] (. clojure.lang.RT (more x))))
+ :added "1.0"
+ :static true}
+ rest (fn ^:static rest [x] (. clojure.lang.RT (more x))))
(def
- ^{:arglists '([coll x] [coll x & xs])
- :doc "conj[oin]. Returns a new collection with the xs
+ ^{:arglists '([coll x] [coll x & xs])
+ :doc "conj[oin]. Returns a new collection with the xs
'added'. (conj nil item) returns (item). The 'addition' may
happen at different 'places' depending on the concrete type."
- :added "1.0"
- :static true}
- conj (fn ^:static conj
- ([] [])
- ([coll] coll)
- ([coll x] (clojure.lang.RT/conj coll x))
- ([coll x & xs]
- (if xs
- (recur (clojure.lang.RT/conj coll x) (first xs) (next xs))
- (clojure.lang.RT/conj coll x)))))
+ :added "1.0"
+ :static true}
+ conj (fn ^:static conj
+ ([] [])
+ ([coll] coll)
+ ([coll x] (clojure.lang.RT/conj coll x))
+ ([coll x & xs]
+ (if xs
+ (recur (clojure.lang.RT/conj coll x) (first xs) (next xs))
+ (clojure.lang.RT/conj coll x)))))
(def
- ^{:doc "Same as (first (next x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- second (fn ^:static second [x] (first (next x))))
+ ^{:doc "Same as (first (next x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ second (fn ^:static second [x] (first (next x))))
(def
- ^{:doc "Same as (first (first x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- ffirst (fn ^:static ffirst [x] (first (first x))))
+ ^{:doc "Same as (first (first x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ ffirst (fn ^:static ffirst [x] (first (first x))))
(def
- ^{:doc "Same as (next (first x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- nfirst (fn ^:static nfirst [x] (next (first x))))
+ ^{:doc "Same as (next (first x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ nfirst (fn ^:static nfirst [x] (next (first x))))
(def
- ^{:doc "Same as (first (next x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- fnext (fn ^:static fnext [x] (first (next x))))
+ ^{:doc "Same as (first (next x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ fnext (fn ^:static fnext [x] (first (next x))))
(def
- ^{:doc "Same as (next (next x))"
- :arglists '([x])
- :added "1.0"
- :static true}
- nnext (fn ^:static nnext [x] (next (next x))))
+ ^{:doc "Same as (next (next x))"
+ :arglists '([x])
+ :added "1.0"
+ :static true}
+ nnext (fn ^:static nnext [x] (next (next x))))
(def
- ^{:arglists '(^clojure.lang.ISeq [coll])
- :doc "Returns a seq on the collection. If the collection is
+ ^{:arglists '(^clojure.lang.ISeq [coll])
+ :doc "Returns a seq on the collection. If the collection is
empty, returns nil. (seq nil) returns nil. seq also works on
Strings, native Java arrays (of reference types) and any objects
that implement Iterable. Note that seqs cache values, thus seq
should not be used on any Iterable whose iterator repeatedly
returns the same mutable object."
- :tag clojure.lang.ISeq
- :added "1.0"
- :static true}
- seq (fn ^:static seq ^clojure.lang.ISeq [coll] (. clojure.lang.RT (seq coll))))
+ :tag clojure.lang.ISeq
+ :added "1.0"
+ :static true}
+ seq (fn ^:static seq ^clojure.lang.ISeq [coll] (. clojure.lang.RT (seq coll))))
(def
- ^{:arglists '([^Class c x])
- :doc "Evaluates x and tests if it is an instance of the class
+ ^{:arglists '([^Class c x])
+ :doc "Evaluates x and tests if it is an instance of the class
c. Returns true or false"
- :added "1.0"}
- instance? (fn instance? [^Class c x] (. c (isInstance x))))
+ :added "1.0"}
+ instance? (fn instance? [^Class c x] (. c (isInstance x))))
(def
- ^{:arglists '([x])
- :doc "Return true if x implements ISeq"
- :added "1.0"
- :static true}
- seq? (fn ^:static seq? [x] (instance? clojure.lang.ISeq x)))
+ ^{:arglists '([x])
+ :doc "Return true if x implements ISeq"
+ :added "1.0"
+ :static true}
+ seq? (fn ^:static seq? [x] (instance? clojure.lang.ISeq x)))
(def
- ^{:arglists '([x])
- :doc "Return true if x is a Character"
- :added "1.0"
- :static true}
- char? (fn ^:static char? [x] (instance? Character x)))
+ ^{:arglists '([x])
+ :doc "Return true if x is a Character"
+ :added "1.0"
+ :static true}
+ char? (fn ^:static char? [x] (instance? Character x)))
(def
- ^{:arglists '([x])
- :doc "Return true if x is a String"
- :added "1.0"
- :static true}
- string? (fn ^:static string? [x] (instance? String x)))
+ ^{:arglists '([x])
+ :doc "Return true if x is a String"
+ :added "1.0"
+ :static true}
+ string? (fn ^:static string? [x] (instance? String x)))
(def
- ^{:arglists '([x])
- :doc "Return true if x implements IPersistentMap"
- :added "1.0"
- :static true}
- map? (fn ^:static map? [x] (instance? clojure.lang.IPersistentMap x)))
+ ^{:arglists '([x])
+ :doc "Return true if x implements IPersistentMap"
+ :added "1.0"
+ :static true}
+ map? (fn ^:static map? [x] (instance? clojure.lang.IPersistentMap x)))
(def
- ^{:arglists '([x])
- :doc "Return true if x implements IPersistentVector"
- :added "1.0"
- :static true}
- vector? (fn ^:static vector? [x] (instance? clojure.lang.IPersistentVector x)))
+ ^{:arglists '([x])
+ :doc "Return true if x implements IPersistentVector"
+ :added "1.0"
+ :static true}
+ vector? (fn ^:static vector? [x] (instance? clojure.lang.IPersistentVector x)))
(def
- ^{:arglists '([map key val] [map key val & kvs])
- :doc "assoc[iate]. When applied to a map, returns a new map of the
+ ^{:arglists '([map key val] [map key val & kvs])
+ :doc "assoc[iate]. When applied to a map, returns a new map of the
same (hashed/sorted) type, that contains the mapping of key(s) to
val(s). When applied to a vector, returns a new vector that
contains val at index. Note - index must be <= (count vector)."
- :added "1.0"
- :static true}
- assoc
- (fn ^:static assoc
- ([map key val] (clojure.lang.RT/assoc map key val))
- ([map key val & kvs]
- (let [ret (clojure.lang.RT/assoc map key val)]
- (if kvs
- (if (next kvs)
- (recur ret (first kvs) (second kvs) (nnext kvs))
- (throw (IllegalArgumentException.
- "assoc expects even number of arguments after map/vector, found odd number")))
- ret)))))
+ :added "1.0"
+ :static true}
+ assoc
+ (fn ^:static assoc
+ ([map key val] (clojure.lang.RT/assoc map key val))
+ ([map key val & kvs]
+ (let [ret (clojure.lang.RT/assoc map key val)]
+ (if kvs
+ (if (next kvs)
+ (recur ret (first kvs) (second kvs) (nnext kvs))
+ (throw (IllegalArgumentException.
+ "assoc expects even number of arguments after map/vector, found odd number")))
+ ret)))))
;;;;;;;;;;;;;;;;; metadata ;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def
- ^{:arglists '([obj])
- :doc "Returns the metadata of obj, returns nil if there is no metadata."
- :added "1.0"
- :static true}
- meta (fn ^:static meta [x]
- (if (instance? clojure.lang.IMeta x)
- (. ^clojure.lang.IMeta x (meta)))))
+ ^{:arglists '([obj])
+ :doc "Returns the metadata of obj, returns nil if there is no metadata."
+ :added "1.0"
+ :static true}
+ meta (fn ^:static meta [x]
+ (if (instance? clojure.lang.IMeta x)
+ (. ^clojure.lang.IMeta x (meta)))))
(def
- ^{:arglists '([^clojure.lang.IObj obj m])
- :doc "Returns an object of the same type and value as obj, with
+ ^{:arglists '([^clojure.lang.IObj obj m])
+ :doc "Returns an object of the same type and value as obj, with
map m as its metadata."
- :added "1.0"
- :static true}
- with-meta (fn ^:static with-meta [^clojure.lang.IObj x m]
- (. x (withMeta m))))
+ :added "1.0"
+ :static true}
+ with-meta (fn ^:static with-meta [^clojure.lang.IObj x m]
+ (. x (withMeta m))))
(def ^{:private true :dynamic true}
assert-valid-fdecl (fn [fdecl]))
(def
- ^{:private true}
- sigs
- (fn [fdecl]
- (assert-valid-fdecl fdecl)
- (let [asig
- (fn [fdecl]
- (let [arglist (first fdecl)
- ;elide implicit macro args
- arglist (if (clojure.lang.Util/equals '&form (first arglist))
- (clojure.lang.RT/subvec arglist 2 (clojure.lang.RT/count arglist))
- arglist)
- body (next fdecl)]
- (if (map? (first body))
- (if (next body)
- (with-meta arglist (conj (if (meta arglist) (meta arglist) {}) (first body)))
- arglist)
- arglist)))
- resolve-tag (fn [argvec]
+ ^{:private true}
+ sigs
+ (fn [fdecl]
+ (assert-valid-fdecl fdecl)
+ (let [asig
+ (fn [fdecl]
+ (let [arglist (first fdecl)
+ ;elide implicit macro args
+ arglist (if (clojure.lang.Util/equals '&form (first arglist))
+ (clojure.lang.RT/subvec arglist 2 (clojure.lang.RT/count arglist))
+ arglist)
+ body (next fdecl)]
+ (if (map? (first body))
+ (if (next body)
+ (with-meta arglist (conj (if (meta arglist) (meta arglist) {}) (first body)))
+ arglist)
+ arglist)))
+ resolve-tag (fn [argvec]
(let [m (meta argvec)
^clojure.lang.Symbol tag (:tag m)]
(if (instance? clojure.lang.Symbol tag)
@@ -251,87 +251,87 @@
argvec)
argvec)
argvec)))]
- (if (seq? (first fdecl))
- (loop [ret [] fdecls fdecl]
- (if fdecls
- (recur (conj ret (resolve-tag (asig (first fdecls)))) (next fdecls))
- (seq ret)))
- (list (resolve-tag (asig fdecl)))))))
+ (if (seq? (first fdecl))
+ (loop [ret [] fdecls fdecl]
+ (if fdecls
+ (recur (conj ret (resolve-tag (asig (first fdecls)))) (next fdecls))
+ (seq ret)))
+ (list (resolve-tag (asig fdecl)))))))
(def
- ^{:arglists '([coll])
- :doc "Return the last item in coll, in linear time"
- :added "1.0"
- :static true}
- last (fn ^:static last [s]
- (if (next s)
- (recur (next s))
- (first s))))
+ ^{:arglists '([coll])
+ :doc "Return the last item in coll, in linear time"
+ :added "1.0"
+ :static true}
+ last (fn ^:static last [s]
+ (if (next s)
+ (recur (next s))
+ (first s))))
(def
- ^{:arglists '([coll])
- :doc "Return a seq of all but the last item in coll, in linear time"
- :added "1.0"
- :static true}
- butlast (fn ^:static butlast [s]
- (loop [ret [] s s]
- (if (next s)
- (recur (conj ret (first s)) (next s))
- (seq ret)))))
+ ^{:arglists '([coll])
+ :doc "Return a seq of all but the last item in coll, in linear time"
+ :added "1.0"
+ :static true}
+ butlast (fn ^:static butlast [s]
+ (loop [ret [] s s]
+ (if (next s)
+ (recur (conj ret (first s)) (next s))
+ (seq ret)))))
(def
- ^{:doc "Same as (def name (fn [params* ] exprs*)) or (def
+ ^{:doc "Same as (def name (fn [params* ] exprs*)) or (def
name (fn ([params* ] exprs*)+)) with any doc-string or attrs added
to the var metadata. prepost-map defines a map with optional keys
:pre and :post that contain collections of pre or post conditions."
- :arglists '([name doc-string? attr-map? [params*] prepost-map? body]
+ :arglists '([name doc-string? attr-map? [params*] prepost-map? body]
[name doc-string? attr-map? ([params*] prepost-map? body)+ attr-map?])
- :added "1.0"}
- defn (fn defn [&form &env name & fdecl]
- ;; Note: Cannot delegate this check to def because of the call to (with-meta name ..)
- (if (instance? clojure.lang.Symbol name)
- nil
- (throw (IllegalArgumentException. "First argument to defn must be a symbol")))
- (let [m (if (string? (first fdecl))
- {:doc (first fdecl)}
- {})
- fdecl (if (string? (first fdecl))
- (next fdecl)
- fdecl)
- m (if (map? (first fdecl))
- (conj m (first fdecl))
- m)
- fdecl (if (map? (first fdecl))
- (next fdecl)
- fdecl)
- fdecl (if (vector? (first fdecl))
- (list fdecl)
- fdecl)
- m (if (map? (last fdecl))
- (conj m (last fdecl))
- m)
- fdecl (if (map? (last fdecl))
- (butlast fdecl)
- fdecl)
- m (conj {:arglists (list 'quote (sigs fdecl))} m)
- m (let [inline (:inline m)
- ifn (first inline)
- iname (second inline)]
- ;; same as: (if (and (= 'fn ifn) (not (symbol? iname))) ...)
- (if (if (clojure.lang.Util/equiv 'fn ifn)
- (if (instance? clojure.lang.Symbol iname) false true))
- ;; inserts the same fn name to the inline fn if it does not have one
- (assoc m :inline (cons ifn (cons (clojure.lang.Symbol/intern (.concat (.getName ^clojure.lang.Symbol name) "__inliner"))
- (next inline))))
- m))
- m (conj (if (meta name) (meta name) {}) m)]
- (list 'def (with-meta name m)
- ;;todo - restore propagation of fn name
- ;;must figure out how to convey primitive hints to self calls first
- ;;(cons `fn fdecl)
- (with-meta (cons `fn fdecl) {:rettag (:tag m)})))))
+ :added "1.0"}
+ defn (fn defn [&form &env name & fdecl]
+ ;; Note: Cannot delegate this check to def because of the call to (with-meta name ..)
+ (if (instance? clojure.lang.Symbol name)
+ nil
+ (throw (IllegalArgumentException. "First argument to defn must be a symbol")))
+ (let [m (if (string? (first fdecl))
+ {:doc (first fdecl)}
+ {})
+ fdecl (if (string? (first fdecl))
+ (next fdecl)
+ fdecl)
+ m (if (map? (first fdecl))
+ (conj m (first fdecl))
+ m)
+ fdecl (if (map? (first fdecl))
+ (next fdecl)
+ fdecl)
+ fdecl (if (vector? (first fdecl))
+ (list fdecl)
+ fdecl)
+ m (if (map? (last fdecl))
+ (conj m (last fdecl))
+ m)
+ fdecl (if (map? (last fdecl))
+ (butlast fdecl)
+ fdecl)
+ m (conj {:arglists (list 'quote (sigs fdecl))} m)
+ m (let [inline (:inline m)
+ ifn (first inline)
+ iname (second inline)]
+ ;; same as: (if (and (= 'fn ifn) (not (symbol? iname))) ...)
+ (if (if (clojure.lang.Util/equiv 'fn ifn)
+ (if (instance? clojure.lang.Symbol iname) false true))
+ ;; inserts the same fn name to the inline fn if it does not have one
+ (assoc m :inline (cons ifn (cons (clojure.lang.Symbol/intern (.concat (.getName ^clojure.lang.Symbol name) "__inliner"))
+ (next inline))))
+ m))
+ m (conj (if (meta name) (meta name) {}) m)]
+ (list 'def (with-meta name m)
+ ;;todo - restore propagation of fn name
+ ;;must figure out how to convey primitive hints to self calls first
+ ;;(cons `fn fdecl)
+ (with-meta (cons `fn fdecl) {:rettag (:tag m)})))))
(. (var defn) (setMacro))
@@ -359,10 +359,10 @@
([a b] [a b])
([a b c] [a b c])
([a b c d] [a b c d])
- ([a b c d e] [a b c d e])
- ([a b c d e f] [a b c d e f])
+ ([a b c d e] [a b c d e])
+ ([a b c d e f] [a b c d e f])
([a b c d e f & args]
- (. clojure.lang.LazilyPersistentVector (create (cons a (cons b (cons c (cons d (cons e (cons f args))))))))))
+ (. clojure.lang.LazilyPersistentVector (create (cons a (cons b (cons c (cons d (cons e (cons f args))))))))))
(defn vec
"Creates a new vector containing the contents of coll. Java arrays
@@ -443,13 +443,13 @@
(def
- ^{:doc "Like defn, but the resulting function name is declared as a
+ ^{:doc "Like defn, but the resulting function name is declared as a
macro and will be used as a macro by the compiler when it is
called."
- :arglists '([name doc-string? attr-map? [params*] body]
- [name doc-string? attr-map? ([params*] body)+ attr-map?])
- :added "1.0"}
- defmacro (fn [&form &env
+ :arglists '([name doc-string? attr-map? [params*] body]
+ [name doc-string? attr-map? ([params*] body)+ attr-map?])
+ :added "1.0"}
+ defmacro (fn [&form &env
name & args]
(let [prefix (loop [p (list name) args args]
(let [f (first args)]
@@ -468,8 +468,8 @@
(list fdecl)
fdecl)
add-implicit-args (fn [fd]
- (let [args (first fd)]
- (cons (vec (cons '&form (cons '&env args))) (next fd))))
+ (let [args (first fd)]
+ (cons (vec (cons '&form (cons '&env args))) (next fd))))
add-args (fn [acc ds]
(if (nil? ds)
acc
@@ -500,7 +500,7 @@
"Evaluates test. If logical false, evaluates body in an implicit do."
{:added "1.0"}
[test & body]
- (list 'if test nil (cons 'do body)))
+ (list 'if test nil (cons 'do body)))
(defn false?
"Returns true if x is the value false, false otherwise."
@@ -552,11 +552,11 @@
(^String [^Object x]
(if (nil? x) "" (. x (toString))))
(^String [x & ys]
- ((fn [^StringBuilder sb more]
- (if more
- (recur (. sb (append (str (first more)))) (next more))
- (str sb)))
- (new StringBuilder (str x)) ys)))
+ ((fn [^StringBuilder sb more]
+ (if more
+ (recur (. sb (append (str (first more)))) (next more))
+ (str sb)))
+ (new StringBuilder (str x)) ys)))
(defn symbol?
@@ -578,13 +578,13 @@
other tests or exprs. (cond) returns nil."
{:added "1.0"}
[& clauses]
- (when clauses
- (list 'if (first clauses)
- (if (next clauses)
- (second clauses)
- (throw (IllegalArgumentException.
- "cond requires an even number of forms")))
- (cons 'clojure.core/cond (next (next clauses))))))
+ (when clauses
+ (list 'if (first clauses)
+ (if (next clauses)
+ (second clauses)
+ (throw (IllegalArgumentException.
+ "cond requires an even number of forms")))
+ (cons 'clojure.core/cond (next (next clauses))))))
(defn symbol
"Returns a Symbol with the given namespace and name. Arity-1 works
@@ -593,12 +593,12 @@
:added "1.0"
:static true}
([name]
- (cond
- (symbol? name) name
- (instance? String name) (clojure.lang.Symbol/intern name)
- (instance? clojure.lang.Var name) (.toSymbol ^clojure.lang.Var name)
- (instance? clojure.lang.Keyword name) (.sym ^clojure.lang.Keyword name)
- :else (throw (IllegalArgumentException. "no conversion to symbol"))))
+ (cond
+ (symbol? name) name
+ (instance? String name) (clojure.lang.Symbol/intern name)
+ (instance? clojure.lang.Var name) (.toSymbol ^clojure.lang.Var name)
+ (instance? clojure.lang.Keyword name) (.sym ^clojure.lang.Keyword name)
+ :else (throw (IllegalArgumentException. "no conversion to symbol"))))
([ns name] (clojure.lang.Symbol/intern ns name)))
(defn gensym
@@ -641,9 +641,9 @@
:static true}
[arglist]
(cond
- (nil? arglist) nil
- (nil? (next arglist)) (seq (first arglist))
- :else (cons (first arglist) (spread (next arglist)))))
+ (nil? arglist) nil
+ (nil? (next arglist)) (seq (first arglist))
+ :else (cons (first arglist) (spread (next arglist)))))
(defn list*
"Creates a new seq containing the items prepended to the rest, the
@@ -655,29 +655,29 @@
([a b args] (cons a (cons b args)))
([a b c args] (cons a (cons b (cons c args))))
([a b c d & more]
- (cons a (cons b (cons c (cons d (spread more)))))))
+ (cons a (cons b (cons c (cons d (spread more)))))))
(defn apply
"Applies fn f to the argument list formed by prepending intervening arguments to args."
{:added "1.0"
:static true}
([^clojure.lang.IFn f args]
- (. f (applyTo (seq args))))
+ (. f (applyTo (seq args))))
([^clojure.lang.IFn f x args]
- (. f (applyTo (list* x args))))
+ (. f (applyTo (list* x args))))
([^clojure.lang.IFn f x y args]
- (. f (applyTo (list* x y args))))
+ (. f (applyTo (list* x y args))))
([^clojure.lang.IFn f x y z args]
- (. f (applyTo (list* x y z args))))
+ (. f (applyTo (list* x y z args))))
([^clojure.lang.IFn f a b c d & args]
- (. f (applyTo (cons a (cons b (cons c (cons d (spread args)))))))))
+ (. f (applyTo (cons a (cons b (cons c (cons d (spread args)))))))))
(defn vary-meta
- "Returns an object of the same type and value as obj, with
+ "Returns an object of the same type and value as obj, with
(apply f (meta obj) args) as its metadata."
- {:added "1.0"
+ {:added "1.0"
:static true}
- [obj f & args]
+ [obj f & args]
(with-meta obj (apply f (meta obj) args)))
(defmacro lazy-seq
@@ -722,25 +722,25 @@
([] (lazy-seq nil))
([x] (lazy-seq x))
([x y]
- (lazy-seq
- (let [s (seq x)]
- (if s
- (if (chunked-seq? s)
- (chunk-cons (chunk-first s) (concat (chunk-rest s) y))
- (cons (first s) (concat (rest s) y)))
- y))))
+ (lazy-seq
+ (let [s (seq x)]
+ (if s
+ (if (chunked-seq? s)
+ (chunk-cons (chunk-first s) (concat (chunk-rest s) y))
+ (cons (first s) (concat (rest s) y)))
+ y))))
([x y & zs]
- (let [cat (fn cat [xys zs]
- (lazy-seq
- (let [xys (seq xys)]
- (if xys
- (if (chunked-seq? xys)
- (chunk-cons (chunk-first xys)
- (cat (chunk-rest xys) zs))
- (cons (first xys) (cat (rest xys) zs)))
- (when zs
- (cat (first zs) (next zs)))))))]
- (cat (concat x y) zs))))
+ (let [cat (fn cat [xys zs]
+ (lazy-seq
+ (let [xys (seq xys)]
+ (if xys
+ (if (chunked-seq? xys)
+ (chunk-cons (chunk-first xys)
+ (cat (chunk-rest xys) zs))
+ (cons (first xys) (cat (rest xys) zs)))
+ (when zs
+ (cat (first zs) (next zs)))))))]
+ (cat (concat x y) zs))))
;;;;;;;;;;;;;;;;at this point all the support for syntax-quote exists;;;;;;;;;;;;;;;;;;;;;;
(defmacro delay
@@ -750,7 +750,7 @@
calls. See also - realized?"
{:added "1.0"}
[& body]
- (list 'new 'clojure.lang.Delay (list* `^{:once true} fn* [] body)))
+ (list 'new 'clojure.lang.Delay (list* `^{:once true} fn* [] body)))
(defn delay?
"returns true if x is a Delay created with delay"
@@ -800,21 +800,21 @@
;equals-based
#_(defn =
- "Equality. Returns true if x equals y, false if not. Same as Java
+ "Equality. Returns true if x equals y, false if not. Same as Java
x.equals(y) except it also works for nil. Boxed numbers must have
same type. Clojure's immutable data structures define equals() (and
thus =) as a value, not an identity, comparison."
- {:inline (fn [x y] `(. clojure.lang.Util equals ~x ~y))
- :inline-arities #{2}
- :added "1.0"}
- ([x] true)
- ([x y] (clojure.lang.Util/equals x y))
- ([x y & more]
- (if (= x y)
- (if (next more)
- (recur y (first more) (next more))
- (= y (first more)))
- false)))
+ {:inline (fn [x y] `(. clojure.lang.Util equals ~x ~y))
+ :inline-arities #{2}
+ :added "1.0"}
+ ([x] true)
+ ([x y] (clojure.lang.Util/equals x y))
+ ([x y & more]
+ (if (= x y)
+ (if (next more)
+ (recur y (first more) (next more))
+ (= y (first more)))
+ false)))
(defn not=
"Same as (not (= obj1 obj2))"
@@ -860,8 +860,8 @@
([] nil)
([x] x)
([x & next]
- `(let [or# ~x]
- (if or# or# (or ~@next)))))
+ `(let [or# ~x]
+ (if or# or# (or ~@next)))))
;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;;
(defn zero?
@@ -929,42 +929,42 @@
;; reduce is defined again later after InternalReduce loads
(defn ^:private ^:static
reduce1
- ([f coll]
- (let [s (seq coll)]
- (if s
- (reduce1 f (first s) (next s))
- (f))))
- ([f val coll]
- (let [s (seq coll)]
- (if s
- (if (chunked-seq? s)
- (recur f
- (.reduce (chunk-first s) f val)
- (chunk-next s))
- (recur f (f val (first s)) (next s)))
- val))))
+ ([f coll]
+ (let [s (seq coll)]
+ (if s
+ (reduce1 f (first s) (next s))
+ (f))))
+ ([f val coll]
+ (let [s (seq coll)]
+ (if s
+ (if (chunked-seq? s)
+ (recur f
+ (.reduce (chunk-first s) f val)
+ (chunk-next s))
+ (recur f (f val (first s)) (next s)))
+ val))))
(defn reverse
"Returns a seq of the items in coll in reverse order. Not lazy."
{:added "1.0"
:static true}
[coll]
- (reduce1 conj () coll))
+ (reduce1 conj () coll))
;;math stuff
(defn ^:private nary-inline
([op] (nary-inline op op))
([op unchecked-op]
- (fn
- ([x] (let [op (if *unchecked-math* unchecked-op op)]
- `(. clojure.lang.Numbers (~op ~x))))
- ([x y] (let [op (if *unchecked-math* unchecked-op op)]
- `(. clojure.lang.Numbers (~op ~x ~y))))
- ([x y & more]
- (let [op (if *unchecked-math* unchecked-op op)]
- (reduce1
- (fn [a b] `(. clojure.lang.Numbers (~op ~a ~b)))
- `(. clojure.lang.Numbers (~op ~x ~y)) more))))))
+ (fn
+ ([x] (let [op (if *unchecked-math* unchecked-op op)]
+ `(. clojure.lang.Numbers (~op ~x))))
+ ([x y] (let [op (if *unchecked-math* unchecked-op op)]
+ `(. clojure.lang.Numbers (~op ~x ~y))))
+ ([x y & more]
+ (let [op (if *unchecked-math* unchecked-op op)]
+ (reduce1
+ (fn [a b] `(. clojure.lang.Numbers (~op ~a ~b)))
+ `(. clojure.lang.Numbers (~op ~x ~y)) more))))))
(defn ^:private >1? [n] (clojure.lang.Numbers/gt n 1))
(defn ^:private >0? [n] (clojure.lang.Numbers/gt n 0))
@@ -991,7 +991,7 @@
([x] (cast Number x))
([x y] (. clojure.lang.Numbers (add x y)))
([x y & more]
- (reduce1 + (+ x y) more)))
+ (reduce1 + (+ x y) more)))
(defn *'
"Returns the product of nums. (*') returns 1. Supports arbitrary precision.
@@ -1015,7 +1015,7 @@
([x] (cast Number x))
([x y] (. clojure.lang.Numbers (multiply x y)))
([x y & more]
- (reduce1 * (* x y) more)))
+ (reduce1 * (* x y) more)))
(defn /
"If no denominators are supplied, returns 1/numerator,
@@ -1050,7 +1050,7 @@
([x] (. clojure.lang.Numbers (minus x)))
([x y] (. clojure.lang.Numbers (minus x y)))
([x y & more]
- (reduce1 - (- x y) more)))
+ (reduce1 - (- x y) more)))
(defn <=
"Returns non-nil if nums are in monotonically non-decreasing order,
@@ -1264,7 +1264,7 @@
:static true
:inline (fn [x y] `(. clojure.lang.Numbers (quotient ~x ~y)))}
[num div]
- (. clojure.lang.Numbers (quotient num div)))
+ (. clojure.lang.Numbers (quotient num div)))
(defn rem
"remainder of dividing numerator by denominator."
@@ -1272,7 +1272,7 @@
:static true
:inline (fn [x y] `(. clojure.lang.Numbers (remainder ~x ~y)))}
[num div]
- (. clojure.lang.Numbers (remainder num div)))
+ (. clojure.lang.Numbers (remainder num div)))
(defn rationalize
"returns the rational value of num"
@@ -1292,12 +1292,12 @@
(defn bit-and
"Bitwise and"
- {:inline (nary-inline 'and)
- :inline-arities >1?
- :added "1.0"}
- ([x y] (. clojure.lang.Numbers and x y))
- ([x y & more]
- (reduce1 bit-and (bit-and x y) more)))
+ {:inline (nary-inline 'and)
+ :inline-arities >1?
+ :added "1.0"}
+ ([x y] (. clojure.lang.Numbers and x y))
+ ([x y & more]
+ (reduce1 bit-and (bit-and x y) more)))
(defn bit-or
"Bitwise or"
@@ -1306,7 +1306,7 @@
:added "1.0"}
([x y] (. clojure.lang.Numbers or x y))
([x y & more]
- (reduce1 bit-or (bit-or x y) more)))
+ (reduce1 bit-or (bit-or x y) more)))
(defn bit-xor
"Bitwise exclusive or"
@@ -1315,7 +1315,7 @@
:added "1.0"}
([x y] (. clojure.lang.Numbers xor x y))
([x y & more]
- (reduce1 bit-xor (bit-xor x y) more)))
+ (reduce1 bit-xor (bit-xor x y) more)))
(defn bit-and-not
"Bitwise and with complement"
@@ -1325,7 +1325,7 @@
:static true}
([x y] (. clojure.lang.Numbers andNot x y))
([x y & more]
- (reduce1 bit-and-not (bit-and-not x y) more)))
+ (reduce1 bit-and-not (bit-and-not x y) more)))
(defn bit-clear
@@ -1387,7 +1387,7 @@
"Returns true if n is even, throws an exception if n is not an integer"
{:added "1.0"
:static true}
- [n] (if (integer? n)
+ [n] (if (integer? n)
(zero? (bit-and (clojure.lang.RT/uncheckedLongCast n) 1))
(throw (IllegalArgumentException. (str "Argument must be an integer: " n)))))
@@ -1479,7 +1479,7 @@
"Return true if x is a map entry"
{:added "1.8"}
[x]
- (instance? java.util.Map$Entry x))
+ (instance? java.util.Map$Entry x))
(defn contains?
"Returns true if key is present in the given collection, otherwise
@@ -1542,15 +1542,15 @@
{:added "1.0"
:static true}
[map keyseq]
- (loop [ret {} keys (seq keyseq)]
- (if keys
- (let [entry (. clojure.lang.RT (find map (first keys)))]
- (recur
- (if entry
- (conj ret entry)
- ret)
- (next keys)))
- (with-meta ret (meta map)))))
+ (loop [ret {} keys (seq keyseq)]
+ (if keys
+ (let [entry (. clojure.lang.RT (find map (first keys)))]
+ (recur
+ (if entry
+ (conj ret entry)
+ ret)
+ (next keys)))
+ (with-meta ret (meta map)))))
(defn keys
"Returns a sequence of the map's keys, in the same order as (seq map)."
@@ -1569,14 +1569,14 @@
{:added "1.0"
:static true}
[^java.util.Map$Entry e]
- (. e (getKey)))
+ (. e (getKey)))
(defn val
"Returns the value in the map entry."
{:added "1.0"
:static true}
[^java.util.Map$Entry e]
- (. e (getValue)))
+ (. e (getValue)))
(defn rseq
"Returns, in constant time, a seq of the items in rev (which
@@ -1584,7 +1584,7 @@
{:added "1.0"
:static true}
[^clojure.lang.Reversible rev]
- (. rev (rseq)))
+ (. rev (rseq)))
(defn name
"Returns the name String of a string, symbol or keyword."
@@ -1600,7 +1600,7 @@
:added "1.0"
:static true}
[^clojure.lang.Named x]
- (. x (getNamespace)))
+ (. x (getNamespace)))
(defn boolean
"Coerce to boolean"
@@ -1651,10 +1651,10 @@
[x & body]
`(let [lockee# ~x]
(try
- (monitor-enter lockee#)
- ~@body
- (finally
- (monitor-exit lockee#)))))
+ (monitor-enter lockee#)
+ ~@body
+ (finally
+ (monitor-exit lockee#)))))
(defmacro ..
"form => fieldName-symbol or (instanceMethodName-symbol args*)
@@ -1701,8 +1701,8 @@
(if forms
(let [form (first forms)
threaded (if (seq? form)
- (with-meta `(~(first form) ~@(next form) ~x) (meta form))
- (list form x))]
+ (with-meta `(~(first form) ~@(next form) ~x) (meta form))
+ (list form x))]
(recur threaded (next forms)))
x)))
@@ -1790,15 +1790,15 @@
"Removes all of the methods of multimethod."
{:added "1.2"
:static true}
- [^clojure.lang.MultiFn multifn]
- (.reset multifn))
+ [^clojure.lang.MultiFn multifn]
+ (.reset multifn))
(defn remove-method
"Removes the method of multimethod associated with dispatch-value."
{:added "1.0"
:static true}
- [^clojure.lang.MultiFn multifn dispatch-val]
- (. multifn removeMethod dispatch-val))
+ [^clojure.lang.MultiFn multifn dispatch-val]
+ (. multifn removeMethod dispatch-val))
(defn prefer-method
"Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y
@@ -1865,9 +1865,9 @@
{:added "1.0"}
[bindings & body]
(assert-args
- (vector? bindings) "a vector for its binding"
- (= 2 (count bindings)) "exactly 2 forms in binding vector")
- (let [form (bindings 0) tst (bindings 1)]
+ (vector? bindings) "a vector for its binding"
+ (= 2 (count bindings)) "exactly 2 forms in binding vector")
+ (let [form (bindings 0) tst (bindings 1)]
`(let [temp# ~tst]
(when temp#
(let [~form temp#]
@@ -1901,9 +1901,9 @@
{:added "1.6"}
[bindings & body]
(assert-args
- (vector? bindings) "a vector for its binding"
- (= 2 (count bindings)) "exactly 2 forms in binding vector")
- (let [form (bindings 0) tst (bindings 1)]
+ (vector? bindings) "a vector for its binding"
+ (= 2 (count bindings)) "exactly 2 forms in binding vector")
+ (let [form (bindings 0) tst (bindings 1)]
`(let [temp# ~tst]
(if (nil? temp#)
nil
@@ -1961,7 +1961,7 @@
(loop [ret [] vvs (seq var-vals)]
(if vvs
(recur (conj (conj ret `(var ~(first vvs))) (second vvs))
- (next (next vvs)))
+ (next (next vvs)))
(seq ret))))]
`(let []
(push-thread-bindings (hash-map ~@(var-ize bindings)))
@@ -2026,20 +2026,20 @@
(let [frame (clojure.lang.Var/cloneThreadBindingFrame)]
(fn
([]
- (clojure.lang.Var/resetThreadBindingFrame frame)
- (f))
+ (clojure.lang.Var/resetThreadBindingFrame frame)
+ (f))
([x]
- (clojure.lang.Var/resetThreadBindingFrame frame)
- (f x))
+ (clojure.lang.Var/resetThreadBindingFrame frame)
+ (f x))
([x y]
- (clojure.lang.Var/resetThreadBindingFrame frame)
- (f x y))
+ (clojure.lang.Var/resetThreadBindingFrame frame)
+ (f x y))
([x y z]
- (clojure.lang.Var/resetThreadBindingFrame frame)
- (f x y z))
+ (clojure.lang.Var/resetThreadBindingFrame frame)
+ (f x y z))
([x y z & args]
- (clojure.lang.Var/resetThreadBindingFrame frame)
- (apply f x y z args)))))
+ (clojure.lang.Var/resetThreadBindingFrame frame)
+ (apply f x y z args)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Refs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn ^{:private true}
@@ -2077,14 +2077,14 @@
:static true
}
([state & options]
- (let [a (new clojure.lang.Agent state)
- opts (apply hash-map options)]
- (setup-reference a options)
- (when (:error-handler opts)
- (.setErrorHandler a (:error-handler opts)))
- (.setErrorMode a (or (:error-mode opts)
- (if (:error-handler opts) :continue :fail)))
- a)))
+ (let [a (new clojure.lang.Agent state)
+ opts (apply hash-map options)]
+ (setup-reference a options)
+ (when (:error-handler opts)
+ (.setErrorHandler a (:error-handler opts)))
+ (.setErrorMode a (or (:error-mode opts)
+ (if (:error-handler opts) :continue :fail)))
+ a)))
(defn set-agent-send-executor!
"Sets the ExecutorService to be used by send"
@@ -2289,19 +2289,19 @@
([x & options]
(let [r ^clojure.lang.Ref (setup-reference (ref x) options)
opts (apply hash-map options)]
- (when (:max-history opts)
- (.setMaxHistory r (:max-history opts)))
- (when (:min-history opts)
- (.setMinHistory r (:min-history opts)))
- r)))
+ (when (:max-history opts)
+ (.setMaxHistory r (:max-history opts)))
+ (when (:min-history opts)
+ (.setMinHistory r (:min-history opts)))
+ r)))
(defn ^:private deref-future
([^java.util.concurrent.Future fut]
- (.get fut))
+ (.get fut))
([^java.util.concurrent.Future fut timeout-ms timeout-val]
- (try (.get fut timeout-ms java.util.concurrent.TimeUnit/MILLISECONDS)
- (catch java.util.concurrent.TimeoutException e
- timeout-val))))
+ (try (.get fut timeout-ms java.util.concurrent.TimeUnit/MILLISECONDS)
+ (catch java.util.concurrent.TimeoutException e
+ timeout-val))))
(defn deref
"Also reader macro: @ref/@agent/@var/@atom/@delay/@future/@promise. Within a transaction,
@@ -2320,9 +2320,9 @@
(.deref ^clojure.lang.IDeref ref)
(deref-future ref)))
([ref timeout-ms timeout-val]
- (if (instance? clojure.lang.IBlockingDeref ref)
- (.deref ^clojure.lang.IBlockingDeref ref timeout-ms timeout-val)
- (deref-future ref timeout-ms timeout-val))))
+ (if (instance? clojure.lang.IBlockingDeref ref)
+ (.deref ^clojure.lang.IBlockingDeref ref timeout-ms timeout-val)
+ (deref-future ref timeout-ms timeout-val))))
(defn atom
"Creates and returns an Atom with an initial value of x and zero or
@@ -2401,7 +2401,7 @@
"Gets the validator-fn for a var/ref/agent/atom."
{:added "1.0"
:static true}
- [^clojure.lang.IRef iref] (. iref (getValidator)))
+ [^clojure.lang.IRef iref] (. iref (getValidator)))
(defn alter-meta!
"Atomically sets the metadata for a namespace/var/ref/agent/atom to be:
@@ -2411,13 +2411,13 @@
f must be free of side-effects"
{:added "1.0"
:static true}
- [^clojure.lang.IReference iref f & args] (.alterMeta iref f args))
+ [^clojure.lang.IReference iref f & args] (.alterMeta iref f args))
(defn reset-meta!
"Atomically resets the metadata for a namespace/var/ref/agent/atom"
{:added "1.0"
:static true}
- [^clojure.lang.IReference iref metadata-map] (.resetMeta iref metadata-map))
+ [^clojure.lang.IReference iref metadata-map] (.resetMeta iref metadata-map))
(defn commute
"Must be called in a transaction. Sets the in-transaction-value of
@@ -2438,7 +2438,7 @@
:static true}
[^clojure.lang.Ref ref fun & args]
- (. ref (commute fun args)))
+ (. ref (commute fun args)))
(defn alter
"Must be called in a transaction. Sets the in-transaction-value of
@@ -2450,7 +2450,7 @@
{:added "1.0"
:static true}
[^clojure.lang.Ref ref fun & args]
- (. ref (alter fun args)))
+ (. ref (alter fun args)))
(defn ref-set
"Must be called in a transaction. Sets the value of ref.
@@ -2458,32 +2458,32 @@
{:added "1.0"
:static true}
[^clojure.lang.Ref ref val]
- (. ref (set val)))
+ (. ref (set val)))
(defn ref-history-count
"Returns the history count of a ref"
{:added "1.1"
:static true}
[^clojure.lang.Ref ref]
- (.getHistoryCount ref))
+ (.getHistoryCount ref))
(defn ref-min-history
"Gets the min-history of a ref, or sets it and returns the ref"
{:added "1.1"
:static true}
([^clojure.lang.Ref ref]
- (.getMinHistory ref))
+ (.getMinHistory ref))
([^clojure.lang.Ref ref n]
- (.setMinHistory ref n)))
+ (.setMinHistory ref n)))
(defn ref-max-history
"Gets the max-history of a ref, or sets it and returns the ref"
{:added "1.1"
:static true}
([^clojure.lang.Ref ref]
- (.getMaxHistory ref))
+ (.getMaxHistory ref))
([^clojure.lang.Ref ref n]
- (.setMaxHistory ref n)))
+ (.setMaxHistory ref n)))
(defn ensure
"Must be called in a transaction. Protects the ref from modification
@@ -2492,8 +2492,8 @@
{:added "1.0"
:static true}
[^clojure.lang.Ref ref]
- (. ref (touch))
- (. ref (deref)))
+ (. ref (touch))
+ (. ref (deref)))
(defmacro sync
"transaction-flags => TBD, pass nil for now
@@ -2564,14 +2564,14 @@
([] identity)
([f] f)
([f g]
- (fn
- ([] (f (g)))
- ([x] (f (g x)))
- ([x y] (f (g x y)))
- ([x y z] (f (g x y z)))
- ([x y z & args] (f (apply g x y z args)))))
+ (fn
+ ([] (f (g)))
+ ([x] (f (g x)))
+ ([x y] (f (g x y)))
+ ([x y z] (f (g x y z)))
+ ([x y z & args] (f (apply g x y z args)))))
([f g & fs]
- (reduce1 comp (list* f g fs))))
+ (reduce1 comp (list* f g fs))))
(defn juxt
"Takes a set of functions and returns a fn that is the juxtaposition
@@ -2582,34 +2582,34 @@
{:added "1.1"
:static true}
([f]
- (fn
- ([] [(f)])
- ([x] [(f x)])
- ([x y] [(f x y)])
- ([x y z] [(f x y z)])
- ([x y z & args] [(apply f x y z args)])))
+ (fn
+ ([] [(f)])
+ ([x] [(f x)])
+ ([x y] [(f x y)])
+ ([x y z] [(f x y z)])
+ ([x y z & args] [(apply f x y z args)])))
([f g]
- (fn
- ([] [(f) (g)])
- ([x] [(f x) (g x)])
- ([x y] [(f x y) (g x y)])
- ([x y z] [(f x y z) (g x y z)])
- ([x y z & args] [(apply f x y z args) (apply g x y z args)])))
+ (fn
+ ([] [(f) (g)])
+ ([x] [(f x) (g x)])
+ ([x y] [(f x y) (g x y)])
+ ([x y z] [(f x y z) (g x y z)])
+ ([x y z & args] [(apply f x y z args) (apply g x y z args)])))
([f g h]
- (fn
- ([] [(f) (g) (h)])
- ([x] [(f x) (g x) (h x)])
- ([x y] [(f x y) (g x y) (h x y)])
- ([x y z] [(f x y z) (g x y z) (h x y z)])
- ([x y z & args] [(apply f x y z args) (apply g x y z args) (apply h x y z args)])))
+ (fn
+ ([] [(f) (g) (h)])
+ ([x] [(f x) (g x) (h x)])
+ ([x y] [(f x y) (g x y) (h x y)])
+ ([x y z] [(f x y z) (g x y z) (h x y z)])
+ ([x y z & args] [(apply f x y z args) (apply g x y z args) (apply h x y z args)])))
([f g h & fs]
- (let [fs (list* f g h fs)]
- (fn
- ([] (reduce1 #(conj %1 (%2)) [] fs))
- ([x] (reduce1 #(conj %1 (%2 x)) [] fs))
- ([x y] (reduce1 #(conj %1 (%2 x y)) [] fs))
- ([x y z] (reduce1 #(conj %1 (%2 x y z)) [] fs))
- ([x y z & args] (reduce1 #(conj %1 (apply %2 x y z args)) [] fs))))))
+ (let [fs (list* f g h fs)]
+ (fn
+ ([] (reduce1 #(conj %1 (%2)) [] fs))
+ ([x] (reduce1 #(conj %1 (%2 x)) [] fs))
+ ([x y] (reduce1 #(conj %1 (%2 x y)) [] fs))
+ ([x y z] (reduce1 #(conj %1 (%2 x y z)) [] fs))
+ ([x y z & args] (reduce1 #(conj %1 (apply %2 x y z args)) [] fs))))))
(defn partial
"Takes a function f and fewer than the normal arguments to f, and
@@ -2656,18 +2656,18 @@
{:added "1.0"
:static true}
([coll]
- (if (seq? coll) coll
- (or (seq coll) ())))
+ (if (seq? coll) coll
+ (or (seq coll) ())))
([xform coll]
- (or (clojure.lang.RT/chunkIteratorSeq
+ (or (clojure.lang.RT/chunkIteratorSeq
(clojure.lang.TransformerIterator/create xform (clojure.lang.RT/iter coll)))
- ()))
+ ()))
([xform coll & colls]
- (or (clojure.lang.RT/chunkIteratorSeq
+ (or (clojure.lang.RT/chunkIteratorSeq
(clojure.lang.TransformerIterator/createMulti
xform
(map #(clojure.lang.RT/iter %) (cons coll colls))))
- ())))
+ ())))
(defn every?
"Returns true if (pred x) is logical true for every x in coll, else
@@ -2677,17 +2677,17 @@
:static true}
[pred coll]
(cond
- (nil? (seq coll)) true
- (pred (first coll)) (recur pred (next coll))
- :else false))
+ (nil? (seq coll)) true
+ (pred (first coll)) (recur pred (next coll))
+ :else false))
(def
- ^{:tag Boolean
- :doc "Returns false if (pred x) is logical true for every x in
+ ^{:tag Boolean
+ :doc "Returns false if (pred x) is logical true for every x in
coll, else true."
- :arglists '([pred coll])
- :added "1.0"}
- not-every? (comp not every?))
+ :arglists '([pred coll])
+ :added "1.0"}
+ not-every? (comp not every?))
(defn some
"Returns the first logical true value of (pred x) for any x in coll,
@@ -2697,16 +2697,16 @@
{:added "1.0"
:static true}
[pred coll]
- (when-let [s (seq coll)]
- (or (pred (first s)) (recur pred (next s)))))
+ (when-let [s (seq coll)]
+ (or (pred (first s)) (recur pred (next s)))))
(def
- ^{:tag Boolean
- :doc "Returns false if (pred x) is logical true for any x in coll,
+ ^{:tag Boolean
+ :doc "Returns false if (pred x) is logical true for any x in coll,
else true."
- :arglists '([pred coll])
- :added "1.0"}
- not-any? (comp not some))
+ :arglists '([pred coll])
+ :added "1.0"}
+ not-any? (comp not some))
;will be redefed later with arg checks
(defmacro dotimes
@@ -2734,40 +2734,40 @@
{:added "1.0"
:static true}
([f]
- (fn [rf]
- (fn
- ([] (rf))
- ([result] (rf result))
- ([result input]
- (rf result (f input)))
- ([result input & inputs]
- (rf result (apply f input inputs))))))
+ (fn [rf]
+ (fn
+ ([] (rf))
+ ([result] (rf result))
+ ([result input]
+ (rf result (f input)))
+ ([result input & inputs]
+ (rf result (apply f input inputs))))))
([f coll]
(lazy-seq
- (when-let [s (seq coll)]
- (if (chunked-seq? s)
- (let [c (chunk-first s)
- size (int (count c))
- b (chunk-buffer size)]
- (dotimes [i size]
- (chunk-append b (f (.nth c i))))
- (chunk-cons (chunk b) (map f (chunk-rest s))))
- (cons (f (first s)) (map f (rest s)))))))
+ (when-let [s (seq coll)]
+ (if (chunked-seq? s)
+ (let [c (chunk-first s)
+ size (int (count c))
+ b (chunk-buffer size)]
+ (dotimes [i size]
+ (chunk-append b (f (.nth c i))))
+ (chunk-cons (chunk b) (map f (chunk-rest s))))
+ (cons (f (first s)) (map f (rest s)))))))
([f c1 c2]
(lazy-seq
- (let [s1 (seq c1) s2 (seq c2)]
- (when (and s1 s2)
- (cons (f (first s1) (first s2))
- (map f (rest s1) (rest s2)))))))
+ (let [s1 (seq c1) s2 (seq c2)]
+ (when (and s1 s2)
+ (cons (f (first s1) (first s2))
+ (map f (rest s1) (rest s2)))))))
([f c1 c2 c3]
(lazy-seq
- (let [s1 (seq c1) s2 (seq c2) s3 (seq c3)]
- (when (and s1 s2 s3)
- (cons (f (first s1) (first s2) (first s3))
- (map f (rest s1) (rest s2) (rest s3)))))))
+ (let [s1 (seq c1) s2 (seq c2) s3 (seq c3)]
+ (when (and s1 s2 s3)
+ (cons (f (first s1) (first s2) (first s3))
+ (map f (rest s1) (rest s2) (rest s3)))))))
([f c1 c2 c3 & colls]
(let [step (fn step [cs]
- (lazy-seq
+ (lazy-seq
(let [ss (map seq cs)]
(when (every? identity ss)
(cons (map first ss) (step (map rest ss)))))))]
@@ -2788,7 +2788,7 @@
:static true}
([f] (comp (map f) cat))
([f & colls]
- (apply concat (apply map f colls))))
+ (apply concat (apply map f colls))))
(defn filter
"Returns a lazy sequence of the items in coll for which
@@ -2797,30 +2797,30 @@
{:added "1.0"
:static true}
([pred]
- (fn [rf]
- (fn
- ([] (rf))
- ([result] (rf result))
- ([result input]
- (if (pred input)
- (rf result input)
- result)))))
+ (fn [rf]
+ (fn
+ ([] (rf))
+ ([result] (rf result))
+ ([result input]
+ (if (pred input)
+ (rf result input)
+ result)))))
([pred coll]
(lazy-seq
- (when-let [s (seq coll)]
- (if (chunked-seq? s)
- (let [c (chunk-first s)
- size (count c)
- b (chunk-buffer size)]
- (dotimes [i size]
- (let [v (.nth c i)]
- (when (pred v)
- (chunk-append b v))))
- (chunk-cons (chunk b) (filter pred (chunk-rest s))))
- (let [f (first s) r (rest s)]
- (if (pred f)
- (cons f (filter pred r))
- (filter pred r))))))))
+ (when-let [s (seq coll)]
+ (if (chunked-seq? s)
+ (let [c (chunk-first s)
+ size (count c)
+ b (chunk-buffer size)]
+ (dotimes [i size]
+ (let [v (.nth c i)]
+ (when (pred v)
+ (chunk-append b v))))
+ (chunk-cons (chunk b) (filter pred (chunk-rest s))))
+ (let [f (first s) r (rest s)]
+ (if (pred f)
+ (cons f (filter pred r))
+ (filter pred r))))))))
(defn remove
@@ -2831,7 +2831,7 @@
:static true}
([pred] (filter (complement pred)))
([pred coll]
- (filter (complement pred) coll)))
+ (filter (complement pred) coll)))
(defn reduced
"Wraps x in a way such that a reduce will terminate with the value x"
@@ -2865,25 +2865,25 @@
{:added "1.0"
:static true}
([n]
- (fn [rf]
- (let [nv (volatile! n)]
- (fn
- ([] (rf))
- ([result] (rf result))
- ([result input]
- (let [n @nv
- nn (vswap! nv dec)
- result (if (pos? n)
- (rf result input)
- result)]
- (if (not (pos? nn))
- (ensure-reduced result)
- result)))))))
+ (fn [rf]
+ (let [nv (volatile! n)]
+ (fn
+ ([] (rf))
+ ([result] (rf result))
+ ([result input]
+ (let [n @nv
+ nn (vswap! nv dec)
+ result (if (pos? n)
+ (rf result input)
+ result)]
+ (if (not (pos? nn))
+ (ensure-reduced result)
+ result)))))))
([n coll]
- (lazy-seq
- (when (pos? n)
- (when-let [s (seq coll)]
- (cons (first s) (take (dec n) (rest s))))))))
+ (lazy-seq
+ (when (pos? n)
+ (when-let [s (seq coll)]
+ (cons (first s) (take (dec n) (rest s))))))))
(defn take-while
"Returns a lazy sequence of successive items from coll while
@@ -2892,19 +2892,19 @@
{:added "1.0"
:static true}
([pred]
- (fn [rf]
- (fn
- ([] (rf))
- ([result] (rf result))
- ([result input]
- (if (pred input)
- (rf result input)
- (reduced result))))))
+ (fn [rf]
+ (fn
+ ([] (rf))
+ ([result] (rf result))
+ ([result input]
+ (if (pred input)
+ (rf result input)
+ (reduced result))))))
([pred coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (when (pred (first s))
- (cons (first s) (take-while pred (rest s))))))))
+ (lazy-seq
+ (when-let [s (seq coll)]
+ (when (pred (first s))
+ (cons (first s) (take-while pred (rest s))))))))
(defn drop
"Returns a lazy sequence of all but the first n items in coll.
@@ -2912,24 +2912,24 @@
{:added "1.0"
:static true}
([n]
- (fn [rf]
- (let [nv (volatile! n)]
- (fn
- ([] (rf))
- ([result] (rf result))
- ([result input]
- (let [n @nv]
- (vswap! nv dec)
- (if (pos? n)
- result
- (rf result input))))))))
+ (fn [rf]
+ (let [nv (volatile! n)]
+ (fn
+ ([] (rf))
+ ([result] (rf result))
+ ([result input]
+ (let [n @nv]
+ (vswap! nv dec)
+ (if (pos? n)
+ result
+ (rf result input))))))))
([n coll]
- (let [step (fn [n coll]
- (let [s (seq coll)]
- (if (and (pos? n) s)
- (recur (dec n) (rest s))
- s)))]
- (lazy-seq (step n coll)))))
+ (let [step (fn [n coll]
+ (let [s (seq coll)]
+ (if (and (pos? n) s)
+ (recur (dec n) (rest s))
+ s)))]
+ (lazy-seq (step n coll)))))
(defn drop-last
"Return a lazy sequence of all but the last n (default 1) items in coll"
@@ -2956,25 +2956,25 @@
{:added "1.0"
:static true}
([pred]
- (fn [rf]
- (let [dv (volatile! true)]
- (fn
- ([] (rf))
- ([result] (rf result))
- ([result input]
- (let [drop? @dv]
- (if (and drop? (pred input))
- result
- (do
- (vreset! dv nil)
- (rf result input)))))))))
+ (fn [rf]
+ (let [dv (volatile! true)]
+ (fn
+ ([] (rf))
+ ([result] (rf result))
+ ([result input]
+ (let [drop? @dv]
+ (if (and drop? (pred input))
+ result
+ (do
+ (vreset! dv nil)
+ (rf result input)))))))))
([pred coll]
- (let [step (fn [pred coll]
- (let [s (seq coll)]
- (if (and s (pred (first s)))
- (recur pred (rest s))
- s)))]
- (lazy-seq (step pred coll)))))
+ (let [step (fn [pred coll]
+ (let [s (seq coll)]
+ (if (and s (pred (first s)))
+ (recur pred (rest s))
+ s)))]
+ (lazy-seq (step pred coll)))))
(defn cycle
"Returns a lazy (infinite!) sequence of repetitions of the items in coll."
@@ -2987,14 +2987,14 @@
{:added "1.0"
:static true}
[n coll]
- [(take n coll) (drop n coll)])
+ [(take n coll) (drop n coll)])
(defn split-with
"Returns a vector of [(take-while pred coll) (drop-while pred coll)]"
{:added "1.0"
:static true}
[pred coll]
- [(take-while pred coll) (drop-while pred coll)])
+ [(take-while pred coll) (drop-while pred coll)])
(defn repeat
"Returns a lazy (infinite!, or length n if supplied) sequence of xs."
@@ -3058,12 +3058,12 @@
[f & maps]
(when (some identity maps)
(let [merge-entry (fn [m e]
- (let [k (key e) v (val e)]
- (if (contains? m k)
- (assoc m k (f (get m k) v))
- (assoc m k v))))
+ (let [k (key e) v (val e)]
+ (if (contains? m k)
+ (assoc m k (f (get m k) v))
+ (assoc m k v))))
merge2 (fn [m1 m2]
- (reduce1 merge-entry (or m1 {}) (seq m2)))]
+ (reduce1 merge-entry (or m1 {}) (seq m2)))]
(reduce1 merge2 maps))))
@@ -3073,14 +3073,14 @@
{:added "1.0"
:static true}
[keys vals]
- (loop [map {}
- ks (seq keys)
- vs (seq vals)]
- (if (and ks vs)
- (recur (assoc map (first ks) (first vs))
- (next ks)
- (next vs))
- map)))
+ (loop [map {}
+ ks (seq keys)
+ vs (seq vals)]
+ (if (and ks vs)
+ (recur (assoc map (first ks) (first vs))
+ (next ks)
+ (next vs))
+ map)))
(defn line-seq
"Returns the lines of text from rdr as a lazy sequence of strings.
@@ -3096,8 +3096,8 @@
{:added "1.0"
:static true}
[pred]
- (fn [x y]
- (cond (pred x y) -1 (pred y x) 1 :else 0)))
+ (fn [x y]
+ (cond (pred x y) -1 (pred y x) 1 :else 0)))
(defn sort
"Returns a sorted sequence of the items in coll. If no comparator is
@@ -3166,20 +3166,20 @@
{:added "1.0"
:static true}
[coll n]
- (loop [n n xs (seq coll)]
- (if (and xs (pos? n))
- (recur (dec n) (next xs))
- xs)))
+ (loop [n n xs (seq coll)]
+ (if (and xs (pos? n))
+ (recur (dec n) (next xs))
+ xs)))
(defn nthrest
"Returns the nth rest of coll, coll when n is 0."
{:added "1.3"
:static true}
[coll n]
- (loop [n n xs coll]
- (if-let [xs (and (pos? n) (seq xs))]
- (recur (dec n) (rest xs))
- xs)))
+ (loop [n n xs coll]
+ (if-let [xs (and (pos? n) (seq xs))]
+ (recur (dec n) (rest xs))
+ xs)))
(defn partition
"Returns a lazy sequence of lists of n items each, at offsets step
@@ -3190,20 +3190,20 @@
{:added "1.0"
:static true}
([n coll]
- (partition n n coll))
+ (partition n n coll))
([n step coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (let [p (doall (take n s))]
- (when (= n (count p))
- (cons p (partition n step (nthrest s step))))))))
+ (lazy-seq
+ (when-let [s (seq coll)]
+ (let [p (doall (take n s))]
+ (when (= n (count p))
+ (cons p (partition n step (nthrest s step))))))))
([n step pad coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (let [p (doall (take n s))]
- (if (= n (count p))
- (cons p (partition n step pad (nthrest s step)))
- (list (take n (concat p pad)))))))))
+ (lazy-seq
+ (when-let [s (seq coll)]
+ (let [p (doall (take n s))]
+ (if (= n (count p))
+ (cons p (partition n step pad (nthrest s step)))
+ (list (take n (concat p pad)))))))))
;; evaluation
@@ -3220,8 +3220,8 @@
{:added "1.0"}
[seq-exprs & body]
(assert-args
- (vector? seq-exprs) "a vector for its binding"
- (even? (count seq-exprs)) "an even number of forms in binding vector")
+ (vector? seq-exprs) "a vector for its binding"
+ (even? (count seq-exprs)) "an even number of forms in binding vector")
(let [step (fn step [recform exprs]
(if-not exprs
[true `(do ~@body)]
@@ -3251,7 +3251,7 @@
needrec (steppair 0)
subform (steppair 1)
recform-chunk
- `(recur ~seq- ~chunk- ~count- (unchecked-inc ~i-))
+ `(recur ~seq- ~chunk- ~count- (unchecked-inc ~i-))
steppair-chunk (step recform-chunk (nnext exprs))
subform-chunk (steppair-chunk 1)]
[true
@@ -3291,7 +3291,7 @@
(defn ^:static await1 [^clojure.lang.Agent a]
(when (pos? (.getQueueCount a))
(await a))
- a)
+ a)
(defn await-for
"Blocks the current thread until all actions dispatched thus
@@ -3301,14 +3301,14 @@
{:added "1.0"
:static true}
[timeout-ms & agents]
- (io! "await-for in transaction"
- (when *agent*
- (throw (new Exception "Can't await in agent action")))
- (let [latch (new java.util.concurrent.CountDownLatch (count agents))
- count-down (fn [agent] (. latch (countDown)) agent)]
- (doseq [agent agents]
- (send agent count-down))
- (. latch (await timeout-ms (. java.util.concurrent.TimeUnit MILLISECONDS))))))
+ (io! "await-for in transaction"
+ (when *agent*
+ (throw (new Exception "Can't await in agent action")))
+ (let [latch (new java.util.concurrent.CountDownLatch (count agents))
+ count-down (fn [agent] (. latch (countDown)) agent)]
+ (doseq [agent agents]
+ (send agent count-down))
+ (. latch (await timeout-ms (. java.util.concurrent.TimeUnit MILLISECONDS))))))
(defmacro dotimes
"bindings => name n
@@ -3318,8 +3318,8 @@
{:added "1.0"}
[bindings & body]
(assert-args
- (vector? bindings) "a vector for its binding"
- (= 2 (count bindings)) "exactly 2 forms in binding vector")
+ (vector? bindings) "a vector for its binding"
+ (= 2 (count bindings)) "exactly 2 forms in binding vector")
(let [i (first bindings)
n (second bindings)]
`(let [n# (long ~n)]
@@ -3329,10 +3329,10 @@
(recur (unchecked-inc ~i)))))))
#_(defn into
- "Returns a new coll consisting of to-coll with all of the items of
+ "Returns a new coll consisting of to-coll with all of the items of
from-coll conjoined."
- {:added "1.0"}
- [to from]
+ {:added "1.0"}
+ [to from]
(let [ret to items (seq from)]
(if items
(recur (conj ret (first items)) (next items))
@@ -3363,7 +3363,7 @@
([] (transient []))
([coll] coll)
([^clojure.lang.ITransientCollection coll x]
- (.conj coll x)))
+ (.conj coll x)))
(defn assoc!
"When applied to a transient map, adds mapping of key(s) to
@@ -3434,11 +3434,11 @@
import-symbols-or-lists)]
`(do ~@(map #(list 'clojure.core/import* %)
(reduce1 (fn [v spec]
- (if (symbol? spec)
- (conj v (name spec))
- (let [p (first spec) cs (rest spec)]
- (into1 v (map #(str p "." %) cs)))))
- [] specs)))))
+ (if (symbol? spec)
+ (conj v (name spec))
+ (let [p (first spec) cs (rest spec)]
+ (into1 v (map #(str p "." %) cs)))))
+ [] specs)))))
(defn into-array
"Returns an array with components set to the values in aseq. The array's
@@ -3449,13 +3449,13 @@
{:added "1.0"
:static true}
([aseq]
- (clojure.lang.RT/seqToTypedArray (seq aseq)))
+ (clojure.lang.RT/seqToTypedArray (seq aseq)))
([type aseq]
- (clojure.lang.RT/seqToTypedArray type (seq aseq))))
+ (clojure.lang.RT/seqToTypedArray type (seq aseq))))
(defn ^{:private true}
array [& items]
- (into-array items))
+ (into-array items))
(defn class
"Returns the Class of x"
@@ -3622,13 +3622,13 @@
:static true
:added "1.3"}
[x] (cond
- (instance? clojure.lang.BigInt x) x
- (instance? BigInteger x) (clojure.lang.BigInt/fromBigInteger x)
- (decimal? x) (bigint (.toBigInteger ^BigDecimal x))
- (float? x) (bigint (. BigDecimal valueOf (double x)))
- (ratio? x) (bigint (.bigIntegerValue ^clojure.lang.Ratio x))
- (number? x) (clojure.lang.BigInt/valueOf (long x))
- :else (bigint (BigInteger. x))))
+ (instance? clojure.lang.BigInt x) x
+ (instance? BigInteger x) (clojure.lang.BigInt/fromBigInteger x)
+ (decimal? x) (bigint (.toBigInteger ^BigDecimal x))
+ (float? x) (bigint (. BigDecimal valueOf (double x)))
+ (ratio? x) (bigint (.bigIntegerValue ^clojure.lang.Ratio x))
+ (number? x) (clojure.lang.BigInt/valueOf (long x))
+ :else (bigint (BigInteger. x))))
(defn biginteger
"Coerce to BigInteger"
@@ -3636,13 +3636,13 @@
:added "1.0"
:static true}
[x] (cond
- (instance? BigInteger x) x
- (instance? clojure.lang.BigInt x) (.toBigInteger ^clojure.lang.BigInt x)
- (decimal? x) (.toBigInteger ^BigDecimal x)
- (float? x) (.toBigInteger (. BigDecimal valueOf (double x)))
- (ratio? x) (.bigIntegerValue ^clojure.lang.Ratio x)
- (number? x) (BigInteger/valueOf (long x))
- :else (BigInteger. x)))
+ (instance? BigInteger x) x
+ (instance? clojure.lang.BigInt x) (.toBigInteger ^clojure.lang.BigInt x)
+ (decimal? x) (.toBigInteger ^BigDecimal x)
+ (float? x) (.toBigInteger (. BigDecimal valueOf (double x)))
+ (ratio? x) (.bigIntegerValue ^clojure.lang.Ratio x)
+ (number? x) (BigInteger/valueOf (long x))
+ :else (BigInteger. x)))
(defn bigdec
"Coerce to BigDecimal"
@@ -3650,13 +3650,13 @@
:added "1.0"
:static true}
[x] (cond
- (decimal? x) x
- (float? x) (. BigDecimal valueOf (double x))
- (ratio? x) (/ (BigDecimal. (.numerator ^clojure.lang.Ratio x)) (.denominator ^clojure.lang.Ratio x))
- (instance? clojure.lang.BigInt x) (.toBigDecimal ^clojure.lang.BigInt x)
- (instance? BigInteger x) (BigDecimal. ^BigInteger x)
- (number? x) (BigDecimal/valueOf (long x))
- :else (BigDecimal. x)))
+ (decimal? x) x
+ (float? x) (. BigDecimal valueOf (double x))
+ (ratio? x) (/ (BigDecimal. (.numerator ^clojure.lang.Ratio x)) (.denominator ^clojure.lang.Ratio x))
+ (instance? clojure.lang.BigInt x) (.toBigDecimal ^clojure.lang.BigInt x)
+ (instance? BigInteger x) (BigDecimal. ^BigInteger x)
+ (number? x) (BigDecimal/valueOf (long x))
+ :else (BigDecimal. x)))
(def ^:dynamic ^{:private true} print-initialized false)
@@ -3683,7 +3683,7 @@
:added "1.0"}
([] nil)
([x]
- (pr-on x *out*))
+ (pr-on x *out*))
([x & more]
(pr x)
(. *out* (append \space))
@@ -3699,8 +3699,8 @@
{:added "1.0"
:static true}
[]
- (. *out* (append system-newline))
- nil)
+ (. *out* (append system-newline))
+ nil)
(defn flush
"Flushes the output stream that is the current value of
@@ -3708,18 +3708,18 @@
{:added "1.0"
:static true}
[]
- (. *out* (flush))
- nil)
+ (. *out* (flush))
+ nil)
(defn prn
"Same as pr followed by (newline). Observes *flush-on-newline*"
{:added "1.0"
:static true}
[& more]
- (apply pr more)
- (newline)
- (when *flush-on-newline*
- (flush)))
+ (apply pr more)
+ (newline)
+ (when *flush-on-newline*
+ (flush)))
(defn print
"Prints the object(s) to the output stream that is the current value
@@ -3727,16 +3727,16 @@
{:added "1.0"
:static true}
[& more]
- (binding [*print-readably* nil]
- (apply pr more)))
+ (binding [*print-readably* nil]
+ (apply pr more)))
(defn println
"Same as print followed by (newline)"
{:added "1.0"
:static true}
[& more]
- (binding [*print-readably* nil]
- (apply prn more)))
+ (binding [*print-readably* nil]
+ (apply prn more)))
(defn read
"Reads the next object from stream, which must be an instance of
@@ -3837,8 +3837,8 @@
{:added "1.0"}
[bindings & body]
(assert-args
- (vector? bindings) "a vector for its binding"
- (even? (count bindings)) "an even number of forms in binding vector")
+ (vector? bindings) "a vector for its binding"
+ (even? (count bindings)) "an even number of forms in binding vector")
(cond
(= (count bindings) 0) `(do ~@body)
(symbol? (bindings 0)) `(let ~(subvec bindings 0 2)
@@ -3857,16 +3857,16 @@
(doto (new java.util.HashMap) (.put \"a\" 1) (.put \"b\" 2))"
{:added "1.0"}
[x & forms]
- (let [gx (gensym)]
- `(let [~gx ~x]
- ~@(map (fn [f]
- (with-meta
- (if (seq? f)
- `(~(first f) ~gx ~@(next f))
- `(~f ~gx))
- (meta f)))
- forms)
- ~gx)))
+ (let [gx (gensym)]
+ `(let [~gx ~x]
+ ~@(map (fn [f]
+ (with-meta
+ (if (seq? f)
+ `(~(first f) ~gx ~@(next f))
+ `(~f ~gx))
+ (meta f)))
+ forms)
+ ~gx)))
(defmacro memfn
"Expands into code that creates a fn that expects to be passed an
@@ -3935,13 +3935,13 @@
(defmacro
^{:private true}
def-aset [name method coerce]
- `(defn ~name
- {:arglists '([~'array ~'idx ~'val] [~'array ~'idx ~'idx2 & ~'idxv])}
- ([array# idx# val#]
- (. Array (~method array# idx# (~coerce val#)))
- val#)
- ([array# idx# idx2# & idxv#]
- (apply ~name (aget array# idx#) idx2# idxv#))))
+ `(defn ~name
+ {:arglists '([~'array ~'idx ~'val] [~'array ~'idx ~'idx2 & ~'idxv])}
+ ([array# idx# val#]
+ (. Array (~method array# idx# (~coerce val#)))
+ val#)
+ ([array# idx# idx2# & idxv#]
+ (apply ~name (aget array# idx#) idx2# idxv#))))
(def-aset
^{:doc "Sets the value at the index/indices. Works on arrays of int. Returns val."
@@ -4008,12 +4008,12 @@
:added "1.0"
:static true}
[^java.util.Collection coll]
- (let [ret (make-array (. Class (forName "[Ljava.lang.Object;")) (. coll (size)))]
- (loop [i 0 xs (seq coll)]
- (when xs
- (aset ret i (to-array (first xs)))
- (recur (inc i) (next xs))))
- ret))
+ (let [ret (make-array (. Class (forName "[Ljava.lang.Object;")) (. coll (size)))]
+ (loop [i 0 xs (seq coll)]
+ (when xs
+ (aset ret i (to-array (first xs)))
+ (recur (inc i) (next xs))))
+ ret))
(defn macroexpand-1
"If form represents a macro form, returns its expansion,
@@ -4021,7 +4021,7 @@
{:added "1.0"
:static true}
[form]
- (. clojure.lang.Compiler (macroexpand1 form)))
+ (. clojure.lang.Compiler (macroexpand1 form)))
(defn macroexpand
"Repeatedly calls macroexpand-1 on form until it no longer
@@ -4030,17 +4030,17 @@
{:added "1.0"
:static true}
[form]
- (let [ex (macroexpand-1 form)]
- (if (identical? ex form)
- form
- (macroexpand ex))))
+ (let [ex (macroexpand-1 form)]
+ (if (identical? ex form)
+ form
+ (macroexpand ex))))
(defn create-struct
"Returns a structure basis object."
{:added "1.0"
:static true}
[& keys]
- (. clojure.lang.PersistentStructMap (createSlotMap keys)))
+ (. clojure.lang.PersistentStructMap (createSlotMap keys)))
(defmacro defstruct
"Same as (def name (create-struct keys...))"
@@ -4057,7 +4057,7 @@
{:added "1.0"
:static true}
[s & inits]
- (. clojure.lang.PersistentStructMap (create s inits)))
+ (. clojure.lang.PersistentStructMap (create s inits)))
(defn struct
"Returns a new structmap instance with the keys of the
@@ -4066,7 +4066,7 @@
{:added "1.0"
:static true}
[s & vals]
- (. clojure.lang.PersistentStructMap (construct s vals)))
+ (. clojure.lang.PersistentStructMap (construct s vals)))
(defn accessor
"Returns a fn that, given an instance of a structmap with the basis,
@@ -4077,7 +4077,7 @@
{:added "1.0"
:static true}
[s key]
- (. clojure.lang.PersistentStructMap (getAccessor s key)))
+ (. clojure.lang.PersistentStructMap (getAccessor s key)))
(defn load-reader
"Sequentially read and evaluate the set of forms contained in the
@@ -4114,14 +4114,14 @@
(persistent! (reduce1 conj! (transient #{}) coll)))))
(defn ^{:private true
- :static true}
+ :static true}
filter-key [keyfn pred amap]
- (loop [ret {} es (seq amap)]
- (if es
- (if (pred (keyfn (first es)))
- (recur (assoc ret (key (first es)) (val (first es))) (next es))
- (recur ret (next es)))
- ret)))
+ (loop [ret {} es (seq amap)]
+ (if es
+ (if (pred (keyfn (first es)))
+ (recur (assoc ret (key (first es)) (val (first es))) (next es))
+ (recur ret (next es)))
+ ret)))
(defn find-ns
"Returns the namespace named by the symbol or nil if it doesn't exist."
@@ -4193,8 +4193,8 @@
[ns]
(let [ns (the-ns ns)]
(filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v)
- (= ns (.ns v))
- (.isPublic v)))
+ (= ns (.ns v))
+ (.isPublic v)))
(ns-map ns))))
(defn ns-imports
@@ -4211,7 +4211,7 @@
[ns]
(let [ns (the-ns ns)]
(filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v)
- (= ns (.ns v))))
+ (= ns (.ns v))))
(ns-map ns))))
(defn refer
@@ -4231,25 +4231,25 @@
clashes. Use :use in the ns macro in preference to calling this directly."
{:added "1.0"}
[ns-sym & filters]
- (let [ns (or (find-ns ns-sym) (throw (new Exception (str "No namespace: " ns-sym))))
- fs (apply hash-map filters)
- nspublics (ns-publics ns)
- rename (or (:rename fs) {})
- exclude (set (:exclude fs))
- to-do (if (= :all (:refer fs))
- (keys nspublics)
- (or (:refer fs) (:only fs) (keys nspublics)))]
- (when (and to-do (not (instance? clojure.lang.Sequential to-do)))
- (throw (new Exception ":only/:refer value must be a sequential collection of symbols")))
- (doseq [sym to-do]
- (when-not (exclude sym)
- (let [v (nspublics sym)]
- (when-not v
- (throw (new java.lang.IllegalAccessError
- (if (get (ns-interns ns) sym)
- (str sym " is not public")
- (str sym " does not exist")))))
- (. *ns* (refer (or (rename sym) sym) v)))))))
+ (let [ns (or (find-ns ns-sym) (throw (new Exception (str "No namespace: " ns-sym))))
+ fs (apply hash-map filters)
+ nspublics (ns-publics ns)
+ rename (or (:rename fs) {})
+ exclude (set (:exclude fs))
+ to-do (if (= :all (:refer fs))
+ (keys nspublics)
+ (or (:refer fs) (:only fs) (keys nspublics)))]
+ (when (and to-do (not (instance? clojure.lang.Sequential to-do)))
+ (throw (new Exception ":only/:refer value must be a sequential collection of symbols")))
+ (doseq [sym to-do]
+ (when-not (exclude sym)
+ (let [v (nspublics sym)]
+ (when-not v
+ (throw (new java.lang.IllegalAccessError
+ (if (get (ns-interns ns) sym)
+ (str sym " is not public")
+ (str sym " does not exist")))))
+ (. *ns* (refer (or (rename sym) sym) v)))))))
(defn ns-refers
"Returns a map of the refer mappings for the namespace."
@@ -4258,7 +4258,7 @@
[ns]
(let [ns (the-ns ns)]
(filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v)
- (not= ns (.ns v))))
+ (not= ns (.ns v))))
(ns-map ns))))
(defn alias
@@ -4291,20 +4291,20 @@
{:added "1.0"
:static true}
([n]
- (fn [rf]
- (let [iv (volatile! -1)]
- (fn
- ([] (rf))
- ([result] (rf result))
- ([result input]
- (let [i (vswap! iv inc)]
- (if (zero? (rem i n))
- (rf result input)
- result)))))))
+ (fn [rf]
+ (let [iv (volatile! -1)]
+ (fn
+ ([] (rf))
+ ([result] (rf result))
+ ([result input]
+ (let [i (vswap! iv inc)]
+ (if (zero? (rem i n))
+ (rf result input)
+ result)))))))
([n coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (cons (first s) (take-nth n (drop n s)))))))
+ (lazy-seq
+ (when-let [s (seq coll)]
+ (cons (first s) (take-nth n (drop n s)))))))
(defn interleave
"Returns a lazy seq of the first item in each coll, then the second etc."
@@ -4313,16 +4313,16 @@
([] ())
([c1] (lazy-seq c1))
([c1 c2]
- (lazy-seq
- (let [s1 (seq c1) s2 (seq c2)]
- (when (and s1 s2)
- (cons (first s1) (cons (first s2)
- (interleave (rest s1) (rest s2))))))))
+ (lazy-seq
+ (let [s1 (seq c1) s2 (seq c2)]
+ (when (and s1 s2)
+ (cons (first s1) (cons (first s2)
+ (interleave (rest s1) (rest s2))))))))
([c1 c2 & colls]
- (lazy-seq
- (let [ss (map seq (conj colls c2 c1))]
- (when (every? identity ss)
- (concat (map first ss) (apply interleave (map rest ss))))))))
+ (lazy-seq
+ (let [ss (map seq (conj colls c2 c1))]
+ (when (every? identity ss)
+ (concat (map first ss) (apply interleave (map rest ss))))))))
(defn var-get
"Gets the value in the var object"
@@ -4347,14 +4347,14 @@
{:added "1.0"}
[name-vals-vec & body]
(assert-args
- (vector? name-vals-vec) "a vector for its binding"
- (even? (count name-vals-vec)) "an even number of forms in binding vector")
+ (vector? name-vals-vec) "a vector for its binding"
+ (even? (count name-vals-vec)) "an even number of forms in binding vector")
`(let [~@(interleave (take-nth 2 name-vals-vec)
(repeat '(.. clojure.lang.Var create setDynamic)))]
(. clojure.lang.Var (pushThreadBindings (hash-map ~@name-vals-vec)))
(try
- ~@body
- (finally (. clojure.lang.Var (popThreadBindings))))))
+ ~@body
+ (finally (. clojure.lang.Var (popThreadBindings))))))
(defn ns-resolve
"Returns the var or Class to which a symbol will be resolved in the
@@ -4364,10 +4364,10 @@
{:added "1.0"
:static true}
([ns sym]
- (ns-resolve ns nil sym))
+ (ns-resolve ns nil sym))
([ns env sym]
- (when-not (contains? env sym)
- (clojure.lang.Compiler/maybeResolveIn (the-ns ns) sym))))
+ (when-not (contains? env sym)
+ (clojure.lang.Compiler/maybeResolveIn (the-ns ns) sym))))
(defn resolve
"same as (ns-resolve *ns* symbol) or (ns-resolve *ns* &env symbol)"
@@ -4383,7 +4383,7 @@
:static true}
([] (. clojure.lang.PersistentArrayMap EMPTY))
([& keyvals]
- (clojure.lang.PersistentArrayMap/createAsIfByAssoc (to-array keyvals))))
+ (clojure.lang.PersistentArrayMap/createAsIfByAssoc (to-array keyvals))))
;;redefine let and loop with destructuring
(defn destructure [bindings]
@@ -4405,25 +4405,25 @@
(if (seq bs)
(let [firstb (first bs)]
(cond
- (= firstb '&) (recur (pb ret (second bs) gseq)
- n
- (nnext bs)
- true)
- (= firstb :as) (pb ret (second bs) gvec)
- :else (if seen-rest?
- (throw (new Exception "Unsupported binding form, only :as can follow & parameter"))
- (recur (pb (if has-rest
- (conj ret
- gfirst `(first ~gseq)
- gseq `(next ~gseq))
- ret)
- firstb
- (if has-rest
- gfirst
- (list `nth gvec n nil)))
- (inc n)
- (next bs)
- seen-rest?))))
+ (= firstb '&) (recur (pb ret (second bs) gseq)
+ n
+ (nnext bs)
+ true)
+ (= firstb :as) (pb ret (second bs) gvec)
+ :else (if seen-rest?
+ (throw (new Exception "Unsupported binding form, only :as can follow & parameter"))
+ (recur (pb (if has-rest
+ (conj ret
+ gfirst `(first ~gseq)
+ gseq `(next ~gseq))
+ ret)
+ firstb
+ (if has-rest
+ gfirst
+ (list `nth gvec n nil)))
+ (inc n)
+ (next bs)
+ seen-rest?))))
ret))))
pmap
(fn [bvec b v]
@@ -4437,25 +4437,25 @@
(conj ret (:as b) gmap)
ret))))
bes (let [transforms
- (reduce1
- (fn [transforms mk]
- (if (keyword? mk)
- (let [mkns (namespace mk)
- mkn (name mk)]
- (cond (= mkn "keys") (assoc transforms mk #(keyword (or mkns (namespace %)) (name %)))
- (= mkn "syms") (assoc transforms mk #(list `quote (symbol (or mkns (namespace %)) (name %))))
- (= mkn "strs") (assoc transforms mk str)
- :else transforms))
- transforms))
- {}
- (keys b))]
+ (reduce1
+ (fn [transforms mk]
+ (if (keyword? mk)
+ (let [mkns (namespace mk)
+ mkn (name mk)]
+ (cond (= mkn "keys") (assoc transforms mk #(keyword (or mkns (namespace %)) (name %)))
+ (= mkn "syms") (assoc transforms mk #(list `quote (symbol (or mkns (namespace %)) (name %))))
+ (= mkn "strs") (assoc transforms mk str)
+ :else transforms))
+ transforms))
+ {}
+ (keys b))]
(reduce1
- (fn [bes entry]
- (reduce1 #(assoc %1 %2 ((val entry) %2))
- (dissoc bes (key entry))
- ((key entry) bes)))
- (dissoc b :as :or)
- transforms))]
+ (fn [bes entry]
+ (reduce1 #(assoc %1 %2 ((val entry) %2))
+ (dissoc bes (key entry))
+ ((key entry) bes)))
+ (dissoc b :as :or)
+ transforms))]
(if (seq bes)
(let [bb (key (first bes))
bk (val (first bes))
@@ -4469,10 +4469,10 @@
(next bes)))
ret))))]
(cond
- (symbol? b) (-> bvec (conj b) (conj v))
- (vector? b) (pvec bvec b v)
- (map? b) (pmap bvec b v)
- :else (throw (new Exception (str "Unsupported binding form: " b))))))
+ (symbol? b) (-> bvec (conj b) (conj v))
+ (vector? b) (pvec bvec b v)
+ (map? b) (pmap bvec b v)
+ :else (throw (new Exception (str "Unsupported binding form: " b))))))
process-entry (fn [bvec b] (pb bvec (first b) (second b)))]
(if (every? symbol? (map first bents))
bindings
@@ -4487,8 +4487,8 @@
{:added "1.0", :special-form true, :forms '[(let [bindings*] exprs*)]}
[bindings & body]
(assert-args
- (vector? bindings) "a vector for its binding"
- (even? (count bindings)) "an even number of forms in binding vector")
+ (vector? bindings) "a vector for its binding"
+ (even? (count bindings)) "an even number of forms in binding vector")
`(let* ~(destructure bindings) ~@body))
(defn ^{:private true}
@@ -4520,57 +4520,57 @@
{:added "1.0", :special-form true,
:forms '[(fn name? [params* ] exprs*) (fn name? ([params* ] exprs*)+)]}
[& sigs]
- (let [name (if (symbol? (first sigs)) (first sigs) nil)
- sigs (if name (next sigs) sigs)
- sigs (if (vector? (first sigs))
- (list sigs)
- (if (seq? (first sigs))
- sigs
- ;; Assume single arity syntax
- (throw (IllegalArgumentException.
- (if (seq sigs)
- (str "Parameter declaration "
- (first sigs)
- " should be a vector")
- (str "Parameter declaration missing"))))))
- psig (fn* [sig]
- ;; Ensure correct type before destructuring sig
- (when (not (seq? sig))
- (throw (IllegalArgumentException.
- (str "Invalid signature " sig
- " should be a list"))))
- (let [[params & body] sig
- _ (when (not (vector? params))
- (throw (IllegalArgumentException.
- (if (seq? (first sigs))
- (str "Parameter declaration " params
- " should be a vector")
- (str "Invalid signature " sig
- " should be a list")))))
- conds (when (and (next body) (map? (first body)))
- (first body))
- body (if conds (next body) body)
- conds (or conds (meta params))
- pre (:pre conds)
- post (:post conds)
- body (if post
- `((let [~'% ~(if (< 1 (count body))
- `(do ~@body)
- (first body))]
- ~@(map (fn* [c] `(assert ~c)) post)
- ~'%))
- body)
- body (if pre
- (concat (map (fn* [c] `(assert ~c)) pre)
- body)
- body)]
- (maybe-destructured params body)))
- new-sigs (map psig sigs)]
- (with-meta
- (if name
- (list* 'fn* name new-sigs)
- (cons 'fn* new-sigs))
- (meta &form))))
+ (let [name (if (symbol? (first sigs)) (first sigs) nil)
+ sigs (if name (next sigs) sigs)
+ sigs (if (vector? (first sigs))
+ (list sigs)
+ (if (seq? (first sigs))
+ sigs
+ ;; Assume single arity syntax
+ (throw (IllegalArgumentException.
+ (if (seq sigs)
+ (str "Parameter declaration "
+ (first sigs)
+ " should be a vector")
+ (str "Parameter declaration missing"))))))
+ psig (fn* [sig]
+ ;; Ensure correct type before destructuring sig
+ (when (not (seq? sig))
+ (throw (IllegalArgumentException.
+ (str "Invalid signature " sig
+ " should be a list"))))
+ (let [[params & body] sig
+ _ (when (not (vector? params))
+ (throw (IllegalArgumentException.
+ (if (seq? (first sigs))
+ (str "Parameter declaration " params
+ " should be a vector")
+ (str "Invalid signature " sig
+ " should be a list")))))
+ conds (when (and (next body) (map? (first body)))
+ (first body))
+ body (if conds (next body) body)
+ conds (or conds (meta params))
+ pre (:pre conds)
+ post (:post conds)
+ body (if post
+ `((let [~'% ~(if (< 1 (count body))
+ `(do ~@body)
+ (first body))]
+ ~@(map (fn* [c] `(assert ~c)) post)
+ ~'%))
+ body)
+ body (if pre
+ (concat (map (fn* [c] `(assert ~c)) pre)
+ body)
+ body)]
+ (maybe-destructured params body)))
+ new-sigs (map psig sigs)]
+ (with-meta
+ (if name
+ (list* 'fn* name new-sigs)
+ (cons 'fn* new-sigs))
+ (meta &form))))
(defmacro loop
"Evaluates the exprs in a lexical context in which the symbols in
@@ -4578,24 +4578,24 @@
therein. Acts as a recur target."
{:added "1.0", :special-form true, :forms '[(loop [bindings*] exprs*)]}
[bindings & body]
- (assert-args
- (vector? bindings) "a vector for its binding"
- (even? (count bindings)) "an even number of forms in binding vector")
- (let [db (destructure bindings)]
- (if (= db bindings)
- `(loop* ~bindings ~@body)
- (let [vs (take-nth 2 (drop 1 bindings))
- bs (take-nth 2 bindings)
- gs (map (fn [b] (if (symbol? b) b (gensym))) bs)
- bfs (reduce1 (fn [ret [b v g]]
- (if (symbol? b)
- (conj ret g v)
- (conj ret g v b g)))
- [] (map vector bs vs gs))]
- `(let ~bfs
- (loop* ~(vec (interleave gs gs))
- (let ~(vec (interleave bs gs))
- ~@body)))))))
+ (assert-args
+ (vector? bindings) "a vector for its binding"
+ (even? (count bindings)) "an even number of forms in binding vector")
+ (let [db (destructure bindings)]
+ (if (= db bindings)
+ `(loop* ~bindings ~@body)
+ (let [vs (take-nth 2 (drop 1 bindings))
+ bs (take-nth 2 bindings)
+ gs (map (fn [b] (if (symbol? b) b (gensym))) bs)
+ bfs (reduce1 (fn [ret [b v g]]
+ (if (symbol? b)
+ (conj ret g v)
+ (conj ret g v b g)))
+ [] (map vector bs vs gs))]
+ `(let ~bfs
+ (loop* ~(vec (interleave gs gs))
+ (let ~(vec (interleave bs gs))
+ ~@body)))))))
(defmacro when-first
"bindings => x xs
@@ -4604,12 +4604,12 @@
{:added "1.0"}
[bindings & body]
(assert-args
- (vector? bindings) "a vector for its binding"
- (= 2 (count bindings)) "exactly 2 forms in binding vector")
+ (vector? bindings) "a vector for its binding"
+ (= 2 (count bindings)) "exactly 2 forms in binding vector")
(let [[x xs] bindings]
`(when-let [xs# (seq ~xs)]
(let [~x (first xs#)]
- ~@body))))
+ ~@body))))
(defmacro lazy-cat
"Expands to code which yields a lazy sequence of the concatenation
@@ -4634,14 +4634,14 @@
{:added "1.0"}
[seq-exprs body-expr]
(assert-args
- (vector? seq-exprs) "a vector for its binding"
- (even? (count seq-exprs)) "an even number of forms in binding vector")
+ (vector? seq-exprs) "a vector for its binding"
+ (even? (count seq-exprs)) "an even number of forms in binding vector")
(let [to-groups (fn [seq-exprs]
(reduce1 (fn [groups [k v]]
- (if (keyword? k)
- (conj (pop groups) (conj (peek groups) [k v]))
- (conj groups [k v])))
- [] (partition 2 seq-exprs)))
+ (if (keyword? k)
+ (conj (pop groups) (conj (peek groups) [k v]))
+ (conj groups [k v])))
+ [] (partition 2 seq-exprs)))
err (fn [& msg] (throw (IllegalArgumentException. ^String (apply str msg))))
emit-bind (fn emit-bind [[[bind expr & mod-pairs]
& [[_ next-expr] :as next-groups]]]
@@ -4656,11 +4656,11 @@
(recur (rest ~gxs)))
(keyword? k) (err "Invalid 'for' keyword " k)
next-groups
- `(let [iterys# ~(emit-bind next-groups)
- fs# (seq (iterys# ~next-expr))]
- (if fs#
- (concat fs# (~giter (rest ~gxs)))
- (recur (rest ~gxs))))
+ `(let [iterys# ~(emit-bind next-groups)
+ fs# (seq (iterys# ~next-expr))]
+ (if fs#
+ (concat fs# (~giter (rest ~gxs)))
+ (recur (rest ~gxs))))
:else `(cons ~body-expr
(~giter (rest ~gxs)))))]
(if next-groups
@@ -4682,10 +4682,10 @@
(recur
(unchecked-inc ~gi)))
(keyword? k)
- (err "Invalid 'for' keyword " k)
+ (err "Invalid 'for' keyword " k)
:else
- `(do (chunk-append ~gb ~body-expr)
- (recur (unchecked-inc ~gi)))))]
+ `(do (chunk-append ~gb ~body-expr)
+ (recur (unchecked-inc ~gi)))))]
`(fn ~giter [~gxs]
(lazy-seq
(loop [~gxs ~gxs]
@@ -4706,7 +4706,7 @@
(let [~bind (first ~gxs)]
~(do-mod mod-pairs)))))))))))]
`(let [iter# ~(emit-bind (to-groups seq-exprs))]
- (iter# ~(second seq-exprs)))))
+ (iter# ~(second seq-exprs)))))
(defmacro comment
"Ignores body, yields nil"
@@ -4739,8 +4739,8 @@
:added "1.0"
:static true}
[& xs]
- (with-out-str
- (apply pr xs)))
+ (with-out-str
+ (apply pr xs)))
(defn prn-str
"prn to a string, returning it"
@@ -4749,7 +4749,7 @@
:static true}
[& xs]
(with-out-str
- (apply prn xs)))
+ (apply prn xs)))
(defn print-str
"print to a string, returning it"
@@ -4757,8 +4757,8 @@
:added "1.0"
:static true}
[& xs]
- (with-out-str
- (apply print xs)))
+ (with-out-str
+ (apply print xs)))
(defn println-str
"println to a string, returning it"
@@ -4766,8 +4766,8 @@
:added "1.0"
:static true}
[& xs]
- (with-out-str
- (apply println xs)))
+ (with-out-str
+ (apply println xs)))
(import clojure.lang.ExceptionInfo clojure.lang.IExceptionInfo)
@@ -4785,9 +4785,9 @@
that carries a map of additional data."
{:added "1.4"}
([msg map]
- (elide-top-frames (ExceptionInfo. msg map) "clojure.core$ex_info"))
+ (elide-top-frames (ExceptionInfo. msg map) "clojure.core$ex_info"))
([msg map cause]
- (elide-top-frames (ExceptionInfo. msg map cause) "clojure.core$ex_info")))
+ (elide-top-frames (ExceptionInfo. msg map cause) "clojure.core$ex_info")))
(defn ex-data
"Returns exception data (a map) if ex is an IExceptionInfo.
@@ -4818,23 +4818,23 @@
logical true."
{:added "1.0"}
([x]
- (when *assert*
- `(when-not ~x
- (throw (new AssertionError (str "Assert failed: " (pr-str '~x)))))))
+ (when *assert*
+ `(when-not ~x
+ (throw (new AssertionError (str "Assert failed: " (pr-str '~x)))))))
([x message]
- (when *assert*
- `(when-not ~x
- (throw (new AssertionError (str "Assert failed: " ~message "\n" (pr-str '~x))))))))
+ (when *assert*
+ `(when-not ~x
+ (throw (new AssertionError (str "Assert failed: " ~message "\n" (pr-str '~x))))))))
(defn test
"test [v] finds fn at key :test in var metadata and calls it,
presuming failure will throw exception"
{:added "1.0"}
[v]
- (let [f (:test (meta v))]
- (if f
- (do (f) :ok)
- :no-test)))
+ (let [f (:test (meta v))]
+ (if f
+ (do (f) :ok)
+ :no-test)))
(defn re-pattern
"Returns an instance of java.util.regex.Pattern, for use, e.g. in
@@ -4853,7 +4853,7 @@
:added "1.0"
:static true}
[^java.util.regex.Pattern re s]
- (. re (matcher s)))
+ (. re (matcher s)))
(defn re-groups
"Returns the groups from the most recent match/find. If there are no
@@ -4863,13 +4863,13 @@
{:added "1.0"
:static true}
[^java.util.regex.Matcher m]
- (let [gc (. m (groupCount))]
- (if (zero? gc)
- (. m (group))
- (loop [ret [] c 0]
- (if (<= c gc)
- (recur (conj ret (. m (group c))) (inc c))
- ret)))))
+ (let [gc (. m (groupCount))]
+ (if (zero? gc)
+ (. m (group))
+ (loop [ret [] c 0]
+ (if (<= c gc)
+ (recur (conj ret (. m (group c))) (inc c))
+ ret)))))
(defn re-seq
"Returns a lazy sequence of successive matches of pattern in string,
@@ -4890,9 +4890,9 @@
{:added "1.0"
:static true}
[^java.util.regex.Pattern re s]
- (let [m (re-matcher re s)]
- (when (. m (matches))
- (re-groups m))))
+ (let [m (re-matcher re s)]
+ (when (. m (matches))
+ (re-groups m))))
(defn re-find
@@ -4926,7 +4926,7 @@
"same as defn, yielding non-public def"
{:added "1.0"}
[name & decls]
- (list* `defn (with-meta name (assoc (meta name) :private true)) decls))
+ (list* `defn (with-meta name (assoc (meta name) :private true)) decls))
(defn tree-seq
"Returns a lazy sequence of the nodes in a tree, via a depth-first walk.
@@ -4937,40 +4937,40 @@
tree."
{:added "1.0"
:static true}
- [branch? children root]
- (let [walk (fn walk [node]
- (lazy-seq
+ [branch? children root]
+ (let [walk (fn walk [node]
+ (lazy-seq
(cons node
- (when (branch? node)
- (mapcat walk (children node))))))]
- (walk root)))
+ (when (branch? node)
+ (mapcat walk (children node))))))]
+ (walk root)))
(defn file-seq
"A tree seq on java.io.Files"
{:added "1.0"
:static true}
[dir]
- (tree-seq
- (fn [^java.io.File f] (. f (isDirectory)))
- (fn [^java.io.File d] (seq (. d (listFiles))))
- dir))
+ (tree-seq
+ (fn [^java.io.File f] (. f (isDirectory)))
+ (fn [^java.io.File d] (seq (. d (listFiles))))
+ dir))
(defn xml-seq
"A tree seq on the xml elements as per xml/parse"
{:added "1.0"
:static true}
[root]
- (tree-seq
- (complement string?)
- (comp seq :content)
- root))
+ (tree-seq
+ (complement string?)
+ (comp seq :content)
+ root))
(defn special-symbol?
"Returns true if s names a special form"
{:added "1.0"
:static true}
[s]
- (contains? (. clojure.lang.Compiler specials) s))
+ (contains? (. clojure.lang.Compiler specials) s))
(defn var?
"Returns true if v is of type clojure.lang.Var"
@@ -5063,15 +5063,15 @@
{:added "1.0"
:static true}
([smap]
- (map #(if-let [e (find smap %)] (val e) %)))
+ (map #(if-let [e (find smap %)] (val e) %)))
([smap coll]
- (if (vector? coll)
- (reduce1 (fn [v i]
- (if-let [e (find smap (nth v i))]
- (assoc v i (val e))
- v))
- coll (range (count coll)))
- (map #(if-let [e (find smap %)] (val e) %) coll))))
+ (if (vector? coll)
+ (reduce1 (fn [v i]
+ (if-let [e (find smap (nth v i))]
+ (assoc v i (val e))
+ v))
+ coll (range (count coll)))
+ (map #(if-let [e (find smap %)] (val e) %) coll))))
(defmacro dosync
"Runs the exprs (in an implicit do) in a transaction that encompasses
@@ -5093,12 +5093,12 @@
HALF_EVEN, UP, DOWN and UNNECESSARY; it defaults to HALF_UP."
{:added "1.0"}
[precision & exprs]
- (let [[body rm] (if (= (first exprs) :rounding)
- [(next (next exprs))
- `((. java.math.RoundingMode ~(second exprs)))]
- [exprs nil])]
- `(binding [*math-context* (java.math.MathContext. ~precision ~@rm)]
- ~@body)))
+ (let [[body rm] (if (= (first exprs) :rounding)
+ [(next (next exprs))
+ `((. java.math.RoundingMode ~(second exprs)))]
+ [exprs nil])]
+ `(binding [*math-context* (java.math.MathContext. ~precision ~@rm)]
+ ~@body)))
(defn mk-bound-fn
{:private true}
@@ -5406,8 +5406,8 @@
([s] (seque 100 s))
([n-or-q s]
(let [^BlockingQueue q (if (instance? BlockingQueue n-or-q)
- n-or-q
- (LinkedBlockingQueue. (int n-or-q)))
+ n-or-q
+ (LinkedBlockingQueue. (int n-or-q)))
NIL (Object.) ;nil sentinel since LBQ doesn't support nils
agt (agent (lazy-seq s)) ; never start with nil; that signifies we've already put eos
log-error (fn [q e]
@@ -5430,13 +5430,13 @@
(log-error q e))))))
drain (fn drain []
(lazy-seq
- (let [x (.take q)]
- (if (identical? x q) ;q itself is eos sentinel
- (do @agt nil) ;touch agent just to propagate errors
- (do
- (send-off agt fill)
- (release-pending-sends)
- (cons (if (identical? x NIL) nil x) (drain)))))))]
+ (let [x (.take q)]
+ (if (identical? x q) ;q itself is eos sentinel
+ (do @agt nil) ;touch agent just to propagate errors
+ (do
+ (send-off agt fill)
+ (release-pending-sends)
+ (cons (if (identical? x NIL) nil x) (drain)))))))]
(send-off agt fill)
(drain))))
@@ -5452,33 +5452,33 @@
(defn- is-runtime-annotation? [^Class c]
(boolean
- (and (is-annotation? c)
- (when-let [^java.lang.annotation.Retention r
- (.getAnnotation c java.lang.annotation.Retention)]
- (= (.value r) java.lang.annotation.RetentionPolicy/RUNTIME)))))
+ (and (is-annotation? c)
+ (when-let [^java.lang.annotation.Retention r
+ (.getAnnotation c java.lang.annotation.Retention)]
+ (= (.value r) java.lang.annotation.RetentionPolicy/RUNTIME)))))
(defn- descriptor [^Class c] (clojure.asm.Type/getDescriptor c))
(declare process-annotation)
(defn- add-annotation [^clojure.asm.AnnotationVisitor av name v]
(cond
- (vector? v) (let [avec (.visitArray av name)]
- (doseq [vval v]
- (add-annotation avec "value" vval))
- (.visitEnd avec))
- (symbol? v) (let [ev (eval v)]
- (cond
- (instance? java.lang.Enum ev)
- (.visitEnum av name (descriptor (class ev)) (str ev))
- (class? ev) (.visit av name (clojure.asm.Type/getType ev))
- :else (throw (IllegalArgumentException.
- (str "Unsupported annotation value: " v " of class " (class ev))))))
- (seq? v) (let [[nested nv] v
- c (resolve nested)
- nav (.visitAnnotation av name (descriptor c))]
- (process-annotation nav nv)
- (.visitEnd nav))
- :else (.visit av name v)))
+ (vector? v) (let [avec (.visitArray av name)]
+ (doseq [vval v]
+ (add-annotation avec "value" vval))
+ (.visitEnd avec))
+ (symbol? v) (let [ev (eval v)]
+ (cond
+ (instance? java.lang.Enum ev)
+ (.visitEnum av name (descriptor (class ev)) (str ev))
+ (class? ev) (.visit av name (clojure.asm.Type/getType ev))
+ :else (throw (IllegalArgumentException.
+ (str "Unsupported annotation value: " v " of class " (class ev))))))
+ (seq? v) (let [[nested nv] v
+ c (resolve nested)
+ nav (.visitAnnotation av name (descriptor c))]
+ (process-annotation nav nv)
+ (.visitEnd nav))
+ :else (.visit av name v)))
(defn- process-annotation [av v]
(if (map? v)
@@ -5489,18 +5489,18 @@
(defn- add-annotations
([visitor m] (add-annotations visitor m nil))
([visitor m i]
- (doseq [[k v] m]
- (when (symbol? k)
- (when-let [c (resolve k)]
- (when (is-annotation? c)
- ;this is known duck/reflective as no common base of ASM Visitors
- (let [av (if i
- (.visitParameterAnnotation visitor i (descriptor c)
- (is-runtime-annotation? c))
- (.visitAnnotation visitor (descriptor c)
- (is-runtime-annotation? c)))]
- (process-annotation av v)
- (.visitEnd av))))))))
+ (doseq [[k v] m]
+ (when (symbol? k)
+ (when-let [c (resolve k)]
+ (when (is-annotation? c)
+ ;this is known duck/reflective as no common base of ASM Visitors
+ (let [av (if i
+ (.visitParameterAnnotation visitor i (descriptor c)
+ (is-runtime-annotation? c))
+ (.visitAnnotation visitor (descriptor c)
+ (is-runtime-annotation? c)))]
+ (process-annotation av v)
+ (.visitEnd av))))))))
(defn alter-var-root
"Atomically alters the root binding of var v by applying f to its
@@ -5590,10 +5590,10 @@
{:added "1.0"}
([tag] (parents global-hierarchy tag))
([h tag] (not-empty
- (let [tp (get (:parents h) tag)]
- (if (class? tag)
- (into1 (set (bases tag)) tp)
- tp)))))
+ (let [tp (get (:parents h) tag)]
+ (if (class? tag)
+ (into1 (set (bases tag)) tp)
+ tp)))))
(defn ancestors
"Returns the immediate and indirect parents of tag, either via a Java type
@@ -5603,13 +5603,13 @@
{:added "1.0"}
([tag] (ancestors global-hierarchy tag))
([h tag] (not-empty
- (let [ta (get (:ancestors h) tag)]
- (if (class? tag)
- (let [superclasses (set (supers tag))]
- (reduce1 into1 superclasses
- (cons ta
- (map #(get (:ancestors h) %) superclasses))))
- ta)))))
+ (let [ta (get (:ancestors h) tag)]
+ (if (class? tag)
+ (let [superclasses (set (supers tag))]
+ (reduce1 into1 superclasses
+ (cons ta
+ (map #(get (:ancestors h) %) superclasses))))
+ ta)))))
(defn descendants
"Returns the immediate and indirect children of tag, through a
@@ -5645,19 +5645,19 @@
ta (:ancestors h)
tf (fn [m source sources target targets]
(reduce1 (fn [ret k]
- (assoc ret k
- (reduce1 conj (get targets k #{}) (cons target (targets target)))))
- m (cons source (sources source))))]
+ (assoc ret k
+ (reduce1 conj (get targets k #{}) (cons target (targets target)))))
+ m (cons source (sources source))))]
(or
- (when-not (contains? (tp tag) parent)
- (when (contains? (ta tag) parent)
- (throw (Exception. (print-str tag "already has" parent "as ancestor"))))
- (when (contains? (ta parent) tag)
- (throw (Exception. (print-str "Cyclic derivation:" parent "has" tag "as ancestor"))))
- {:parents (assoc (:parents h) tag (conj (get tp tag #{}) parent))
- :ancestors (tf (:ancestors h) tag td parent ta)
- :descendants (tf (:descendants h) parent ta tag td)})
- h))))
+ (when-not (contains? (tp tag) parent)
+ (when (contains? (ta tag) parent)
+ (throw (Exception. (print-str tag "already has" parent "as ancestor"))))
+ (when (contains? (ta parent) tag)
+ (throw (Exception. (print-str "Cyclic derivation:" parent "has" tag "as ancestor"))))
+ {:parents (assoc (:parents h) tag (conj (get tp tag #{}) parent))
+ :ancestors (tf (:ancestors h) tag td parent ta)
+ :descendants (tf (:descendants h) parent ta tag td)})
+ h))))
(declare flatten)
@@ -5668,18 +5668,18 @@
{:added "1.0"}
([tag parent] (alter-var-root #'global-hierarchy underive tag parent) nil)
([h tag parent]
- (let [parentMap (:parents h)
- childsParents (if (parentMap tag)
- (disj (parentMap tag) parent) #{})
- newParents (if (not-empty childsParents)
- (assoc parentMap tag childsParents)
- (dissoc parentMap tag))
- deriv-seq (flatten (map #(cons (key %) (interpose (key %) (val %)))
- (seq newParents)))]
- (if (contains? (parentMap tag) parent)
- (reduce1 #(apply derive %1 %2) (make-hierarchy)
- (partition 2 deriv-seq))
- h))))
+ (let [parentMap (:parents h)
+ childsParents (if (parentMap tag)
+ (disj (parentMap tag) parent) #{})
+ newParents (if (not-empty childsParents)
+ (assoc parentMap tag childsParents)
+ (dissoc parentMap tag))
+ deriv-seq (flatten (map #(cons (key %) (interpose (key %) (val %)))
+ (seq newParents)))]
+ (if (contains? (parentMap tag) parent)
+ (reduce1 #(apply derive %1 %2) (make-hierarchy)
+ (partition 2 deriv-seq))
+ h))))
(defn distinct?
@@ -5704,19 +5704,19 @@
the rows in the java.sql.ResultSet rs"
{:added "1.0"}
[^java.sql.ResultSet rs]
- (let [rsmeta (. rs (getMetaData))
- idxs (range 1 (inc (. rsmeta (getColumnCount))))
- keys (map (comp keyword #(.toLowerCase ^String %))
- (map (fn [i] (. rsmeta (getColumnLabel i))) idxs))
- check-keys
- (or (apply distinct? keys)
- (throw (Exception. "ResultSet must have unique column labels")))
- row-struct (apply create-struct keys)
- row-values (fn [] (map (fn [^Integer i] (. rs (getObject i))) idxs))
- rows (fn thisfn []
- (when (. rs (next))
- (cons (apply struct row-struct (row-values)) (lazy-seq (thisfn)))))]
- (rows)))
+ (let [rsmeta (. rs (getMetaData))
+ idxs (range 1 (inc (. rsmeta (getColumnCount))))
+ keys (map (comp keyword #(.toLowerCase ^String %))
+ (map (fn [i] (. rsmeta (getColumnLabel i))) idxs))
+ check-keys
+ (or (apply distinct? keys)
+ (throw (Exception. "ResultSet must have unique column labels")))
+ row-struct (apply create-struct keys)
+ row-values (fn [] (map (fn [^Integer i] (. rs (getObject i))) idxs))
+ rows (fn thisfn []
+ (when (. rs (next))
+ (cons (apply struct row-struct (row-values)) (lazy-seq (thisfn)))))]
+ (rows)))
(defn iterator-seq
"Returns a seq on a java.util.Iterator. Note that most collections
@@ -5757,9 +5757,9 @@
(. clojure.lang.Var (pushThreadBindings {clojure.lang.Compiler/LOADER
(.getClassLoader (.getClass ^Object loading#))}))
(try
- ~@body
- (finally
- (. clojure.lang.Var (popThreadBindings)))))))
+ ~@body
+ (finally
+ (. clojure.lang.Var (popThreadBindings)))))))
(defmacro ns
"Sets *ns* to the namespace named by name (unevaluated), creating it
@@ -5788,7 +5788,7 @@
(let [process-reference
(fn [[kname & args]]
`(~(symbol "clojure.core" (clojure.core/name kname))
- ~@(map #(list 'quote %) args)))
+ ~@(map #(list 'quote %) args)))
docstring (when (string? (first references)) (first references))
references (if docstring (next references) references)
name (if docstring
@@ -5801,8 +5801,8 @@
name)
gen-class-clause (first (filter #(= :gen-class (first %)) references))
gen-class-call
- (when gen-class-clause
- (list* `gen-class :name (.replace (str name) \- \_) :impl-ns name :main true (next gen-class-clause)))
+ (when gen-class-clause
+ (list* `gen-class :name (.replace (str name) \- \_) :impl-ns name :main true (next gen-class-clause)))
references (remove #(= :gen-class (first %)) references)
;ns-effect (clojure.core/in-ns name)
name-metadata (meta name)]
@@ -5811,13 +5811,13 @@
~@(when name-metadata
`((.resetMeta (clojure.lang.Namespace/find '~name) ~name-metadata)))
(with-loading-context
- ~@(when gen-class-call (list gen-class-call))
- ~@(when (and (not= name 'clojure.core) (not-any? #(= :refer-clojure (first %)) references))
- `((clojure.core/refer '~'clojure.core)))
- ~@(map process-reference references))
- (if (.equals '~name 'clojure.core)
- nil
- (do (dosync (commute @#'*loaded-libs* conj '~name)) nil)))))
+ ~@(when gen-class-call (list gen-class-call))
+ ~@(when (and (not= name 'clojure.core) (not-any? #(= :refer-clojure (first %)) references))
+ `((clojure.core/refer '~'clojure.core)))
+ ~@(map process-reference references))
+ (if (.equals '~name 'clojure.core)
+ nil
+ (do (dosync (commute @#'*loaded-libs* conj '~name)) nil)))))
(defmacro refer-clojure
"Same as (refer 'clojure.core <filters>)"
@@ -5838,17 +5838,17 @@
(defonce ^:dynamic
^{:private true
- :doc "A ref to a sorted set of symbols representing loaded libs"}
+ :doc "A ref to a sorted set of symbols representing loaded libs"}
*loaded-libs* (ref (sorted-set)))
(defonce ^:dynamic
^{:private true
- :doc "A stack of paths currently being loaded by this thread"}
+ :doc "A stack of paths currently being loaded by this thread"}
*pending-paths* ())
(defonce ^:dynamic
^{:private true :doc
- "True while a verbose load is pending"}
+ "True while a verbose load is pending"}
*loading-verbosely* false)
(defn- throw-if
@@ -5862,10 +5862,10 @@
trace (into-array StackTraceElement (drop 2 (drop-while boring? raw-trace)))]
(.setStackTrace exception trace)
(throw (clojure.lang.Compiler$CompilerException.
- *file*
- (.deref clojure.lang.Compiler/LINE)
- (.deref clojure.lang.Compiler/COLUMN)
- exception)))))
+ *file*
+ (.deref clojure.lang.Compiler/LINE)
+ (.deref clojure.lang.Compiler/COLUMN)
+ exception)))))
(defn- libspec?
"Returns true if x is a libspec"
@@ -5873,8 +5873,8 @@
(or (symbol? x)
(and (vector? x)
(or
- (nil? (second x))
- (keyword? (second x))))))
+ (nil? (second x))
+ (keyword? (second x))))))
(defn- prependss
"Prepends a symbol or a seq to coll"
@@ -5911,7 +5911,7 @@
lib (root-resource lib))
(when require
(dosync
- (commute *loaded-libs* conj lib))))
+ (commute *loaded-libs* conj lib))))
(defn- load-all
"Loads a lib given its name and forces a load of any libs it directly or
@@ -5920,10 +5920,10 @@
can be skipped."
[lib need-ns require]
(dosync
- (commute *loaded-libs* #(reduce1 conj %1 %2)
- (binding [*loaded-libs* (ref (sorted-set))]
- (load-one lib need-ns require)
- @*loaded-libs*))))
+ (commute *loaded-libs* #(reduce1 conj %1 %2)
+ (binding [*loaded-libs* (ref (sorted-set))]
+ (load-one lib need-ns require)
+ @*loaded-libs*))))
(defn- load-lib
"Loads a lib with options"
@@ -5978,7 +5978,7 @@
unsupported (seq (remove supported flags))]
(throw-if unsupported
(apply str "Unsupported option(s) supplied: "
- (interpose \, unsupported))))
+ (interpose \, unsupported))))
; check a load target was specified
(throw-if (not (seq args)) "Nothing specified to load")
(doseq [arg args]
@@ -6115,8 +6115,8 @@ fails, attempts to require sym's namespace and retries."
[& paths]
(doseq [^String path paths]
(let [^String path (if (.startsWith path "/")
- path
- (str (root-directory (ns-name *ns*)) \/ path))]
+ path
+ (str (root-directory (ns-name *ns*)) \/ path))]
(when *loading-verbosely*
(printf "(clojure.core/load \"%s\")\n" path)
(flush))
@@ -6146,17 +6146,17 @@ fails, attempts to require sym's namespace and retries."
{:added "1.2"
:static true}
([m ks]
- (reduce1 get m ks))
+ (reduce1 get m ks))
([m ks not-found]
- (loop [sentinel (Object.)
- m m
- ks (seq ks)]
- (if ks
- (let [m (get m (first ks) sentinel)]
- (if (identical? sentinel m)
- not-found
- (recur sentinel m (next ks))))
- m))))
+ (loop [sentinel (Object.)
+ m m
+ ks (seq ks)]
+ (if ks
+ (let [m (get m (first ks) sentinel)]
+ (if (identical? sentinel m)
+ not-found
+ (recur sentinel m (next ks))))
+ m))))
(defn assoc-in
"Associates a value in a nested associative structure, where ks is a
@@ -6178,12 +6178,12 @@ fails, attempts to require sym's namespace and retries."
{:added "1.0"
:static true}
([m ks f & args]
- (let [up (fn up [m ks f args]
- (let [[k & ks] ks]
- (if ks
- (assoc m k (up (get m k) ks f args))
- (assoc m k (apply f (get m k) args)))))]
- (up m ks f args))))
+ (let [up (fn up [m ks f args]
+ (let [[k & ks] ks]
+ (if ks
+ (assoc m k (up (get m k) ks f args))
+ (assoc m k (apply f (get m k) args)))))]
+ (up m ks f args))))
(defn update
"'Updates' a value in an associative structure, where k is a
@@ -6242,32 +6242,32 @@ fails, attempts to require sym's namespace and retries."
(defn associative?
- "Returns true if coll implements Associative"
- {:added "1.0"
- :static true}
+ "Returns true if coll implements Associative"
+ {:added "1.0"
+ :static true}
[coll] (instance? clojure.lang.Associative coll))
(defn sequential?
- "Returns true if coll implements Sequential"
- {:added "1.0"
- :static true}
+ "Returns true if coll implements Sequential"
+ {:added "1.0"
+ :static true}
[coll] (instance? clojure.lang.Sequential coll))
(defn sorted?
- "Returns true if coll implements Sorted"
- {:added "1.0"
+ "Returns true if coll implements Sorted"
+ {:added "1.0"
:static true}
[coll] (instance? clojure.lang.Sorted coll))
(defn counted?
- "Returns true if coll implements count in constant time"
- {:added "1.0"
+ "Returns true if coll implements count in constant time"
+ {:added "1.0"
:static true}
[coll] (instance? clojure.lang.Counted coll))
(defn reversible?
- "Returns true if coll implements Reversible"
- {:added "1.0"
+ "Returns true if coll implements Reversible"
+ {:added "1.0"
:static true}
[coll] (instance? clojure.lang.Reversible coll))
@@ -6277,24 +6277,24 @@ fails, attempts to require sym's namespace and retries."
[coll] (instance? clojure.lang.Indexed coll))
(def ^:dynamic
- ^{:doc "bound in a repl thread to the most recent value printed"
- :added "1.0"}
- *1)
+ ^{:doc "bound in a repl thread to the most recent value printed"
+ :added "1.0"}
+ *1)
(def ^:dynamic
- ^{:doc "bound in a repl thread to the second most recent value printed"
- :added "1.0"}
- *2)
+ ^{:doc "bound in a repl thread to the second most recent value printed"
+ :added "1.0"}
+ *2)
(def ^:dynamic
- ^{:doc "bound in a repl thread to the third most recent value printed"
- :added "1.0"}
- *3)
+ ^{:doc "bound in a repl thread to the third most recent value printed"
+ :added "1.0"}
+ *3)
(def ^:dynamic
- ^{:doc "bound in a repl thread to the most recent exception caught by the repl"
- :added "1.0"}
- *e)
+ ^{:doc "bound in a repl thread to the most recent exception caught by the repl"
+ :added "1.0"}
+ *e)
(defn trampoline
"trampoline can be used to convert algorithms requiring mutual
@@ -6307,12 +6307,12 @@ fails, attempts to require sym's namespace and retries."
{:added "1.0"
:static true}
([f]
- (let [ret (f)]
- (if (fn? ret)
- (recur ret)
- ret)))
+ (let [ret (f)]
+ (if (fn? ret)
+ (recur ret)
+ ret)))
([f & args]
- (trampoline #(apply f args))))
+ (trampoline #(apply f args))))
(defn intern
"Finds or creates a var named by the symbol name in the namespace
@@ -6322,13 +6322,13 @@ fails, attempts to require sym's namespace and retries."
{:added "1.0"
:static true}
([ns ^clojure.lang.Symbol name]
- (let [v (clojure.lang.Var/intern (the-ns ns) name)]
- (when (meta name) (.setMeta v (meta name)))
- v))
+ (let [v (clojure.lang.Var/intern (the-ns ns) name)]
+ (when (meta name) (.setMeta v (meta name)))
+ v))
([ns name val]
- (let [v (clojure.lang.Var/intern (the-ns ns) name val)]
- (when (meta name) (.setMeta v (meta name)))
- v)))
+ (let [v (clojure.lang.Var/intern (the-ns ns) name val)]
+ (when (meta name) (.setMeta v (meta name)))
+ v)))
(defmacro while
"Repeatedly executes body while test expression is true. Presumes
@@ -6382,17 +6382,17 @@ fails, attempts to require sym's namespace and retries."
gexpr (gensym "expr__")
emit (fn emit [pred expr args]
(let [[[a b c :as clause] more]
- (split-at (if (= :>> (second args)) 3 2) args)
- n (count clause)]
+ (split-at (if (= :>> (second args)) 3 2) args)
+ n (count clause)]
(cond
- (= 0 n) `(throw (IllegalArgumentException. (str "No matching clause: " ~expr)))
- (= 1 n) a
- (= 2 n) `(if (~pred ~a ~expr)
- ~b
- ~(emit pred expr more))
- :else `(if-let [p# (~pred ~a ~expr)]
- (~c p#)
- ~(emit pred expr more)))))]
+ (= 0 n) `(throw (IllegalArgumentException. (str "No matching clause: " ~expr)))
+ (= 1 n) a
+ (= 2 n) `(if (~pred ~a ~expr)
+ ~b
+ ~(emit pred expr more))
+ :else `(if-let [p# (~pred ~a ~expr)]
+ (~c p#)
+ ~(emit pred expr more)))))]
`(let [~gpred ~pred
~gexpr ~expr]
~(emit gpred gexpr clauses))))
@@ -6502,7 +6502,7 @@ fails, attempts to require sym's namespace and retries."
{:added "1.0"})
(add-doc-and-meta *read-eval*
- "Defaults to true (or value specified by system property, see below)
+ "Defaults to true (or value specified by system property, see below)
***This setting implies that the full power of the reader is in play,
including syntax that can cause code to execute. It should never be
used with untrusted sources. See also: clojure.edn/read.***
@@ -6732,11 +6732,11 @@ fails, attempts to require sym's namespace and retries."
(throw (IllegalArgumentException. (str "Duplicate case test constant: " test)))
(assoc m test expr)))
pairs (reduce1
- (fn [m [test expr]]
- (if (seq? test)
- (reduce1 #(assoc-test %1 %2 expr) m test)
- (assoc-test m test expr)))
- {} pairs)
+ (fn [m [test expr]]
+ (if (seq? test)
+ (reduce1 #(assoc-test %1 %2 expr) m test)
+ (assoc-test m test expr)))
+ {} pairs)
tests (keys pairs)
thens (vals pairs)
mode (cond
@@ -6819,30 +6819,30 @@ fails, attempts to require sym's namespace and retries."
items, returns val and f is not called."
{:added "1.0"}
([f coll]
- (if (instance? clojure.lang.IReduce coll)
- (.reduce ^clojure.lang.IReduce coll f)
- (clojure.core.protocols/coll-reduce coll f)))
+ (if (instance? clojure.lang.IReduce coll)
+ (.reduce ^clojure.lang.IReduce coll f)
+ (clojure.core.protocols/coll-reduce coll f)))
([f val coll]
- (if (instance? clojure.lang.IReduceInit coll)
- (.reduce ^clojure.lang.IReduceInit coll f val)
- (clojure.core.protocols/coll-reduce coll f val))))
+ (if (instance? clojure.lang.IReduceInit coll)
+ (.reduce ^clojure.lang.IReduceInit coll f val)
+ (clojure.core.protocols/coll-reduce coll f val))))
(extend-protocol clojure.core.protocols/IKVReduce
- nil
- (kv-reduce
- [_ f init]
- init)
-
- ;;slow path default
- clojure.lang.IPersistentMap
- (kv-reduce
- [amap f init]
- (reduce (fn [ret [k v]] (f ret k v)) init amap))
-
- clojure.lang.IKVReduce
- (kv-reduce
- [amap f init]
- (.kvreduce amap f init)))
+ nil
+ (kv-reduce
+ [_ f init]
+ init)
+
+ ;;slow path default
+ clojure.lang.IPersistentMap
+ (kv-reduce
+ [amap f init]
+ (reduce (fn [ret [k v]] (f ret k v)) init amap))
+
+ clojure.lang.IKVReduce
+ (kv-reduce
+ [amap f init]
+ (.kvreduce amap f init)))
(defn reduce-kv
"Reduces an associative collection. f should be a function of 3
@@ -6853,7 +6853,7 @@ fails, attempts to require sym's namespace and retries."
where the keys will be the ordinals."
{:added "1.4"}
([f init coll]
- (clojure.core.protocols/kv-reduce coll f init)))
+ (clojure.core.protocols/kv-reduce coll f init)))
(defn completing
"Takes a reducing function f of 2 args and returns a fn suitable for
@@ -6862,10 +6862,10 @@ fails, attempts to require sym's namespace and retries."
{:added "1.7"}
([f] (completing f identity))
([f cf]
- (fn
- ([] (f))
- ([x] (cf x))
- ([x y] (f x y)))))
+ (fn
+ ([] (f))
+ ([x] (cf x))
+ ([x y] (f x y)))))
(defn transduce
"reduce with a transformation of f (xf). If init is not
@@ -6878,11 +6878,11 @@ fails, attempts to require sym's namespace and retries."
certain transforms may inject or skip items." {:added "1.7"}
([xform f coll] (transduce xform f (f) coll))
([xform f init coll]
- (let [f (xform f)
- ret (if (instance? clojure.lang.IReduceInit coll)
- (.reduce ^clojure.lang.IReduceInit coll f init)
- (clojure.core.protocols/coll-reduce coll f init))]
- (f ret))))
+ (let [f (xform f)
+ ret (if (instance? clojure.lang.IReduceInit coll)
+ (.reduce ^clojure.lang.IReduceInit coll f init)
+ (clojure.core.protocols/coll-reduce coll f init))]
+ (f ret))))
(defn into
"Returns a new coll consisting of to-coll with all of the items of
@@ -6892,13 +6892,13 @@ fails, attempts to require sym's namespace and retries."
([] [])
([to] to)
([to from]
- (if (instance? clojure.lang.IEditableCollection to)
- (with-meta (persistent! (reduce conj! (transient to) from)) (meta to))
- (reduce conj to from)))
+ (if (instance? clojure.lang.IEditableCollection to)
+ (with-meta (persistent! (reduce conj! (transient to) from)) (meta to))
+ (reduce conj to from)))
([to xform from]
- (if (instance? clojure.lang.IEditableCollection to)
- (with-meta (persistent! (transduce xform conj! (transient to) from)) (meta to))
- (transduce xform conj to from))))
+ (if (instance? clojure.lang.IEditableCollection to)
+ (with-meta (persistent! (transduce xform conj! (transient to) from)) (meta to))
+ (transduce xform conj to from))))
(defn mapv
"Returns a vector consisting of the result of applying f to the
@@ -6909,14 +6909,14 @@ fails, attempts to require sym's namespace and retries."
{:added "1.4"
:static true}
([f coll]
- (-> (reduce (fn [v o] (conj! v (f o))) (transient []) coll)
- persistent!))
+ (-> (reduce (fn [v o] (conj! v (f o))) (transient []) coll)
+ persistent!))
([f c1 c2]
- (into [] (map f c1 c2)))
+ (into [] (map f c1 c2)))
([f c1 c2 c3]
- (into [] (map f c1 c2 c3)))
+ (into [] (map f c1 c2 c3)))
([f c1 c2 c3 & colls]
- (into [] (apply map f c1 c2 c3 colls))))
+ (into [] (apply map f c1 c2 c3 colls))))
(defn filterv
"Returns a vector of the items in coll for which
@@ -6945,11 +6945,11 @@ fails, attempts to require sym's namespace and retries."
{:added "1.0"
:tag String}
([f & opts]
- (let [opts (normalize-slurp-opts opts)
- sw (java.io.StringWriter.)]
- (with-open [^java.io.Reader r (apply jio/reader f opts)]
- (jio/copy r sw)
- (.toString sw)))))
+ (let [opts (normalize-slurp-opts opts)
+ sw (java.io.StringWriter.)]
+ (with-open [^java.io.Reader r (apply jio/reader f opts)]
+ (jio/copy r sw)
+ (.toString sw)))))
(defn spit
"Opposite of slurp. Opens f with writer, writes content, then
@@ -6972,15 +6972,15 @@ fails, attempts to require sym's namespace and retries."
(let [f (binding-conveyor-fn f)
fut (.submit clojure.lang.Agent/soloExecutor ^Callable f)]
(reify
- clojure.lang.IDeref
- (deref [_] (deref-future fut))
- clojure.lang.IBlockingDeref
- (deref
- [_ timeout-ms timeout-val]
- (deref-future fut timeout-ms timeout-val))
- clojure.lang.IPending
- (isRealized [_] (.isDone fut))
- java.util.concurrent.Future
+ clojure.lang.IDeref
+ (deref [_] (deref-future fut))
+ clojure.lang.IBlockingDeref
+ (deref
+ [_ timeout-ms timeout-val]
+ (deref-future fut timeout-ms timeout-val))
+ clojure.lang.IPending
+ (isRealized [_] (.isDone fut))
+ java.util.concurrent.Future
(get [_] (.get fut))
(get [_ timeout unit] (.get fut timeout unit))
(isCancelled [_] (.isCancelled fut))
@@ -7022,16 +7022,16 @@ fails, attempts to require sym's namespace and retries."
rets (map #(future (f %)) coll)
step (fn step [[x & xs :as vs] fs]
(lazy-seq
- (if-let [s (seq fs)]
- (cons (deref x) (step xs (rest s)))
- (map deref vs))))]
+ (if-let [s (seq fs)]
+ (cons (deref x) (step xs (rest s)))
+ (map deref vs))))]
(step rets (drop n rets))))
([f coll & colls]
(let [step (fn step [cs]
(lazy-seq
- (let [ss (map seq cs)]
- (when (every? identity ss)
- (cons (map first ss) (step (map rest ss)))))))]
+ (let [ss (map seq cs)]
+ (when (every? identity ss)
+ (cons (map first ss) (step (map rest ss)))))))]
(pmap #(apply f %) (step (cons coll colls))))))
(defn pcalls
@@ -7053,15 +7053,15 @@ fails, attempts to require sym's namespace and retries."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; clojure version number ;;;;;;;;;;;;;;;;;;;;;;
(let [properties (with-open [version-stream (.getResourceAsStream
- (clojure.lang.RT/baseLoader)
- "clojure/version.properties")]
+ (clojure.lang.RT/baseLoader)
+ "clojure/version.properties")]
(doto (new java.util.Properties)
(.load version-stream)))
version-string (.getProperty properties "version")
[_ major minor incremental qualifier snapshot]
(re-matches
- #"(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9_]+))?(?:-(SNAPSHOT))?"
- version-string)
+ #"(\d+)\.(\d+)\.(\d+)(?:-([a-zA-Z0-9_]+))?(?:-(SNAPSHOT))?"
+ version-string)
clojure-version {:major (Integer/valueOf ^String major)
:minor (Integer/valueOf ^String minor)
:incremental (Integer/valueOf ^String incremental)
@@ -7105,24 +7105,24 @@ fails, attempts to require sym's namespace and retries."
(let [d (java.util.concurrent.CountDownLatch. 1)
v (atom d)]
(reify
- clojure.lang.IDeref
- (deref [_] (.await d) @v)
- clojure.lang.IBlockingDeref
- (deref
+ clojure.lang.IDeref
+ (deref [_] (.await d) @v)
+ clojure.lang.IBlockingDeref
+ (deref
[_ timeout-ms timeout-val]
(if (.await d timeout-ms java.util.concurrent.TimeUnit/MILLISECONDS)
@v
timeout-val))
- clojure.lang.IPending
+ clojure.lang.IPending
(isRealized [this]
- (zero? (.getCount d)))
- clojure.lang.IFn
- (invoke
- [this x]
- (when (and (pos? (.getCount d))
- (compare-and-set! v d x))
- (.countDown d)
- this)))))
+ (zero? (.getCount d)))
+ clojure.lang.IFn
+ (invoke
+ [this x]
+ (when (and (pos? (.getCount d))
+ (compare-and-set! v d x))
+ (.countDown d)
+ this)))))
(defn deliver
"Delivers the supplied value to the promise, releasing any pending
@@ -7151,11 +7151,11 @@ fails, attempts to require sym's namespace and retries."
:static true}
[f coll]
(persistent!
- (reduce
- (fn [ret x]
- (let [k (f x)]
- (assoc! ret k (conj (get ret k []) x))))
- (transient {}) coll)))
+ (reduce
+ (fn [ret x]
+ (let [k (f x)]
+ (assoc! ret k (conj (get ret k []) x))))
+ (transient {}) coll)))
(defn partition-by
"Applies f to each value in coll, splitting it each time f returns a
@@ -7164,41 +7164,41 @@ fails, attempts to require sym's namespace and retries."
{:added "1.2"
:static true}
([f]
- (fn [rf]
- (let [a (java.util.ArrayList.)
- pv (volatile! ::none)]
- (fn
- ([] (rf))
- ([result]
- (let [result (if (.isEmpty a)
- result
- (let [v (vec (.toArray a))]
- ;;clear first!
- (.clear a)
- (unreduced (rf result v))))]
- (rf result)))
- ([result input]
- (let [pval @pv
- val (f input)]
- (vreset! pv val)
- (if (or (identical? pval ::none)
- (= val pval))
- (do
- (.add a input)
- result)
- (let [v (vec (.toArray a))]
- (.clear a)
- (let [ret (rf result v)]
- (when-not (reduced? ret)
- (.add a input))
- ret)))))))))
+ (fn [rf]
+ (let [a (java.util.ArrayList.)
+ pv (volatile! ::none)]
+ (fn
+ ([] (rf))
+ ([result]
+ (let [result (if (.isEmpty a)
+ result
+ (let [v (vec (.toArray a))]
+ ;;clear first!
+ (.clear a)
+ (unreduced (rf result v))))]
+ (rf result)))
+ ([result input]
+ (let [pval @pv
+ val (f input)]
+ (vreset! pv val)
+ (if (or (identical? pval ::none)
+ (= val pval))
+ (do
+ (.add a input)
+ result)
+ (let [v (vec (.toArray a))]
+ (.clear a)
+ (let [ret (rf result v)]
+ (when-not (reduced? ret)
+ (.add a input))
+ ret)))))))))
([f coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (let [fst (first s)
- fv (f fst)
- run (cons fst (take-while #(= fv (f %)) (next s)))]
- (cons run (partition-by f (lazy-seq (drop (count run) s)))))))))
+ (lazy-seq
+ (when-let [s (seq coll)]
+ (let [fst (first s)
+ fv (f fst)
+ run (cons fst (take-while #(= fv (f %)) (next s)))]
+ (cons run (partition-by f (lazy-seq (drop (count run) s)))))))))
(defn frequencies
"Returns a map from distinct items in coll to the number of times
@@ -7207,26 +7207,26 @@ fails, attempts to require sym's namespace and retries."
:static true}
[coll]
(persistent!
- (reduce (fn [counts x]
- (assoc! counts x (inc (get counts x 0))))
- (transient {}) coll)))
+ (reduce (fn [counts x]
+ (assoc! counts x (inc (get counts x 0))))
+ (transient {}) coll)))
(defn reductions
"Returns a lazy seq of the intermediate values of the reduction (as
per reduce) of coll by f, starting with init."
{:added "1.2"}
([f coll]
- (lazy-seq
- (if-let [s (seq coll)]
- (reductions f (first s) (rest s))
- (list (f)))))
+ (lazy-seq
+ (if-let [s (seq coll)]
+ (reductions f (first s) (rest s))
+ (list (f)))))
([f init coll]
- (if (reduced? init)
- (list @init)
- (cons init
- (lazy-seq
- (when-let [s (seq coll)]
- (reductions f (f init (first s)) (rest s))))))))
+ (if (reduced? init)
+ (list @init)
+ (cons init
+ (lazy-seq
+ (when-let [s (seq coll)]
+ (reductions f (f init (first s)) (rest s))))))))
(defn rand-nth
"Return a random element of the (sequential) collection. Will have
@@ -7249,27 +7249,27 @@ fails, attempts to require sym's namespace and retries."
(fn
([] (rf))
([result]
- (let [result (if (.isEmpty a)
- result
- (let [v (vec (.toArray a))]
- ;;clear first!
- (.clear a)
- (unreduced (rf result v))))]
- (rf result)))
+ (let [result (if (.isEmpty a)
+ result
+ (let [v (vec (.toArray a))]
+ ;;clear first!
+ (.clear a)
+ (unreduced (rf result v))))]
+ (rf result)))
([result input]
- (.add a input)
- (if (= n (.size a))
- (let [v (vec (.toArray a))]
- (.clear a)
- (rf result v))
- result))))))
+ (.add a input)
+ (if (= n (.size a))
+ (let [v (vec (.toArray a))]
+ (.clear a)
+ (rf result v))
+ result))))))
([n coll]
- (partition-all n n coll))
+ (partition-all n n coll))
([n step coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (let [seg (doall (take n s))]
- (cons seg (partition-all n step (nthrest s step))))))))
+ (lazy-seq
+ (when-let [s (seq coll)]
+ (let [seg (doall (take n s))]
+ (cons seg (partition-all n step (nthrest s step))))))))
(defn shuffle
"Return a random permutation of coll"
@@ -7322,26 +7322,26 @@ fails, attempts to require sym's namespace and retries."
([] (rf))
([result] (rf result))
([result input]
- (let [v (f input)]
- (if (nil? v)
- result
- (rf result v)))))))
+ (let [v (f input)]
+ (if (nil? v)
+ result
+ (rf result v)))))))
([f coll]
(lazy-seq
- (when-let [s (seq coll)]
- (if (chunked-seq? s)
- (let [c (chunk-first s)
- size (count c)
- b (chunk-buffer size)]
- (dotimes [i size]
- (let [x (f (.nth c i))]
- (when-not (nil? x)
- (chunk-append b x))))
- (chunk-cons (chunk b) (keep f (chunk-rest s))))
- (let [x (f (first s))]
- (if (nil? x)
- (keep f (rest s))
- (cons x (keep f (rest s))))))))))
+ (when-let [s (seq coll)]
+ (if (chunked-seq? s)
+ (let [c (chunk-first s)
+ size (count c)
+ b (chunk-buffer size)]
+ (dotimes [i size]
+ (let [x (f (.nth c i))]
+ (when-not (nil? x)
+ (chunk-append b x))))
+ (chunk-cons (chunk b) (keep f (chunk-rest s))))
+ (let [x (f (first s))]
+ (if (nil? x)
+ (keep f (rest s))
+ (cons x (keep f (rest s))))))))))
(defn keep-indexed
"Returns a lazy sequence of the non-nil results of (f index item). Note,
@@ -7357,29 +7357,29 @@ fails, attempts to require sym's namespace and retries."
([] (rf))
([result] (rf result))
([result input]
- (let [i (vswap! iv inc)
- v (f i input)]
- (if (nil? v)
- result
- (rf result v))))))))
+ (let [i (vswap! iv inc)
+ v (f i input)]
+ (if (nil? v)
+ result
+ (rf result v))))))))
([f coll]
- (letfn [(keepi [idx coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (if (chunked-seq? s)
- (let [c (chunk-first s)
- size (count c)
- b (chunk-buffer size)]
- (dotimes [i size]
- (let [x (f (+ idx i) (.nth c i))]
- (when-not (nil? x)
- (chunk-append b x))))
- (chunk-cons (chunk b) (keepi (+ idx size) (chunk-rest s))))
- (let [x (f idx (first s))]
- (if (nil? x)
- (keepi (inc idx) (rest s))
- (cons x (keepi (inc idx) (rest s)))))))))]
- (keepi 0 coll))))
+ (letfn [(keepi [idx coll]
+ (lazy-seq
+ (when-let [s (seq coll)]
+ (if (chunked-seq? s)
+ (let [c (chunk-first s)
+ size (count c)
+ b (chunk-buffer size)]
+ (dotimes [i size]
+ (let [x (f (+ idx i) (.nth c i))]
+ (when-not (nil? x)
+ (chunk-append b x))))
+ (chunk-cons (chunk b) (keepi (+ idx size) (chunk-rest s))))
+ (let [x (f idx (first s))]
+ (if (nil? x)
+ (keepi (inc idx) (rest s))
+ (cons x (keepi (inc idx) (rest s)))))))))]
+ (keepi 0 coll))))
(defn bounded-count
"If coll is counted? returns its count, else will count at most the first n
@@ -7400,38 +7400,38 @@ fails, attempts to require sym's namespace and retries."
argument that triggers a logical false result against the original predicates."
{:added "1.3"}
([p]
- (fn ep1
- ([] true)
- ([x] (boolean (p x)))
- ([x y] (boolean (and (p x) (p y))))
- ([x y z] (boolean (and (p x) (p y) (p z))))
- ([x y z & args] (boolean (and (ep1 x y z)
- (every? p args))))))
+ (fn ep1
+ ([] true)
+ ([x] (boolean (p x)))
+ ([x y] (boolean (and (p x) (p y))))
+ ([x y z] (boolean (and (p x) (p y) (p z))))
+ ([x y z & args] (boolean (and (ep1 x y z)
+ (every? p args))))))
([p1 p2]
- (fn ep2
- ([] true)
- ([x] (boolean (and (p1 x) (p2 x))))
- ([x y] (boolean (and (p1 x) (p1 y) (p2 x) (p2 y))))
- ([x y z] (boolean (and (p1 x) (p1 y) (p1 z) (p2 x) (p2 y) (p2 z))))
- ([x y z & args] (boolean (and (ep2 x y z)
- (every? #(and (p1 %) (p2 %)) args))))))
+ (fn ep2
+ ([] true)
+ ([x] (boolean (and (p1 x) (p2 x))))
+ ([x y] (boolean (and (p1 x) (p1 y) (p2 x) (p2 y))))
+ ([x y z] (boolean (and (p1 x) (p1 y) (p1 z) (p2 x) (p2 y) (p2 z))))
+ ([x y z & args] (boolean (and (ep2 x y z)
+ (every? #(and (p1 %) (p2 %)) args))))))
([p1 p2 p3]
- (fn ep3
- ([] true)
- ([x] (boolean (and (p1 x) (p2 x) (p3 x))))
- ([x y] (boolean (and (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y))))
- ([x y z] (boolean (and (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y) (p1 z) (p2 z) (p3 z))))
- ([x y z & args] (boolean (and (ep3 x y z)
- (every? #(and (p1 %) (p2 %) (p3 %)) args))))))
+ (fn ep3
+ ([] true)
+ ([x] (boolean (and (p1 x) (p2 x) (p3 x))))
+ ([x y] (boolean (and (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y))))
+ ([x y z] (boolean (and (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y) (p1 z) (p2 z) (p3 z))))
+ ([x y z & args] (boolean (and (ep3 x y z)
+ (every? #(and (p1 %) (p2 %) (p3 %)) args))))))
([p1 p2 p3 & ps]
- (let [ps (list* p1 p2 p3 ps)]
- (fn epn
- ([] true)
- ([x] (every? #(% x) ps))
- ([x y] (every? #(and (% x) (% y)) ps))
- ([x y z] (every? #(and (% x) (% y) (% z)) ps))
- ([x y z & args] (boolean (and (epn x y z)
- (every? #(every? % args) ps))))))))
+ (let [ps (list* p1 p2 p3 ps)]
+ (fn epn
+ ([] true)
+ ([x] (every? #(% x) ps))
+ ([x y] (every? #(and (% x) (% y)) ps))
+ ([x y z] (every? #(and (% x) (% y) (% z)) ps))
+ ([x y z & args] (boolean (and (epn x y z)
+ (every? #(every? % args) ps))))))))
(defn some-fn
"Takes a set of predicates and returns a function f that returns the first logical true value
@@ -7440,38 +7440,38 @@ fails, attempts to require sym's namespace and retries."
argument that triggers a logical true result against the original predicates."
{:added "1.3"}
([p]
- (fn sp1
- ([] nil)
- ([x] (p x))
- ([x y] (or (p x) (p y)))
- ([x y z] (or (p x) (p y) (p z)))
- ([x y z & args] (or (sp1 x y z)
- (some p args)))))
+ (fn sp1
+ ([] nil)
+ ([x] (p x))
+ ([x y] (or (p x) (p y)))
+ ([x y z] (or (p x) (p y) (p z)))
+ ([x y z & args] (or (sp1 x y z)
+ (some p args)))))
([p1 p2]
- (fn sp2
- ([] nil)
- ([x] (or (p1 x) (p2 x)))
- ([x y] (or (p1 x) (p1 y) (p2 x) (p2 y)))
- ([x y z] (or (p1 x) (p1 y) (p1 z) (p2 x) (p2 y) (p2 z)))
- ([x y z & args] (or (sp2 x y z)
- (some #(or (p1 %) (p2 %)) args)))))
+ (fn sp2
+ ([] nil)
+ ([x] (or (p1 x) (p2 x)))
+ ([x y] (or (p1 x) (p1 y) (p2 x) (p2 y)))
+ ([x y z] (or (p1 x) (p1 y) (p1 z) (p2 x) (p2 y) (p2 z)))
+ ([x y z & args] (or (sp2 x y z)
+ (some #(or (p1 %) (p2 %)) args)))))
([p1 p2 p3]
- (fn sp3
- ([] nil)
- ([x] (or (p1 x) (p2 x) (p3 x)))
- ([x y] (or (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y)))
- ([x y z] (or (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y) (p1 z) (p2 z) (p3 z)))
- ([x y z & args] (or (sp3 x y z)
- (some #(or (p1 %) (p2 %) (p3 %)) args)))))
+ (fn sp3
+ ([] nil)
+ ([x] (or (p1 x) (p2 x) (p3 x)))
+ ([x y] (or (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y)))
+ ([x y z] (or (p1 x) (p2 x) (p3 x) (p1 y) (p2 y) (p3 y) (p1 z) (p2 z) (p3 z)))
+ ([x y z & args] (or (sp3 x y z)
+ (some #(or (p1 %) (p2 %) (p3 %)) args)))))
([p1 p2 p3 & ps]
- (let [ps (list* p1 p2 p3 ps)]
- (fn spn
- ([] nil)
- ([x] (some #(% x) ps))
- ([x y] (some #(or (% x) (% y)) ps))
- ([x y z] (some #(or (% x) (% y) (% z)) ps))
- ([x y z & args] (or (spn x y z)
- (some #(some % args) ps)))))))
+ (let [ps (list* p1 p2 p3 ps)]
+ (fn spn
+ ([] nil)
+ ([x] (some #(% x) ps))
+ ([x y] (some #(or (% x) (% y)) ps))
+ ([x y z] (some #(or (% x) (% y) (% z)) ps))
+ ([x y z & args] (or (spn x y z)
+ (some #(some % args) ps)))))))
(defn- ^{:dynamic true} assert-valid-fdecl
"A good fdecl looks like (([a] ...) ([a b] ...)) near the end of defn."
@@ -7482,13 +7482,13 @@ fails, attempts to require sym's namespace and retries."
#(if (seq? %)
(first %)
(throw (IllegalArgumentException.
- (if (seq? (first fdecl))
- (str "Invalid signature \""
- %
- "\" should be a list")
- (str "Parameter declaration \""
- %
- "\" should be a vector")))))
+ (if (seq? (first fdecl))
+ (str "Invalid signature \""
+ %
+ "\" should be a list")
+ (str "Parameter declaration \""
+ %
+ "\" should be a vector")))))
fdecl)
bad-args (seq (remove #(vector? %) argdecls))]
(when bad-args
@@ -7528,7 +7528,7 @@ fails, attempts to require sym's namespace and retries."
[bindings & body]
`(with-redefs-fn ~(zipmap (map #(list `var %) (take-nth 2 bindings))
(take-nth 2 (next bindings)))
- (fn [] ~@body)))
+ (fn [] ~@body)))
(defn realized?
"Returns true if a value has been produced for a promise, delay, future or lazy sequence."
@@ -7626,7 +7626,7 @@ fails, attempts to require sym's namespace and retries."
([] (rf))
([result] (rf result))
([result input]
- (reduce rrf result input)))))
+ (reduce rrf result input)))))
(defn halt-when
"Returns a transducer that ends transduction when pred returns true
@@ -7640,17 +7640,17 @@ fails, attempts to require sym's namespace and retries."
{:added "1.9"}
([pred] (halt-when pred nil))
([pred retf]
- (fn [rf]
- (fn
- ([] (rf))
- ([result]
- (if (and (map? result) (contains? result ::halt))
- (::halt result)
- (rf result)))
- ([result input]
- (if (pred input)
- (reduced {::halt (if retf (retf (rf result) input) input)})
- (rf result input)))))))
+ (fn [rf]
+ (fn
+ ([] (rf))
+ ([result]
+ (if (and (map? result) (contains? result ::halt))
+ (::halt result)
+ (rf result)))
+ ([result input]
+ (if (pred input)
+ (reduced {::halt (if retf (retf (rf result) input) input)})
+ (rf result input)))))))
(defn dedupe
"Returns a lazy sequence removing consecutive duplicates in coll.
@@ -7663,11 +7663,11 @@ fails, attempts to require sym's namespace and retries."
([] (rf))
([result] (rf result))
([result input]
- (let [prior @pv]
- (vreset! pv input)
- (if (= prior input)
- result
- (rf result input))))))))
+ (let [prior @pv]
+ (vreset! pv input)
+ (if (= prior input)
+ result
+ (rf result input))))))))
([coll] (sequence (dedupe) coll)))
(defn random-sample
@@ -7675,21 +7675,21 @@ fails, attempts to require sym's namespace and retries."
1.0). Returns a transducer when no collection is provided."
{:added "1.7"}
([prob]
- (filter (fn [_] (< (rand) prob))))
+ (filter (fn [_] (< (rand) prob))))
([prob coll]
- (filter (fn [_] (< (rand) prob)) coll)))
+ (filter (fn [_] (< (rand) prob)) coll)))
(deftype Eduction [xform coll]
- Iterable
- (iterator [_]
- (clojure.lang.TransformerIterator/create xform (clojure.lang.RT/iter coll)))
+ Iterable
+ (iterator [_]
+ (clojure.lang.TransformerIterator/create xform (clojure.lang.RT/iter coll)))
- clojure.lang.IReduceInit
- (reduce [_ f init]
- ;; NB (completing f) isolates completion of inner rf from outer rf
- (transduce xform (completing f) init coll))
+ clojure.lang.IReduceInit
+ (reduce [_ f init]
+ ;; NB (completing f) isolates completion of inner rf from outer rf
+ (transduce xform (completing f) init coll))
- clojure.lang.Sequential)
+ clojure.lang.Sequential)
(defn eduction
"Returns a reducible/iterable application of the transducers
@@ -7803,8 +7803,8 @@ fails, attempts to require sym's namespace and retries."
(defn- load-data-reader-file [mappings ^java.net.URL url]
(with-open [rdr (clojure.lang.LineNumberingPushbackReader.
- (java.io.InputStreamReader.
- (.openStream url) "UTF-8"))]
+ (java.io.InputStreamReader.
+ (.openStream url) "UTF-8"))]
(binding [*file* (.getFile url)]
(let [read-opts (if (.endsWith (.getPath url) "cljc")
{:eof nil :read-cond :allow}
@@ -7814,21 +7814,21 @@ fails, attempts to require sym's namespace and retries."
(throw (ex-info (str "Not a valid data-reader map")
{:url url})))
(reduce
- (fn [m [k v]]
- (when (not (symbol? k))
- (throw (ex-info (str "Invalid form in data-reader file")
- {:url url
- :form k})))
- (let [v-var (data-reader-var v)]
- (when (and (contains? mappings k)
- (not= (mappings k) v-var))
- (throw (ex-info "Conflicting data-reader mapping"
- {:url url
- :conflict k
- :mappings m})))
- (assoc m k v-var)))
- mappings
- new-mappings)))))
+ (fn [m [k v]]
+ (when (not (symbol? k))
+ (throw (ex-info (str "Invalid form in data-reader file")
+ {:url url
+ :form k})))
+ (let [v-var (data-reader-var v)]
+ (when (and (contains? mappings k)
+ (not= (mappings k) v-var))
+ (throw (ex-info "Conflicting data-reader mapping"
+ {:url url
+ :conflict k
+ :mappings m})))
+ (assoc m k v-var)))
+ mappings
+ new-mappings)))))
(defn- load-data-readers []
(alter-var-root #'*data-readers*
@@ -7837,10 +7837,10 @@ fails, attempts to require sym's namespace and retries."
mappings (data-reader-urls)))))
(try
- (load-data-readers)
- (catch Throwable t
- (.printStackTrace t)
- (throw t)))
+ (load-data-readers)
+ (catch Throwable t
+ (.printStackTrace t)
+ (throw t)))
(defn uri?
"Return true if x is a java.net.URI"
@@ -7852,18 +7852,18 @@ fails, attempts to require sym's namespace and retries."
(defonce ^:private tap-loop
(delay
- (doto (Thread.
- #(let [t (.take tapq)
- x (if (identical? ::tap-nil t) nil t)
- taps @tapset]
- (doseq [tap taps]
- (try
- (tap x)
- (catch Throwable ex)))
- (recur))
- "clojure.core/tap-loop")
- (.setDaemon true)
- (.start))))
+ (doto (Thread.
+ #(let [t (.take tapq)
+ x (if (identical? ::tap-nil t) nil t)
+ taps @tapset]
+ (doseq [tap taps]
+ (try
+ (tap x)
+ (catch Throwable ex)))
+ (recur))
+ "clojure.core/tap-loop")
+ (.setDaemon true)
+ (.start))))
(defn add-tap
"adds f, a fn of one argument, to the tap set. This function will be called with anything sent via tap>.
diff --git a/src/clj/clojure/core/protocols.clj b/src/clj/clojure/core/protocols.clj
index 10c02291..df594c55 100644
--- a/src/clj/clojure/core/protocols.clj
+++ b/src/clj/clojure/core/protocols.clj
@@ -23,12 +23,12 @@
(defn- seq-reduce
([coll f]
- (if-let [s (seq coll)]
- (internal-reduce (next s) f (first s))
- (f)))
+ (if-let [s (seq coll)]
+ (internal-reduce (next s) f (first s))
+ (f)))
([coll f val]
- (let [s (seq coll)]
- (internal-reduce s f val))))
+ (let [s (seq coll)]
+ (internal-reduce s f val))))
(defn- iter-reduce
([^java.lang.Iterable coll f]
@@ -75,13 +75,13 @@
(extend-protocol CollReduce
nil
(coll-reduce
- ([coll f] (f))
- ([coll f val] val))
+ ([coll f] (f))
+ ([coll f val] val))
Object
(coll-reduce
- ([coll f] (seq-reduce coll f))
- ([coll f val] (seq-reduce coll f val)))
+ ([coll f] (seq-reduce coll f))
+ ([coll f val] (seq-reduce coll f val)))
clojure.lang.IReduceInit
(coll-reduce
@@ -91,25 +91,25 @@
;;aseqs are iterable, masking internal-reducers
clojure.lang.ASeq
(coll-reduce
- ([coll f] (seq-reduce coll f))
- ([coll f val] (seq-reduce coll f val)))
+ ([coll f] (seq-reduce coll f))
+ ([coll f val] (seq-reduce coll f val)))
;;for range
clojure.lang.LazySeq
(coll-reduce
- ([coll f] (seq-reduce coll f))
- ([coll f val] (seq-reduce coll f val)))
+ ([coll f] (seq-reduce coll f))
+ ([coll f val] (seq-reduce coll f val)))
;;vector's chunked seq is faster than its iter
clojure.lang.PersistentVector
(coll-reduce
- ([coll f] (seq-reduce coll f))
- ([coll f val] (seq-reduce coll f val)))
+ ([coll f] (seq-reduce coll f))
+ ([coll f val] (seq-reduce coll f val)))
Iterable
(coll-reduce
- ([coll f] (iter-reduce coll f))
- ([coll f val] (iter-reduce coll f val)))
+ ([coll f] (iter-reduce coll f))
+ ([coll f val] (iter-reduce coll f val)))
clojure.lang.APersistentMap$KeySeq
(coll-reduce
@@ -124,53 +124,53 @@
(extend-protocol InternalReduce
nil
(internal-reduce
- [s f val]
- val)
+ [s f val]
+ val)
;; handles vectors and ranges
clojure.lang.IChunkedSeq
(internal-reduce
- [s f val]
- (if-let [s (seq s)]
- (if (chunked-seq? s)
- (let [ret (.reduce (chunk-first s) f val)]
- (if (reduced? ret)
- @ret
- (recur (chunk-next s)
- f
- ret)))
- (interface-or-naive-reduce s f val))
- val))
+ [s f val]
+ (if-let [s (seq s)]
+ (if (chunked-seq? s)
+ (let [ret (.reduce (chunk-first s) f val)]
+ (if (reduced? ret)
+ @ret
+ (recur (chunk-next s)
+ f
+ ret)))
+ (interface-or-naive-reduce s f val))
+ val))
clojure.lang.StringSeq
(internal-reduce
- [str-seq f val]
- (let [s (.s str-seq)
- len (.length s)]
- (loop [i (.i str-seq)
- val val]
- (if (< i len)
- (let [ret (f val (.charAt s i))]
- (if (reduced? ret)
- @ret
- (recur (inc i) ret)))
- val))))
+ [str-seq f val]
+ (let [s (.s str-seq)
+ len (.length s)]
+ (loop [i (.i str-seq)
+ val val]
+ (if (< i len)
+ (let [ret (f val (.charAt s i))]
+ (if (reduced? ret)
+ @ret
+ (recur (inc i) ret)))
+ val))))
java.lang.Object
(internal-reduce
- [s f val]
- (loop [cls (class s)
- s s
- f f
- val val]
- (if-let [s (seq s)]
- (if (identical? (class s) cls)
- (let [ret (f val (first s))]
- (if (reduced? ret)
- @ret
- (recur cls (next s) f ret)))
- (interface-or-naive-reduce s f val))
- val))))
+ [s f val]
+ (loop [cls (class s)
+ s s
+ f f
+ val val]
+ (if-let [s (seq s)]
+ (if (identical? (class s) cls)
+ (let [ret (f val (first s))]
+ (if (reduced? ret)
+ @ret
+ (recur cls (next s) f ret)))
+ (interface-or-naive-reduce s f val))
+ val))))
(defprotocol IKVReduce
"Protocol for concrete associative types that can reduce themselves
diff --git a/src/clj/clojure/core/reducers.clj b/src/clj/clojure/core/reducers.clj
index 94b1a7dd..ce3a946a 100644
--- a/src/clj/clojure/core/reducers.clj
+++ b/src/clj/clojure/core/reducers.clj
@@ -41,9 +41,9 @@
Maps are reduced with reduce-kv"
([f coll] (reduce f (f) coll))
([f init coll]
- (if (instance? java.util.Map coll)
- (clojure.core.protocols/kv-reduce coll f init)
- (clojure.core.protocols/coll-reduce coll f init))))
+ (if (instance? java.util.Map coll)
+ (clojure.core.protocols/kv-reduce coll f init)
+ (clojure.core.protocols/coll-reduce coll f init))))
(defprotocol CollFold
(coll-fold [coll n combinef reducef]))
@@ -62,7 +62,7 @@
([reducef coll] (fold reducef reducef coll))
([combinef reducef coll] (fold 512 combinef reducef coll))
([n combinef reducef coll]
- (coll-fold coll n combinef reducef)))
+ (coll-fold coll n combinef reducef)))
(defn reducer
"Given a reducible collection, and a transformation function xf,
@@ -71,12 +71,12 @@
reducing fn."
{:added "1.5"}
([coll xf]
- (reify
- clojure.core.protocols/CollReduce
- (coll-reduce [this f1]
- (clojure.core.protocols/coll-reduce this f1 (f1)))
- (coll-reduce [_ f1 init]
- (clojure.core.protocols/coll-reduce coll (xf f1) init)))))
+ (reify
+ clojure.core.protocols/CollReduce
+ (coll-reduce [this f1]
+ (clojure.core.protocols/coll-reduce this f1 (f1)))
+ (coll-reduce [_ f1 init]
+ (clojure.core.protocols/coll-reduce coll (xf f1) init)))))
(defn folder
"Given a foldable collection, and a transformation function xf,
@@ -85,16 +85,16 @@
reducing fn."
{:added "1.5"}
([coll xf]
- (reify
- clojure.core.protocols/CollReduce
- (coll-reduce [_ f1]
- (clojure.core.protocols/coll-reduce coll (xf f1) (f1)))
- (coll-reduce [_ f1 init]
- (clojure.core.protocols/coll-reduce coll (xf f1) init))
+ (reify
+ clojure.core.protocols/CollReduce
+ (coll-reduce [_ f1]
+ (clojure.core.protocols/coll-reduce coll (xf f1) (f1)))
+ (coll-reduce [_ f1 init]
+ (clojure.core.protocols/coll-reduce coll (xf f1) init))
- CollFold
- (coll-fold [_ n combinef reducef]
- (coll-fold coll n combinef (xf reducef))))))
+ CollFold
+ (coll-fold [_ n combinef reducef]
+ (coll-fold coll n combinef (xf reducef))))))
(defn- do-curried
[name doc meta args body]
@@ -113,11 +113,11 @@
`(fn
([] (~f1))
~(clojure.walk/postwalk
- #(if (sequential? %)
- ((if (vector? %) vec identity)
- (core/remove #{k} %))
- %)
- fkv)
+ #(if (sequential? %)
+ ((if (vector? %) vec identity)
+ (core/remove #{k} %))
+ %)
+ fkv)
~fkv))
(defmacro ^:private rfn
@@ -130,10 +130,10 @@
{:added "1.5"}
[f coll]
(folder coll
- (fn [f1]
- (rfn [f1 k]
- ([ret k v]
- (f1 ret (f k v)))))))
+ (fn [f1]
+ (rfn [f1 k]
+ ([ret k v]
+ (f1 ret (f k v)))))))
(defcurried mapcat
"Applies f to every value in the reduction of coll, concatenating the result
@@ -141,15 +141,15 @@
{:added "1.5"}
[f coll]
(folder coll
- (fn [f1]
- (let [f1 (fn
- ([ret v]
+ (fn [f1]
+ (let [f1 (fn
+ ([ret v]
(let [x (f1 ret v)] (if (reduced? x) (reduced x) x)))
- ([ret k v]
+ ([ret k v]
(let [x (f1 ret k v)] (if (reduced? x) (reduced x) x))))]
- (rfn [f1 k]
- ([ret k v]
- (reduce f1 ret (f k v))))))))
+ (rfn [f1 k]
+ ([ret k v]
+ (reduce f1 ret (f k v))))))))
(defcurried filter
"Retains values in the reduction of coll for which (pred val)
@@ -157,12 +157,12 @@
{:added "1.5"}
[pred coll]
(folder coll
- (fn [f1]
- (rfn [f1 k]
- ([ret k v]
- (if (pred k v)
- (f1 ret k v)
- ret))))))
+ (fn [f1]
+ (rfn [f1 k]
+ ([ret k v]
+ (if (pred k v)
+ (f1 ret k v)
+ ret))))))
(defcurried remove
"Removes values in the reduction of coll for which (pred val)
@@ -178,53 +178,53 @@
{:added "1.5"}
[coll]
(folder coll
- (fn [f1]
- (fn
- ([] (f1))
- ([ret v]
- (if (sequential? v)
- (clojure.core.protocols/coll-reduce (flatten v) f1 ret)
- (f1 ret v)))))))
+ (fn [f1]
+ (fn
+ ([] (f1))
+ ([ret v]
+ (if (sequential? v)
+ (clojure.core.protocols/coll-reduce (flatten v) f1 ret)
+ (f1 ret v)))))))
(defcurried take-while
"Ends the reduction of coll when (pred val) returns logical false."
{:added "1.5"}
[pred coll]
(reducer coll
- (fn [f1]
- (rfn [f1 k]
- ([ret k v]
- (if (pred k v)
- (f1 ret k v)
- (reduced ret)))))))
+ (fn [f1]
+ (rfn [f1 k]
+ ([ret k v]
+ (if (pred k v)
+ (f1 ret k v)
+ (reduced ret)))))))
(defcurried take
"Ends the reduction of coll after consuming n values."
{:added "1.5"}
[n coll]
(reducer coll
- (fn [f1]
- (let [cnt (atom n)]
- (rfn [f1 k]
- ([ret k v]
- (swap! cnt dec)
- (if (neg? @cnt)
- (reduced ret)
- (f1 ret k v))))))))
+ (fn [f1]
+ (let [cnt (atom n)]
+ (rfn [f1 k]
+ ([ret k v]
+ (swap! cnt dec)
+ (if (neg? @cnt)
+ (reduced ret)
+ (f1 ret k v))))))))
(defcurried drop
"Elides the first n values from the reduction of coll."
{:added "1.5"}
[n coll]
(reducer coll
- (fn [f1]
- (let [cnt (atom n)]
- (rfn [f1 k]
- ([ret k v]
- (swap! cnt dec)
- (if (neg? @cnt)
- (f1 ret k v)
- ret)))))))
+ (fn [f1]
+ (let [cnt (atom n)]
+ (rfn [f1 k]
+ ([ret k v]
+ (swap! cnt dec)
+ (if (neg? @cnt)
+ (f1 ret k v)
+ ret)))))))
;;do not construct this directly, use cat
(deftype Cat [cnt left right]
@@ -237,20 +237,20 @@
clojure.core.protocols/CollReduce
(coll-reduce [this f1] (clojure.core.protocols/coll-reduce this f1 (f1)))
(coll-reduce
- [_ f1 init]
- (clojure.core.protocols/coll-reduce
- right f1
- (clojure.core.protocols/coll-reduce left f1 init)))
+ [_ f1 init]
+ (clojure.core.protocols/coll-reduce
+ right f1
+ (clojure.core.protocols/coll-reduce left f1 init)))
CollFold
(coll-fold
- [_ n combinef reducef]
- (fjinvoke
- (fn []
- (let [rt (fjfork (fjtask #(coll-fold right n combinef reducef)))]
- (combinef
- (coll-fold left n combinef reducef)
- (fjjoin rt)))))))
+ [_ n combinef reducef]
+ (fjinvoke
+ (fn []
+ (let [rt (fjfork (fjtask #(coll-fold right n combinef reducef)))]
+ (combinef
+ (coll-fold left n combinef reducef)
+ (fjjoin rt)))))))
(defn cat
"A high-performance combining fn that yields the catenation of the
@@ -262,15 +262,15 @@
{:added "1.5"}
([] (java.util.ArrayList.))
([ctor]
- (fn
- ([] (ctor))
- ([left right] (cat left right))))
+ (fn
+ ([] (ctor))
+ ([left right] (cat left right))))
([left right]
- (cond
- (zero? (count left)) right
- (zero? (count right)) left
- :else
- (Cat. (+ (count left) (count right)) left right))))
+ (cond
+ (zero? (count left)) right
+ (zero? (count right)) left
+ :else
+ (Cat. (+ (count left) (count right)) left right))))
(defn append!
".adds x to acc and returns acc"
@@ -298,37 +298,37 @@
(defn- foldvec
[v n combinef reducef]
(cond
- (empty? v) (combinef)
- (<= (count v) n) (reduce reducef (combinef) v)
- :else
- (let [split (quot (count v) 2)
- v1 (subvec v 0 split)
- v2 (subvec v split (count v))
- fc (fn [child] #(foldvec child n combinef reducef))]
- (fjinvoke
- #(let [f1 (fc v1)
- t2 (fjtask (fc v2))]
- (fjfork t2)
- (combinef (f1) (fjjoin t2)))))))
+ (empty? v) (combinef)
+ (<= (count v) n) (reduce reducef (combinef) v)
+ :else
+ (let [split (quot (count v) 2)
+ v1 (subvec v 0 split)
+ v2 (subvec v split (count v))
+ fc (fn [child] #(foldvec child n combinef reducef))]
+ (fjinvoke
+ #(let [f1 (fc v1)
+ t2 (fjtask (fc v2))]
+ (fjfork t2)
+ (combinef (f1) (fjjoin t2)))))))
(extend-protocol CollFold
- nil
- (coll-fold
- [coll n combinef reducef]
- (combinef))
-
- Object
- (coll-fold
- [coll n combinef reducef]
- ;;can't fold, single reduce
- (reduce reducef (combinef) coll))
-
- clojure.lang.IPersistentVector
- (coll-fold
- [v n combinef reducef]
- (foldvec v n combinef reducef))
+ nil
+ (coll-fold
+ [coll n combinef reducef]
+ (combinef))
+
+ Object
+ (coll-fold
+ [coll n combinef reducef]
+ ;;can't fold, single reduce
+ (reduce reducef (combinef) coll))
- clojure.lang.PersistentHashMap
- (coll-fold
- [m n combinef reducef]
- (.fold m n combinef reducef fjinvoke fjtask fjfork fjjoin)))
+ clojure.lang.IPersistentVector
+ (coll-fold
+ [v n combinef reducef]
+ (foldvec v n combinef reducef))
+
+ clojure.lang.PersistentHashMap
+ (coll-fold
+ [m n combinef reducef]
+ (.fold m n combinef reducef fjinvoke fjtask fjfork fjjoin)))
diff --git a/src/clj/clojure/core/server.clj b/src/clj/clojure/core/server.clj
index c103888c..6e5df951 100644
--- a/src/clj/clojure/core/server.clj
+++ b/src/clj/clojure/core/server.clj
@@ -10,8 +10,8 @@
:author "Alex Miller"}
clojure.core.server
(:require [clojure.string :as str]
- [clojure.edn :as edn]
- [clojure.main :as m])
+ [clojure.edn :as edn]
+ [clojure.main :as m])
(:import
[clojure.lang LineNumberingPushbackReader]
[java.net InetAddress Socket ServerSocket SocketException]
@@ -38,8 +38,8 @@
(defmacro ^:private thread
[^String name daemon & body]
`(doto (Thread. (fn [] ~@body) ~name)
- (.setDaemon ~daemon)
- (.start)))
+ (.setDaemon ~daemon)
+ (.start)))
(defn- required
"Throw if opts does not contain prop."
@@ -98,8 +98,8 @@
:or {bind-err true
server-daemon true
client-daemon true}} opts
- address (InetAddress/getByName address) ;; nil returns loopback
- socket (ServerSocket. port 0 address)]
+ address (InetAddress/getByName address) ;; nil returns loopback
+ socket (ServerSocket. port 0 address)]
(with-lock lock
(alter-var-root #'servers assoc name {:name name, :socket socket, :sessions {}}))
(thread
@@ -170,7 +170,7 @@
"Enhanced :read hook for repl supporting :repl/quit."
[request-prompt request-exit]
(or ({:line-start request-prompt :stream-end request-exit}
- (m/skip-whitespace *in*))
+ (m/skip-whitespace *in*))
(let [input (read {:read-cond :allow} *in*)]
(m/skip-if-eol *in*)
(case input
@@ -258,7 +258,7 @@
true))
(recur)))
(finally
- (remove-tap tapfn)))))))
+ (remove-tap tapfn)))))))
(defn- resolve-fn [valf]
(if (symbol? valf)
@@ -289,7 +289,7 @@
(assoc m :val (valf (:val m)))
(catch Throwable ex
(assoc m :val (ex->data ex :print-eval-result)
- :exception true)))
+ :exception true)))
m))))))))
(defn remote-prepl
@@ -317,16 +317,16 @@
(let [{:keys [tag val] :as m} (readf rd EOF)]
(when-not (identical? m EOF)
(out-fn
- (if (#{:ret :tap} tag)
- (try
- (assoc m :val (valf val))
- (catch Throwable ex
- (assoc m :val (ex->data ex :read-eval-result)
- :exception true)))
- m))
+ (if (#{:ret :tap} tag)
+ (try
+ (assoc m :val (valf val))
+ (catch Throwable ex
+ (assoc m :val (ex->data ex :read-eval-result)
+ :exception true)))
+ m))
(recur))))
(finally
- (.close wr))))
+ (.close wr))))
(let [buf (char-array 1024)]
(try (loop []
(let [n (.read in-reader buf)]
@@ -335,4 +335,4 @@
(.flush wr)
(recur))))
(finally
- (.close rd))))))
+ (.close rd))))))
diff --git a/src/clj/clojure/core_deftype.clj b/src/clj/clojure/core_deftype.clj
index 786f0d4b..e2ac7800 100644
--- a/src/clj/clojure/core_deftype.clj
+++ b/src/clj/clojure/core_deftype.clj
@@ -132,18 +132,18 @@
(defn- imap-cons
[^IPersistentMap this o]
(cond
- (map-entry? o)
- (let [^java.util.Map$Entry pair o]
- (.assoc this (.getKey pair) (.getValue pair)))
- (instance? clojure.lang.IPersistentVector o)
- (let [^clojure.lang.IPersistentVector vec o]
- (.assoc this (.nth vec 0) (.nth vec 1)))
- :else (loop [this this
- o o]
- (if (seq o)
- (let [^java.util.Map$Entry pair (first o)]
- (recur (.assoc this (.getKey pair) (.getValue pair)) (rest o)))
- this))))
+ (map-entry? o)
+ (let [^java.util.Map$Entry pair o]
+ (.assoc this (.getKey pair) (.getValue pair)))
+ (instance? clojure.lang.IPersistentVector o)
+ (let [^clojure.lang.IPersistentVector vec o]
+ (.assoc this (.nth vec 0) (.nth vec 1)))
+ :else (loop [this this
+ o o]
+ (if (seq o)
+ (let [^java.util.Map$Entry pair (first o)]
+ (recur (.assoc this (.getKey pair) (.getValue pair)) (rest o)))
+ this))))
(defn- emit-defrecord
"Do not use this directly - use defrecord"
@@ -163,105 +163,105 @@
(when (some #{:volatile-mutable :unsynchronized-mutable} (mapcat (comp keys meta) hinted-fields))
(throw (IllegalArgumentException. ":volatile-mutable or :unsynchronized-mutable not supported for record fields")))
(let [gs (gensym)]
- (letfn
- [(irecord [[i m]]
- [(conj i 'clojure.lang.IRecord)
- m])
- (eqhash [[i m]]
- [(conj i 'clojure.lang.IHashEq)
- (conj m
- `(hasheq [this#] (let [hq# ~'__hasheq]
- (if (zero? hq#)
- (let [h# (int (bit-xor ~type-hash (clojure.lang.APersistentMap/mapHasheq this#)))]
- (set! ~'__hasheq h#)
- h#)
- hq#)))
- `(hashCode [this#] (let [hash# ~'__hash]
- (if (zero? hash#)
- (let [h# (clojure.lang.APersistentMap/mapHash this#)]
- (set! ~'__hash h#)
- h#)
- hash#)))
- `(equals [this# ~gs] (clojure.lang.APersistentMap/mapEquals this# ~gs)))])
- (iobj [[i m]]
- [(conj i 'clojure.lang.IObj)
- (conj m `(meta [this#] ~'__meta)
- `(withMeta [this# ~gs] (new ~tagname ~@(replace {'__meta gs} fields))))])
- (ilookup [[i m]]
- [(conj i 'clojure.lang.ILookup 'clojure.lang.IKeywordLookup)
- (conj m `(valAt [this# k#] (.valAt this# k# nil))
- `(valAt [this# k# else#]
- (case k# ~@(mapcat (fn [fld] [(keyword fld) fld])
- base-fields)
- (get ~'__extmap k# else#)))
- `(getLookupThunk [this# k#]
- (let [~'gclass (class this#)]
- (case k#
- ~@(let [hinted-target (with-meta 'gtarget {:tag tagname})]
- (mapcat
- (fn [fld]
- [(keyword fld)
- `(reify clojure.lang.ILookupThunk
- (get [~'thunk ~'gtarget]
- (if (identical? (class ~'gtarget) ~'gclass)
- (. ~hinted-target ~(symbol (str "-" fld)))
- ~'thunk)))])
- base-fields))
- nil))))])
- (imap [[i m]]
- [(conj i 'clojure.lang.IPersistentMap)
- (conj m
- `(count [this#] (+ ~(count base-fields) (count ~'__extmap)))
- `(empty [this#] (throw (UnsupportedOperationException. (str "Can't create empty: " ~(str classname)))))
- `(cons [this# e#] ((var imap-cons) this# e#))
- `(equiv [this# ~gs]
- (boolean
- (or (identical? this# ~gs)
- (when (identical? (class this#) (class ~gs))
- (let [~gs ~(with-meta gs {:tag tagname})]
- (and ~@(map (fn [fld] `(= ~fld (. ~gs ~(symbol (str "-" fld))))) base-fields)
- (= ~'__extmap (. ~gs ~'__extmap))))))))
- `(containsKey [this# k#] (not (identical? this# (.valAt this# k# this#))))
- `(entryAt [this# k#] (let [v# (.valAt this# k# this#)]
- (when-not (identical? this# v#)
- (clojure.lang.MapEntry/create k# v#))))
- `(seq [this#] (seq (concat [~@(map #(list `clojure.lang.MapEntry/create (keyword %) %) base-fields)]
- ~'__extmap)))
- `(iterator [~gs]
- (clojure.lang.RecordIterator. ~gs [~@(map keyword base-fields)] (RT/iter ~'__extmap)))
- `(assoc [this# k# ~gs]
- (condp identical? k#
- ~@(mapcat (fn [fld]
- [(keyword fld) (list* `new tagname (replace {fld gs} (remove '#{__hash __hasheq} fields)))])
- base-fields)
- (new ~tagname ~@(remove '#{__extmap __hash __hasheq} fields) (assoc ~'__extmap k# ~gs))))
- `(without [this# k#] (if (contains? #{~@(map keyword base-fields)} k#)
- (dissoc (with-meta (into {} this#) ~'__meta) k#)
- (new ~tagname ~@(remove '#{__extmap __hash __hasheq} fields)
- (not-empty (dissoc ~'__extmap k#))))))])
- (ijavamap [[i m]]
- [(conj i 'java.util.Map 'java.io.Serializable)
- (conj m
- `(size [this#] (.count this#))
- `(isEmpty [this#] (= 0 (.count this#)))
- `(containsValue [this# v#] (boolean (some #{v#} (vals this#))))
- `(get [this# k#] (.valAt this# k#))
- `(put [this# k# v#] (throw (UnsupportedOperationException.)))
- `(remove [this# k#] (throw (UnsupportedOperationException.)))
- `(putAll [this# m#] (throw (UnsupportedOperationException.)))
- `(clear [this#] (throw (UnsupportedOperationException.)))
- `(keySet [this#] (set (keys this#)))
- `(values [this#] (vals this#))
- `(entrySet [this#] (set this#)))])
- ]
- (let [[i m] (-> [interfaces methods] irecord eqhash iobj ilookup imap ijavamap)]
- `(deftype* ~(symbol (name (ns-name *ns*)) (name tagname)) ~classname
- ~(conj hinted-fields '__meta '__extmap
- '^int ^:unsynchronized-mutable __hash
- '^int ^:unsynchronized-mutable __hasheq)
- :implements ~(vec i)
- ~@(mapcat identity opts)
- ~@m))))))
+ (letfn
+ [(irecord [[i m]]
+ [(conj i 'clojure.lang.IRecord)
+ m])
+ (eqhash [[i m]]
+ [(conj i 'clojure.lang.IHashEq)
+ (conj m
+ `(hasheq [this#] (let [hq# ~'__hasheq]
+ (if (zero? hq#)
+ (let [h# (int (bit-xor ~type-hash (clojure.lang.APersistentMap/mapHasheq this#)))]
+ (set! ~'__hasheq h#)
+ h#)
+ hq#)))
+ `(hashCode [this#] (let [hash# ~'__hash]
+ (if (zero? hash#)
+ (let [h# (clojure.lang.APersistentMap/mapHash this#)]
+ (set! ~'__hash h#)
+ h#)
+ hash#)))
+ `(equals [this# ~gs] (clojure.lang.APersistentMap/mapEquals this# ~gs)))])
+ (iobj [[i m]]
+ [(conj i 'clojure.lang.IObj)
+ (conj m `(meta [this#] ~'__meta)
+ `(withMeta [this# ~gs] (new ~tagname ~@(replace {'__meta gs} fields))))])
+ (ilookup [[i m]]
+ [(conj i 'clojure.lang.ILookup 'clojure.lang.IKeywordLookup)
+ (conj m `(valAt [this# k#] (.valAt this# k# nil))
+ `(valAt [this# k# else#]
+ (case k# ~@(mapcat (fn [fld] [(keyword fld) fld])
+ base-fields)
+ (get ~'__extmap k# else#)))
+ `(getLookupThunk [this# k#]
+ (let [~'gclass (class this#)]
+ (case k#
+ ~@(let [hinted-target (with-meta 'gtarget {:tag tagname})]
+ (mapcat
+ (fn [fld]
+ [(keyword fld)
+ `(reify clojure.lang.ILookupThunk
+ (get [~'thunk ~'gtarget]
+ (if (identical? (class ~'gtarget) ~'gclass)
+ (. ~hinted-target ~(symbol (str "-" fld)))
+ ~'thunk)))])
+ base-fields))
+ nil))))])
+ (imap [[i m]]
+ [(conj i 'clojure.lang.IPersistentMap)
+ (conj m
+ `(count [this#] (+ ~(count base-fields) (count ~'__extmap)))
+ `(empty [this#] (throw (UnsupportedOperationException. (str "Can't create empty: " ~(str classname)))))
+ `(cons [this# e#] ((var imap-cons) this# e#))
+ `(equiv [this# ~gs]
+ (boolean
+ (or (identical? this# ~gs)
+ (when (identical? (class this#) (class ~gs))
+ (let [~gs ~(with-meta gs {:tag tagname})]
+ (and ~@(map (fn [fld] `(= ~fld (. ~gs ~(symbol (str "-" fld))))) base-fields)
+ (= ~'__extmap (. ~gs ~'__extmap))))))))
+ `(containsKey [this# k#] (not (identical? this# (.valAt this# k# this#))))
+ `(entryAt [this# k#] (let [v# (.valAt this# k# this#)]
+ (when-not (identical? this# v#)
+ (clojure.lang.MapEntry/create k# v#))))
+ `(seq [this#] (seq (concat [~@(map #(list `clojure.lang.MapEntry/create (keyword %) %) base-fields)]
+ ~'__extmap)))
+ `(iterator [~gs]
+ (clojure.lang.RecordIterator. ~gs [~@(map keyword base-fields)] (RT/iter ~'__extmap)))
+ `(assoc [this# k# ~gs]
+ (condp identical? k#
+ ~@(mapcat (fn [fld]
+ [(keyword fld) (list* `new tagname (replace {fld gs} (remove '#{__hash __hasheq} fields)))])
+ base-fields)
+ (new ~tagname ~@(remove '#{__extmap __hash __hasheq} fields) (assoc ~'__extmap k# ~gs))))
+ `(without [this# k#] (if (contains? #{~@(map keyword base-fields)} k#)
+ (dissoc (with-meta (into {} this#) ~'__meta) k#)
+ (new ~tagname ~@(remove '#{__extmap __hash __hasheq} fields)
+ (not-empty (dissoc ~'__extmap k#))))))])
+ (ijavamap [[i m]]
+ [(conj i 'java.util.Map 'java.io.Serializable)
+ (conj m
+ `(size [this#] (.count this#))
+ `(isEmpty [this#] (= 0 (.count this#)))
+ `(containsValue [this# v#] (boolean (some #{v#} (vals this#))))
+ `(get [this# k#] (.valAt this# k#))
+ `(put [this# k# v#] (throw (UnsupportedOperationException.)))
+ `(remove [this# k#] (throw (UnsupportedOperationException.)))
+ `(putAll [this# m#] (throw (UnsupportedOperationException.)))
+ `(clear [this#] (throw (UnsupportedOperationException.)))
+ `(keySet [this#] (set (keys this#)))
+ `(values [this#] (vals this#))
+ `(entrySet [this#] (set this#)))])
+ ]
+ (let [[i m] (-> [interfaces methods] irecord eqhash iobj ilookup imap ijavamap)]
+ `(deftype* ~(symbol (name (ns-name *ns*)) (name tagname)) ~classname
+ ~(conj hinted-fields '__meta '__extmap
+ '^int ^:unsynchronized-mutable __hash
+ '^int ^:unsynchronized-mutable __hasheq)
+ :implements ~(vec i)
+ ~@(mapcat identity opts)
+ ~@m))))))
(defn- build-positional-factory
"Used to build a positional factory for a given type/record. Because of the
@@ -301,13 +301,13 @@
(let [non-syms (remove symbol? fields)]
(when (seq non-syms)
(throw (clojure.lang.Compiler$CompilerException.
- *file*
- (.deref clojure.lang.Compiler/LINE)
- (.deref clojure.lang.Compiler/COLUMN)
- (AssertionError.
- (str "defrecord and deftype fields must be symbols, "
- *ns* "." name " had: "
- (apply str (interpose ", " non-syms)))))))))
+ *file*
+ (.deref clojure.lang.Compiler/LINE)
+ (.deref clojure.lang.Compiler/COLUMN)
+ (AssertionError.
+ (str "defrecord and deftype fields must be symbols, "
+ *ns* "." name " had: "
+ (apply str (interpose ", " non-syms)))))))))
(defmacro defrecord
"(defrecord name [fields*] options* specs*)
@@ -530,7 +530,7 @@
([] nil)
([a] a)
([^Class a ^Class b]
- (if (.isAssignableFrom a b) b a)))
+ (if (.isAssignableFrom a b) b a)))
(defn find-protocol-impl [protocol x]
(if (instance? (:on-interface protocol) x)
@@ -578,8 +578,8 @@
interf
(find-protocol-method (.protocol cache) (.methodk cache) x))]
(when-not f
- (throw (IllegalArgumentException. (str "No implementation of method: " (.methodk cache)
- " of protocol: " (:var (.protocol cache))
+ (throw (IllegalArgumentException. (str "No implementation of method: " (.methodk cache)
+ " of protocol: " (:var (.protocol cache))
" found for class: " (if (nil? x) "nil" (.getName (class x)))))))
(set! (.__methodImplCache pf) (expand-method-impl-cache cache (class x) f))
f))
@@ -592,36 +592,36 @@
(let [~ginterf
(fn
~@(map
- (fn [args]
- (let [gargs (map #(gensym (str "gf__" % "__")) args)
- target (first gargs)]
- `([~@gargs]
- (. ~(with-meta target {:tag on-interface}) (~(or on-method method) ~@(rest gargs))))))
- arglists))
+ (fn [args]
+ (let [gargs (map #(gensym (str "gf__" % "__")) args)
+ target (first gargs)]
+ `([~@gargs]
+ (. ~(with-meta target {:tag on-interface}) (~(or on-method method) ~@(rest gargs))))))
+ arglists))
^clojure.lang.AFunction f#
(fn ~gthis
~@(map
- (fn [args]
- (let [gargs (map #(gensym (str "gf__" % "__")) args)
- target (first gargs)]
- (if extend-via-meta
- `([~@gargs]
- (let [cache# (.__methodImplCache ~gthis)
- f# (.fnFor cache# (clojure.lang.Util/classOf ~target))]
- (if (identical? f# ~ginterf)
- (f# ~@gargs)
- (if-let [meta# (when-let [m# (meta ~target)] ((.sym cache#) m#))]
- (meta# ~@gargs)
- (if f#
- (f# ~@gargs)
- ((-cache-protocol-fn ~gthis ~target ~on-interface ~ginterf) ~@gargs))))))
- `([~@gargs]
- (let [cache# (.__methodImplCache ~gthis)
- f# (.fnFor cache# (clojure.lang.Util/classOf ~target))]
- (if f#
- (f# ~@gargs)
- ((-cache-protocol-fn ~gthis ~target ~on-interface ~ginterf) ~@gargs)))))))
- arglists))]
+ (fn [args]
+ (let [gargs (map #(gensym (str "gf__" % "__")) args)
+ target (first gargs)]
+ (if extend-via-meta
+ `([~@gargs]
+ (let [cache# (.__methodImplCache ~gthis)
+ f# (.fnFor cache# (clojure.lang.Util/classOf ~target))]
+ (if (identical? f# ~ginterf)
+ (f# ~@gargs)
+ (if-let [meta# (when-let [m# (meta ~target)] ((.sym cache#) m#))]
+ (meta# ~@gargs)
+ (if f#
+ (f# ~@gargs)
+ ((-cache-protocol-fn ~gthis ~target ~on-interface ~ginterf) ~@gargs))))))
+ `([~@gargs]
+ (let [cache# (.__methodImplCache ~gthis)
+ f# (.fnFor cache# (clojure.lang.Util/classOf ~target))]
+ (if f#
+ (f# ~@gargs)
+ ((-cache-protocol-fn ~gthis ~target ~on-interface ~ginterf) ~@gargs)))))))
+ arglists))]
(set! (.__methodImplCache f#) cache#)
f#))))
@@ -673,33 +673,33 @@
(map #(vector m (vec (repeat (dec (count %))'Object)) 'Object)
(:arglists sig))))
(vals sigs))]
- `(do
- (defonce ~name {})
- (gen-interface :name ~iname :methods ~meths)
- (alter-meta! (var ~name) assoc :doc ~(:doc opts))
- ~(when sigs
- `(#'assert-same-protocol (var ~name) '~(map :name (vals sigs))))
- (alter-var-root (var ~name) merge
- (assoc ~opts
- :sigs '~sigs
- :var (var ~name)
- :method-map
+ `(do
+ (defonce ~name {})
+ (gen-interface :name ~iname :methods ~meths)
+ (alter-meta! (var ~name) assoc :doc ~(:doc opts))
+ ~(when sigs
+ `(#'assert-same-protocol (var ~name) '~(map :name (vals sigs))))
+ (alter-var-root (var ~name) merge
+ (assoc ~opts
+ :sigs '~sigs
+ :var (var ~name)
+ :method-map
~(and (:on opts)
(apply hash-map
(mapcat
- (fn [s]
- [(keyword (:name s)) (keyword (or (:on s) (:name s)))])
- (vals sigs))))
- :method-builders
- ~(apply hash-map
- (mapcat
- (fn [s]
- [`(intern *ns* (with-meta '~(:name s) (merge '~s {:protocol (var ~name)})))
- (emit-method-builder (:on-interface opts) (:name s) (:on s) (:arglists s)
- (:extend-via-metadata opts))])
- (vals sigs)))))
- (-reset-methods ~name)
- '~name)))
+ (fn [s]
+ [(keyword (:name s)) (keyword (or (:on s) (:name s)))])
+ (vals sigs))))
+ :method-builders
+ ~(apply hash-map
+ (mapcat
+ (fn [s]
+ [`(intern *ns* (with-meta '~(:name s) (merge '~s {:protocol (var ~name)})))
+ (emit-method-builder (:on-interface opts) (:name s) (:on s) (:arglists s)
+ (:extend-via-metadata opts))])
+ (vals sigs)))))
+ (-reset-methods ~name)
+ '~name)))
(defmacro defprotocol
"A protocol is a named set of named methods and their signatures:
@@ -805,11 +805,11 @@
(doseq [[proto mmap] (partition 2 proto+mmaps)]
(when-not (protocol? proto)
(throw (IllegalArgumentException.
- (str proto " is not a protocol"))))
+ (str proto " is not a protocol"))))
(when (implements? proto atype)
(throw (IllegalArgumentException.
- (str atype " already directly implements " (:on-interface proto) " for protocol:"
- (:var proto)))))
+ (str atype " already directly implements " (:on-interface proto) " for protocol:"
+ (:var proto)))))
(-reset-methods (alter-var-root (:var proto) assoc-in [:impls atype] mmap))))
(defn- emit-impl [[p fs]]
@@ -819,8 +819,8 @@
(defn- emit-hinted-impl [c [p fs]]
(let [hint (fn [specs]
(let [specs (if (vector? (first specs))
- (list specs)
- specs)]
+ (list specs)
+ specs)]
(map (fn [[[target & args] & body]]
(cons (apply vector (vary-meta target assoc :tag c) args)
body))
diff --git a/src/clj/clojure/core_print.clj b/src/clj/clojure/core_print.clj
index b4992aad..fa8ac706 100644
--- a/src/clj/clojure/core_print.clj
+++ b/src/clj/clojure/core_print.clj
@@ -14,18 +14,18 @@
(set! *warn-on-reflection* true)
(def ^:dynamic
- ^{:doc "*print-length* controls how many items of each collection the
+ ^{:doc "*print-length* controls how many items of each collection the
printer will print. If it is bound to logical false, there is no
limit. Otherwise, it must be bound to an integer indicating the maximum
number of items of each collection to print. If a collection contains
more items, the printer will print items up to the limit followed by
'...' to represent the remaining items. The root binding is nil
indicating no limit."
- :added "1.0"}
- *print-length* nil)
+ :added "1.0"}
+ *print-length* nil)
(def ^:dynamic
- ^{:doc "*print-level* controls how many levels deep the printer will
+ ^{:doc "*print-level* controls how many levels deep the printer will
print nested objects. If it is bound to logical false, there is no
limit. Otherwise, it must be bound to an integer indicating the maximum
level to print. Each argument to print is at level 0; if an argument is a
@@ -33,17 +33,17 @@
collection and is at a level greater than or equal to the value bound to
*print-level*, the printer prints '#' to represent it. The root binding
is nil indicating no limit."
- :added "1.0"}
- *print-level* nil)
+ :added "1.0"}
+ *print-level* nil)
(def ^:dynamic *verbose-defrecords* false)
(def ^:dynamic
- ^{:doc "*print-namespace-maps* controls whether the printer will print
+ ^{:doc "*print-namespace-maps* controls whether the printer will print
namespace map literal syntax. It defaults to false, but the REPL binds
to true."
- :added "1.9"}
- *print-namespace-maps* false)
+ :added "1.9"}
+ *print-namespace-maps* false)
(defn- print-sequential [^String begin, print-one, ^String sep, ^String end, sequence, ^Writer w]
(binding [*print-level* (and (not *print-dup*) *print-level* (dec *print-level*))]
@@ -185,7 +185,7 @@
(defmethod print-dup java.util.Collection [o, ^Writer w]
- (print-ctor o #(print-sequential "[" print-dup " " "]" %1 %2) w))
+ (print-ctor o #(print-sequential "[" print-dup " " "]" %1 %2) w))
(defmethod print-dup clojure.lang.IPersistentCollection [o, ^Writer w]
(print-meta o w)
@@ -201,13 +201,13 @@
:doc "Returns escape string for char or nil if none"
:added "1.0"}
char-escape-string
- {\newline "\\n"
- \tab "\\t"
- \return "\\r"
- \" "\\\""
- \\ "\\\\"
- \formfeed "\\f"
- \backspace "\\b"})
+ {\newline "\\n"
+ \tab "\\t"
+ \return "\\r"
+ \" "\\\""
+ \\ "\\\\"
+ \formfeed "\\f"
+ \backspace "\\b"})
(defmethod print-method String [^String s, ^Writer w]
(if (or *print-dup* *print-readably*)
@@ -342,13 +342,13 @@
(def ^{:tag String
:doc "Returns name string for char or nil if none"
:added "1.0"}
- char-name-string
- {\newline "newline"
- \tab "tab"
- \space "space"
- \backspace "backspace"
- \formfeed "formfeed"
- \return "return"})
+ char-name-string
+ {\newline "newline"
+ \tab "tab"
+ \space "space"
+ \backspace "backspace"
+ \formfeed "formfeed"
+ \return "return"})
(defmethod print-method java.lang.Character [^Character c, ^Writer w]
(if (or *print-dup* *print-readably*)
@@ -414,8 +414,8 @@
(.append w \\)
(.append w c2)
(if qmode
- (recur r2 (not= c2 \E))
- (recur r2 (= c2 \Q))))
+ (recur r2 (not= c2 \E))
+ (recur r2 (= c2 \Q))))
(= c \") (do
(if qmode
(.write w "\\E\\\"\\Q")
@@ -443,16 +443,16 @@
[true e])))]
{:status
(cond
- (or ex
- (and (instance? clojure.lang.Agent o)
- (agent-error o)))
- :failed
+ (or ex
+ (and (instance? clojure.lang.Agent o)
+ (agent-error o)))
+ :failed
- pending
- :pending
+ pending
+ :pending
- :else
- :ready)
+ :else
+ :ready)
:val val}))
@@ -508,16 +508,16 @@
(.write w "#error {\n :cause ")
(let [{:keys [cause data via trace]} (Throwable->map o)
print-via #(do (.write w "{:type ")
- (print-method (:type %) w)
- (.write w "\n :message ")
- (print-method (:message %) w)
- (when-let [data (:data %)]
- (.write w "\n :data ")
- (print-method data w))
- (when-let [at (:at %)]
- (.write w "\n :at ")
- (print-method (:at %) w))
- (.write w "}"))]
+ (print-method (:type %) w)
+ (.write w "\n :message ")
+ (print-method (:message %) w)
+ (when-let [data (:data %)]
+ (.write w "\n :data ")
+ (print-method data w))
+ (when-let [at (:at %)]
+ (.write w "\n :at ")
+ (print-method (:at %) w))
+ (.write w "}"))]
(print-method cause w)
(when data
(.write w "\n :data ")
@@ -525,10 +525,10 @@
(when via
(.write w "\n :via\n [")
(when-let [fv (first via)]
- (print-via fv)
+ (print-via fv)
(doseq [v (rest via)]
(.write w "\n ")
- (print-via v)))
+ (print-via v)))
(.write w "]"))
(when trace
(.write w "\n :trace\n [")
diff --git a/src/clj/clojure/core_proxy.clj b/src/clj/clojure/core_proxy.clj
index cacd2dce..1340fa3e 100644
--- a/src/clj/clojure/core_proxy.clj
+++ b/src/clj/clojure/core_proxy.clj
@@ -11,11 +11,11 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;; proxy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(import
- '(clojure.asm ClassWriter ClassVisitor Opcodes Type)
- '(java.lang.reflect Modifier Constructor)
- '(java.io Serializable NotSerializableException)
- '(clojure.asm.commons Method GeneratorAdapter)
- '(clojure.lang IProxy Reflector DynamicClassLoader IPersistentMap PersistentHashMap RT))
+ '(clojure.asm ClassWriter ClassVisitor Opcodes Type)
+ '(java.lang.reflect Modifier Constructor)
+ '(java.io Serializable NotSerializableException)
+ '(clojure.asm.commons Method GeneratorAdapter)
+ '(clojure.lang IProxy Reflector DynamicClassLoader IPersistentMap PersistentHashMap RT))
(defn method-sig [^java.lang.reflect.Method meth]
[(. meth (getName)) (seq (. meth (getParameterTypes))) (. meth getReturnType)])
@@ -29,14 +29,14 @@
return-types to meths."
[coll]
(vals (reduce1 (fn [m [msig meth]]
- (let [rtype (peek msig)
- argsig (pop msig)]
- (assoc m argsig (assoc (m argsig {}) rtype meth))))
+ (let [rtype (peek msig)
+ argsig (pop msig)]
+ (assoc m argsig (assoc (m argsig {}) rtype meth))))
{} coll)))
(defn proxy-name
- {:tag String}
- [^Class super interfaces]
+ {:tag String}
+ [^Class super interfaces]
(let [inames (into1 (sorted-set) (map #(.getName ^Class %) interfaces))]
(apply str (.replace (str *ns*) \- \_) ".proxy"
(interleave (repeat "$")
@@ -75,7 +75,7 @@
(. gen (visitCode))
(. gen (loadThis))
(dotimes [i (count ptypes)]
- (. gen (loadArg i)))
+ (. gen (loadArg i)))
(if (-> dest .getDeclaringClass .isInterface)
(. gen (invokeInterface dtype dm))
(. gen (invokeVirtual dtype dm)))
@@ -99,28 +99,28 @@
(. gen (getField ctype fmap imap-type))
(. gen (push (. meth (getName))))
- ;lookup fn in map
+ ;lookup fn in map
(. gen (invokeStatic rt-type (. Method (getMethod "Object get(Object, Object)"))))
(. gen (dup))
(. gen (ifNull else-label))
- ;if found
+ ;if found
(.checkCast gen ifn-type)
(. gen (loadThis))
- ;box args
+ ;box args
(dotimes [i (count ptypes)]
- (. gen (loadArg i))
+ (. gen (loadArg i))
(. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i))))
- ;call fn
+ ;call fn
(. gen (invokeInterface ifn-type (new Method "invoke" obj-type
(into-array (cons obj-type
(replicate (count ptypes) obj-type))))))
- ;unbox return
+ ;unbox return
(. gen (unbox rtype))
(when (= (. rtype (getSort)) (. Type VOID))
(. gen (pop)))
(. gen (goTo end-label))
- ;else call supplied alternative generator
+ ;else call supplied alternative generator
(. gen (mark else-label))
(. gen (pop))
@@ -130,29 +130,29 @@
(. gen (returnValue))
(. gen (endMethod))))]
- ;start class definition
+ ;start class definition
(. cv (visit (. Opcodes V1_5) (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_SUPER))
cname nil (iname super)
(into-array (map iname (cons IProxy interfaces)))))
- ;add field for fn mappings
+ ;add field for fn mappings
(. cv (visitField (+ (. Opcodes ACC_PRIVATE) (. Opcodes ACC_VOLATILE))
fmap (. imap-type (getDescriptor)) nil nil))
- ;add ctors matching/calling super's
+ ;add ctors matching/calling super's
(doseq [^Constructor ctor (. super (getDeclaredConstructors))]
- (when-not (. Modifier (isPrivate (. ctor (getModifiers))))
- (let [ptypes (to-types (. ctor (getParameterTypes)))
- m (new Method "<init>" (. Type VOID_TYPE) ptypes)
- gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
- (. gen (visitCode))
- ;call super ctor
- (. gen (loadThis))
- (. gen (dup))
- (. gen (loadArgs))
- (. gen (invokeConstructor super-type m))
+ (when-not (. Modifier (isPrivate (. ctor (getModifiers))))
+ (let [ptypes (to-types (. ctor (getParameterTypes)))
+ m (new Method "<init>" (. Type VOID_TYPE) ptypes)
+ gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
+ (. gen (visitCode))
+ ;call super ctor
+ (. gen (loadThis))
+ (. gen (dup))
+ (. gen (loadArgs))
+ (. gen (invokeConstructor super-type m))
- (. gen (returnValue))
- (. gen (endMethod)))))
- ;disable serialization
+ (. gen (returnValue))
+ (. gen (endMethod)))))
+ ;disable serialization
(when (some #(isa? % Serializable) (cons super interfaces))
(let [m (. Method (getMethod "void writeObject(java.io.ObjectOutputStream)"))
gen (new GeneratorAdapter (. Opcodes ACC_PRIVATE) m nil nil cv)]
@@ -168,7 +168,7 @@
(. gen (loadArgs))
(. gen (throwException (totype NotSerializableException) pname))
(. gen (endMethod))))
- ;add IProxy methods
+ ;add IProxy methods
(let [m (. Method (getMethod "void __initClojureFnMappings(clojure.lang.IPersistentMap)"))
gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
(. gen (visitCode))
@@ -201,31 +201,31 @@
(. gen (returnValue))
(. gen (endMethod)))
- ;calc set of supers' non-private instance methods
+ ;calc set of supers' non-private instance methods
(let [[mm considered]
- (loop [mm {} considered #{} c super]
- (if c
- (let [[mm considered]
- (loop [mm mm
- considered considered
- meths (concat
- (seq (. c (getDeclaredMethods)))
- (seq (. c (getMethods))))]
- (if (seq meths)
- (let [^java.lang.reflect.Method meth (first meths)
- mods (. meth (getModifiers))
- mk (method-sig meth)]
- (if (or (considered mk)
- (not (or (Modifier/isPublic mods) (Modifier/isProtected mods)))
- ;(. Modifier (isPrivate mods))
- (. Modifier (isStatic mods))
- (. Modifier (isFinal mods))
- (= "finalize" (.getName meth)))
- (recur mm (conj considered mk) (next meths))
- (recur (assoc mm mk meth) (conj considered mk) (next meths))))
- [mm considered]))]
- (recur mm considered (. c (getSuperclass))))
- [mm considered]))
+ (loop [mm {} considered #{} c super]
+ (if c
+ (let [[mm considered]
+ (loop [mm mm
+ considered considered
+ meths (concat
+ (seq (. c (getDeclaredMethods)))
+ (seq (. c (getMethods))))]
+ (if (seq meths)
+ (let [^java.lang.reflect.Method meth (first meths)
+ mods (. meth (getModifiers))
+ mk (method-sig meth)]
+ (if (or (considered mk)
+ (not (or (Modifier/isPublic mods) (Modifier/isProtected mods)))
+ ;(. Modifier (isPrivate mods))
+ (. Modifier (isStatic mods))
+ (. Modifier (isFinal mods))
+ (= "finalize" (.getName meth)))
+ (recur mm (conj considered mk) (next meths))
+ (recur (assoc mm mk meth) (conj considered mk) (next meths))))
+ [mm considered]))]
+ (recur mm considered (. c (getSuperclass))))
+ [mm considered]))
ifaces-meths (into1 {}
(for [^Class iface interfaces meth (. iface (getMethods))
:let [msig (method-sig meth)] :when (not (considered msig))]
@@ -242,29 +242,29 @@
bridge? (reduce1 into1 #{} (map second mb))
ifaces-meths (remove bridge? (vals ifaces-meths))
mm (remove bridge? (vals mm))]
- ;add methods matching supers', if no mapping -> call super
+ ;add methods matching supers', if no mapping -> call super
(doseq [[^java.lang.reflect.Method dest bridges] mb
^java.lang.reflect.Method meth bridges]
- (gen-bridge meth dest))
+ (gen-bridge meth dest))
(doseq [^java.lang.reflect.Method meth mm]
- (gen-method meth
- (fn [^GeneratorAdapter gen ^Method m]
- (. gen (loadThis))
- ;push args
+ (gen-method meth
+ (fn [^GeneratorAdapter gen ^Method m]
+ (. gen (loadThis))
+ ;push args
(. gen (loadArgs))
- ;call super
+ ;call super
(. gen (visitMethodInsn (. Opcodes INVOKESPECIAL)
(. super-type (getInternalName))
(. m (getName))
(. m (getDescriptor)))))))
- ;add methods matching interfaces', if no mapping -> throw
+ ;add methods matching interfaces', if no mapping -> throw
(doseq [^java.lang.reflect.Method meth ifaces-meths]
- (gen-method meth
- (fn [^GeneratorAdapter gen ^Method m]
- (. gen (throwException ex-type (. m (getName))))))))
+ (gen-method meth
+ (fn [^GeneratorAdapter gen ^Method m]
+ (. gen (throwException ex-type (. m (getName))))))))
- ;finish class def
+ ;finish class def
(. cv (visitEnd))
[cname (. cv toByteArray)]))
@@ -281,18 +281,18 @@
requests for the same class set. Returns a Class object."
{:added "1.0"}
[& bases]
- (let [[super interfaces] (get-super-and-interfaces bases)
- pname (proxy-name super interfaces)]
- (or (RT/loadClassForName pname)
- (let [[cname bytecode] (generate-proxy super interfaces)]
- (. ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER) (defineClass pname bytecode [super interfaces]))))))
+ (let [[super interfaces] (get-super-and-interfaces bases)
+ pname (proxy-name super interfaces)]
+ (or (RT/loadClassForName pname)
+ (let [[cname bytecode] (generate-proxy super interfaces)]
+ (. ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER) (defineClass pname bytecode [super interfaces]))))))
(defn construct-proxy
"Takes a proxy class and any arguments for its superclass ctor and
creates and returns an instance of the proxy."
{:added "1.0"}
[c & ctor-args]
- (. Reflector (invokeConstructor c (to-array ctor-args))))
+ (. Reflector (invokeConstructor c (to-array ctor-args))))
(defn init-proxy
"Takes a proxy instance and a map of strings (which must
@@ -302,8 +302,8 @@
sets the proxy's fn map. Returns the proxy."
{:added "1.0"}
[^IProxy proxy mappings]
- (. proxy (__initClojureFnMappings mappings))
- proxy)
+ (. proxy (__initClojureFnMappings mappings))
+ proxy)
(defn update-proxy
"Takes a proxy instance and a map of strings (which must
@@ -317,14 +317,14 @@
Returns the proxy."
{:added "1.0"}
[^IProxy proxy mappings]
- (. proxy (__updateClojureFnMappings mappings))
- proxy)
+ (. proxy (__updateClojureFnMappings mappings))
+ proxy)
(defn proxy-mappings
"Takes a proxy instance and returns the proxy's fn map."
{:added "1.0"}
[^IProxy proxy]
- (. proxy (__getClojureFnMappings)))
+ (. proxy (__getClojureFnMappings)))
(defmacro proxy
"class-and-interfaces - a vector of class names
@@ -352,19 +352,19 @@
proxied."
{:added "1.0"}
[class-and-interfaces args & fs]
- (let [bases (map #(or (resolve %) (throw (Exception. (str "Can't resolve: " %))))
- class-and-interfaces)
- [super interfaces] (get-super-and-interfaces bases)
- compile-effect (when *compile-files*
- (let [[cname bytecode] (generate-proxy super interfaces)]
- (clojure.lang.Compiler/writeClassFile cname bytecode)))
- pc-effect (apply get-proxy-class bases)
- pname (proxy-name super interfaces)]
- ;remember the class to prevent it from disappearing before use
- (intern *ns* (symbol pname) pc-effect)
- `(let [;pc# (get-proxy-class ~@class-and-interfaces)
- p# (new ~(symbol pname) ~@args)] ;(construct-proxy pc# ~@args)]
- (init-proxy p#
+ (let [bases (map #(or (resolve %) (throw (Exception. (str "Can't resolve: " %))))
+ class-and-interfaces)
+ [super interfaces] (get-super-and-interfaces bases)
+ compile-effect (when *compile-files*
+ (let [[cname bytecode] (generate-proxy super interfaces)]
+ (clojure.lang.Compiler/writeClassFile cname bytecode)))
+ pc-effect (apply get-proxy-class bases)
+ pname (proxy-name super interfaces)]
+ ;remember the class to prevent it from disappearing before use
+ (intern *ns* (symbol pname) pc-effect)
+ `(let [;pc# (get-proxy-class ~@class-and-interfaces)
+ p# (new ~(symbol pname) ~@args)] ;(construct-proxy pc# ~@args)]
+ (init-proxy p#
~(loop [fmap {} fs fs]
(if fs
(let [[sym & meths] (first fs)
@@ -375,14 +375,14 @@
(cons (apply vector 'this params) body))
meths)]
(if-not (contains? fmap (name sym))
- (recur (assoc fmap (name sym) (cons `fn meths)) (next fs))
- (throw (IllegalArgumentException.
- (str "Method '" (name sym) "' redefined")))))
+ (recur (assoc fmap (name sym) (cons `fn meths)) (next fs))
+ (throw (IllegalArgumentException.
+ (str "Method '" (name sym) "' redefined")))))
fmap)))
- p#)))
+ p#)))
(defn proxy-call-with-super [call this meth]
- (let [m (proxy-mappings this)]
+ (let [m (proxy-mappings this)]
(update-proxy this (assoc m meth nil))
(try
(call)
@@ -393,7 +393,7 @@
Note, expansion captures 'this"
{:added "1.0"}
[meth & args]
- `(proxy-call-with-super (fn [] (. ~'this ~meth ~@args)) ~'this ~(name meth)))
+ `(proxy-call-with-super (fn [] (. ~'this ~meth ~@args)) ~'this ~(name meth)))
(defn bean
"Takes a Java object and returns a read-only implementation of the
@@ -401,21 +401,21 @@
{:added "1.0"}
[^Object x]
(let [c (. x (getClass))
- pmap (reduce1 (fn [m ^java.beans.PropertyDescriptor pd]
- (let [name (. pd (getName))
- method (. pd (getReadMethod))]
- (if (and method (zero? (alength (. method (getParameterTypes)))))
- (assoc m (keyword name) (fn [] (clojure.lang.Reflector/prepRet (.getPropertyType pd) (. method (invoke x nil)))))
- m)))
- {}
- (seq (.. java.beans.Introspector
- (getBeanInfo c)
- (getPropertyDescriptors))))
- v (fn [k] ((pmap k)))
+ pmap (reduce1 (fn [m ^java.beans.PropertyDescriptor pd]
+ (let [name (. pd (getName))
+ method (. pd (getReadMethod))]
+ (if (and method (zero? (alength (. method (getParameterTypes)))))
+ (assoc m (keyword name) (fn [] (clojure.lang.Reflector/prepRet (.getPropertyType pd) (. method (invoke x nil)))))
+ m)))
+ {}
+ (seq (.. java.beans.Introspector
+ (getBeanInfo c)
+ (getPropertyDescriptors))))
+ v (fn [k] ((pmap k)))
snapshot (fn []
(reduce1 (fn [m e]
- (assoc m (key e) ((val e))))
- {} (seq pmap)))
+ (assoc m (key e) ((val e))))
+ {} (seq pmap)))
thisfn (fn thisfn [plseq]
(lazy-seq
(when-let [pseq (seq plseq)]
@@ -423,16 +423,16 @@
(thisfn (rest pseq))))))]
(proxy [clojure.lang.APersistentMap]
[]
- (iterator [] (clojure.lang.SeqIterator. ^java.util.Iterator (thisfn (keys pmap))))
- (containsKey [k] (contains? pmap k))
- (entryAt [k] (when (contains? pmap k) (clojure.lang.MapEntry/create k (v k))))
- (valAt ([k] (when (contains? pmap k) (v k)))
- ([k default] (if (contains? pmap k) (v k) default)))
- (cons [m] (conj (snapshot) m))
- (count [] (count pmap))
- (assoc [k v] (assoc (snapshot) k v))
- (without [k] (dissoc (snapshot) k))
- (seq [] (thisfn (keys pmap))))))
+ (iterator [] (clojure.lang.SeqIterator. ^java.util.Iterator (thisfn (keys pmap))))
+ (containsKey [k] (contains? pmap k))
+ (entryAt [k] (when (contains? pmap k) (clojure.lang.MapEntry/create k (v k))))
+ (valAt ([k] (when (contains? pmap k) (v k)))
+ ([k default] (if (contains? pmap k) (v k) default)))
+ (cons [m] (conj (snapshot) m))
+ (count [] (count pmap))
+ (assoc [k v] (assoc (snapshot) k v))
+ (without [k] (dissoc (snapshot) k))
+ (seq [] (thisfn (keys pmap))))))
diff --git a/src/clj/clojure/data.clj b/src/clj/clojure/data.clj
index 345b2346..e89b37aa 100644
--- a/src/clj/clojure/data.clj
+++ b/src/clj/clojure/data.clj
@@ -26,9 +26,9 @@
[m]
(when (seq m)
(reduce
- (fn [result [k v]] (assoc result k v))
- (vec (repeat (apply max (keys m)) nil))
- m)))
+ (fn [result [k v]] (assoc result k v))
+ (vec (repeat (apply max (keys m)) nil))
+ m)))
(defn- diff-associative-key
"Diff associative things a and b, comparing only the key k."
@@ -50,19 +50,19 @@
"Diff associative things a and b, comparing only keys in ks."
[a b ks]
(reduce
- (fn [diff1 diff2]
- (doall (map merge diff1 diff2)))
- [nil nil nil]
- (map
- (partial diff-associative-key a b)
- ks)))
+ (fn [diff1 diff2]
+ (doall (map merge diff1 diff2)))
+ [nil nil nil]
+ (map
+ (partial diff-associative-key a b)
+ ks)))
(defn- diff-sequential
[a b]
(vec (map vectorize (diff-associative
- (if (vector? a) a (vec a))
- (if (vector? b) b (vec b))
- (range (max (count a) (count b)))))))
+ (if (vector? a) a (vec a))
+ (if (vector? b) b (vec b))
+ (range (max (count a) (count b)))))))
(defprotocol ^{:added "1.3"} EqualityPartition
"Implementation detail. Subject to change."
@@ -102,12 +102,12 @@
(extend-protocol Diff
java.util.Set
(diff-similar
- [a b]
- (let [aval (as-set-value a)
- bval (as-set-value b)]
- [(not-empty (set/difference aval bval))
- (not-empty (set/difference bval aval))
- (not-empty (set/intersection aval bval))]))
+ [a b]
+ (let [aval (as-set-value a)
+ bval (as-set-value b)]
+ [(not-empty (set/difference aval bval))
+ (not-empty (set/difference bval aval))
+ (not-empty (set/intersection aval bval))]))
java.util.List
(diff-similar [a b]
diff --git a/src/clj/clojure/edn.clj b/src/clj/clojure/edn.clj
index 6d1634af..dd22d115 100644
--- a/src/clj/clojure/edn.clj
+++ b/src/clj/clojure/edn.clj
@@ -32,7 +32,7 @@
([stream]
(read {} stream))
([opts stream]
- (clojure.lang.EdnReader/read stream opts)))
+ (clojure.lang.EdnReader/read stream opts)))
(defn read-string
"Reads one object from the string s. Returns nil when s is nil or empty.
diff --git a/src/clj/clojure/genclass.clj b/src/clj/clojure/genclass.clj
index a4fa0ec5..44705528 100644
--- a/src/clj/clojure/genclass.clj
+++ b/src/clj/clojure/genclass.clj
@@ -103,13 +103,13 @@
(defn- ^Class the-class [x]
(cond
- (class? x) x
- (contains? prim->class x) (prim->class x)
- :else (let [strx (str x)]
- (clojure.lang.RT/classForName
- (if (some #{\. \[} strx)
- strx
- (str "java.lang." strx))))))
+ (class? x) x
+ (contains? prim->class x) (prim->class x)
+ :else (let [strx (str x)]
+ (clojure.lang.RT/classForName
+ (if (some #{\. \[} strx)
+ strx
+ (str "java.lang." strx))))))
;; someday this can be made codepoint aware
(defn- valid-java-method-name
@@ -126,7 +126,7 @@
(let [default-options {:prefix "-" :load-impl-ns true :impl-ns (ns-name *ns*)}
{:keys [name extends implements constructors methods main factory state init exposes
exposes-methods prefix load-impl-ns impl-ns post-init]}
- (merge default-options options-map)
+ (merge default-options options-map)
name-meta (meta name)
name (str name)
super (if extends (the-class extends) Object)
@@ -222,28 +222,28 @@
(. gen (ifNull else-label))
(when is-overload
(. gen (mark found-label)))
- ;if found
+ ;if found
(.checkCast gen ifn-type)
(when-not as-static
(. gen (loadThis)))
- ;box args
+ ;box args
(dotimes [i (count ptypes)]
(. gen (loadArg i))
(. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i))))
- ;call fn
+ ;call fn
(. gen (invokeInterface ifn-type (new Method "invoke" obj-type
(to-types (replicate (+ (count ptypes)
(if as-static 0 1))
Object)))))
- ;(into-array (cons obj-type
- ; (replicate (count ptypes) obj-type))))))
- ;unbox return
+ ;(into-array (cons obj-type
+ ; (replicate (count ptypes) obj-type))))))
+ ;unbox return
(. gen (unbox rtype))
(when (= (. rtype (getSort)) (. Type VOID))
(. gen (pop)))
(. gen (goTo end-label))
- ;else call supplied alternative generator
+ ;else call supplied alternative generator
(. gen (mark else-label))
(. gen (pop))
@@ -253,30 +253,30 @@
(. gen (returnValue))
(. gen (endMethod))))
]
- ;start class definition
+ ;start class definition
(. cv (visit (. Opcodes V1_8) (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_SUPER))
cname nil (iname super)
(when-let [ifc (seq interfaces)]
(into-array (map iname ifc)))))
- ; class annotations
+ ; class annotations
(add-annotations cv name-meta)
- ;static fields for vars
+ ;static fields for vars
(doseq [v var-fields]
(. cv (visitField (+ (. Opcodes ACC_PRIVATE) (. Opcodes ACC_FINAL) (. Opcodes ACC_STATIC))
(var-name v)
(. var-type getDescriptor)
nil nil)))
- ;instance field for state
+ ;instance field for state
(when state
(. cv (visitField (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_FINAL))
state-name
(. obj-type getDescriptor)
nil nil)))
- ;static init to set up var fields and load init
+ ;static init to set up var fields and load init
(let [gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_STATIC))
(. Method getMethod "void <clinit> ()")
nil nil cv)]
@@ -291,14 +291,14 @@
(. gen push (str "/" impl-cname))
(. gen push ctype)
(. gen (invokeStatic util-type (. Method (getMethod "Object loadWithClass(String,Class)"))))
-; (. gen push (str (.replace impl-pkg-name \- \_) "__init"))
-; (. gen (invokeStatic class-type (. Method (getMethod "Class forName(String)"))))
+ ; (. gen push (str (.replace impl-pkg-name \- \_) "__init"))
+ ; (. gen (invokeStatic class-type (. Method (getMethod "Class forName(String)"))))
(. gen pop))
(. gen (returnValue))
(. gen (endMethod)))
- ;ctors
+ ;ctors
(doseq [[pclasses super-pclasses] ctor-sig-map]
(let [constructor-annotations (meta pclasses)
pclasses (map the-class pclasses)
@@ -323,14 +323,14 @@
(. gen dup)
(. gen ifNull no-init-label)
(.checkCast gen ifn-type)
- ;box init args
+ ;box init args
(dotimes [i (count pclasses)]
(. gen (loadArg i))
(. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i))))
- ;call init fn
+ ;call init fn
(. gen (invokeInterface ifn-type (new Method "invoke" obj-type
(arg-types (count ptypes)))))
- ;expecting [[super-ctor-args] state] returned
+ ;expecting [[super-ctor-args] state] returned
(. gen dup)
(. gen push (int 0))
(. gen (invokeStatic rt-type nth-method))
@@ -353,7 +353,7 @@
(. gen pop))
(. gen goTo end-label)
- ;no init found
+ ;no init found
(. gen mark no-init-label)
(. gen (throwException ex-type (str impl-pkg-name "/" prefix init-name " not defined")))
(. gen mark end-label))
@@ -370,23 +370,23 @@
(. gen ifNull no-post-init-label)
(.checkCast gen ifn-type)
(. gen (loadThis))
- ;box init args
+ ;box init args
(dotimes [i (count pclasses)]
(. gen (loadArg i))
(. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i))))
- ;call init fn
+ ;call init fn
(. gen (invokeInterface ifn-type (new Method "invoke" obj-type
(arg-types (inc (count ptypes))))))
(. gen pop)
(. gen goTo end-post-init-label)
- ;no init found
+ ;no init found
(. gen mark no-post-init-label)
(. gen (throwException ex-type (str impl-pkg-name "/" prefix post-init-name " not defined")))
(. gen mark end-post-init-label))
(. gen (returnValue))
(. gen (endMethod))
- ;factory
+ ;factory
(when factory
(let [fm (new Method factory-name ctype ptypes)
gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_STATIC))
@@ -399,52 +399,52 @@
(. gen (returnValue))
(. gen (endMethod))))))
- ;add methods matching supers', if no fn -> call super
+ ;add methods matching supers', if no fn -> call super
(let [mm (non-private-methods super)]
(doseq [^java.lang.reflect.Method meth (vals mm)]
(emit-forwarding-method (.getName meth) (.getParameterTypes meth) (.getReturnType meth) false
(fn [^GeneratorAdapter gen ^Method m]
(. gen (loadThis))
- ;push args
+ ;push args
(. gen (loadArgs))
- ;call super
+ ;call super
(. gen (visitMethodInsn (. Opcodes INVOKESPECIAL)
(. super-type (getInternalName))
(. m (getName))
(. m (getDescriptor)))))))
- ;add methods matching interfaces', if no fn -> throw
+ ;add methods matching interfaces', if no fn -> throw
(reduce1 (fn [mm ^java.lang.reflect.Method meth]
- (if (contains? mm (method-sig meth))
- mm
- (do
- (emit-forwarding-method (.getName meth) (.getParameterTypes meth) (.getReturnType meth) false
- emit-unsupported)
- (assoc mm (method-sig meth) meth))))
- mm (mapcat #(.getMethods ^Class %) interfaces))
- ;extra methods
- (doseq [[mname pclasses rclass :as msig] methods]
- (emit-forwarding-method mname pclasses rclass (:static (meta msig))
- emit-unsupported))
- ;expose specified overridden superclass methods
- (doseq [[local-mname ^java.lang.reflect.Method m] (reduce1 (fn [ms [[name _ _] m]]
- (if (contains? exposes-methods (symbol name))
- (conj ms [((symbol name) exposes-methods) m])
- ms)) [] (concat (seq mm)
- (seq (protected-final-methods super))))]
- (let [ptypes (to-types (.getParameterTypes m))
- rtype (totype (.getReturnType m))
- exposer-m (new Method (str local-mname) rtype ptypes)
- target-m (new Method (.getName m) rtype ptypes)
- gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) exposer-m nil nil cv)]
- (. gen (loadThis))
- (. gen (loadArgs))
- (. gen (visitMethodInsn (. Opcodes INVOKESPECIAL)
- (. super-type (getInternalName))
- (. target-m (getName))
- (. target-m (getDescriptor))))
- (. gen (returnValue))
- (. gen (endMethod)))))
- ;main
+ (if (contains? mm (method-sig meth))
+ mm
+ (do
+ (emit-forwarding-method (.getName meth) (.getParameterTypes meth) (.getReturnType meth) false
+ emit-unsupported)
+ (assoc mm (method-sig meth) meth))))
+ mm (mapcat #(.getMethods ^Class %) interfaces))
+ ;extra methods
+ (doseq [[mname pclasses rclass :as msig] methods]
+ (emit-forwarding-method mname pclasses rclass (:static (meta msig))
+ emit-unsupported))
+ ;expose specified overridden superclass methods
+ (doseq [[local-mname ^java.lang.reflect.Method m] (reduce1 (fn [ms [[name _ _] m]]
+ (if (contains? exposes-methods (symbol name))
+ (conj ms [((symbol name) exposes-methods) m])
+ ms)) [] (concat (seq mm)
+ (seq (protected-final-methods super))))]
+ (let [ptypes (to-types (.getParameterTypes m))
+ rtype (totype (.getReturnType m))
+ exposer-m (new Method (str local-mname) rtype ptypes)
+ target-m (new Method (.getName m) rtype ptypes)
+ gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) exposer-m nil nil cv)]
+ (. gen (loadThis))
+ (. gen (loadArgs))
+ (. gen (visitMethodInsn (. Opcodes INVOKESPECIAL)
+ (. super-type (getInternalName))
+ (. target-m (getName))
+ (. target-m (getDescriptor))))
+ (. gen (returnValue))
+ (. gen (endMethod)))))
+ ;main
(when main
(let [m (. Method getMethod "void main (String[])")
gen (new GeneratorAdapter (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_STATIC))
@@ -463,13 +463,13 @@
(into-array [iseq-type]))))
(. gen pop)
(. gen goTo end-label)
- ;no main found
+ ;no main found
(. gen mark no-main-label)
(. gen (throwException ex-type (str impl-pkg-name "/" prefix main-name " not defined")))
(. gen mark end-label)
(. gen (returnValue))
(. gen (endMethod))))
- ;field exposers
+ ;field exposers
(doseq [[f {getter :get setter :set}] exposes]
(let [fld (find-field super (str f))
ftype (totype (.getType fld))
@@ -500,7 +500,7 @@
(. gen putField ctype (str f) ftype)))
(. gen (returnValue))
(. gen (endMethod))))))
- ;finish class def
+ ;finish class def
(. cv (visitEnd))
[cname (. cv (toByteArray))]))
@@ -632,10 +632,10 @@
{:added "1.0"}
[& options]
- (when *compile-files*
- (let [options-map (into1 {} (map vec (partition 2 options)))
- [cname bytecode] (generate-class options-map)]
- (clojure.lang.Compiler/writeClassFile cname bytecode))))
+ (when *compile-files*
+ (let [options-map (into1 {} (map vec (partition 2 options)))
+ [cname bytecode] (generate-class options-map)]
+ (clojure.lang.Compiler/writeClassFile cname bytecode))))
;;;;;;;;;;;;;;;;;;;; gen-interface ;;;;;;;;;;;;;;;;;;;;;;
;; based on original contribution by Chris Houser
@@ -650,10 +650,10 @@
(Type/getType (the-class c))
(let [strx (str c)]
(Type/getObjectType
- (.replace (if (some #{\. \[} strx)
- strx
- (str "java.lang." strx))
- "." "/")))))
+ (.replace (if (some #{\. \[} strx)
+ strx
+ (str "java.lang." strx))
+ "." "/")))))
(defn- generate-interface
[{:keys [name extends methods]}]
@@ -715,27 +715,27 @@
{:added "1.0"}
[& options]
- (let [options-map (apply hash-map options)
- [cname bytecode] (generate-interface options-map)]
- (when *compile-files*
- (clojure.lang.Compiler/writeClassFile cname bytecode))
- (.defineClass ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER)
- (str (:name options-map)) bytecode options)))
+ (let [options-map (apply hash-map options)
+ [cname bytecode] (generate-interface options-map)]
+ (when *compile-files*
+ (clojure.lang.Compiler/writeClassFile cname bytecode))
+ (.defineClass ^DynamicClassLoader (deref clojure.lang.Compiler/LOADER)
+ (str (:name options-map)) bytecode options)))
(comment
-(defn gen-and-load-class
- "Generates and immediately loads the bytecode for the specified
+ (defn gen-and-load-class
+ "Generates and immediately loads the bytecode for the specified
class. Note that a class generated this way can be loaded only once
- the JVM supports only one class with a given name per
classloader. Subsequent to generation you can import it into any
desired namespaces just like any other class. See gen-class for a
description of the options."
- {:added "1.0"}
+ {:added "1.0"}
- [& options]
- (let [options-map (apply hash-map options)
- [cname bytecode] (generate-class options-map)]
- (.. (clojure.lang.RT/getRootClassLoader) (defineClass cname bytecode options))))
+ [& options]
+ (let [options-map (apply hash-map options)
+ [cname bytecode] (generate-class options-map)]
+ (.. (clojure.lang.RT/getRootClassLoader) (defineClass cname bytecode options))))
-)
+ )
diff --git a/src/clj/clojure/gvec.clj b/src/clj/clojure/gvec.clj
index 6208f553..b6d51955 100644
--- a/src/clj/clojure/gvec.clj
+++ b/src/clj/clojure/gvec.clj
@@ -60,23 +60,23 @@
clojure.core.protocols.InternalReduce
(internal-reduce
- [_ f val]
- (loop [result val
- aidx (+ i offset)]
- (if (< aidx (count vec))
- (let [node (.arrayFor vec aidx)
- result (loop [result result
- node-idx (bit-and 0x1f aidx)]
- (if (< node-idx (.alength am node))
- (let [result (f result (.aget am node node-idx))]
- (if (reduced? result)
- result
- (recur result (inc node-idx))))
- result))]
- (if (reduced? result)
- @result
- (recur result (bit-and 0xffe0 (+ aidx 32)))))
- result)))
+ [_ f val]
+ (loop [result val
+ aidx (+ i offset)]
+ (if (< aidx (count vec))
+ (let [node (.arrayFor vec aidx)
+ result (loop [result result
+ node-idx (bit-and 0x1f aidx)]
+ (if (< node-idx (.alength am node))
+ (let [result (f result (.aget am node node-idx))]
+ (if (reduced? result)
+ result
+ (recur result (inc node-idx))))
+ result))]
+ (if (reduced? result)
+ @result
+ (recur result (bit-and 0xffe0 (+ aidx 32)))))
+ result)))
clojure.lang.ISeq
(first [_] (.aget am anode offset))
@@ -99,15 +99,15 @@
i)))
(equiv [this o]
(cond
- (identical? this o) true
- (or (instance? clojure.lang.Sequential o) (instance? java.util.List o))
- (loop [me this
- you (seq o)]
- (if (nil? me)
- (nil? you)
- (and (clojure.lang.Util/equiv (first me) (first you))
- (recur (next me) (next you)))))
- :else false))
+ (identical? this o) true
+ (or (instance? clojure.lang.Sequential o) (instance? java.util.List o))
+ (loop [me this
+ you (seq o)]
+ (if (nil? me)
+ (nil? you)
+ (and (clojure.lang.Util/equiv (first me) (first you))
+ (recur (next me) (next you)))))
+ :else false))
(empty [_]
clojure.lang.PersistentList/EMPTY)
@@ -118,9 +118,9 @@
clojure.lang.IChunkedSeq
(chunkedFirst [_] (ArrayChunk. am anode offset (.alength am anode)))
(chunkedNext [_]
- (let [nexti (+ i (.alength am anode))]
- (when (< nexti (count vec))
- (new VecSeq am vec (.arrayFor vec nexti) nexti 0))))
+ (let [nexti (+ i (.alength am anode))]
+ (when (< nexti (count vec))
+ (new VecSeq am vec (.arrayFor vec nexti) nexti 0))))
(chunkedMore [this]
(let [s (.chunkedNext this)]
(or s (clojure.lang.PersistentList/EMPTY)))))
@@ -132,19 +132,19 @@
Object
(equals [this o]
(cond
- (identical? this o) true
- (or (instance? clojure.lang.IPersistentVector o) (instance? java.util.RandomAccess o))
- (and (= cnt (count o))
- (loop [i (int 0)]
- (cond
+ (identical? this o) true
+ (or (instance? clojure.lang.IPersistentVector o) (instance? java.util.RandomAccess o))
+ (and (= cnt (count o))
+ (loop [i (int 0)]
+ (cond
(= i cnt) true
(.equals (.nth this i) (nth o i)) (recur (inc i))
:else false)))
- (or (instance? clojure.lang.Sequential o) (instance? java.util.List o))
- (if-let [st (seq this)]
- (.equals st (seq o))
- (nil? (seq o)))
- :else false))
+ (or (instance? clojure.lang.Sequential o) (instance? java.util.List o))
+ (if-let [st (seq this)]
+ (.equals st (seq o))
+ (nil? (seq o)))
+ :else false))
;todo - cache
(hashCode [this]
@@ -153,7 +153,7 @@
hash
(let [val (.nth this i)]
(recur (unchecked-add-int (unchecked-multiply-int 31 hash)
- (clojure.lang.Util/hash val))
+ (clojure.lang.Util/hash val))
(inc i))))))
;todo - cache
@@ -182,7 +182,7 @@
clojure.lang.IPersistentCollection
(cons [this val]
- (if (< (- cnt (.tailoff this)) (int 32))
+ (if (< (- cnt (.tailoff this)) (int 32))
(let [new-tail (.array am (inc (.alength am tail)))]
(System/arraycopy tail 0 new-tail 0 (.alength am tail))
(.aset am new-tail (.alength am tail) val)
@@ -195,21 +195,21 @@
(aset 1 (.newPath this (.edit root) shift tail-node)))
(new Vec am (inc cnt) (+ shift (int 5)) new-root (let [tl (.array am 1)] (.aset am tl 0 val) tl) (meta this)))
(new Vec am (inc cnt) shift (.pushTail this shift root tail-node)
- (let [tl (.array am 1)] (.aset am tl 0 val) tl) (meta this))))))
+ (let [tl (.array am 1)] (.aset am tl 0 val) tl) (meta this))))))
(empty [_] (new Vec am 0 5 EMPTY-NODE (.array am 0) nil))
(equiv [this o]
(cond
- (or (instance? clojure.lang.IPersistentVector o) (instance? java.util.RandomAccess o))
- (and (= cnt (count o))
- (loop [i (int 0)]
- (cond
+ (or (instance? clojure.lang.IPersistentVector o) (instance? java.util.RandomAccess o))
+ (and (= cnt (count o))
+ (loop [i (int 0)]
+ (cond
(= i cnt) true
(= (.nth this i) (nth o i)) (recur (inc i))
:else false)))
- (or (instance? clojure.lang.Sequential o) (instance? java.util.List o))
- (clojure.lang.Util/equiv (seq this) (seq o))
- :else false))
+ (or (instance? clojure.lang.Sequential o) (instance? java.util.List o))
+ (clojure.lang.Util/equiv (seq this) (seq o))
+ :else false))
clojure.lang.IPersistentStack
(peek [this]
@@ -217,38 +217,38 @@
(.nth this (dec cnt))))
(pop [this]
- (cond
- (zero? cnt)
+ (cond
+ (zero? cnt)
(throw (IllegalStateException. "Can't pop empty vector"))
- (= 1 cnt)
+ (= 1 cnt)
(new Vec am 0 5 EMPTY-NODE (.array am 0) (meta this))
- (> (- cnt (.tailoff this)) 1)
+ (> (- cnt (.tailoff this)) 1)
(let [new-tail (.array am (dec (.alength am tail)))]
(System/arraycopy tail 0 new-tail 0 (.alength am new-tail))
(new Vec am (dec cnt) shift root new-tail (meta this)))
- :else
+ :else
(let [new-tail (.arrayFor this (- cnt 2))
new-root ^clojure.core.VecNode (.popTail this shift root)]
(cond
- (nil? new-root)
- (new Vec am (dec cnt) shift EMPTY-NODE new-tail (meta this))
- (and (> shift 5) (nil? (aget ^objects (.arr new-root) 1)))
- (new Vec am (dec cnt) (- shift 5) (aget ^objects (.arr new-root) 0) new-tail (meta this))
- :else
- (new Vec am (dec cnt) shift new-root new-tail (meta this))))))
+ (nil? new-root)
+ (new Vec am (dec cnt) shift EMPTY-NODE new-tail (meta this))
+ (and (> shift 5) (nil? (aget ^objects (.arr new-root) 1)))
+ (new Vec am (dec cnt) (- shift 5) (aget ^objects (.arr new-root) 0) new-tail (meta this))
+ :else
+ (new Vec am (dec cnt) shift new-root new-tail (meta this))))))
clojure.lang.IPersistentVector
(assocN [this i val]
(cond
- (and (<= (int 0) i) (< i cnt))
- (if (>= i (.tailoff this))
- (let [new-tail (.array am (.alength am tail))]
- (System/arraycopy tail 0 new-tail 0 (.alength am tail))
- (.aset am new-tail (bit-and i (int 0x1f)) val)
- (new Vec am cnt shift root new-tail (meta this)))
- (new Vec am cnt shift (.doAssoc this shift root i val) tail (meta this)))
- (= i cnt) (.cons this val)
- :else (throw (IndexOutOfBoundsException.))))
+ (and (<= (int 0) i) (< i cnt))
+ (if (>= i (.tailoff this))
+ (let [new-tail (.array am (.alength am tail))]
+ (System/arraycopy tail 0 new-tail 0 (.alength am tail))
+ (.aset am new-tail (bit-and i (int 0x1f)) val)
+ (new Vec am cnt shift root new-tail (meta this)))
+ (new Vec am cnt shift (.doAssoc this shift root i val) tail (meta this)))
+ (= i cnt) (.cons this val)
+ :else (throw (IndexOutOfBoundsException.))))
(length [_] cnt)
clojure.lang.Reversible
@@ -332,17 +332,17 @@
(let [node ^clojure.core.VecNode node
subidx (bit-and (bit-shift-right (- cnt (int 2)) level) (int 0x1f))]
(cond
- (> level 5)
- (let [new-child (.popTail this (- level 5) (aget ^objects (.arr node) subidx))]
- (if (and (nil? new-child) (zero? subidx))
- nil
- (let [arr (aclone ^objects (.arr node))]
- (aset arr subidx new-child)
- (VecNode. (.edit root) arr))))
- (zero? subidx) nil
- :else (let [arr (aclone ^objects (.arr node))]
- (aset arr subidx nil)
- (VecNode. (.edit root) arr)))))
+ (> level 5)
+ (let [new-child (.popTail this (- level 5) (aget ^objects (.arr node) subidx))]
+ (if (and (nil? new-child) (zero? subidx))
+ nil
+ (let [arr (aclone ^objects (.arr node))]
+ (aset arr subidx new-child)
+ (VecNode. (.edit root) arr))))
+ (zero? subidx) nil
+ :else (let [arr (aclone ^objects (.arr node))]
+ (aset arr subidx nil)
+ (VecNode. (.edit root) arr)))))
(newPath [this edit ^int level node]
(if (zero? level)
@@ -373,13 +373,13 @@
(< cnt vcnt) -1
(> cnt vcnt) 1
:else
- (loop [i (int 0)]
- (if (= i cnt)
- 0
- (let [comp (clojure.lang.Util/compare (.nth this i) (.nth v i))]
- (if (= 0 comp)
- (recur (inc i))
- comp))))))))
+ (loop [i (int 0)]
+ (if (= i cnt)
+ 0
+ (let [comp (clojure.lang.Util/compare (.nth this i) (.nth v i))]
+ (if (= 0 comp)
+ (recur (inc i))
+ comp))))))))
java.lang.Iterable
(iterator [this]
@@ -398,12 +398,12 @@
(isEmpty [_] (zero? cnt))
(toArray [this] (into-array Object this))
(^objects toArray [this ^objects arr]
- (if (>= (count arr) cnt)
- (do
- (dotimes [i cnt]
- (aset arr i (.nth this i)))
- arr)
- (into-array Object this)))
+ (if (>= (count arr) cnt)
+ (do
+ (dotimes [i cnt]
+ (aset arr i (.nth this i)))
+ arr)
+ (into-array Object this)))
(size [_] cnt)
(add [_ o] (throw (UnsupportedOperationException.)))
(addAll [_ c] (throw (UnsupportedOperationException.)))
@@ -450,7 +450,7 @@
(addAll [_ i c] (throw (UnsupportedOperationException.)))
(^Object remove [_ ^int i] (throw (UnsupportedOperationException.)))
(set [_ i e] (throw (UnsupportedOperationException.)))
-)
+ )
(defmethod print-method ::Vec [v w]
((get (methods print-method) clojure.lang.IPersistentVector) v w))
diff --git a/src/clj/clojure/inspector.clj b/src/clj/clojure/inspector.clj
index bd84d9a8..f16070da 100644
--- a/src/clj/clojure/inspector.clj
+++ b/src/clj/clojure/inspector.clj
@@ -7,7 +7,7 @@
; You must not remove this notice, or any other, from this software.
(ns ^{:doc "Graphical object inspector for Clojure data structures."
- :author "Rich Hickey"}
+ :author "Rich Hickey"}
clojure.inspector
(:import
(java.awt BorderLayout)
@@ -21,12 +21,12 @@
(defn collection-tag [x]
(cond
- (map-entry? x) :entry
- (instance? java.util.Map x) :seqable
- (instance? java.util.Set x) :seqable
- (sequential? x) :seq
- (instance? clojure.lang.Seqable x) :seqable
- :else :atom))
+ (map-entry? x) :entry
+ (instance? java.util.Map x) :seqable
+ (instance? java.util.Set x) :seqable
+ (sequential? x) :seq
+ (instance? clojure.lang.Seqable x) :seqable
+ :else :atom))
(defmulti is-leaf collection-tag)
(defmulti get-child (fn [parent index] (collection-tag parent)))
@@ -60,7 +60,7 @@
(getChild [parent index]
(get-child parent index))
(getChildCount [parent]
- (get-child-count parent))
+ (get-child-count parent))
(isLeaf [node]
(is-leaf node))
(valueForPathChanged [path newValue])
@@ -71,20 +71,20 @@
(defn old-table-model [data]
(let [row1 (first data)
- colcnt (count row1)
- cnt (count data)
- vals (if (map? row1) vals identity)]
+ colcnt (count row1)
+ cnt (count data)
+ vals (if (map? row1) vals identity)]
(proxy [TableModel] []
(addTableModelListener [tableModelListener])
(getColumnClass [columnIndex] Object)
(getColumnCount [] colcnt)
(getColumnName [columnIndex]
- (if (map? row1)
- (name (nth (keys row1) columnIndex))
- (str columnIndex)))
+ (if (map? row1)
+ (name (nth (keys row1) columnIndex))
+ (str columnIndex)))
(getRowCount [] cnt)
(getValueAt [rowIndex columnIndex]
- (nth (vals (nth data rowIndex)) columnIndex))
+ (nth (vals (nth data rowIndex)) columnIndex))
(isCellEditable [rowIndex columnIndex] false)
(removeTableModelListener [tableModelListener]))))
@@ -102,7 +102,7 @@
data, which must be a sequential data structure of data structures
of equal length"
{:added "1.0"}
- [data]
+ [data]
(doto (JFrame. "Clojure Inspector")
(.add (JScrollPane. (JTable. (old-table-model data))))
(.setSize 400 600)
@@ -133,8 +133,8 @@
(getRowCount [] nrows)
(getValueAt [rowIndex columnIndex]
(cond
- (= 0 columnIndex) (get-label rowIndex)
- (= 1 columnIndex) (print-str (get-value rowIndex)))))))
+ (= 0 columnIndex) (get-label rowIndex)
+ (= 1 columnIndex) (print-str (get-value rowIndex)))))))
(defmulti table-model class)
@@ -181,9 +181,9 @@
(comment
-(load-file "src/inspector.clj")
-(refer 'inspector)
-(inspect-tree {:a 1 :b 2 :c [1 2 3 {:d 4 :e 5 :f [6 7 8]}]})
-(inspect-table [[1 2 3][4 5 6][7 8 9][10 11 12]])
+ (load-file "src/inspector.clj")
+ (refer 'inspector)
+ (inspect-tree {:a 1 :b 2 :c [1 2 3 {:d 4 :e 5 :f [6 7 8]}]})
+ (inspect-table [[1 2 3][4 5 6][7 8 9][10 11 12]])
-)
+ )
diff --git a/src/clj/clojure/instant.clj b/src/clj/clojure/instant.clj
index 2c052c03..c14c8b37 100644
--- a/src/clj/clojure/instant.clj
+++ b/src/clj/clojure/instant.clj
@@ -8,7 +8,7 @@
(ns clojure.instant
(:import [java.util Calendar Date GregorianCalendar TimeZone]
- [java.sql Timestamp]))
+ [java.sql Timestamp]))
(set! *warn-on-reflection* true)
@@ -51,7 +51,7 @@
#"(\d\d\d\d)(?:-(\d\d)(?:-(\d\d)(?:[T](\d\d)(?::(\d\d)(?::(\d\d)(?:[.](\d+))?)?)?)?)?)?(?:[Z]|([-+])(\d\d):(\d\d))?")
(defn parse-timestamp
- "Parse a string containing an RFC3339-like like timestamp.
+ "Parse a string containing an RFC3339-like like timestamp.
The function new-instant is called with the following arguments.
@@ -101,24 +101,24 @@ Though time-offset is syntactically optional, a missing time-offset
will be treated as if the time-offset zero (+00:00) had been
specified.
"
- [new-instant ^CharSequence cs]
- (if-let [[_ years months days hours minutes seconds fraction
- offset-sign offset-hours offset-minutes]
- (re-matches timestamp cs)]
- (new-instant
- (parse-int years)
- (if-not months 1 (parse-int months))
- (if-not days 1 (parse-int days))
- (if-not hours 0 (parse-int hours))
- (if-not minutes 0 (parse-int minutes))
- (if-not seconds 0 (parse-int seconds))
- (if-not fraction 0 (parse-int (zero-fill-right fraction 9)))
- (cond (= "-" offset-sign) -1
- (= "+" offset-sign) 1
- :else 0)
- (if-not offset-hours 0 (parse-int offset-hours))
- (if-not offset-minutes 0 (parse-int offset-minutes)))
- (fail (str "Unrecognized date/time syntax: " cs))))
+ [new-instant ^CharSequence cs]
+ (if-let [[_ years months days hours minutes seconds fraction
+ offset-sign offset-hours offset-minutes]
+ (re-matches timestamp cs)]
+ (new-instant
+ (parse-int years)
+ (if-not months 1 (parse-int months))
+ (if-not days 1 (parse-int days))
+ (if-not hours 0 (parse-int hours))
+ (if-not minutes 0 (parse-int minutes))
+ (if-not seconds 0 (parse-int seconds))
+ (if-not fraction 0 (parse-int (zero-fill-right fraction 9)))
+ (cond (= "-" offset-sign) -1
+ (= "+" offset-sign) 1
+ :else 0)
+ (if-not offset-hours 0 (parse-int offset-hours))
+ (if-not offset-minutes 0 (parse-int offset-minutes)))
+ (fail (str "Unrecognized date/time syntax: " cs))))
;;; ------------------------------------------------------------------------
@@ -246,9 +246,9 @@ offset, but truncating the subsecond fraction to milliseconds."
(doto (GregorianCalendar. years (dec months) days hours minutes seconds)
(.set Calendar/MILLISECOND (quot nanoseconds 1000000))
(.setTimeZone (TimeZone/getTimeZone
- (format "GMT%s%02d:%02d"
- (if (neg? offset-sign) "-" "+")
- offset-hours offset-minutes)))))
+ (format "GMT%s%02d:%02d"
+ (if (neg? offset-sign) "-" "+")
+ offset-hours offset-minutes)))))
(defn- construct-date
"Construct a java.util.Date, which expresses the original instant as
@@ -264,10 +264,10 @@ milliseconds since the epoch, UTC."
[years months days hours minutes seconds nanoseconds
offset-sign offset-hours offset-minutes]
(doto (Timestamp.
- (.getTimeInMillis
- (construct-calendar years months days
- hours minutes seconds 0
- offset-sign offset-hours offset-minutes)))
+ (.getTimeInMillis
+ (construct-calendar years months days
+ hours minutes seconds 0
+ offset-sign offset-hours offset-minutes)))
;; nanos must be set separately, pass 0 above for the base calendar
(.setNanos nanoseconds)))
diff --git a/src/clj/clojure/java/browse.clj b/src/clj/clojure/java/browse.clj
index 6fcc6507..c53e8aef 100644
--- a/src/clj/clojure/java/browse.clj
+++ b/src/clj/clojure/java/browse.clj
@@ -11,7 +11,7 @@
:doc "Start a web browser from Clojure"}
clojure.java.browse
(:require [clojure.java.shell :as sh]
- [clojure.string :as str])
+ [clojure.string :as str])
(:import (java.net URI)))
(defn- macosx? []
@@ -46,7 +46,7 @@
[url]
(try
(when (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop"
- "isDesktopSupported" (to-array nil))
+ "isDesktopSupported" (to-array nil))
(-> (clojure.lang.Reflector/invokeStaticMethod "java.awt.Desktop"
"getDesktop" (to-array nil))
(.browse (URI. url)))
@@ -55,8 +55,8 @@
nil)))
(defn- open-url-in-swing
- "Opens url (a string) in a Swing window."
- [url]
+ "Opens url (a string) in a Swing window."
+ [url]
; the implementation of this function resides in another namespace to be loaded "on demand"
; this fixes a bug on mac os x where the process turns into a GUI app
; see http://code.google.com/p/clojure-contrib/issues/detail?id=32
diff --git a/src/clj/clojure/java/browse_ui.clj b/src/clj/clojure/java/browse_ui.clj
index 2c002a29..ae0eb038 100644
--- a/src/clj/clojure/java/browse_ui.clj
+++ b/src/clj/clojure/java/browse_ui.clj
@@ -7,8 +7,8 @@
; You must not remove this notice, or any other, from this software.
(ns
- ^{:author "Christophe Grand",
- :doc "Helper namespace for clojure.java.browse.
+ ^{:author "Christophe Grand",
+ :doc "Helper namespace for clojure.java.browse.
Prevents console apps from becoming GUI unnecessarily."}
clojure.java.browse-ui)
diff --git a/src/clj/clojure/java/io.clj b/src/clj/clojure/java/io.clj
index 72a30ed7..ef4e5f14 100644
--- a/src/clj/clojure/java/io.clj
+++ b/src/clj/clojure/java/io.clj
@@ -8,29 +8,29 @@
(ns
^{:author "Stuart Sierra, Chas Emerick, Stuart Halloway",
- :doc "This file defines polymorphic I/O utility functions for Clojure."}
- clojure.java.io
- (:require clojure.string)
- (:import
- (java.io Reader InputStream InputStreamReader PushbackReader
- BufferedReader File OutputStream
- OutputStreamWriter BufferedWriter Writer
- FileInputStream FileOutputStream ByteArrayOutputStream
- StringReader ByteArrayInputStream
- BufferedInputStream BufferedOutputStream
- CharArrayReader Closeable)
- (java.net URI URL MalformedURLException Socket URLDecoder URLEncoder)))
+ :doc "This file defines polymorphic I/O utility functions for Clojure."}
+ clojure.java.io
+ (:require clojure.string)
+ (:import
+ (java.io Reader InputStream InputStreamReader PushbackReader
+ BufferedReader File OutputStream
+ OutputStreamWriter BufferedWriter Writer
+ FileInputStream FileOutputStream ByteArrayOutputStream
+ StringReader ByteArrayInputStream
+ BufferedInputStream BufferedOutputStream
+ CharArrayReader Closeable)
+ (java.net URI URL MalformedURLException Socket URLDecoder URLEncoder)))
(def
- ^{:doc "Type object for a Java primitive byte array."
- :private true
- }
- byte-array-type (class (make-array Byte/TYPE 0)))
+ ^{:doc "Type object for a Java primitive byte array."
+ :private true
+ }
+ byte-array-type (class (make-array Byte/TYPE 0)))
(def
- ^{:doc "Type object for a Java primitive char array."
- :private true}
- char-array-type (class (make-array Character/TYPE 0)))
+ ^{:doc "Type object for a Java primitive char array."
+ :private true}
+ char-array-type (class (make-array Character/TYPE 0)))
(defprotocol ^{:added "1.2"} Coercions
"Coerce between various 'resource-namish' things."
@@ -59,7 +59,7 @@
(as-file [u]
(if (= "file" (.getProtocol u))
(as-file (escaped-utf8-urlstring->str
- (.replace (.getFile u) \/ File/separatorChar)))
+ (.replace (.getFile u) \/ File/separatorChar)))
(throw (IllegalArgumentException. (str "Not a file: " u)))))
URI
@@ -166,10 +166,10 @@
:make-writer (fn [x opts] (make-writer (make-output-stream x opts) opts))
:make-input-stream (fn [x opts]
(throw (IllegalArgumentException.
- (str "Cannot open <" (pr-str x) "> as an InputStream."))))
+ (str "Cannot open <" (pr-str x) "> as an InputStream."))))
:make-output-stream (fn [x opts]
(throw (IllegalArgumentException.
- (str "Cannot open <" (pr-str x) "> as an OutputStream."))))})
+ (str "Cannot open <" (pr-str x) "> as an OutputStream."))))})
(defn- inputstream->reader
[^InputStream is opts]
@@ -234,9 +234,9 @@
(assoc default-streams-impl
:make-input-stream (fn [^URL x opts]
(make-input-stream
- (if (= "file" (.getProtocol x))
- (FileInputStream. (as-file x))
- (.openStream x)) opts))
+ (if (= "file" (.getProtocol x))
+ (FileInputStream. (as-file x))
+ (.openStream x)) opts))
:make-output-stream (fn [^URL x opts]
(if (= "file" (.getProtocol x))
(make-output-stream (as-file x) opts)
@@ -253,14 +253,14 @@
(assoc default-streams-impl
:make-input-stream (fn [^String x opts]
(try
- (make-input-stream (URL. x) opts)
- (catch MalformedURLException e
- (make-input-stream (File. x) opts))))
+ (make-input-stream (URL. x) opts)
+ (catch MalformedURLException e
+ (make-input-stream (File. x) opts))))
:make-output-stream (fn [^String x opts]
(try
- (make-output-stream (URL. x) opts)
- (catch MalformedURLException err
- (make-output-stream (File. x) opts))))))
+ (make-output-stream (URL. x) opts)
+ (catch MalformedURLException err
+ (make-output-stream (File. x) opts))))))
(extend Socket
IOFactory
@@ -287,15 +287,15 @@
(assoc default-streams-impl
:make-reader (fn [x opts]
(throw (IllegalArgumentException.
- (str "Cannot open <" (pr-str x) "> as a Reader."))))
+ (str "Cannot open <" (pr-str x) "> as a Reader."))))
:make-writer (fn [x opts]
(throw (IllegalArgumentException.
- (str "Cannot open <" (pr-str x) "> as a Writer."))))))
+ (str "Cannot open <" (pr-str x) "> as a Writer."))))))
(defmulti
^{:doc "Internal helper for copy"
- :private true
- :arglists '([input output opts])}
+ :private true
+ :arglists '([input output opts])}
do-copy
(fn [input output opts] [(type input) (type output)]))
@@ -421,11 +421,11 @@
children relative to the parent."
{:added "1.2"}
([arg]
- (as-file arg))
+ (as-file arg))
([parent child]
- (File. ^File (as-file parent) ^String (as-relative-path child)))
+ (File. ^File (as-file parent) ^String (as-relative-path child)))
([parent child & more]
- (reduce file (file parent child) more)))
+ (reduce file (file parent child) more)))
(defn delete-file
"Delete file f. If silently is nil or false, raise an exception on failure, else return the value of silently."
diff --git a/src/clj/clojure/java/javadoc.clj b/src/clj/clojure/java/javadoc.clj
index 2e9e0fbb..a95e44cd 100644
--- a/src/clj/clojure/java/javadoc.clj
+++ b/src/clj/clojure/java/javadoc.clj
@@ -7,7 +7,7 @@
; You must not remove this notice, or any other, from this software.
(ns
^{:author "Christophe Grand, Stuart Sierra",
- :doc "A repl helper to quickly open javadocs."}
+ :doc "A repl helper to quickly open javadocs."}
clojure.java.javadoc
(:use [clojure.java.browse :only (browse-url)] )
(:import
@@ -27,18 +27,18 @@
"http://docs.oracle.com/javase/8/docs/api/"))
(def ^:dynamic *remote-javadocs*
- (ref (sorted-map
- "com.google.common." "http://google.github.io/guava/releases/23.0/api/docs/"
- "java." *core-java-api*
- "javax." *core-java-api*
- "org.ietf.jgss." *core-java-api*
- "org.omg." *core-java-api*
- "org.w3c.dom." *core-java-api*
- "org.xml.sax." *core-java-api*
- "org.apache.commons.codec." "http://commons.apache.org/proper/commons-codec/apidocs/"
- "org.apache.commons.io." "http://commons.apache.org/proper/commons-io/javadocs/api-release/"
- "org.apache.commons.lang." "http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/"
- "org.apache.commons.lang3." "http://commons.apache.org/proper/commons-lang/javadocs/api-release/")))
+ (ref (sorted-map
+ "com.google.common." "http://google.github.io/guava/releases/23.0/api/docs/"
+ "java." *core-java-api*
+ "javax." *core-java-api*
+ "org.ietf.jgss." *core-java-api*
+ "org.omg." *core-java-api*
+ "org.w3c.dom." *core-java-api*
+ "org.xml.sax." *core-java-api*
+ "org.apache.commons.codec." "http://commons.apache.org/proper/commons-codec/apidocs/"
+ "org.apache.commons.io." "http://commons.apache.org/proper/commons-io/javadocs/api-release/"
+ "org.apache.commons.lang." "http://commons.apache.org/proper/commons-lang/javadocs/api-2.6/"
+ "org.apache.commons.lang3." "http://commons.apache.org/proper/commons-lang/javadocs/api-release/")))
(defn add-local-javadoc
"Adds to the list of local Javadoc paths."
@@ -62,9 +62,9 @@
(let [file-path (.replace classname \. File/separatorChar)
url-path (.replace classname \. \/)]
(if-let [file ^File (first
- (filter #(.exists ^File %)
- (map #(File. (str %) (str file-path ".html"))
- @*local-javadocs*)))]
+ (filter #(.exists ^File %)
+ (map #(File. (str %) (str file-path ".html"))
+ @*local-javadocs*)))]
(-> file .toURI str)
;; If no local file, try remote URLs:
(or (some (fn [[prefix url]]
@@ -80,8 +80,8 @@
{:added "1.2"}
[class-or-object]
(let [^Class c (if (instance? Class class-or-object)
- class-or-object
- (class class-or-object))]
+ class-or-object
+ (class class-or-object))]
(if-let [url (javadoc-url (.getName c))]
(browse-url url)
(println "Could not find Javadoc for" c))))
diff --git a/src/clj/clojure/java/shell.clj b/src/clj/clojure/java/shell.clj
index cb3f90a2..cde6ae7e 100644
--- a/src/clj/clojure/java/shell.clj
+++ b/src/clj/clojure/java/shell.clj
@@ -13,7 +13,7 @@ collecting its stdout"}
clojure.java.shell
(:use [clojure.java.io :only (as-file copy)])
(:import (java.io ByteArrayOutputStream StringWriter)
- (java.nio.charset Charset)))
+ (java.nio.charset Charset)))
(def ^:dynamic *sh-dir* nil)
(def ^:dynamic *sh-env* nil)
@@ -53,9 +53,9 @@ collecting its stdout"}
"Helper so that callers can pass a Clojure map for the :env to sh."
[arg]
(cond
- (nil? arg) nil
- (map? arg) (into-array String (map (fn [[k v]] (str (name k) "=" v)) arg))
- true arg))
+ (nil? arg) nil
+ (map? arg) (into-array String (map (fn [[k v]] (str (name k) "=" v)) arg))
+ true arg))
(defn- stream-to-bytes
[in]
@@ -66,9 +66,9 @@ collecting its stdout"}
(defn- stream-to-string
([in] (stream-to-string in (.name (Charset/defaultCharset))))
([in enc]
- (with-open [bout (StringWriter.)]
- (copy in bout :encoding enc)
- (.toString bout))))
+ (with-open [bout (StringWriter.)]
+ (copy in bout :encoding enc)
+ (.toString bout))))
(defn- stream-to-enc
[stream enc]
@@ -129,14 +129,14 @@ collecting its stdout"}
(comment
-(println (sh "ls" "-l"))
-(println (sh "ls" "-l" "/no-such-thing"))
-(println (sh "sed" "s/[aeiou]/oo/g" :in "hello there\n"))
-(println (sh "sed" "s/[aeiou]/oo/g" :in (java.io.StringReader. "hello there\n")))
-(println (sh "cat" :in "x\u25bax\n"))
-(println (sh "echo" "x\u25bax"))
-(println (sh "echo" "x\u25bax" :out-enc "ISO-8859-1")) ; reads 4 single-byte chars
-(println (sh "cat" "myimage.png" :out-enc :bytes)) ; reads binary file into bytes[]
-(println (sh "cmd" "/c dir 1>&2"))
-
-)
+ (println (sh "ls" "-l"))
+ (println (sh "ls" "-l" "/no-such-thing"))
+ (println (sh "sed" "s/[aeiou]/oo/g" :in "hello there\n"))
+ (println (sh "sed" "s/[aeiou]/oo/g" :in (java.io.StringReader. "hello there\n")))
+ (println (sh "cat" :in "x\u25bax\n"))
+ (println (sh "echo" "x\u25bax"))
+ (println (sh "echo" "x\u25bax" :out-enc "ISO-8859-1")) ; reads 4 single-byte chars
+ (println (sh "cat" "myimage.png" :out-enc :bytes)) ; reads binary file into bytes[]
+ (println (sh "cmd" "/c dir 1>&2"))
+
+ )
diff --git a/src/clj/clojure/main.clj b/src/clj/clojure/main.clj
index dbe3240e..62434c54 100644
--- a/src/clj/clojure/main.clj
+++ b/src/clj/clojure/main.clj
@@ -9,13 +9,13 @@
;; Originally contributed by Stephen C. Gilardi
(ns ^{:doc "Top-level main function for Clojure REPL and scripts."
- :author "Stephen C. Gilardi and Rich Hickey"}
+ :author "Stephen C. Gilardi and Rich Hickey"}
clojure.main
(:refer-clojure :exclude [with-bindings])
(:require [clojure.spec.alpha :as spec])
(:import (java.io StringReader)
- (clojure.lang Compiler Compiler$CompilerException
- LineNumberingPushbackReader RT LispReader$ReaderException))
+ (clojure.lang Compiler Compiler$CompilerException
+ LineNumberingPushbackReader RT LispReader$ReaderException))
;;(:use [clojure.repl :only (demunge root-cause stack-element-str)])
)
@@ -113,9 +113,9 @@
[s]
(let [c (.read s)]
(cond
- (= c (int \newline)) :line-start
- (= c -1) :stream-end
- :else (do (.unread s c) :body))))
+ (= c (int \newline)) :line-start
+ (= c -1) :stream-end
+ :else (do (.unread s c) :body))))
(defn skip-whitespace
"Skips whitespace characters on stream s. Returns :line-start, :stream-end,
@@ -129,11 +129,11 @@
[s]
(loop [c (.read s)]
(cond
- (= c (int \newline)) :line-start
- (= c -1) :stream-end
- (= c (int \;)) (do (.readLine s) :line-start)
- (or (Character/isWhitespace (char c)) (= c (int \,))) (recur (.read s))
- :else (do (.unread s c) :body))))
+ (= c (int \newline)) :line-start
+ (= c -1) :stream-end
+ (= c (int \;)) (do (.readLine s) :line-start)
+ (or (Character/isWhitespace (char c)) (= c (int \,))) (recur (.read s))
+ :else (do (.unread s c) :body))))
(defn renumbering-read
"Reads from reader, which must be a LineNumberingPushbackReader, while capturing
@@ -410,37 +410,37 @@ by default when a new command-line REPL is started."} repl-requires
(with-read-known (read request-prompt request-exit))
(catch LispReader$ReaderException e
(throw (ex-info nil {:clojure.error/phase :read-source} e))))]
- (or (#{request-prompt request-exit} input)
- (let [value (binding [*read-eval* read-eval] (eval input))]
- (set! *3 *2)
- (set! *2 *1)
- (set! *1 value)
- (try
- (print value)
- (catch Throwable e
- (throw (ex-info nil {:clojure.error/phase :print-eval-result} e)))))))
- (catch Throwable e
- (caught e)
- (set! *e e))))]
+ (or (#{request-prompt request-exit} input)
+ (let [value (binding [*read-eval* read-eval] (eval input))]
+ (set! *3 *2)
+ (set! *2 *1)
+ (set! *1 value)
+ (try
+ (print value)
+ (catch Throwable e
+ (throw (ex-info nil {:clojure.error/phase :print-eval-result} e)))))))
+ (catch Throwable e
+ (caught e)
+ (set! *e e))))]
(with-bindings
- (try
- (init)
- (catch Throwable e
- (caught e)
- (set! *e e)))
- (prompt)
- (flush)
- (loop []
- (when-not
- (try (identical? (read-eval-print) request-exit)
- (catch Throwable e
- (caught e)
- (set! *e e)
- nil))
- (when (need-prompt)
- (prompt)
- (flush))
- (recur))))))
+ (try
+ (init)
+ (catch Throwable e
+ (caught e)
+ (set! *e e)))
+ (prompt)
+ (flush)
+ (loop []
+ (when-not
+ (try (identical? (read-eval-print) request-exit)
+ (catch Throwable e
+ (caught e)
+ (set! *e e)
+ nil))
+ (when (need-prompt)
+ (prompt)
+ (flush))
+ (recur))))))
(defn load-script
"Loads Clojure source from a file or resource given its path. Paths
@@ -448,7 +448,7 @@ by default when a new command-line REPL is started."} repl-requires
[^String path]
(if (.startsWith path "@")
(RT/loadResourceScript
- (.substring path (if (.startsWith path "@/") 2 1)))
+ (.substring path (if (.startsWith path "@/") 2 1)))
(Compiler/loadFile path)))
(defn- init-opt
@@ -461,12 +461,12 @@ by default when a new command-line REPL is started."} repl-requires
[str]
(let [eof (Object.)
reader (LineNumberingPushbackReader. (java.io.StringReader. str))]
- (loop [input (with-read-known (read reader false eof))]
- (when-not (= input eof)
- (let [value (eval input)]
- (when-not (nil? value)
- (prn value))
- (recur (with-read-known (read reader false eof))))))))
+ (loop [input (with-read-known (read reader false eof))]
+ (when-not (= input eof)
+ (let [value (eval input)]
+ (when-not (nil? value)
+ (prn value))
+ (recur (with-read-known (read reader false eof))))))))
(defn- init-dispatch
"Returns the handler associated with an init opt"
@@ -528,15 +528,15 @@ by default when a new command-line REPL is started."} repl-requires
"Returns the handler associated with a main option"
[opt]
(or
- ({"-r" repl-opt
- "--repl" repl-opt
- "-m" main-opt
- "--main" main-opt
- nil null-opt
- "-h" help-opt
- "--help" help-opt
- "-?" help-opt} opt)
- script-opt))
+ ({"-r" repl-opt
+ "--repl" repl-opt
+ "-m" main-opt
+ "--main" main-opt
+ nil null-opt
+ "-h" help-opt
+ "--help" help-opt
+ "-?" help-opt} opt)
+ script-opt))
(defn- legacy-repl
"Called by the clojure.lang.Repl.main stub to run a repl with args
@@ -591,12 +591,12 @@ java -cp clojure.jar clojure.main -i init.clj script.clj args...")
classpath. Classpath-relative paths have prefix of @ or @/"
[& args]
(try
- (if args
- (loop [[opt arg & more :as args] args inits []]
- (if (init-dispatch opt)
- (recur more (conj inits [opt arg]))
- ((main-dispatch opt) args inits)))
- (repl-opt nil nil))
- (finally
- (flush))))
+ (if args
+ (loop [[opt arg & more :as args] args inits []]
+ (if (init-dispatch opt)
+ (recur more (conj inits [opt arg]))
+ ((main-dispatch opt) args inits)))
+ (repl-opt nil nil))
+ (finally
+ (flush))))
diff --git a/src/clj/clojure/parallel.clj b/src/clj/clojure/parallel.clj
index 29b01e21..bb746767 100644
--- a/src/clj/clojure/parallel.clj
+++ b/src/clj/clojure/parallel.clj
@@ -7,7 +7,7 @@
; You must not remove this notice, or any other, from this software.
(ns ^{:doc "DEPRECATED Wrapper of the ForkJoin library (JSR-166)."
- :author "Rich Hickey"}
+ :author "Rich Hickey"}
clojure.parallel)
(alias 'parallel 'clojure.parallel)
@@ -115,24 +115,24 @@ pvec.
elements of the 2 collections."
([coll]
- (if (instance? ParallelArrayWithMapping coll)
- coll
- (. ParallelArray createUsingHandoff
- (to-array coll)
- (. ParallelArray defaultExecutor))))
+ (if (instance? ParallelArrayWithMapping coll)
+ coll
+ (. ParallelArray createUsingHandoff
+ (to-array coll)
+ (. ParallelArray defaultExecutor))))
([coll & ops]
- (reduce (fn [pa [op args]]
- (cond
- (= op :bound) (. pa withBounds (args 0) (args 1))
- (= op :filter) (. pa withFilter (predicate args))
- (= op :filter-with) (. pa withFilter (binary-predicate (args 0)) (par (args 1)))
- (= op :filter-index) (. pa withIndexedFilter (int-and-object-predicate args))
- (= op :map) (. pa withMapping (parallel/op args))
- (= op :map-with) (. pa withMapping (binary-op (args 0)) (par (args 1)))
- (= op :map-index) (. pa withIndexedMapping (int-and-object-to-object args))
- :else (throw (Exception. (str "Unsupported par op: " op)))))
- (par coll)
- (partition 2 ops))))
+ (reduce (fn [pa [op args]]
+ (cond
+ (= op :bound) (. pa withBounds (args 0) (args 1))
+ (= op :filter) (. pa withFilter (predicate args))
+ (= op :filter-with) (. pa withFilter (binary-predicate (args 0)) (par (args 1)))
+ (= op :filter-index) (. pa withIndexedFilter (int-and-object-predicate args))
+ (= op :map) (. pa withMapping (parallel/op args))
+ (= op :map-with) (. pa withMapping (binary-op (args 0)) (par (args 1)))
+ (= op :map-index) (. pa withIndexedMapping (int-and-object-to-object args))
+ :else (throw (Exception. (str "Unsupported par op: " op)))))
+ (par coll)
+ (partition 2 ops))))
;;;;;;;;;;;;;;;;;;;;; aggregate operations ;;;;;;;;;;;;;;;;;;;;;;
(defn pany
@@ -214,37 +214,37 @@ pvec.
(comment
-(load-file "src/parallel.clj")
-(refer 'parallel)
-(pdistinct [1 2 3 2 1])
-;(pcumulate [1 2 3 2 1] + 0) ;broken, not exposed
-(def a (make-array Object 1000000))
-(dotimes i (count a)
- (aset a i (rand-int i)))
-(time (reduce + 0 a))
-(time (preduce + 0 a))
-(time (count (distinct a)))
-(time (count (pdistinct a)))
-
-(preduce + 0 [1 2 3 2 1])
-(preduce + 0 (psort a))
-(pvec (par [11 2 3 2] :filter-index (fn [x i] (> i x))))
-(pvec (par [11 2 3 2] :filter-with [(fn [x y] (> y x)) [110 2 33 2]]))
-
-(psummary ;or pvec/pmax etc
- (par [11 2 3 2]
- :filter-with [(fn [x y] (> y x))
- [110 2 33 2]]
- :map #(* % 2)))
-
-(preduce + 0
- (par [11 2 3 2]
- :filter-with [< [110 2 33 2]]))
-
-(time (reduce + 0 (map #(* % %) (range 1000000))))
-(time (preduce + 0 (par (range 1000000) :map-index *)))
-(def v (range 1000000))
-(time (preduce + 0 (par v :map-index *)))
-(time (preduce + 0 (par v :map #(* % %))))
-(time (reduce + 0 (map #(* % %) v)))
-)
\ No newline at end of file
+ (load-file "src/parallel.clj")
+ (refer 'parallel)
+ (pdistinct [1 2 3 2 1])
+ ;(pcumulate [1 2 3 2 1] + 0) ;broken, not exposed
+ (def a (make-array Object 1000000))
+ (dotimes i (count a)
+ (aset a i (rand-int i)))
+ (time (reduce + 0 a))
+ (time (preduce + 0 a))
+ (time (count (distinct a)))
+ (time (count (pdistinct a)))
+
+ (preduce + 0 [1 2 3 2 1])
+ (preduce + 0 (psort a))
+ (pvec (par [11 2 3 2] :filter-index (fn [x i] (> i x))))
+ (pvec (par [11 2 3 2] :filter-with [(fn [x y] (> y x)) [110 2 33 2]]))
+
+ (psummary ;or pvec/pmax etc
+ (par [11 2 3 2]
+ :filter-with [(fn [x y] (> y x))
+ [110 2 33 2]]
+ :map #(* % 2)))
+
+ (preduce + 0
+ (par [11 2 3 2]
+ :filter-with [< [110 2 33 2]]))
+
+ (time (reduce + 0 (map #(* % %) (range 1000000))))
+ (time (preduce + 0 (par (range 1000000) :map-index *)))
+ (def v (range 1000000))
+ (time (preduce + 0 (par v :map-index *)))
+ (time (preduce + 0 (par v :map #(* % %))))
+ (time (reduce + 0 (map #(* % %) v)))
+ )
\ No newline at end of file
diff --git a/src/clj/clojure/pprint.clj b/src/clj/clojure/pprint.clj
index 42836ac8..093ddd9f 100644
--- a/src/clj/clojure/pprint.clj
+++ b/src/clj/clojure/pprint.clj
@@ -12,8 +12,8 @@
;; April 3, 2009
(ns
- ^{:author "Tom Faulhaber",
- :doc "A Pretty Printer for Clojure
+ ^{:author "Tom Faulhaber",
+ :doc "A Pretty Printer for Clojure
clojure.pprint implements a flexible system for printing structured data
in a pleasing, easy-to-understand format. Basic use of the pretty printer is
@@ -33,10 +33,10 @@ a more powerful alternative to Clojure's standard format function.
See documentation for pprint and cl-format for more information or
complete documentation on the Clojure web site on GitHub.",
- :added "1.2"}
- clojure.pprint
- (:refer-clojure :exclude (deftype))
- (:use [clojure.walk :only [walk]]))
+ :added "1.2"}
+ clojure.pprint
+ (:refer-clojure :exclude (deftype))
+ (:use [clojure.walk :only [walk]]))
(set! *warn-on-reflection* true)
diff --git a/src/clj/clojure/pprint/cl_format.clj b/src/clj/clojure/pprint/cl_format.clj
index 1399e3ad..8441b8a9 100644
--- a/src/clj/clojure/pprint/cl_format.clj
+++ b/src/clj/clojure/pprint/cl_format.clj
@@ -67,7 +67,7 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
(defn- format-error [message offset]
(let [full-message (str message \newline *format-str* \newline
- (apply str (repeat offset \space)) "^" \newline)]
+ (apply str (repeat offset \space)) "^" \newline)]
(throw (RuntimeException. full-message))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -91,7 +91,7 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
(let [ rst (:rest navigator) ]
(if rst
[(first rst) (struct arg-navigator (:seq navigator ) (next rst) (inc (:pos navigator)))]
- (throw (new Exception "Not enough arguments for format definition")))))
+ (throw (new Exception "Not enough arguments for format definition")))))
(defn- next-arg-or-nil [navigator]
(let [rst (:rest navigator)]
@@ -103,8 +103,8 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
(defn- get-format-arg [navigator]
(let [[raw-format navigator] (next-arg navigator)
compiled-format (if (instance? String raw-format)
- (compile-format raw-format)
- raw-format)]
+ (compile-format raw-format)
+ raw-format)]
[compiled-format navigator]))
(declare relative-reposition)
@@ -134,17 +134,17 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
(defn- realize-parameter [[param [raw-val offset]] navigator]
(let [[real-param new-navigator]
(cond
- (contains? #{ :at :colon } param) ;pass flags through unchanged - this really isn't necessary
- [raw-val navigator]
+ (contains? #{ :at :colon } param) ;pass flags through unchanged - this really isn't necessary
+ [raw-val navigator]
- (= raw-val :parameter-from-args)
- (next-arg navigator)
+ (= raw-val :parameter-from-args)
+ (next-arg navigator)
- (= raw-val :remaining-arg-count)
- [(count (:rest navigator)) navigator]
+ (= raw-val :remaining-arg-count)
+ [(count (:rest navigator)) navigator]
- true
- [raw-val navigator])]
+ true
+ [raw-val navigator])]
[[param [real-param offset]] new-navigator]))
(defn- realize-parameter-list [parameter-map navigator]
@@ -170,28 +170,28 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
(integer? n) (if (= *print-base* 10)
(str n (if *print-radix* "."))
(str
- (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r")))
- (opt-base-str *print-base* n)))
+ (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r")))
+ (opt-base-str *print-base* n)))
(ratio? n) (str
- (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r")))
- (opt-base-str *print-base* (.numerator ^clojure.lang.Ratio n))
- "/"
- (opt-base-str *print-base* (.denominator ^clojure.lang.Ratio n)))
+ (if *print-radix* (or (get special-radix-markers *print-base*) (str "#" *print-base* "r")))
+ (opt-base-str *print-base* (.numerator ^clojure.lang.Ratio n))
+ "/"
+ (opt-base-str *print-base* (.denominator ^clojure.lang.Ratio n)))
:else nil))
(defn- format-ascii [print-func params arg-navigator offsets]
(let [ [arg arg-navigator] (next-arg arg-navigator)
- ^String base-output (or (format-simple-number arg) (print-func arg))
- base-width (.length base-output)
- min-width (+ base-width (:minpad params))
- width (if (>= min-width (:mincol params))
- min-width
- (+ min-width
- (* (+ (quot (- (:mincol params) min-width 1)
- (:colinc params) )
- 1)
- (:colinc params))))
- chars (apply str (repeat (- width base-width) (:padchar params)))]
+ ^String base-output (or (format-simple-number arg) (print-func arg))
+ base-width (.length base-output)
+ min-width (+ base-width (:minpad params))
+ width (if (>= min-width (:mincol params))
+ min-width
+ (+ min-width
+ (* (+ (quot (- (:mincol params) min-width 1)
+ (:colinc params) )
+ 1)
+ (:colinc params))))
+ chars (apply str (repeat (- width base-width) (:padchar params)))]
(if (:at params)
(print (str chars base-output))
(print (str base-output chars)))
@@ -206,22 +206,22 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
"returns true if a number is actually an integer (that is, has no fractional part)"
[x]
(cond
- (integer? x) true
- (decimal? x) (>= (.ulp (.stripTrailingZeros (bigdec 0))) 1) ; true iff no fractional part
- (float? x) (= x (Math/floor x))
- (ratio? x) (let [^clojure.lang.Ratio r x]
- (= 0 (rem (.numerator r) (.denominator r))))
- :else false))
+ (integer? x) true
+ (decimal? x) (>= (.ulp (.stripTrailingZeros (bigdec 0))) 1) ; true iff no fractional part
+ (float? x) (= x (Math/floor x))
+ (ratio? x) (let [^clojure.lang.Ratio r x]
+ (= 0 (rem (.numerator r) (.denominator r))))
+ :else false))
(defn- remainders
"Return the list of remainders (essentially the 'digits') of val in the given base"
[base val]
(reverse
- (first
- (consume #(if (pos? %)
- [(rem % base) (quot % base)]
- [nil nil])
- val))))
+ (first
+ (consume #(if (pos? %)
+ [(rem % base) (quot % base)]
+ [nil nil])
+ val))))
;;; TODO: xlated-val does not seem to be used here.
(defn- base-str
@@ -236,8 +236,8 @@ http://www.lispworks.com/documentation/HyperSpec/Body/22_c.htm
:else val)]
(apply str
(map
- #(if (< % 10) (char (+ (int \0) %)) (char (+ (int \a) (- % 10))))
- (remainders base val))))))
+ #(if (< % 10) (char (+ (int \0) %)) (char (+ (int \a) (- % 10))))
+ (remainders base val))))))
(def ^{:private true}
java-base-formats {8 "%o", 10 "%d", 16 "%x"})
@@ -253,8 +253,8 @@ for improved performance"
(defn- group-by* [unit lis]
(reverse
- (first
- (consume (fn [x] [(seq (reverse (take unit x))) (seq (drop unit x))]) (reverse lis)))))
+ (first
+ (consume (fn [x] [(seq (reverse (take unit x))) (seq (drop unit x))]) (reverse lis)))))
(defn- format-integer [base params arg-navigator offsets]
(let [[arg arg-navigator] (next-arg arg-navigator)]
@@ -268,9 +268,9 @@ for improved performance"
(apply str (next (interleave commas groups))))
raw-str)
^String signed-str (cond
- neg (str "-" group-str)
- (:at params) (str "+" group-str)
- true group-str)
+ neg (str "-" group-str)
+ (:at params) (str "+" group-str)
+ true group-str)
padded-str (if (< (.length signed-str) (:mincol params))
(str (apply str (repeat (- (:mincol params) (.length signed-str))
(:padchar params)))
@@ -325,17 +325,17 @@ for improved performance"
(let [hundreds (quot num 100)
tens (rem num 100)]
(str
- (if (pos? hundreds) (str (nth english-cardinal-units hundreds) " hundred"))
- (if (and (pos? hundreds) (pos? tens)) " ")
- (if (pos? tens)
- (if (< tens 20)
- (nth english-cardinal-units tens)
- (let [ten-digit (quot tens 10)
- unit-digit (rem tens 10)]
- (str
- (if (pos? ten-digit) (nth english-cardinal-tens ten-digit))
- (if (and (pos? ten-digit) (pos? unit-digit)) "-")
- (if (pos? unit-digit) (nth english-cardinal-units unit-digit)))))))))
+ (if (pos? hundreds) (str (nth english-cardinal-units hundreds) " hundred"))
+ (if (and (pos? hundreds) (pos? tens)) " ")
+ (if (pos? tens)
+ (if (< tens 20)
+ (nth english-cardinal-units tens)
+ (let [ten-digit (quot tens 10)
+ unit-digit (rem tens 10)]
+ (str
+ (if (pos? ten-digit) (nth english-cardinal-tens ten-digit))
+ (if (and (pos? ten-digit) (pos? unit-digit)) "-")
+ (if (pos? unit-digit) (nth english-cardinal-units unit-digit)))))))))
(defn- add-english-scales
"Take a sequence of parts, add scale numbers (e.g., million) and combine into a string
@@ -353,12 +353,12 @@ offset is a factor of 10^3 to multiply by"
(if (and (not (empty? this)) (pos? (+ pos offset)))
(str " " (nth english-scale-numbers (+ pos offset)))))
(recur
- (if (empty? this)
- acc
- (conj acc (str this " " (nth english-scale-numbers (+ pos offset)))))
- (dec pos)
- (first remainder)
- (next remainder))))))
+ (if (empty? this)
+ acc
+ (conj acc (str this " " (nth english-scale-numbers (+ pos offset)))))
+ (dec pos)
+ (first remainder)
+ (next remainder))))))
(defn- format-cardinal-english [params navigator offsets]
(let [[arg navigator] (next-arg navigator)]
@@ -371,10 +371,10 @@ offset is a factor of 10^3 to multiply by"
full-str (add-english-scales parts-strs 0)]
(print (str (if (neg? arg) "minus ") full-str)))
(format-integer ;; for numbers > 10^63, we fall back on ~D
- 10
- { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true}
- (init-navigator [arg])
- { :mincol 0, :padchar 0, :commachar 0 :commainterval 0}))))
+ 10
+ { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true}
+ (init-navigator [arg])
+ { :mincol 0, :padchar 0, :commachar 0 :commainterval 0}))))
navigator))
(defn- format-simple-ordinal
@@ -384,20 +384,20 @@ Note this should only be used for the last one in the sequence"
(let [hundreds (quot num 100)
tens (rem num 100)]
(str
- (if (pos? hundreds) (str (nth english-cardinal-units hundreds) " hundred"))
- (if (and (pos? hundreds) (pos? tens)) " ")
- (if (pos? tens)
- (if (< tens 20)
- (nth english-ordinal-units tens)
- (let [ten-digit (quot tens 10)
- unit-digit (rem tens 10)]
- (if (and (pos? ten-digit) (not (pos? unit-digit)))
- (nth english-ordinal-tens ten-digit)
- (str
- (if (pos? ten-digit) (nth english-cardinal-tens ten-digit))
- (if (and (pos? ten-digit) (pos? unit-digit)) "-")
- (if (pos? unit-digit) (nth english-ordinal-units unit-digit))))))
- (if (pos? hundreds) "th")))))
+ (if (pos? hundreds) (str (nth english-cardinal-units hundreds) " hundred"))
+ (if (and (pos? hundreds) (pos? tens)) " ")
+ (if (pos? tens)
+ (if (< tens 20)
+ (nth english-ordinal-units tens)
+ (let [ten-digit (quot tens 10)
+ unit-digit (rem tens 10)]
+ (if (and (pos? ten-digit) (not (pos? unit-digit)))
+ (nth english-ordinal-tens ten-digit)
+ (str
+ (if (pos? ten-digit) (nth english-cardinal-tens ten-digit))
+ (if (and (pos? ten-digit) (pos? unit-digit)) "-")
+ (if (pos? unit-digit) (nth english-ordinal-units unit-digit))))))
+ (if (pos? hundreds) "th")))))
(defn- format-ordinal-english [params navigator offsets]
(let [[arg navigator] (next-arg navigator)]
@@ -411,24 +411,24 @@ Note this should only be used for the last one in the sequence"
tail-str (format-simple-ordinal (last parts))]
(print (str (if (neg? arg) "minus ")
(cond
- (and (not (empty? head-str)) (not (empty? tail-str)))
- (str head-str ", " tail-str)
+ (and (not (empty? head-str)) (not (empty? tail-str)))
+ (str head-str ", " tail-str)
- (not (empty? head-str)) (str head-str "th")
- :else tail-str))))
+ (not (empty? head-str)) (str head-str "th")
+ :else tail-str))))
(do (format-integer ;; for numbers > 10^63, we fall back on ~D
- 10
- { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true}
- (init-navigator [arg])
- { :mincol 0, :padchar 0, :commachar 0 :commainterval 0})
+ 10
+ { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true}
+ (init-navigator [arg])
+ { :mincol 0, :padchar 0, :commachar 0 :commainterval 0})
(let [low-two-digits (rem arg 100)
not-teens (or (< 11 low-two-digits) (> 19 low-two-digits))
low-digit (rem low-two-digits 10)]
(print (cond
- (and (== low-digit 1) not-teens) "st"
- (and (== low-digit 2) not-teens) "nd"
- (and (== low-digit 3) not-teens) "rd"
- :else "th")))))))
+ (and (== low-digit 1) not-teens) "st"
+ (and (== low-digit 2) not-teens) "nd"
+ (and (== low-digit 3) not-teens) "rd"
+ :else "th")))))))
navigator))
@@ -468,10 +468,10 @@ Note this should only be used for the last one in the sequence"
(dec pos)
(next digits))))))
(format-integer ;; for anything <= 0 or > 3999, we fall back on ~D
- 10
- { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true}
- (init-navigator [arg])
- { :mincol 0, :padchar 0, :commachar 0 :commainterval 0}))
+ 10
+ { :mincol 0, :padchar \space, :commachar \, :commainterval 3, :colon true}
+ (init-navigator [arg])
+ { :mincol 0, :padchar 0, :commachar 0 :commainterval 0}))
navigator))
(defn- format-old-roman [params navigator offsets]
@@ -495,10 +495,10 @@ Note this should only be used for the last one in the sequence"
special (get special-chars base-char)]
(if (> meta 0) (print "Meta-"))
(print (cond
- special special
- (< base-char 32) (str "Control-" (char (+ base-char 64)))
- (= base-char 127) "Control-?"
- :else (char base-char)))
+ special special
+ (< base-char 32) (str "Control-" (char (+ base-char 64)))
+ (= base-char 127) "Control-?"
+ :else (char base-char)))
navigator))
(defn- readable-character [params navigator offsets]
@@ -523,16 +523,16 @@ Note this should only be used for the last one in the sequence"
;; Handle the execution of "sub-clauses" in bracket constructions
(defn- execute-sub-format [format args base-args]
(second
- (map-passing-context
- (fn [element context]
- (if (abort? context)
- [nil context] ; just keep passing it along
- (let [[params args] (realize-parameter-list (:params element) context)
- [params offsets] (unzip-map params)
- params (assoc params :base-args base-args)]
- [nil (apply (:func element) [params args offsets])])))
- args
- format)))
+ (map-passing-context
+ (fn [element context]
+ (if (abort? context)
+ [nil context] ; just keep passing it along
+ (let [[params args] (realize-parameter-list (:params element) context)
+ [params offsets] (unzip-map params)
+ params (assoc params :base-args base-args)]
+ [nil (apply (:func element) [params args offsets])])))
+ args
+ format)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Support for real number formats
@@ -576,11 +576,11 @@ string, or one character longer."
(let [len-1 (dec (count s))]
(loop [i (int len-1)]
(cond
- (neg? i) (apply str "1" (repeat (inc len-1) "0"))
- (= \9 (.charAt s i)) (recur (dec i))
- :else (apply str (subs s 0 i)
- (char (inc (int (.charAt s i))))
- (repeat (- len-1 i) "0"))))))
+ (neg? i) (apply str "1" (repeat (inc len-1) "0"))
+ (= \9 (.charAt s i)) (recur (dec i))
+ :else (apply str (subs s 0 i)
+ (char (inc (int (.charAt s i))))
+ (repeat (- len-1 i) "0"))))))
(defn- round-str [m e d w]
(if (or d w)
@@ -589,20 +589,20 @@ string, or one character longer."
;; least one decimal digit and a decimal point.
w (if w (max 2 w))
round-pos (cond
- ;; If d was given, that forces the rounding
- ;; position, regardless of any width that may
- ;; have been specified.
- d (+ e d 1)
- ;; Otherwise w was specified, so pick round-pos
- ;; based upon that.
- ;; If e>=0, then abs value of number is >= 1.0,
- ;; and e+1 is number of decimal digits before the
- ;; decimal point when the number is written
- ;; without scientific notation. Never round the
- ;; number before the decimal point.
- (>= e 0) (max (inc e) (dec w))
- ;; e < 0, so number abs value < 1.0
- :else (+ w e))
+ ;; If d was given, that forces the rounding
+ ;; position, regardless of any width that may
+ ;; have been specified.
+ d (+ e d 1)
+ ;; Otherwise w was specified, so pick round-pos
+ ;; based upon that.
+ ;; If e>=0, then abs value of number is >= 1.0,
+ ;; and e+1 is number of decimal digits before the
+ ;; decimal point when the number is written
+ ;; without scientific notation. Never round the
+ ;; number before the decimal point.
+ (>= e 0) (max (inc e) (dec w))
+ ;; e < 0, so number abs value < 1.0
+ :else (+ w e))
[m1 e1 round-pos len] (if (= round-pos 0)
[(str "0" m) (inc e) 1 (inc len)]
[m e round-pos len])]
@@ -701,16 +701,16 @@ string, or one character longer."
(if (and (> full-len w) (:overflowchar params))
(print (apply str (repeat w (:overflowchar params))))
(print (str
- (apply str (repeat (- w full-len) (:padchar params)))
- (if add-sign sign)
- (if prepend-zero "0")
- fixed-repr
- (if append-zero "0")))))
+ (apply str (repeat (- w full-len) (:padchar params)))
+ (if add-sign sign)
+ (if prepend-zero "0")
+ fixed-repr
+ (if append-zero "0")))))
(print (str
- (if add-sign sign)
- (if prepend-zero "0")
- fixed-repr
- (if append-zero "0"))))
+ (if add-sign sign)
+ (if prepend-zero "0")
+ fixed-repr
+ (if append-zero "0"))))
navigator))
@@ -733,9 +733,9 @@ string, or one character longer."
scaled-exp-str (str expchar (if (neg? scaled-exp) \- \+)
(if e (apply str
(repeat
- (- e
- (count scaled-exp-str))
- \0)))
+ (- e
+ (count scaled-exp-str))
+ \0)))
scaled-exp-str)
exp-width (count scaled-exp-str)
base-mantissa-width (count mantissa)
@@ -744,17 +744,17 @@ string, or one character longer."
(if d
(apply str
(repeat
- (- d (dec base-mantissa-width)
- (if (neg? k) (- k) 0)) \0))))
+ (- d (dec base-mantissa-width)
+ (if (neg? k) (- k) 0)) \0))))
w-mantissa (if w (- w exp-width))
[rounded-mantissa _ incr-exp] (round-str
- scaled-mantissa 0
- (cond
- (= k 0) (dec d)
- (pos? k) d
- (neg? k) (dec d))
- (if w-mantissa
- (- w-mantissa (if add-sign 1 0))))
+ scaled-mantissa 0
+ (cond
+ (= k 0) (dec d)
+ (pos? k) d
+ (neg? k) (dec d))
+ (if w-mantissa
+ (- w-mantissa (if add-sign 1 0))))
full-mantissa (insert-scaled-decimal rounded-mantissa k)
append-zero (and (= k (count rounded-mantissa)) (nil? d))]
(if (not incr-exp)
@@ -768,21 +768,21 @@ string, or one character longer."
(:overflowchar params))
(print (apply str (repeat w (:overflowchar params))))
(print (str
- (apply str
- (repeat
- (- w full-len (if append-zero 1 0) )
- (:padchar params)))
- (if add-sign (if (neg? arg) \- \+))
- (if prepend-zero "0")
- full-mantissa
- (if append-zero "0")
- scaled-exp-str))))
+ (apply str
+ (repeat
+ (- w full-len (if append-zero 1 0) )
+ (:padchar params)))
+ (if add-sign (if (neg? arg) \- \+))
+ (if prepend-zero "0")
+ full-mantissa
+ (if append-zero "0")
+ scaled-exp-str))))
(print (str
- (if add-sign (if (neg? arg) \- \+))
- (if prepend-zero "0")
- full-mantissa
- (if append-zero "0")
- scaled-exp-str)))
+ (if add-sign (if (neg? arg) \- \+))
+ (if prepend-zero "0")
+ full-mantissa
+ (if append-zero "0")
+ scaled-exp-str)))
(recur [rounded-mantissa (inc exp)]))))
navigator))
@@ -826,10 +826,10 @@ string, or one character longer."
full-repr (str (apply str (repeat (- n (.indexOf fixed-repr (int \.))) \0)) fixed-repr)
full-len (+ (count full-repr) (if add-sign 1 0))]
(print (str
- (if (and (:colon params) add-sign) (if (neg? arg) \- \+))
- (apply str (repeat (- w full-len) (:padchar params)))
- (if (and (not (:colon params)) add-sign) (if (neg? arg) \- \+))
- full-repr))
+ (if (and (:colon params) add-sign) (if (neg? arg) \- \+))
+ (apply str (repeat (- w full-len) (:padchar params)))
+ (if (and (not (:colon params)) add-sign) (if (neg? arg) \- \+))
+ full-repr))
navigator))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -922,9 +922,9 @@ string, or one character longer."
(and max-count (>= count max-count)))
navigator
(let [iter-result (execute-sub-format
- clause
- (init-navigator (first arg-list))
- (init-navigator (next arg-list)))]
+ clause
+ (init-navigator (first arg-list))
+ (init-navigator (next arg-list)))]
(if (= :colon-up-arrow (first iter-result))
navigator
(recur (inc count) (next arg-list))))))))
@@ -951,7 +951,7 @@ string, or one character longer."
(if (= :up-arrow (first iter-result))
(second iter-result)
(recur
- (inc count) iter-result (:pos navigator))))))))
+ (inc count) iter-result (:pos navigator))))))))
;; ~@:{...~} with both colon and at sign uses the main argument list as a set of sublists, one
;; of which is consumed with each iteration
@@ -1055,10 +1055,10 @@ string, or one character longer."
(if (or pad-only (next strs) (:at params)) pad-str)
(if (pos? extra-pad) (:padchar params))))
(recur
- (dec slots)
- (dec extra-pad)
- (if pad-only strs (next strs))
- false))))
+ (dec slots)
+ (dec extra-pad)
+ (if pad-only strs (next strs))
+ false))))
navigator))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -1076,16 +1076,16 @@ string, or one character longer."
(close [] (.close writer))
(flush [] (.flush writer))
(write ([^chars cbuf ^Integer off ^Integer len]
- (.write writer cbuf off len))
+ (.write writer cbuf off len))
([x]
- (condp = (class x)
- String
- (let [s ^String x]
- (.write writer (.toLowerCase s)))
+ (condp = (class x)
+ String
+ (let [s ^String x]
+ (.write writer (.toLowerCase s)))
- Integer
- (let [c ^Character x]
- (.write writer (int (Character/toLowerCase (char c))))))))))
+ Integer
+ (let [c ^Character x]
+ (.write writer (int (Character/toLowerCase (char c))))))))))
(defn- upcase-writer
"Returns a proxy that wraps writer, converting all characters to upper case"
@@ -1094,16 +1094,16 @@ string, or one character longer."
(close [] (.close writer))
(flush [] (.flush writer))
(write ([^chars cbuf ^Integer off ^Integer len]
- (.write writer cbuf off len))
+ (.write writer cbuf off len))
([x]
- (condp = (class x)
- String
- (let [s ^String x]
- (.write writer (.toUpperCase s)))
+ (condp = (class x)
+ String
+ (let [s ^String x]
+ (.write writer (.toUpperCase s)))
- Integer
- (let [c ^Character x]
- (.write writer (int (Character/toUpperCase (char c))))))))))
+ Integer
+ (let [c ^Character x]
+ (.write writer (int (Character/toUpperCase (char c))))))))))
(defn- capitalize-string
"Capitalizes the words in a string. If first? is false, don't capitalize the
@@ -1115,19 +1115,19 @@ string, or one character longer."
s)]
(apply str
(first
- (consume
- (fn [s]
- (if (empty? s)
- [nil nil]
- (let [m (re-matcher #"\W\w" s)
- match (re-find m)
- offset (and match (inc (.start m)))]
- (if offset
- [(str (subs s 0 offset)
- (Character/toUpperCase ^Character (nth s offset)))
- (subs s (inc offset))]
- [s nil]))))
- s)))))
+ (consume
+ (fn [s]
+ (if (empty? s)
+ [nil nil]
+ (let [m (re-matcher #"\W\w" s)
+ match (re-find m)
+ offset (and match (inc (.start m)))]
+ (if offset
+ [(str (subs s 0 offset)
+ (Character/toUpperCase ^Character (nth s offset)))
+ (subs s (inc offset))]
+ [s nil]))))
+ s)))))
(defn- capitalize-word-writer
"Returns a proxy that wraps writer, capitalizing all words"
@@ -1137,25 +1137,25 @@ string, or one character longer."
(close [] (.close writer))
(flush [] (.flush writer))
(write
- ([^chars cbuf ^Integer off ^Integer len]
- (.write writer cbuf off len))
- ([x]
- (condp = (class x)
- String
- (let [s ^String x]
- (.write writer
- ^String (capitalize-string (.toLowerCase s) @last-was-whitespace?))
- (when (pos? (.length s))
- (dosync
+ ([^chars cbuf ^Integer off ^Integer len]
+ (.write writer cbuf off len))
+ ([x]
+ (condp = (class x)
+ String
+ (let [s ^String x]
+ (.write writer
+ ^String (capitalize-string (.toLowerCase s) @last-was-whitespace?))
+ (when (pos? (.length s))
+ (dosync
(ref-set last-was-whitespace?
(Character/isWhitespace
- ^Character (nth s (dec (count s))))))))
+ ^Character (nth s (dec (count s))))))))
- Integer
- (let [c (char x)]
- (let [mod-c (if @last-was-whitespace? (Character/toUpperCase (char x)) c)]
- (.write writer (int mod-c))
- (dosync (ref-set last-was-whitespace? (Character/isWhitespace (char x))))))))))))
+ Integer
+ (let [c (char x)]
+ (let [mod-c (if @last-was-whitespace? (Character/toUpperCase (char x)) c)]
+ (.write writer (int mod-c))
+ (dosync (ref-set last-was-whitespace? (Character/isWhitespace (char x))))))))))))
(defn- init-cap-writer
"Returns a proxy that wraps writer, capitalizing the first word"
@@ -1165,31 +1165,31 @@ string, or one character longer."
(close [] (.close writer))
(flush [] (.flush writer))
(write ([^chars cbuf ^Integer off ^Integer len]
- (.write writer cbuf off len))
+ (.write writer cbuf off len))
([x]
- (condp = (class x)
- String
- (let [s (.toLowerCase ^String x)]
- (if (not @capped)
- (let [m (re-matcher #"\S" s)
- match (re-find m)
- offset (and match (.start m))]
- (if offset
- (do (.write writer
- (str (subs s 0 offset)
- (Character/toUpperCase ^Character (nth s offset))
- (.toLowerCase ^String (subs s (inc offset)))))
- (dosync (ref-set capped true)))
- (.write writer s)))
- (.write writer (.toLowerCase s))))
-
- Integer
- (let [c ^Character (char x)]
- (if (and (not @capped) (Character/isLetter c))
- (do
- (dosync (ref-set capped true))
- (.write writer (int (Character/toUpperCase c))))
- (.write writer (int (Character/toLowerCase c)))))))))))
+ (condp = (class x)
+ String
+ (let [s (.toLowerCase ^String x)]
+ (if (not @capped)
+ (let [m (re-matcher #"\S" s)
+ match (re-find m)
+ offset (and match (.start m))]
+ (if offset
+ (do (.write writer
+ (str (subs s 0 offset)
+ (Character/toUpperCase ^Character (nth s offset))
+ (.toLowerCase ^String (subs s (inc offset)))))
+ (dosync (ref-set capped true)))
+ (.write writer s)))
+ (.write writer (.toLowerCase s))))
+
+ Integer
+ (let [c ^Character (char x)]
+ (if (and (not @capped) (Character/isLetter c))
+ (do
+ (dosync (ref-set capped true))
+ (.write writer (int (Character/toUpperCase c))))
+ (.write writer (int (Character/toLowerCase c)))))))))))
(defn- modify-case [make-writer params navigator offsets]
(let [clause (first (:clauses params))]
@@ -1257,9 +1257,9 @@ not a pretty writer (which keeps track of columns), this function always outputs
colinc (:colinc params)
current (get-column (:base @@*out*))
space-count (cond
- (< current colnum) (- colnum current)
- (= colinc 0) 0
- :else (- colinc (rem (- current colnum) colinc)))]
+ (< current colnum) (- colnum current)
+ (= colinc 0) 0
+ :else (- colinc (rem (- current colnum) colinc)))]
(print (apply str (repeat space-count \space))))
navigator)
@@ -1283,18 +1283,18 @@ not a pretty writer (which keeps track of columns), this function always outputs
(let [clauses (:clauses params)
clause-count (count clauses)
prefix (cond
- (> clause-count 1) (:string (:params (first (first clauses))))
- (:colon params) "(")
+ (> clause-count 1) (:string (:params (first (first clauses))))
+ (:colon params) "(")
body (nth clauses (if (> clause-count 1) 1 0))
suffix (cond
- (> clause-count 2) (:string (:params (first (nth clauses 2))))
- (:colon params) ")")
+ (> clause-count 2) (:string (:params (first (nth clauses 2))))
+ (:colon params) ")")
[arg navigator] (next-arg navigator)]
(pprint-logical-block :prefix prefix :suffix suffix
(execute-sub-format
- body
- (init-navigator arg)
- (:base-args params)))
+ body
+ (init-navigator arg)
+ (:base-args params)))
navigator))
(defn- set-indent [params navigator offsets]
@@ -1588,8 +1588,8 @@ not a pretty writer (which keeps track of columns), this function always outputs
#{:at :colon :both :pretty} {}
(if (or (:at params) (:colon params))
(let [bindings (concat
- (if (:at params) [:level nil :length nil] [])
- (if (:colon params) [:pretty true] []))]
+ (if (:at params) [:level nil :length nil] [])
+ (if (:colon params) [:pretty true] []))]
(fn [params navigator offsets]
(let [[arg navigator] (next-arg navigator)]
(if (apply write arg bindings)
@@ -1645,11 +1645,11 @@ not a pretty writer (which keeps track of columns), this function always outputs
representation"
[[^String p offset]]
[(cond
- (= (.length p) 0) nil
- (and (= (.length p) 1) (contains? #{\v \V} (nth p 0))) :parameter-from-args
- (and (= (.length p) 1) (= \# (nth p 0))) :remaining-arg-count
- (and (= (.length p) 2) (= \' (nth p 0))) (nth p 1)
- true (Integer/parseInt p))
+ (= (.length p) 0) nil
+ (and (= (.length p) 1) (contains? #{\v \V} (nth p 0))) :parameter-from-args
+ (and (= (.length p) 1) (= \# (nth p 0))) :remaining-arg-count
+ (and (= (.length p) 2) (= \' (nth p 0))) (nth p 1)
+ true (Integer/parseInt p))
offset])
(def ^{:private true}
@@ -1657,18 +1657,18 @@ not a pretty writer (which keeps track of columns), this function always outputs
(defn- extract-flags [s offset]
(consume
- (fn [[s offset flags]]
- (if (empty? s)
- [nil [s offset flags]]
- (let [flag (get flag-defs (first s))]
- (if flag
- (if (contains? flags flag)
- (format-error
- (str "Flag \"" (first s) "\" appears more than once in a directive")
- offset)
- [true [(subs s 1) (inc offset) (assoc flags flag [true offset])]])
- [nil [s offset flags]]))))
- [s offset {}]))
+ (fn [[s offset flags]]
+ (if (empty? s)
+ [nil [s offset flags]]
+ (let [flag (get flag-defs (first s))]
+ (if flag
+ (if (contains? flags flag)
+ (format-error
+ (str "Flag \"" (first s) "\" appears more than once in a directive")
+ offset)
+ [true [(subs s 1) (inc offset) (assoc flags flag [true offset])]])
+ [nil [s offset flags]]))))
+ [s offset {}]))
(defn- check-flags [def flags]
(let [allowed (:flags def)]
@@ -1692,26 +1692,26 @@ of parameters as well."
(check-flags def flags)
(if (> (count params) (count (:params def)))
(format-error
- (cl-format
- nil
- "Too many parameters for directive \"~C\": ~D~:* ~[were~;was~:;were~] specified but only ~D~:* ~[are~;is~:;are~] allowed"
- (:directive def) (count params) (count (:params def)))
- (second (first params))))
+ (cl-format
+ nil
+ "Too many parameters for directive \"~C\": ~D~:* ~[were~;was~:;were~] specified but only ~D~:* ~[are~;is~:;are~] allowed"
+ (:directive def) (count params) (count (:params def)))
+ (second (first params))))
(doall
- (map #(let [val (first %1)]
- (if (not (or (nil? val) (contains? special-params val)
- (instance? (second (second %2)) val)))
- (format-error (str "Parameter " (name (first %2))
- " has bad type in directive \"" (:directive def) "\": "
- (class val))
- (second %1))) )
- params (:params def)))
+ (map #(let [val (first %1)]
+ (if (not (or (nil? val) (contains? special-params val)
+ (instance? (second (second %2)) val)))
+ (format-error (str "Parameter " (name (first %2))
+ " has bad type in directive \"" (:directive def) "\": "
+ (class val))
+ (second %1))) )
+ params (:params def)))
(merge ; create the result map
- (into (array-map) ; start with the default values, make sure the order is right
- (reverse (for [[name [default]] (:params def)] [name [default offset]])))
- (reduce #(apply assoc %1 %2) {} (filter #(first (nth % 1)) (zipmap (keys (:params def)) params))) ; add the specified parameters, filtering out nils
- flags)) ; and finally add the flags
+ (into (array-map) ; start with the default values, make sure the order is right
+ (reverse (for [[name [default]] (:params def)] [name [default offset]])))
+ (reduce #(apply assoc %1 %2) {} (filter #(first (nth % 1)) (zipmap (keys (:params def)) params))) ; add the specified parameters, filtering out nils
+ flags)) ; and finally add the flags
(defn- compile-directive [s offset]
(let [[raw-params [rest offset]] (extract-params s offset)
@@ -1756,112 +1756,112 @@ of parameters as well."
(defn- process-clause [bracket-info offset remainder]
(consume
- (fn [remainder]
- (if (empty? remainder)
- (format-error "No closing bracket found." offset)
- (let [this (first remainder)
- remainder (next remainder)]
- (cond
- (right-bracket this)
- (process-bracket this remainder)
+ (fn [remainder]
+ (if (empty? remainder)
+ (format-error "No closing bracket found." offset)
+ (let [this (first remainder)
+ remainder (next remainder)]
+ (cond
+ (right-bracket this)
+ (process-bracket this remainder)
- (= (:right bracket-info) (:directive (:def this)))
- [ nil [:right-bracket (:params this) nil remainder]]
+ (= (:right bracket-info) (:directive (:def this)))
+ [ nil [:right-bracket (:params this) nil remainder]]
- (else-separator? this)
- [nil [:else nil (:params this) remainder]]
+ (else-separator? this)
+ [nil [:else nil (:params this) remainder]]
- (separator? this)
- [nil [:separator nil nil remainder]] ;; TODO: check to make sure that there are no params on ~;
+ (separator? this)
+ [nil [:separator nil nil remainder]] ;; TODO: check to make sure that there are no params on ~;
- true
- [this remainder]))))
- remainder))
+ true
+ [this remainder]))))
+ remainder))
(defn- collect-clauses [bracket-info offset remainder]
(second
- (consume
- (fn [[clause-map saw-else remainder]]
- (let [[clause [type right-params else-params remainder]]
- (process-clause bracket-info offset remainder)]
- (cond
- (= type :right-bracket)
- [nil [(merge-with concat clause-map
- {(if saw-else :else :clauses) [clause]
- :right-params right-params})
- remainder]]
-
- (= type :else)
- (cond
- (:else clause-map)
- (format-error "Two else clauses (\"~:;\") inside bracket construction." offset)
+ (consume
+ (fn [[clause-map saw-else remainder]]
+ (let [[clause [type right-params else-params remainder]]
+ (process-clause bracket-info offset remainder)]
+ (cond
+ (= type :right-bracket)
+ [nil [(merge-with concat clause-map
+ {(if saw-else :else :clauses) [clause]
+ :right-params right-params})
+ remainder]]
+
+ (= type :else)
+ (cond
+ (:else clause-map)
+ (format-error "Two else clauses (\"~:;\") inside bracket construction." offset)
- (not (:else bracket-info))
- (format-error "An else clause (\"~:;\") is in a bracket type that doesn't support it."
- offset)
-
- (and (= :first (:else bracket-info)) (seq (:clauses clause-map)))
- (format-error
- "The else clause (\"~:;\") is only allowed in the first position for this directive."
- offset)
+ (not (:else bracket-info))
+ (format-error "An else clause (\"~:;\") is in a bracket type that doesn't support it."
+ offset)
+
+ (and (= :first (:else bracket-info)) (seq (:clauses clause-map)))
+ (format-error
+ "The else clause (\"~:;\") is only allowed in the first position for this directive."
+ offset)
- true ; if the ~:; is in the last position, the else clause
- ; is next, this was a regular clause
- (if (= :first (:else bracket-info))
- [true [(merge-with concat clause-map { :else [clause] :else-params else-params})
- false remainder]]
- [true [(merge-with concat clause-map { :clauses [clause] })
- true remainder]]))
-
- (= type :separator)
- (cond
- saw-else
- (format-error "A plain clause (with \"~;\") follows an else clause (\"~:;\") inside bracket construction." offset)
+ true ; if the ~:; is in the last position, the else clause
+ ; is next, this was a regular clause
+ (if (= :first (:else bracket-info))
+ [true [(merge-with concat clause-map { :else [clause] :else-params else-params})
+ false remainder]]
+ [true [(merge-with concat clause-map { :clauses [clause] })
+ true remainder]]))
+
+ (= type :separator)
+ (cond
+ saw-else
+ (format-error "A plain clause (with \"~;\") follows an else clause (\"~:;\") inside bracket construction." offset)
- (not (:allows-separator bracket-info))
- (format-error "A separator (\"~;\") is in a bracket type that doesn't support it."
- offset)
+ (not (:allows-separator bracket-info))
+ (format-error "A separator (\"~;\") is in a bracket type that doesn't support it."
+ offset)
- true
- [true [(merge-with concat clause-map { :clauses [clause] })
- false remainder]]))))
- [{ :clauses [] } false remainder])))
+ true
+ [true [(merge-with concat clause-map { :clauses [clause] })
+ false remainder]]))))
+ [{ :clauses [] } false remainder])))
(defn- process-nesting
"Take a linearly compiled format and process the bracket directives to give it
the appropriate tree structure"
[format]
(first
- (consume
- (fn [remainder]
- (let [this (first remainder)
- remainder (next remainder)
- bracket (:bracket-info (:def this))]
- (if (:right bracket)
- (process-bracket this remainder)
- [this remainder])))
- format)))
+ (consume
+ (fn [remainder]
+ (let [this (first remainder)
+ remainder (next remainder)
+ bracket (:bracket-info (:def this))]
+ (if (:right bracket)
+ (process-bracket this remainder)
+ [this remainder])))
+ format)))
(defn- compile-format
"Compiles format-str into a compiled format which can be used as an argument
to cl-format just like a plain format string. Use this function for improved
performance when you're using the same format string repeatedly"
[ format-str ]
-; (prlabel compiling format-str)
+ ; (prlabel compiling format-str)
(binding [*format-str* format-str]
(process-nesting
- (first
- (consume
- (fn [[^String s offset]]
- (if (empty? s)
- [nil s]
- (let [tilde (.indexOf s (int \~))]
- (cond
- (neg? tilde) [(compile-raw-string s offset) ["" (+ offset (.length s))]]
- (zero? tilde) (compile-directive (subs s 1) (inc offset))
- true
- [(compile-raw-string (subs s 0 tilde) offset) [(subs s tilde) (+ tilde offset)]]))))
- [format-str 0])))))
+ (first
+ (consume
+ (fn [[^String s offset]]
+ (if (empty? s)
+ [nil s]
+ (let [tilde (.indexOf s (int \~))]
+ (cond
+ (neg? tilde) [(compile-raw-string s offset) ["" (+ offset (.length s))]]
+ (zero? tilde) (compile-directive (subs s 1) (inc offset))
+ true
+ [(compile-raw-string (subs s 0 tilde) offset) [(subs s tilde) (+ tilde offset)]]))))
+ [format-str 0])))))
(defn- needs-pretty
"determine whether a given compiled format has any directives that depend on the
@@ -1880,34 +1880,34 @@ column number or pretty printing"
"Executes the format with the arguments."
{:skip-wiki true}
([stream format args]
- (let [^java.io.Writer real-stream (cond
- (not stream) (java.io.StringWriter.)
- (true? stream) *out*
- :else stream)
- ^java.io.Writer wrapped-stream (if (and (needs-pretty format)
- (not (pretty-writer? real-stream)))
- (get-pretty-writer real-stream)
- real-stream)]
- (binding [*out* wrapped-stream]
- (try
- (execute-format format args)
- (finally
+ (let [^java.io.Writer real-stream (cond
+ (not stream) (java.io.StringWriter.)
+ (true? stream) *out*
+ :else stream)
+ ^java.io.Writer wrapped-stream (if (and (needs-pretty format)
+ (not (pretty-writer? real-stream)))
+ (get-pretty-writer real-stream)
+ real-stream)]
+ (binding [*out* wrapped-stream]
+ (try
+ (execute-format format args)
+ (finally
(if-not (identical? real-stream wrapped-stream)
(.flush wrapped-stream))))
- (if (not stream) (.toString real-stream)))))
+ (if (not stream) (.toString real-stream)))))
([format args]
- (map-passing-context
- (fn [element context]
- (if (abort? context)
- [nil context]
- (let [[params args] (realize-parameter-list
+ (map-passing-context
+ (fn [element context]
+ (if (abort? context)
+ [nil context]
+ (let [[params args] (realize-parameter-list
(:params element) context)
- [params offsets] (unzip-map params)
- params (assoc params :base-args args)]
- [nil (apply (:func element) [params args offsets])])))
- args
- format)
- nil))
+ [params offsets] (unzip-map params)
+ params (assoc params :base-args args)]
+ [nil (apply (:func element) [params args offsets])])))
+ args
+ format)
+ nil))
;;; This is a bad idea, but it prevents us from leaking private symbols
;;; This should all be replaced by really compiled formats anyway.
diff --git a/src/clj/clojure/pprint/column_writer.clj b/src/clj/clojure/pprint/column_writer.clj
index 704fc0c3..bc01c83c 100644
--- a/src/clj/clojure/pprint/column_writer.clj
+++ b/src/clj/clojure/pprint/column_writer.clj
@@ -46,38 +46,38 @@
(defn- c-write-char [^Writer this ^Integer c]
(dosync (if (= c (int \newline))
- (do
+ (do
(set-field this :cur 0)
(set-field this :line (inc (get-field this :line))))
- (set-field this :cur (inc (get-field this :cur)))))
+ (set-field this :cur (inc (get-field this :cur)))))
(.write ^Writer (get-field this :base) c))
(defn- column-writer
([writer] (column-writer writer *default-page-width*))
([^Writer writer max-columns]
- (let [fields (ref {:max max-columns, :cur 0, :line 0 :base writer})]
- (proxy [Writer IDeref] []
- (deref [] fields)
- (flush []
- (.flush writer))
- (write
- ([^chars cbuf ^Integer off ^Integer len]
- (let [^Writer writer (get-field this :base)]
- (.write writer cbuf off len)))
- ([x]
- (condp = (class x)
- String
- (let [^String s x
- nl (.lastIndexOf s (int \newline))]
- (dosync (if (neg? nl)
- (set-field this :cur (+ (get-field this :cur) (count s)))
- (do
- (set-field this :cur (- (count s) nl 1))
- (set-field this :line (+ (get-field this :line)
- (count (filter #(= % \newline) s)))))))
- (.write ^Writer (get-field this :base) s))
-
- Integer
- (c-write-char this x)
- Long
- (c-write-char this x))))))))
+ (let [fields (ref {:max max-columns, :cur 0, :line 0 :base writer})]
+ (proxy [Writer IDeref] []
+ (deref [] fields)
+ (flush []
+ (.flush writer))
+ (write
+ ([^chars cbuf ^Integer off ^Integer len]
+ (let [^Writer writer (get-field this :base)]
+ (.write writer cbuf off len)))
+ ([x]
+ (condp = (class x)
+ String
+ (let [^String s x
+ nl (.lastIndexOf s (int \newline))]
+ (dosync (if (neg? nl)
+ (set-field this :cur (+ (get-field this :cur) (count s)))
+ (do
+ (set-field this :cur (- (count s) nl 1))
+ (set-field this :line (+ (get-field this :line)
+ (count (filter #(= % \newline) s)))))))
+ (.write ^Writer (get-field this :base) s))
+
+ Integer
+ (c-write-char this x)
+ Long
+ (c-write-char this x))))))))
diff --git a/src/clj/clojure/pprint/dispatch.clj b/src/clj/clojure/pprint/dispatch.clj
index 1ef9a578..fe25ce7b 100644
--- a/src/clj/clojure/pprint/dispatch.clj
+++ b/src/clj/clojure/pprint/dispatch.clj
@@ -67,11 +67,11 @@
(pprint-logical-block :prefix "(" :suffix ")"
(print-length-loop [alis (seq alis)]
(when alis
- (write-out (first alis))
- (when (next alis)
- (.write ^java.io.Writer *out* " ")
- (pprint-newline :linear)
- (recur (next alis)))))))
+ (write-out (first alis))
+ (when (next alis)
+ (.write ^java.io.Writer *out* " ")
+ (pprint-newline :linear)
+ (recur (next alis)))))))
(defn- pprint-list [alis]
(if-not (pprint-reader-macro alis)
@@ -82,11 +82,11 @@
(pprint-logical-block :prefix "[" :suffix "]"
(print-length-loop [aseq (seq avec)]
(when aseq
- (write-out (first aseq))
- (when (next aseq)
- (.write ^java.io.Writer *out* " ")
- (pprint-newline :linear)
- (recur (next aseq)))))))
+ (write-out (first aseq))
+ (when (next aseq)
+ (.write ^java.io.Writer *out* " ")
+ (pprint-newline :linear)
+ (recur (next aseq)))))))
(def ^{:private true} pprint-array (formatter-out "~<[~;~@{~w~^, ~:_~}~;]~:>"))
@@ -135,9 +135,9 @@
(pprint-indent :block (-> (count prefix) (- 2) -))
(pprint-newline :linear)
(write-out (cond
- (and (future? o) (not (future-done? o))) :pending
- (and (instance? clojure.lang.IPending o) (not (.isRealized ^clojure.lang.IPending o))) :not-delivered
- :else @o)))))
+ (and (future? o) (not (future-done? o))) :pending
+ (and (instance? clojure.lang.IPending o) (not (.isRealized ^clojure.lang.IPending o))) :not-delivered
+ :else @o)))))
(def ^{:private true} pprint-pqueue (formatter-out "~<<-(~;~@{~w~^ ~_~}~;)-<~:>"))
@@ -287,8 +287,8 @@
((formatter-out " ~_~w") attr-map))
;; Note: the multi-defn case will work OK for malformed defns too
(cond
- (vector? (first stuff)) (single-defn stuff (or doc-str attr-map))
- :else (multi-defn stuff (or doc-str attr-map)))))
+ (vector? (first stuff)) (single-defn stuff (or doc-str attr-map))
+ :else (multi-defn stuff (or doc-str attr-map)))))
(pprint-simple-code-list alis)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -334,18 +334,18 @@
(when (next alis)
(.write ^java.io.Writer *out* " ")
(pprint-newline :linear)
- (print-length-loop [alis (next alis)]
- (when alis
- (pprint-logical-block alis
- (write-out (first alis))
- (when (next alis)
+ (print-length-loop [alis (next alis)]
+ (when alis
+ (pprint-logical-block alis
+ (write-out (first alis))
+ (when (next alis)
+ (.write ^java.io.Writer *out* " ")
+ (pprint-newline :miser)
+ (write-out (second alis))))
+ (when (next (rest alis))
(.write ^java.io.Writer *out* " ")
- (pprint-newline :miser)
- (write-out (second alis))))
- (when (next (rest alis))
- (.write ^java.io.Writer *out* " ")
- (pprint-newline :linear)
- (recur (next (rest alis)))))))))
+ (pprint-newline :linear)
+ (recur (next (rest alis)))))))))
(defn- pprint-condp [alis]
(if (> (count alis) 3)
@@ -377,9 +377,9 @@
{(first args) "%"}
(into {}
(map
- #(vector %1 (str \% %2))
- args
- (range 1 (inc (count args))))))]
+ #(vector %1 (str \% %2))
+ args
+ (range 1 (inc (count args))))))]
((formatter-out "~<#(~;~@{~w~^ ~_~}~;)~:>") nlis))
(pprint-simple-code-list alis))))
@@ -396,20 +396,20 @@
(pprint-indent :block 1)
(print-length-loop [alis (seq alis)]
(when alis
- (write-out (first alis))
- (when (next alis)
- (.write ^java.io.Writer *out* " ")
- (pprint-newline :linear)
- (recur (next alis)))))))
+ (write-out (first alis))
+ (when (next alis)
+ (.write ^java.io.Writer *out* " ")
+ (pprint-newline :linear)
+ (recur (next alis)))))))
;;; Take a map with symbols as keys and add versions with no namespace.
;;; That is, if ns/sym->val is in the map, add sym->val to the result.
(defn- two-forms [amap]
(into {}
(mapcat
- identity
- (for [x amap]
- [x [(symbol (name (first x))) (second x)]]))))
+ identity
+ (for [x amap]
+ [x [(symbol (name (first x))) (second x)]]))))
(defn- add-core-ns [amap]
(let [core "clojure.core"]
@@ -422,20 +422,20 @@
(def ^:dynamic ^{:private true} *code-table*
(two-forms
- (add-core-ns
- {'def pprint-hold-first, 'defonce pprint-hold-first,
- 'defn pprint-defn, 'defn- pprint-defn, 'defmacro pprint-defn, 'fn pprint-defn,
- 'let pprint-let, 'loop pprint-let, 'binding pprint-let,
- 'with-local-vars pprint-let, 'with-open pprint-let, 'when-let pprint-let,
- 'if-let pprint-let, 'doseq pprint-let, 'dotimes pprint-let,
- 'when-first pprint-let,
- 'if pprint-if, 'if-not pprint-if, 'when pprint-if, 'when-not pprint-if,
- 'cond pprint-cond, 'condp pprint-condp,
- 'fn* pprint-anon-func,
- '. pprint-hold-first, '.. pprint-hold-first, '-> pprint-hold-first,
- 'locking pprint-hold-first, 'struct pprint-hold-first,
- 'struct-map pprint-hold-first, 'ns pprint-ns
- })))
+ (add-core-ns
+ {'def pprint-hold-first, 'defonce pprint-hold-first,
+ 'defn pprint-defn, 'defn- pprint-defn, 'defmacro pprint-defn, 'fn pprint-defn,
+ 'let pprint-let, 'loop pprint-let, 'binding pprint-let,
+ 'with-local-vars pprint-let, 'with-open pprint-let, 'when-let pprint-let,
+ 'if-let pprint-let, 'doseq pprint-let, 'dotimes pprint-let,
+ 'when-first pprint-let,
+ 'if pprint-if, 'if-not pprint-if, 'when pprint-if, 'when-not pprint-if,
+ 'cond pprint-cond, 'condp pprint-condp,
+ 'fn* pprint-anon-func,
+ '. pprint-hold-first, '.. pprint-hold-first, '-> pprint-hold-first,
+ 'locking pprint-hold-first, 'struct pprint-hold-first,
+ 'struct-map pprint-hold-first, 'ns pprint-ns
+ })))
(defn- pprint-code-list [alis]
(if-not (pprint-reader-macro alis)
@@ -474,72 +474,72 @@
;;; For testing
(comment
-(with-pprint-dispatch code-dispatch
- (pprint
- '(defn cl-format
- "An implementation of a Common Lisp compatible format function"
- [stream format-in & args]
- (let [compiled-format (if (string? format-in) (compile-format format-in) format-in)
- navigator (init-navigator args)]
- (execute-format stream compiled-format navigator)))))
-
-(with-pprint-dispatch code-dispatch
- (pprint
- '(defn cl-format
- [stream format-in & args]
- (let [compiled-format (if (string? format-in) (compile-format format-in) format-in)
- navigator (init-navigator args)]
- (execute-format stream compiled-format navigator)))))
-
-(with-pprint-dispatch code-dispatch
- (pprint
- '(defn- -write
- ([this x]
- (condp = (class x)
- String
- (let [s0 (write-initial-lines this x)
- s (.replaceFirst s0 "\\s+$" "")
- white-space (.substring s0 (count s))
- mode (getf :mode)]
- (if (= mode :writing)
- (dosync
- (write-white-space this)
- (.col_write this s)
- (setf :trailing-white-space white-space))
- (add-to-buffer this (make-buffer-blob s white-space))))
-
- Integer
- (let [c ^Character x]
- (if (= (getf :mode) :writing)
- (do
- (write-white-space this)
- (.col_write this x))
- (if (= c (int \newline))
- (write-initial-lines this "\n")
- (add-to-buffer this (make-buffer-blob (str (char c)) nil))))))))))
-
-(with-pprint-dispatch code-dispatch
- (pprint
- '(defn pprint-defn [writer alis]
- (if (next alis)
- (let [[defn-sym defn-name & stuff] alis
- [doc-str stuff] (if (string? (first stuff))
- [(first stuff) (next stuff)]
- [nil stuff])
- [attr-map stuff] (if (map? (first stuff))
- [(first stuff) (next stuff)]
- [nil stuff])]
- (pprint-logical-block writer :prefix "(" :suffix ")"
- (cl-format true "~w ~1I~@_~w" defn-sym defn-name)
- (if doc-str
- (cl-format true " ~_~w" doc-str))
- (if attr-map
- (cl-format true " ~_~w" attr-map))
- ;; Note: the multi-defn case will work OK for malformed defns too
- (cond
- (vector? (first stuff)) (single-defn stuff (or doc-str attr-map))
- :else (multi-defn stuff (or doc-str attr-map)))))
- (pprint-simple-code-list writer alis)))))
-)
+ (with-pprint-dispatch code-dispatch
+ (pprint
+ '(defn cl-format
+ "An implementation of a Common Lisp compatible format function"
+ [stream format-in & args]
+ (let [compiled-format (if (string? format-in) (compile-format format-in) format-in)
+ navigator (init-navigator args)]
+ (execute-format stream compiled-format navigator)))))
+
+ (with-pprint-dispatch code-dispatch
+ (pprint
+ '(defn cl-format
+ [stream format-in & args]
+ (let [compiled-format (if (string? format-in) (compile-format format-in) format-in)
+ navigator (init-navigator args)]
+ (execute-format stream compiled-format navigator)))))
+
+ (with-pprint-dispatch code-dispatch
+ (pprint
+ '(defn- -write
+ ([this x]
+ (condp = (class x)
+ String
+ (let [s0 (write-initial-lines this x)
+ s (.replaceFirst s0 "\\s+$" "")
+ white-space (.substring s0 (count s))
+ mode (getf :mode)]
+ (if (= mode :writing)
+ (dosync
+ (write-white-space this)
+ (.col_write this s)
+ (setf :trailing-white-space white-space))
+ (add-to-buffer this (make-buffer-blob s white-space))))
+
+ Integer
+ (let [c ^Character x]
+ (if (= (getf :mode) :writing)
+ (do
+ (write-white-space this)
+ (.col_write this x))
+ (if (= c (int \newline))
+ (write-initial-lines this "\n")
+ (add-to-buffer this (make-buffer-blob (str (char c)) nil))))))))))
+
+ (with-pprint-dispatch code-dispatch
+ (pprint
+ '(defn pprint-defn [writer alis]
+ (if (next alis)
+ (let [[defn-sym defn-name & stuff] alis
+ [doc-str stuff] (if (string? (first stuff))
+ [(first stuff) (next stuff)]
+ [nil stuff])
+ [attr-map stuff] (if (map? (first stuff))
+ [(first stuff) (next stuff)]
+ [nil stuff])]
+ (pprint-logical-block writer :prefix "(" :suffix ")"
+ (cl-format true "~w ~1I~@_~w" defn-sym defn-name)
+ (if doc-str
+ (cl-format true " ~_~w" doc-str))
+ (if attr-map
+ (cl-format true " ~_~w" attr-map))
+ ;; Note: the multi-defn case will work OK for malformed defns too
+ (cond
+ (vector? (first stuff)) (single-defn stuff (or doc-str attr-map))
+ :else (multi-defn stuff (or doc-str attr-map)))))
+ (pprint-simple-code-list writer alis)))))
+ )
nil
diff --git a/src/clj/clojure/pprint/pprint_base.clj b/src/clj/clojure/pprint/pprint_base.clj
index d95bd261..abc59a6f 100644
--- a/src/clj/clojure/pprint/pprint_base.clj
+++ b/src/clj/clojure/pprint/pprint_base.clj
@@ -28,66 +28,66 @@
(def ^:dynamic
- ^{:doc "Bind to true if you want write to use pretty printing", :added "1.2"}
- *print-pretty* true)
+ ^{:doc "Bind to true if you want write to use pretty printing", :added "1.2"}
+ *print-pretty* true)
(defonce ^:dynamic ; If folks have added stuff here, don't overwrite
- ^{:doc "The pretty print dispatch function. Use with-pprint-dispatch or set-pprint-dispatch
+ ^{:doc "The pretty print dispatch function. Use with-pprint-dispatch or set-pprint-dispatch
to modify.",
- :added "1.2"}
- *print-pprint-dispatch* nil)
+ :added "1.2"}
+ *print-pprint-dispatch* nil)
(def ^:dynamic
- ^{:doc "Pretty printing will try to avoid anything going beyond this column.
+ ^{:doc "Pretty printing will try to avoid anything going beyond this column.
Set it to nil to have pprint let the line be arbitrarily long. This will ignore all
non-mandatory newlines.",
- :added "1.2"}
- *print-right-margin* 72)
+ :added "1.2"}
+ *print-right-margin* 72)
(def ^:dynamic
- ^{:doc "The column at which to enter miser style. Depending on the dispatch table,
+ ^{:doc "The column at which to enter miser style. Depending on the dispatch table,
miser style add newlines in more places to try to keep lines short allowing for further
levels of nesting.",
- :added "1.2"}
- *print-miser-width* 40)
+ :added "1.2"}
+ *print-miser-width* 40)
;;; TODO implement output limiting
(def ^:dynamic
- ^{:private true,
- :doc "Maximum number of lines to print in a pretty print instance (N.B. This is not yet used)"}
- *print-lines* nil)
+ ^{:private true,
+ :doc "Maximum number of lines to print in a pretty print instance (N.B. This is not yet used)"}
+ *print-lines* nil)
;;; TODO: implement circle and shared
(def ^:dynamic
- ^{:private true,
- :doc "Mark circular structures (N.B. This is not yet used)"}
- *print-circle* nil)
+ ^{:private true,
+ :doc "Mark circular structures (N.B. This is not yet used)"}
+ *print-circle* nil)
;;; TODO: should we just use *print-dup* here?
(def ^:dynamic
- ^{:private true,
- :doc "Mark repeated structures rather than repeat them (N.B. This is not yet used)"}
- *print-shared* nil)
+ ^{:private true,
+ :doc "Mark repeated structures rather than repeat them (N.B. This is not yet used)"}
+ *print-shared* nil)
(def ^:dynamic
- ^{:doc "Don't print namespaces with symbols. This is particularly useful when
+ ^{:doc "Don't print namespaces with symbols. This is particularly useful when
pretty printing the results of macro expansions"
- :added "1.2"}
- *print-suppress-namespaces* nil)
+ :added "1.2"}
+ *print-suppress-namespaces* nil)
;;; TODO: support print-base and print-radix in cl-format
;;; TODO: support print-base and print-radix in rationals
(def ^:dynamic
- ^{:doc "Print a radix specifier in front of integers and rationals. If *print-base* is 2, 8,
+ ^{:doc "Print a radix specifier in front of integers and rationals. If *print-base* is 2, 8,
or 16, then the radix specifier used is #b, #o, or #x, respectively. Otherwise the
radix specifier is in the form #XXr where XX is the decimal value of *print-base* "
- :added "1.2"}
- *print-radix* nil)
+ :added "1.2"}
+ *print-radix* nil)
(def ^:dynamic
- ^{:doc "The base to use for printing integers and rationals."
- :added "1.2"}
- *print-base* 10)
+ ^{:doc "The base to use for printing integers and rationals."
+ :added "1.2"}
+ *print-base* 10)
@@ -139,14 +139,14 @@ radix specifier is in the form #XXr where XX is the decimal value of *print-base
`(do
(. clojure.lang.Var (pushThreadBindings ~amap))
(try
- ~@body
- (finally
- (. clojure.lang.Var (popThreadBindings)))))))
+ ~@body
+ (finally
+ (. clojure.lang.Var (popThreadBindings)))))))
(defn- table-ize [t m]
(apply hash-map (mapcat
- #(when-let [v (get t (key %))] [(find-var v) (val %)])
- m)))
+ #(when-let [v (get t (key %))] [(find-var v) (val %)])
+ m)))
(defn- pretty-writer?
"Return true iff x is a PrettyWriter"
@@ -161,8 +161,8 @@ radix specifier is in the form #XXr where XX is the decimal value of *print-base
`(let [base-writer# ~base-writer
new-writer# (not (pretty-writer? base-writer#))]
(binding [*out* (if new-writer#
- (make-pretty-writer base-writer# *print-right-margin* *print-miser-width*)
- base-writer#)]
+ (make-pretty-writer base-writer# *print-right-margin* *print-miser-width*)
+ base-writer#)]
~@body
(.ppflush ^PrettyFlush *out*))))
@@ -182,9 +182,9 @@ Normal library clients should use the standard \"write\" interface. "
{:added "1.2"}
[object]
(let [length-reached (and
- *current-length*
- *print-length*
- (>= *current-length* *print-length*))]
+ *current-length*
+ *print-length*
+ (>= *current-length* *print-length*))]
(if-not *print-pretty*
(pr object)
(if length-reached
@@ -244,12 +244,12 @@ print the object to the currently bound value of *out*."
{:added "1.2"}
([object] (pprint object *out*))
([object writer]
- (with-pretty-writer writer
- (binding [*print-pretty* true]
- (binding-map (if (or (not (= *print-base* 10)) *print-radix*) {#'pr pr-with-base} {})
- (write-out object)))
- (if (not (= 0 (get-column *out*)))
- (prn)))))
+ (with-pretty-writer writer
+ (binding [*print-pretty* true]
+ (binding-map (if (or (not (= *print-base* 10)) *print-radix*) {#'pr pr-with-base} {})
+ (write-out object)))
+ (if (not (= 0 (get-column *out*)))
+ (prn)))))
(defmacro pp
"A convenience macro that pretty prints the last thing output. This is
@@ -292,9 +292,9 @@ clojure.pprint.dispatch.clj."
(defn- check-enumerated-arg [arg choices]
(if-not (choices arg)
(throw
- (IllegalArgumentException.
- ;; TODO clean up choices string
- (str "Bad argument: " arg ". It must be one of " choices)))))
+ (IllegalArgumentException.
+ ;; TODO clean up choices string
+ (str "Bad argument: " arg ". It must be one of " choices)))))
(defn- level-exceeded []
(and *print-level* (>= *current-level* *print-level*)))
@@ -318,12 +318,12 @@ and :suffix."
(inc (var-get #'clojure.pprint/*current-level*))
#'clojure.pprint/*current-length* 0})
(try
- (#'clojure.pprint/start-block *out*
- ~(:prefix options) ~(:per-line-prefix options) ~(:suffix options))
- ~@body
- (#'clojure.pprint/end-block *out*)
- (finally
- (pop-thread-bindings)))))
+ (#'clojure.pprint/start-block *out*
+ ~(:prefix options) ~(:per-line-prefix options) ~(:suffix options))
+ ~@body
+ (#'clojure.pprint/end-block *out*)
+ (finally
+ (pop-thread-bindings)))))
nil)))
(defn pprint-newline
diff --git a/src/clj/clojure/pprint/pretty_writer.clj b/src/clj/clojure/pprint/pretty_writer.clj
index 49023b82..c6f7a954 100644
--- a/src/clj/clojure/pprint/pretty_writer.clj
+++ b/src/clj/clojure/pprint/pretty_writer.clj
@@ -77,9 +77,9 @@
(defn- ancestor? [parent child]
(loop [child (:parent child)]
(cond
- (nil? child) false
- (identical? parent child) true
- :else (recur (:parent child)))))
+ (nil? child) false
+ (identical? parent child) true
+ :else (recur (:parent child)))))
(defstruct ^{:private true} section :parent)
@@ -111,14 +111,14 @@
(defmulti ^{:private true} write-token #(:type-tag %2))
(defmethod write-token :start-block-t [^Writer this token]
- (when-let [cb (getf :logical-block-callback)] (cb :start))
- (let [lb (:logical-block token)]
+ (when-let [cb (getf :logical-block-callback)] (cb :start))
+ (let [lb (:logical-block token)]
(dosync
- (when-let [^String prefix (:prefix lb)]
- (write-to-base prefix))
- (let [col (get-column (getf :base))]
- (ref-set (:start-col lb) col)
- (ref-set (:indent lb) col)))))
+ (when-let [^String prefix (:prefix lb)]
+ (write-to-base prefix))
+ (let [col (get-column (getf :base))]
+ (ref-set (:start-col lb) col)
+ (ref-set (:indent lb) col)))))
(defmethod write-token :end-block-t [^Writer this token]
(when-let [cb (getf :logical-block-callback)] (cb :end))
@@ -130,18 +130,18 @@
(ref-set (:indent lb)
(+ (:offset token)
(condp = (:relative-to token)
- :block @(:start-col lb)
- :current (get-column (getf :base)))))))
+ :block @(:start-col lb)
+ :current (get-column (getf :base)))))))
(defmethod write-token :buffer-blob [^Writer this token]
(write-to-base ^String (:data token)))
(defmethod write-token :nl-t [^Writer this token]
-; (prlabel wt @(:done-nl (:logical-block token)))
-; (prlabel wt (:type token) (= (:type token) :mandatory))
+ ; (prlabel wt @(:done-nl (:logical-block token)))
+ ; (prlabel wt (:type token) (= (:type token) :mandatory))
(if (or (= (:type token) :mandatory)
- (and (not (= (:type token) :fill))
- @(:done-nl (:logical-block token))))
+ (and (not (= (:type token) :fill))
+ @(:done-nl (:logical-block token))))
(emit-nl this token)
(if-let [^String tws (getf :trailing-white-space)]
(write-to-base tws)))
@@ -151,7 +151,7 @@
(doseq [token tokens]
(if-not (= (:type-tag token) :nl-t)
(if-let [^String tws (getf :trailing-white-space)]
- (write-to-base tws)))
+ (write-to-base tws)))
(write-token this token)
(setf :trailing-white-space (:trailing-white-space token)))
(let [^String tws (getf :trailing-white-space)]
@@ -166,14 +166,14 @@
(defn- tokens-fit? [^Writer this tokens]
-;;; (prlabel tf? (get-column (getf :base) (buffer-length tokens))
+ ;;; (prlabel tf? (get-column (getf :base) (buffer-length tokens))
(let [maxcol (get-max-column (getf :base))]
(or
- (nil? maxcol)
- (< (+ (get-column (getf :base)) (buffer-length tokens)) maxcol))))
+ (nil? maxcol)
+ (< (+ (get-column (getf :base)) (buffer-length tokens)) maxcol))))
(defn- linear-nl? [this lb section]
-; (prlabel lnl? @(:done-nl lb) (tokens-fit? this section))
+ ; (prlabel lnl? @(:done-nl lb) (tokens-fit? this section))
(or @(:done-nl lb)
(not (tokens-fit? this section))))
@@ -220,18 +220,18 @@
lb (:logical-block nl)
section (seq (take-while #(let [nl-lb (:logical-block %)]
(not (and (nl-t? %) (or (= nl-lb lb) (ancestor? nl-lb lb)))))
- (next buffer)))]
+ (next buffer)))]
section))
(defn- update-nl-state [lb]
(dosync
- (ref-set (:intra-block-nl lb) false)
- (ref-set (:done-nl lb) true)
- (loop [lb (:parent lb)]
- (if lb
- (do (ref-set (:done-nl lb) true)
- (ref-set (:intra-block-nl lb) true)
- (recur (:parent lb)))))))
+ (ref-set (:intra-block-nl lb) false)
+ (ref-set (:done-nl lb) true)
+ (loop [lb (:parent lb)]
+ (if lb
+ (do (ref-set (:done-nl lb) true)
+ (ref-set (:intra-block-nl lb) true)
+ (recur (:parent lb)))))))
(defn- emit-nl [^Writer this nl]
(write-to-base ^String (pp-newline))
@@ -241,7 +241,7 @@
(if prefix
(write-to-base prefix))
(let [^String istr (apply str (repeat (- @(:indent lb) (count prefix))
- \space))]
+ \space))]
(write-to-base istr))
(update-nl-state lb)))
@@ -265,53 +265,53 @@
(defn- write-token-string [this tokens]
(let [[a b] (split-at-newline tokens)]
-;; (prlabel wts (toks a) (toks b))
+ ;; (prlabel wts (toks a) (toks b))
(if a (write-tokens this a false))
(if b
(let [[section remainder] (get-section b)
newl (first b)]
-;; (prlabel wts (toks section)) (prlabel wts (:type newl)) (prlabel wts (toks remainder))
+ ;; (prlabel wts (toks section)) (prlabel wts (:type newl)) (prlabel wts (toks remainder))
(let [do-nl (emit-nl? newl this section (get-sub-section b))
result (if do-nl
(do
-;; (prlabel emit-nl (:type newl))
+ ;; (prlabel emit-nl (:type newl))
(emit-nl this newl)
(next b))
b)
long-section (not (tokens-fit? this result))
result (if long-section
(let [rem2 (write-token-string this section)]
-;;; (prlabel recurse (toks rem2))
+ ;;; (prlabel recurse (toks rem2))
(if (= rem2 section)
(do ; If that didn't produce any output, it has no nls
- ; so we'll force it
+ ; so we'll force it
(write-tokens this section false)
remainder)
(into [] (concat rem2 remainder))))
result)
-;; ff (prlabel wts (toks result))
+ ;; ff (prlabel wts (toks result))
]
result)))))
(defn- write-line [^Writer this]
(dosync
- (loop [buffer (getf :buffer)]
-;; (prlabel wl1 (toks buffer))
- (setf :buffer (into [] buffer))
- (if (not (tokens-fit? this buffer))
- (let [new-buffer (write-token-string this buffer)]
-;; (prlabel wl new-buffer)
- (if-not (identical? buffer new-buffer)
- (recur new-buffer)))))))
+ (loop [buffer (getf :buffer)]
+ ;; (prlabel wl1 (toks buffer))
+ (setf :buffer (into [] buffer))
+ (if (not (tokens-fit? this buffer))
+ (let [new-buffer (write-token-string this buffer)]
+ ;; (prlabel wl new-buffer)
+ (if-not (identical? buffer new-buffer)
+ (recur new-buffer)))))))
;;; Add a buffer token to the buffer and see if it's time to start
;;; writing
(defn- add-to-buffer [^Writer this token]
-; (prlabel a2b token)
+ ; (prlabel a2b token)
(dosync
- (setf :buffer (conj (getf :buffer) token))
- (if (not (tokens-fit? this (getf :buffer)))
- (write-line this))))
+ (setf :buffer (conj (getf :buffer) token))
+ (if (not (tokens-fit? this (getf :buffer)))
+ (write-line this))))
;;; Write all the tokens that have been buffered
(defn- write-buffered-output [^Writer this]
@@ -326,7 +326,7 @@
; (prlabel wws (str "*" tws "*"))
(write-to-base tws)
(dosync
- (setf :trailing-white-space nil))))
+ (setf :trailing-white-space nil))))
;;; If there are newlines in the string, print the lines up until the last newline,
;;; making the appropriate adjustments. Return the remainder of the string
@@ -336,25 +336,25 @@
(if (= (count lines) 1)
s
(dosync
- (let [^String prefix (:per-line-prefix (first (getf :logical-blocks)))
- ^String l (first lines)]
- (if (= :buffering (getf :mode))
- (let [oldpos (getf :pos)
- newpos (+ oldpos (count l))]
- (setf :pos newpos)
- (add-to-buffer this (make-buffer-blob l nil oldpos newpos))
- (write-buffered-output this))
- (do
- (write-white-space this)
- (write-to-base l)))
- (write-to-base (int \newline))
- (doseq [^String l (next (butlast lines))]
- (write-to-base l)
- (write-to-base ^String (pp-newline))
- (if prefix
- (write-to-base prefix)))
- (setf :buffering :writing)
- (last lines))))))
+ (let [^String prefix (:per-line-prefix (first (getf :logical-blocks)))
+ ^String l (first lines)]
+ (if (= :buffering (getf :mode))
+ (let [oldpos (getf :pos)
+ newpos (+ oldpos (count l))]
+ (setf :pos newpos)
+ (add-to-buffer this (make-buffer-blob l nil oldpos newpos))
+ (write-buffered-output this))
+ (do
+ (write-white-space this)
+ (write-to-base l)))
+ (write-to-base (int \newline))
+ (doseq [^String l (next (butlast lines))]
+ (write-to-base l)
+ (write-to-base ^String (pp-newline))
+ (if prefix
+ (write-to-base prefix)))
+ (setf :buffering :writing)
+ (last lines))))))
(defn- p-write-char [^Writer this ^Integer c]
@@ -367,8 +367,8 @@
(let [oldpos (getf :pos)
newpos (inc oldpos)]
(dosync
- (setf :pos newpos)
- (add-to-buffer this (make-buffer-blob (str (char c)) nil oldpos newpos)))))))
+ (setf :pos newpos)
+ (add-to-buffer this (make-buffer-blob (str (char c)) nil oldpos newpos)))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -393,15 +393,15 @@
(deref [] fields)
(write
- ([x]
- ;; (prlabel write x (getf :mode))
- (condp = (class x)
- String
- (let [^String s0 (write-initial-lines this x)
- ^String s (.replaceFirst s0 "\\s+$" "")
- white-space (.substring s0 (count s))
- mode (getf :mode)]
- (dosync
+ ([x]
+ ;; (prlabel write x (getf :mode))
+ (condp = (class x)
+ String
+ (let [^String s0 (write-initial-lines this x)
+ ^String s (.replaceFirst s0 "\\s+$" "")
+ white-space (.substring s0 (count s))
+ mode (getf :mode)]
+ (dosync
(if (= mode :writing)
(do
(write-white-space this)
@@ -412,19 +412,19 @@
(setf :pos newpos)
(add-to-buffer this (make-buffer-blob s white-space oldpos newpos))))))
- Integer
- (p-write-char this x)
- Long
- (p-write-char this x)))
+ Integer
+ (p-write-char this x)
+ Long
+ (p-write-char this x)))
([x off len]
- (.write ^Writer this (subs (str x) off (+ off len)))))
+ (.write ^Writer this (subs (str x) off (+ off len)))))
(ppflush []
- (if (= (getf :mode) :buffering)
- (dosync
- (write-tokens this (getf :buffer) true)
- (setf :buffer []))
- (write-white-space this)))
+ (if (= (getf :mode) :buffering)
+ (dosync
+ (write-tokens this (getf :buffer) true)
+ (setf :buffer []))
+ (write-white-space this)))
(flush []
(.ppflush ^PrettyFlush this)
@@ -443,58 +443,58 @@
[^Writer this
^String prefix ^String per-line-prefix ^String suffix]
(dosync
- (let [lb (struct logical-block (getf :logical-blocks) nil (ref 0) (ref 0)
- (ref false) (ref false)
- prefix per-line-prefix suffix)]
- (setf :logical-blocks lb)
- (if (= (getf :mode) :writing)
- (do
- (write-white-space this)
+ (let [lb (struct logical-block (getf :logical-blocks) nil (ref 0) (ref 0)
+ (ref false) (ref false)
+ prefix per-line-prefix suffix)]
+ (setf :logical-blocks lb)
+ (if (= (getf :mode) :writing)
+ (do
+ (write-white-space this)
(when-let [cb (getf :logical-block-callback)] (cb :start))
(if prefix
- (write-to-base prefix))
- (let [col (get-column (getf :base))]
- (ref-set (:start-col lb) col)
- (ref-set (:indent lb) col)))
- (let [oldpos (getf :pos)
- newpos (+ oldpos (if prefix (count prefix) 0))]
- (setf :pos newpos)
- (add-to-buffer this (make-start-block-t lb oldpos newpos)))))))
+ (write-to-base prefix))
+ (let [col (get-column (getf :base))]
+ (ref-set (:start-col lb) col)
+ (ref-set (:indent lb) col)))
+ (let [oldpos (getf :pos)
+ newpos (+ oldpos (if prefix (count prefix) 0))]
+ (setf :pos newpos)
+ (add-to-buffer this (make-start-block-t lb oldpos newpos)))))))
(defn- end-block [^Writer this]
(dosync
- (let [lb (getf :logical-blocks)
- ^String suffix (:suffix lb)]
- (if (= (getf :mode) :writing)
- (do
- (write-white-space this)
- (if suffix
- (write-to-base suffix))
- (when-let [cb (getf :logical-block-callback)] (cb :end)))
- (let [oldpos (getf :pos)
- newpos (+ oldpos (if suffix (count suffix) 0))]
- (setf :pos newpos)
- (add-to-buffer this (make-end-block-t lb oldpos newpos))))
- (setf :logical-blocks (:parent lb)))))
+ (let [lb (getf :logical-blocks)
+ ^String suffix (:suffix lb)]
+ (if (= (getf :mode) :writing)
+ (do
+ (write-white-space this)
+ (if suffix
+ (write-to-base suffix))
+ (when-let [cb (getf :logical-block-callback)] (cb :end)))
+ (let [oldpos (getf :pos)
+ newpos (+ oldpos (if suffix (count suffix) 0))]
+ (setf :pos newpos)
+ (add-to-buffer this (make-end-block-t lb oldpos newpos))))
+ (setf :logical-blocks (:parent lb)))))
(defn- nl [^Writer this type]
(dosync
- (setf :mode :buffering)
- (let [pos (getf :pos)]
- (add-to-buffer this (make-nl-t type (getf :logical-blocks) pos pos)))))
+ (setf :mode :buffering)
+ (let [pos (getf :pos)]
+ (add-to-buffer this (make-nl-t type (getf :logical-blocks) pos pos)))))
(defn- indent [^Writer this relative-to offset]
(dosync
- (let [lb (getf :logical-blocks)]
- (if (= (getf :mode) :writing)
- (do
- (write-white-space this)
- (ref-set (:indent lb)
- (+ offset (condp = relative-to
- :block @(:start-col lb)
- :current (get-column (getf :base))))))
- (let [pos (getf :pos)]
- (add-to-buffer this (make-indent-t lb relative-to offset pos pos)))))))
+ (let [lb (getf :logical-blocks)]
+ (if (= (getf :mode) :writing)
+ (do
+ (write-white-space this)
+ (ref-set (:indent lb)
+ (+ offset (condp = relative-to
+ :block @(:start-col lb)
+ :current (get-column (getf :base))))))
+ (let [pos (getf :pos)]
+ (add-to-buffer this (make-indent-t lb relative-to offset pos pos)))))))
(defn- get-miser-width [^Writer this]
(getf :miser-width))
diff --git a/src/clj/clojure/pprint/print_table.clj b/src/clj/clojure/pprint/print_table.clj
index 337f45d0..855dea0e 100644
--- a/src/clj/clojure/pprint/print_table.clj
+++ b/src/clj/clojure/pprint/print_table.clj
@@ -14,22 +14,22 @@
in ks. If ks are not specified, use the keys of the first item in rows."
{:added "1.3"}
([ks rows]
- (when (seq rows)
- (let [widths (map
- (fn [k]
- (apply max (count (str k)) (map #(count (str (get % k))) rows)))
- ks)
- spacers (map #(apply str (repeat % "-")) widths)
- fmts (map #(str "%" % "s") widths)
- fmt-row (fn [leader divider trailer row]
- (str leader
- (apply str (interpose divider
- (for [[col fmt] (map vector (map #(get row %) ks) fmts)]
- (format fmt (str col)))))
- trailer))]
- (println)
- (println (fmt-row "| " " | " " |" (zipmap ks ks)))
- (println (fmt-row "|-" "-+-" "-|" (zipmap ks spacers)))
- (doseq [row rows]
- (println (fmt-row "| " " | " " |" row))))))
+ (when (seq rows)
+ (let [widths (map
+ (fn [k]
+ (apply max (count (str k)) (map #(count (str (get % k))) rows)))
+ ks)
+ spacers (map #(apply str (repeat % "-")) widths)
+ fmts (map #(str "%" % "s") widths)
+ fmt-row (fn [leader divider trailer row]
+ (str leader
+ (apply str (interpose divider
+ (for [[col fmt] (map vector (map #(get row %) ks) fmts)]
+ (format fmt (str col)))))
+ trailer))]
+ (println)
+ (println (fmt-row "| " " | " " |" (zipmap ks ks)))
+ (println (fmt-row "|-" "-+-" "-|" (zipmap ks spacers)))
+ (doseq [row rows]
+ (println (fmt-row "| " " | " " |" row))))))
([rows] (print-table (keys (first rows)) rows)))
diff --git a/src/clj/clojure/pprint/utilities.clj b/src/clj/clojure/pprint/utilities.clj
index 95655bd6..bab28636 100644
--- a/src/clj/clojure/pprint/utilities.clj
+++ b/src/clj/clojure/pprint/utilities.clj
@@ -29,10 +29,10 @@
acc []]
(if (empty? lis)
[acc context]
- (let [this (first lis)
- remainder (next lis)
- [result new-context] (apply func [this context])]
- (recur new-context remainder (conj acc result))))))
+ (let [this (first lis)
+ remainder (next lis)
+ [result new-context] (apply func [this context])]
+ (recur new-context remainder (conj acc result))))))
(defn- consume [func initial-context]
(loop [context initial-context
@@ -40,7 +40,7 @@
(let [[result new-context] (apply func [context])]
(if (not result)
[acc new-context]
- (recur new-context (conj acc result))))))
+ (recur new-context (conj acc result))))))
(defn- consume-while [func initial-context]
(loop [context initial-context
@@ -48,7 +48,7 @@
(let [[result continue new-context] (apply func [context])]
(if (not continue)
[acc context]
- (recur new-context (conj acc result))))))
+ (recur new-context (conj acc result))))))
(defn- unzip-map
"Take a map that has pairs in the value slots and produce a pair of
@@ -70,9 +70,9 @@
(if (and (pos? len) (= (nth s (dec (count s))) c))
(loop [n (dec len)]
(cond
- (neg? n) ""
- (not (= (nth s n) c)) (subs s 0 (inc n))
- true (recur (dec n))))
+ (neg? n) ""
+ (not (= (nth s n) c)) (subs s 0 (inc n))
+ true (recur (dec n))))
s)))
(defn- ltrim
@@ -93,9 +93,9 @@
[aseq val]
(let [test (if (coll? val) (set val) #{val})]
(loop [pos 0]
- (if (or (= pos (count aseq)) (not (test (nth aseq pos))))
- pos
- (recur (inc pos))))))
+ (if (or (= pos (count aseq)) (not (test (nth aseq pos))))
+ pos
+ (recur (inc pos))))))
(defn- prerr
"Println to *err*"
@@ -107,7 +107,7 @@
"Print args to *err* in name = value format"
[prefix arg & more-args]
`(prerr ~@(cons (list 'quote prefix) (mapcat #(list (list 'quote %) "=" %)
- (cons arg (seq more-args))))))
+ (cons arg (seq more-args))))))
;; Flush the pretty-print buffer without flushing the underlying stream
(definterface PrettyFlush
diff --git a/src/clj/clojure/reflect.clj b/src/clj/clojure/reflect.clj
index 11050977..a1cc923a 100644
--- a/src/clj/clojure/reflect.clj
+++ b/src/clj/clojure/reflect.clj
@@ -101,11 +101,11 @@ Platform implementers must:
;; could make simpler loop of two args: names an
(if ancestors
(let [make-ancestor-map (fn [names]
- (zipmap names (map refl names)))]
+ (zipmap names (map refl names)))]
(loop [reflections (make-ancestor-map (:bases result))]
(let [ancestors-visited (set (keys reflections))
ancestors-to-visit (set/difference (set (mapcat :bases (vals reflections)))
- ancestors-visited)]
+ ancestors-visited)]
(if (seq ancestors-to-visit)
(recur (merge reflections (make-ancestor-map ancestors-to-visit)))
(apply merge-with into result {:ancestors ancestors-visited}
diff --git a/src/clj/clojure/reflect/java.clj b/src/clj/clojure/reflect/java.clj
index 0cdfe581..02dfba89 100644
--- a/src/clj/clojure/reflect/java.clj
+++ b/src/clj/clojure/reflect/java.clj
@@ -13,8 +13,8 @@
'[clojure.set :as set]
'[clojure.string :as str])
(import '[clojure.asm ClassReader ClassVisitor Type Opcodes]
- '[java.lang.reflect Modifier]
- java.io.InputStream)
+ '[java.lang.reflect Modifier]
+ java.io.InputStream)
(set! *warn-on-reflection* true)
@@ -25,24 +25,24 @@
Class
;; neither .getName not .getSimpleName returns the right thing, so best to delegate to Type
(typename
- [c]
- (typename (Type/getType c)))
+ [c]
+ (typename (Type/getType c)))
Type
(typename
- [t]
- (-> (.getClassName t))))
+ [t]
+ (-> (.getClassName t))))
(defn- typesym
"Given a typeref, create a legal Clojure symbol version of the
type's name."
[t]
(cond->
- (-> (typename t)
- (str/replace "[]" "<>")
- (symbol))
- (class? t) (with-meta {'clojure.core.protocols/datafy
- (fn [_] (datafy t))})))
+ (-> (typename t)
+ (str/replace "[]" "<>")
+ (symbol))
+ (class? t) (with-meta {'clojure.core.protocols/datafy
+ (fn [_] (datafy t))})))
(defn- resource-name
"Given a typeref, return implied resource name. Used by Reflectors
@@ -78,39 +78,39 @@
the kinds of objects to which they can apply."}
flag-descriptors
(vec
- (map access-flag
- [[:public 0x0001 :class :field :method]
- [:private 0x002 :class :field :method]
- [:protected 0x0004 :class :field :method]
- [:static 0x0008 :field :method]
- [:final 0x0010 :class :field :method]
- ;; :super is ancient history and is unfindable (?) by
- ;; reflection. skip it
- #_[:super 0x0020 :class]
- [:synchronized 0x0020 :method]
- [:volatile 0x0040 :field]
- [:bridge 0x0040 :method]
- [:varargs 0x0080 :method]
- [:transient 0x0080 :field]
- [:native 0x0100 :method]
- [:interface 0x0200 :class]
- [:abstract 0x0400 :class :method]
- [:strict 0x0800 :method]
- [:synthetic 0x1000 :class :field :method]
- [:annotation 0x2000 :class]
- [:enum 0x4000 :class :field :inner]])))
+ (map access-flag
+ [[:public 0x0001 :class :field :method]
+ [:private 0x002 :class :field :method]
+ [:protected 0x0004 :class :field :method]
+ [:static 0x0008 :field :method]
+ [:final 0x0010 :class :field :method]
+ ;; :super is ancient history and is unfindable (?) by
+ ;; reflection. skip it
+ #_[:super 0x0020 :class]
+ [:synchronized 0x0020 :method]
+ [:volatile 0x0040 :field]
+ [:bridge 0x0040 :method]
+ [:varargs 0x0080 :method]
+ [:transient 0x0080 :field]
+ [:native 0x0100 :method]
+ [:interface 0x0200 :class]
+ [:abstract 0x0400 :class :method]
+ [:strict 0x0800 :method]
+ [:synthetic 0x1000 :class :field :method]
+ [:annotation 0x2000 :class]
+ [:enum 0x4000 :class :field :inner]])))
(defn- parse-flags
"Convert reflection bitflags into a set of keywords."
[flags context]
(reduce
- (fn [result fd]
- (if (and (get (:contexts fd) context)
- (not (zero? (bit-and flags (:flag fd)))))
- (conj result (:name fd))
- result))
- #{}
- flag-descriptors))
+ (fn [result fd]
+ (if (and (get (:contexts fd) context)
+ (not (zero? (bit-and flags (:flag fd)))))
+ (conj result (:name fd))
+ result))
+ #{}
+ flag-descriptors))
(defrecord Constructor
[name declaring-class parameter-types exception-types flags])
@@ -118,18 +118,18 @@ the kinds of objects to which they can apply."}
(defn- constructor->map
[^java.lang.reflect.Constructor constructor]
(Constructor.
- (symbol (.getName constructor))
- (typesym (.getDeclaringClass constructor))
- (vec (map typesym (.getParameterTypes constructor)))
- (vec (map typesym (.getExceptionTypes constructor)))
- (parse-flags (.getModifiers constructor) :method)))
+ (symbol (.getName constructor))
+ (typesym (.getDeclaringClass constructor))
+ (vec (map typesym (.getParameterTypes constructor)))
+ (vec (map typesym (.getExceptionTypes constructor)))
+ (parse-flags (.getModifiers constructor) :method)))
(defn- declared-constructors
"Return a set of the declared constructors of class as a Clojure map."
[^Class cls]
(set (map
- constructor->map
- (.getDeclaredConstructors cls))))
+ constructor->map
+ (.getDeclaredConstructors cls))))
(defrecord Method
[name return-type declaring-class parameter-types exception-types flags])
@@ -137,19 +137,19 @@ the kinds of objects to which they can apply."}
(defn- method->map
[^java.lang.reflect.Method method]
(Method.
- (symbol (.getName method))
- (typesym (.getReturnType method))
- (typesym (.getDeclaringClass method))
- (vec (map typesym (.getParameterTypes method)))
- (vec (map typesym (.getExceptionTypes method)))
- (parse-flags (.getModifiers method) :method)))
+ (symbol (.getName method))
+ (typesym (.getReturnType method))
+ (typesym (.getDeclaringClass method))
+ (vec (map typesym (.getParameterTypes method)))
+ (vec (map typesym (.getExceptionTypes method)))
+ (parse-flags (.getModifiers method) :method)))
(defn- declared-methods
"Return a set of the declared constructors of class as a Clojure map."
[^Class cls]
(set (map
- method->map
- (.getDeclaredMethods cls))))
+ method->map
+ (.getDeclaredMethods cls))))
(defrecord Field
[name type declaring-class flags])
@@ -157,17 +157,17 @@ the kinds of objects to which they can apply."}
(defn- field->map
[^java.lang.reflect.Field field]
(Field.
- (symbol (.getName field))
- (typesym (.getType field))
- (typesym (.getDeclaringClass field))
- (parse-flags (.getModifiers field) :field)))
+ (symbol (.getName field))
+ (typesym (.getType field))
+ (typesym (.getDeclaringClass field))
+ (parse-flags (.getModifiers field) :field)))
(defn- declared-fields
"Return a set of the declared fields of class as a Clojure map."
[^Class cls]
(set (map
- field->map
- (.getDeclaredFields cls))))
+ field->map
+ (.getDeclaredFields cls))))
(defn- typeref->class
^Class [typeref classloader]
@@ -178,12 +178,12 @@ the kinds of objects to which they can apply."}
(deftype JavaReflector [classloader]
Reflector
(do-reflect [_ typeref]
- (let [cls (typeref->class typeref classloader)]
- {:bases (not-empty (set (map typesym (bases cls))))
- :flags (parse-flags (.getModifiers cls) :class)
- :members (set/union (declared-fields cls)
- (declared-methods cls)
- (declared-constructors cls))})))
+ (let [cls (typeref->class typeref classloader)]
+ {:bases (not-empty (set (map typesym (bases cls))))
+ :flags (parse-flags (.getModifiers cls) :class)
+ :members (set/union (declared-fields cls)
+ (declared-methods cls)
+ (declared-constructors cls))})))
(def ^:private default-reflector
(JavaReflector. (.getContextClassLoader (Thread/currentThread))))
@@ -195,7 +195,7 @@ the kinds of objects to which they can apply."}
(defprotocol ClassResolver
(^InputStream resolve-class [this name]
- "Given a class name, return that typeref's class bytes as an InputStream."))
+ "Given a class name, return that typeref's class bytes as an InputStream."))
(extend-protocol ClassResolver
clojure.lang.Fn
@@ -213,55 +213,55 @@ the kinds of objects to which they can apply."}
r (ClassReader. is)
result (atom {:bases #{} :flags #{} :members #{}})]
(.accept
- r
- (proxy
- [ClassVisitor]
- [Opcodes/ASM4]
- (visit [version access name signature superName interfaces]
- (let [flags (parse-flags access :class)
- ;; ignore java.lang.Object on interfaces to match reflection
- superName (if (and (flags :interface)
- (= superName "java/lang/Object"))
- nil
- superName)
- bases (->> (cons superName interfaces)
- (remove nil?)
- (map internal-name->class-symbol)
- (map symbol)
- (set)
- (not-empty))]
- (swap! result merge {:bases bases
- :flags flags})))
- (visitAnnotation [desc visible])
- (visitSource [name debug])
- (visitInnerClass [name outerName innerName access])
- (visitField [access name desc signature value]
- (swap! result update :members (fnil conj #{})
- (Field. (symbol name)
- (field-descriptor->class-symbol desc)
- class-symbol
- (parse-flags access :field)))
- nil)
- (visitMethod [access name desc signature exceptions]
- (when-not (= name "<clinit>")
- (let [constructor? (= name "<init>")]
- (swap! result update :members (fnil conj #{})
- (let [{:keys [parameter-types return-type]} (parse-method-descriptor desc)
- flags (parse-flags access :method)]
- (if constructor?
- (Constructor. class-symbol
- class-symbol
- parameter-types
- (vec (map internal-name->class-symbol exceptions))
- flags)
- (Method. (symbol name)
- return-type
- class-symbol
- parameter-types
- (vec (map internal-name->class-symbol exceptions))
- flags))))))
- nil)
- (visitEnd [])
- ) 0)
+ r
+ (proxy
+ [ClassVisitor]
+ [Opcodes/ASM4]
+ (visit [version access name signature superName interfaces]
+ (let [flags (parse-flags access :class)
+ ;; ignore java.lang.Object on interfaces to match reflection
+ superName (if (and (flags :interface)
+ (= superName "java/lang/Object"))
+ nil
+ superName)
+ bases (->> (cons superName interfaces)
+ (remove nil?)
+ (map internal-name->class-symbol)
+ (map symbol)
+ (set)
+ (not-empty))]
+ (swap! result merge {:bases bases
+ :flags flags})))
+ (visitAnnotation [desc visible])
+ (visitSource [name debug])
+ (visitInnerClass [name outerName innerName access])
+ (visitField [access name desc signature value]
+ (swap! result update :members (fnil conj #{})
+ (Field. (symbol name)
+ (field-descriptor->class-symbol desc)
+ class-symbol
+ (parse-flags access :field)))
+ nil)
+ (visitMethod [access name desc signature exceptions]
+ (when-not (= name "<clinit>")
+ (let [constructor? (= name "<init>")]
+ (swap! result update :members (fnil conj #{})
+ (let [{:keys [parameter-types return-type]} (parse-method-descriptor desc)
+ flags (parse-flags access :method)]
+ (if constructor?
+ (Constructor. class-symbol
+ class-symbol
+ parameter-types
+ (vec (map internal-name->class-symbol exceptions))
+ flags)
+ (Method. (symbol name)
+ return-type
+ class-symbol
+ parameter-types
+ (vec (map internal-name->class-symbol exceptions))
+ flags))))))
+ nil)
+ (visitEnd [])
+ ) 0)
@result))))
diff --git a/src/clj/clojure/repl.clj b/src/clj/clojure/repl.clj
index ac63c613..a03457d5 100644
--- a/src/clj/clojure/repl.clj
+++ b/src/clj/clojure/repl.clj
@@ -14,7 +14,7 @@
clojure.repl
(:require [clojure.spec.alpha :as spec])
(:import (java.io LineNumberReader InputStreamReader PushbackReader)
- (clojure.lang RT Reflector)))
+ (clojure.lang RT Reflector)))
(def ^:private special-doc-map
'{. {:url "java_interop#dot"
@@ -118,16 +118,16 @@ itself (not its value) is returned. The reader macro #'x expands to (var x)."}})
contains a match for re-string-or-pattern"
{:added "1.0"}
[re-string-or-pattern]
- (let [re (re-pattern re-string-or-pattern)
- ms (concat (mapcat #(sort-by :name (map meta (vals (ns-interns %))))
- (all-ns))
- (map namespace-doc (all-ns))
- (map special-doc (keys special-doc-map)))]
- (doseq [m ms
- :when (and (:doc m)
- (or (re-find (re-matcher re (:doc m)))
- (re-find (re-matcher re (str (:name m))))))]
- (print-doc m))))
+ (let [re (re-pattern re-string-or-pattern)
+ ms (concat (mapcat #(sort-by :name (map meta (vals (ns-interns %))))
+ (all-ns))
+ (map namespace-doc (all-ns))
+ (map special-doc (keys special-doc-map)))]
+ (doseq [m ms
+ :when (and (:doc m)
+ (or (re-find (re-matcher re (:doc m)))
+ (re-find (re-matcher re (str (:name m))))))]
+ (print-doc m))))
(defmacro doc
"Prints documentation for a var or special form given its name,
@@ -244,29 +244,29 @@ str-or-pattern."
{:added "1.3"}
([] (pst 12))
([e-or-depth]
- (if (instance? Throwable e-or-depth)
- (pst e-or-depth 12)
- (when-let [e *e]
- (pst (root-cause e) e-or-depth))))
+ (if (instance? Throwable e-or-depth)
+ (pst e-or-depth 12)
+ (when-let [e *e]
+ (pst (root-cause e) e-or-depth))))
([^Throwable e depth]
- (binding [*out* *err*]
- (when (#{:read-source :macro-syntax-check :macroexpansion :compile-syntax-check :compilation}
- (-> e ex-data :clojure.error/phase))
- (println "Note: The following stack trace applies to the reader or compiler, your code was not executed."))
- (println (str (-> e class .getSimpleName) " "
- (.getMessage e)
- (when-let [info (ex-data e)] (str " " (pr-str info)))))
- (let [st (.getStackTrace e)
- cause (.getCause e)]
- (doseq [el (take depth
- (remove #(#{"clojure.lang.RestFn" "clojure.lang.AFn"} (.getClassName %))
- st))]
- (println (str \tab (stack-element-str el))))
- (when cause
- (println "Caused by:")
- (pst cause (min depth
- (+ 2 (- (count (.getStackTrace cause))
- (count st))))))))))
+ (binding [*out* *err*]
+ (when (#{:read-source :macro-syntax-check :macroexpansion :compile-syntax-check :compilation}
+ (-> e ex-data :clojure.error/phase))
+ (println "Note: The following stack trace applies to the reader or compiler, your code was not executed."))
+ (println (str (-> e class .getSimpleName) " "
+ (.getMessage e)
+ (when-let [info (ex-data e)] (str " " (pr-str info)))))
+ (let [st (.getStackTrace e)
+ cause (.getCause e)]
+ (doseq [el (take depth
+ (remove #(#{"clojure.lang.RestFn" "clojure.lang.AFn"} (.getClassName %))
+ st))]
+ (println (str \tab (stack-element-str el))))
+ (when cause
+ (println "Caused by:")
+ (pst cause (min depth
+ (+ 2 (- (count (.getStackTrace cause))
+ (count st))))))))))
;; ----------------------------------------------------------------------
;; Handle Ctrl-C keystrokes
diff --git a/src/clj/clojure/set.clj b/src/clj/clojure/set.clj
index b63a0044..94c7c028 100644
--- a/src/clj/clojure/set.clj
+++ b/src/clj/clojure/set.clj
@@ -7,8 +7,8 @@
; You must not remove this notice, or any other, from this software.
(ns ^{:doc "Set operations such as union/intersection."
- :author "Rich Hickey"}
- clojure.set)
+ :author "Rich Hickey"}
+ clojure.set)
(defn- bubble-max-key
"Move a maximal element of coll according to fn k (which returns a
@@ -23,51 +23,51 @@
([] #{})
([s1] s1)
([s1 s2]
- (if (< (count s1) (count s2))
- (reduce conj s2 s1)
- (reduce conj s1 s2)))
+ (if (< (count s1) (count s2))
+ (reduce conj s2 s1)
+ (reduce conj s1 s2)))
([s1 s2 & sets]
- (let [bubbled-sets (bubble-max-key count (conj sets s2 s1))]
- (reduce into (first bubbled-sets) (rest bubbled-sets)))))
+ (let [bubbled-sets (bubble-max-key count (conj sets s2 s1))]
+ (reduce into (first bubbled-sets) (rest bubbled-sets)))))
(defn intersection
"Return a set that is the intersection of the input sets"
{:added "1.0"}
([s1] s1)
([s1 s2]
- (if (< (count s2) (count s1))
- (recur s2 s1)
- (reduce (fn [result item]
- (if (contains? s2 item)
- result
- (disj result item)))
- s1 s1)))
+ (if (< (count s2) (count s1))
+ (recur s2 s1)
+ (reduce (fn [result item]
+ (if (contains? s2 item)
+ result
+ (disj result item)))
+ s1 s1)))
([s1 s2 & sets]
- (let [bubbled-sets (bubble-max-key #(- (count %)) (conj sets s2 s1))]
- (reduce intersection (first bubbled-sets) (rest bubbled-sets)))))
+ (let [bubbled-sets (bubble-max-key #(- (count %)) (conj sets s2 s1))]
+ (reduce intersection (first bubbled-sets) (rest bubbled-sets)))))
(defn difference
"Return a set that is the first set without elements of the remaining sets"
{:added "1.0"}
([s1] s1)
([s1 s2]
- (if (< (count s1) (count s2))
- (reduce (fn [result item]
- (if (contains? s2 item)
- (disj result item)
- result))
- s1 s1)
- (reduce disj s1 s2)))
+ (if (< (count s1) (count s2))
+ (reduce (fn [result item]
+ (if (contains? s2 item)
+ (disj result item)
+ result))
+ s1 s1)
+ (reduce disj s1 s2)))
([s1 s2 & sets]
- (reduce difference s1 (conj sets s2))))
+ (reduce difference s1 (conj sets s2))))
(defn select
"Returns a set of the elements for which pred is true"
{:added "1.0"}
[pred xset]
- (reduce (fn [s k] (if (pred k) s (disj s k)))
- xset xset))
+ (reduce (fn [s k] (if (pred k) s (disj s k)))
+ xset xset))
(defn project
"Returns a rel of the elements of xrel with only the keys in ks"
@@ -79,12 +79,12 @@
"Returns the map with the keys in kmap renamed to the vals in kmap"
{:added "1.0"}
[map kmap]
- (reduce
- (fn [m [old new]]
- (if (contains? map old)
- (assoc m new (get map old))
- m))
- (apply dissoc map (keys kmap)) kmap))
+ (reduce
+ (fn [m [old new]]
+ (if (contains? map old)
+ (assoc m new (get map old))
+ m))
+ (apply dissoc map (keys kmap)) kmap))
(defn rename
"Returns a rel of the maps in xrel with the keys in kmap renamed to the vals in kmap"
@@ -97,11 +97,11 @@
set of the maps in xrel with the corresponding values of ks."
{:added "1.0"}
[xrel ks]
- (reduce
- (fn [m x]
- (let [ik (select-keys x ks)]
- (assoc m ik (conj (get m ik #{}) x))))
- {} xrel))
+ (reduce
+ (fn [m x]
+ (let [ik (select-keys x ks)]
+ (assoc m ik (conj (get m ik #{}) x))))
+ {} xrel))
(defn map-invert
"Returns the map with the vals mapped to the keys."
@@ -156,22 +156,22 @@
(every? #(contains? set1 %) set2)))
(comment
-(refer 'set)
-(def xs #{{:a 11 :b 1 :c 1 :d 4}
- {:a 2 :b 12 :c 2 :d 6}
- {:a 3 :b 3 :c 3 :d 8 :f 42}})
+ (refer 'set)
+ (def xs #{{:a 11 :b 1 :c 1 :d 4}
+ {:a 2 :b 12 :c 2 :d 6}
+ {:a 3 :b 3 :c 3 :d 8 :f 42}})
-(def ys #{{:a 11 :b 11 :c 11 :e 5}
- {:a 12 :b 11 :c 12 :e 3}
- {:a 3 :b 3 :c 3 :e 7 }})
+ (def ys #{{:a 11 :b 11 :c 11 :e 5}
+ {:a 12 :b 11 :c 12 :e 3}
+ {:a 3 :b 3 :c 3 :e 7 }})
-(join xs ys)
-(join xs (rename ys {:b :yb :c :yc}) {:a :a})
+ (join xs ys)
+ (join xs (rename ys {:b :yb :c :yc}) {:a :a})
-(union #{:a :b :c} #{:c :d :e })
-(difference #{:a :b :c} #{:c :d :e})
-(intersection #{:a :b :c} #{:c :d :e})
+ (union #{:a :b :c} #{:c :d :e })
+ (difference #{:a :b :c} #{:c :d :e})
+ (intersection #{:a :b :c} #{:c :d :e})
-(index ys [:b])
-)
+ (index ys [:b])
+ )
diff --git a/src/clj/clojure/stacktrace.clj b/src/clj/clojure/stacktrace.clj
index a4f62255..15d1ef38 100644
--- a/src/clj/clojure/stacktrace.clj
+++ b/src/clj/clojure/stacktrace.clj
@@ -12,7 +12,7 @@
;; January 6, 2009
(ns ^{:doc "Print stack traces oriented towards Clojure, not Java."
- :author "Stuart Sierra"}
+ :author "Stuart Sierra"}
clojure.stacktrace)
(defn root-cause
@@ -28,11 +28,11 @@
{:added "1.1"}
[e]
(let [class (.getClassName e)
- method (.getMethodName e)]
+ method (.getMethodName e)]
(let [match (re-matches #"^([A-Za-z0-9_.-]+)\$(\w+)__\d+$" (str class))]
(if (and match (= "invoke" method))
- (apply printf "%s/%s" (rest match))
- (printf "%s.%s" class method))))
+ (apply printf "%s/%s" (rest match))
+ (printf "%s.%s" class method))))
(printf " (%s:%d)" (or (.getFileName e) "") (.getLineNumber e)))
(defn print-throwable
@@ -52,30 +52,30 @@
{:added "1.1"}
([tr] (print-stack-trace tr nil))
([^Throwable tr n]
- (let [st (.getStackTrace tr)]
- (print-throwable tr)
- (newline)
- (print " at ")
- (if-let [e (first st)]
- (print-trace-element e)
- (print "[empty stack trace]"))
- (newline)
- (doseq [e (if (nil? n)
- (rest st)
- (take (dec n) (rest st)))]
- (print " ")
- (print-trace-element e)
- (newline)))))
+ (let [st (.getStackTrace tr)]
+ (print-throwable tr)
+ (newline)
+ (print " at ")
+ (if-let [e (first st)]
+ (print-trace-element e)
+ (print "[empty stack trace]"))
+ (newline)
+ (doseq [e (if (nil? n)
+ (rest st)
+ (take (dec n) (rest st)))]
+ (print " ")
+ (print-trace-element e)
+ (newline)))))
(defn print-cause-trace
"Like print-stack-trace but prints chained exceptions (causes)."
{:added "1.1"}
([tr] (print-cause-trace tr nil))
([tr n]
- (print-stack-trace tr n)
- (when-let [cause (.getCause tr)]
- (print "Caused by: " )
- (recur cause n))))
+ (print-stack-trace tr n)
+ (when-let [cause (.getCause tr)]
+ (print "Caused by: " )
+ (recur cause n))))
(defn e
"REPL utility. Prints a brief stack trace for the root cause of the
diff --git a/src/clj/clojure/string.clj b/src/clj/clojure/string.clj
index 35e0650f..16fa32bd 100644
--- a/src/clj/clojure/string.clj
+++ b/src/clj/clojure/string.clj
@@ -41,7 +41,7 @@ Design notes for clojure.string:
clojure.string
(:refer-clojure :exclude (replace reverse))
(:import (java.util.regex Pattern Matcher)
- clojure.lang.LazilyPersistentVector))
+ clojure.lang.LazilyPersistentVector))
(set! *warn-on-reflection* true)
@@ -100,13 +100,13 @@ Design notes for clojure.string:
[^CharSequence s match replacement]
(let [s (.toString s)]
(cond
- (instance? Character match) (.replace s ^Character match ^Character replacement)
- (instance? CharSequence match) (.replace s ^CharSequence match ^CharSequence replacement)
- (instance? Pattern match) (if (instance? CharSequence replacement)
- (.replaceAll (re-matcher ^Pattern match s)
- (.toString ^CharSequence replacement))
- (replace-by s match replacement))
- :else (throw (IllegalArgumentException. (str "Invalid match arg: " match))))))
+ (instance? Character match) (.replace s ^Character match ^Character replacement)
+ (instance? CharSequence match) (.replace s ^CharSequence match ^CharSequence replacement)
+ (instance? Pattern match) (if (instance? CharSequence replacement)
+ (.replaceAll (re-matcher ^Pattern match s)
+ (.toString ^CharSequence replacement))
+ (replace-by s match replacement))
+ :else (throw (IllegalArgumentException. (str "Invalid match arg: " match))))))
(defn- replace-first-by
[^CharSequence s ^Pattern re f]
@@ -164,17 +164,17 @@ Design notes for clojure.string:
[^CharSequence s match replacement]
(let [s (.toString s)]
(cond
- (instance? Character match)
- (replace-first-char s match replacement)
- (instance? CharSequence match)
- (replace-first-str s (.toString ^CharSequence match)
- (.toString ^CharSequence replacement))
- (instance? Pattern match)
- (if (instance? CharSequence replacement)
- (.replaceFirst (re-matcher ^Pattern match s)
- (.toString ^CharSequence replacement))
- (replace-first-by s match replacement))
- :else (throw (IllegalArgumentException. (str "Invalid match arg: " match))))))
+ (instance? Character match)
+ (replace-first-char s match replacement)
+ (instance? CharSequence match)
+ (replace-first-str s (.toString ^CharSequence match)
+ (.toString ^CharSequence replacement))
+ (instance? Pattern match)
+ (if (instance? CharSequence replacement)
+ (.replaceFirst (re-matcher ^Pattern match s)
+ (.toString ^CharSequence replacement))
+ (replace-first-by s match replacement))
+ :else (throw (IllegalArgumentException. (str "Invalid match arg: " match))))))
(defn ^String join
@@ -182,16 +182,16 @@ Design notes for clojure.string:
separated by an optional separator."
{:added "1.2"}
([coll]
- (apply str coll))
+ (apply str coll))
([separator coll]
- (loop [sb (StringBuilder. (str (first coll)))
- more (next coll)
- sep (str separator)]
- (if more
- (recur (-> sb (.append sep) (.append (str (first more))))
- (next more)
- sep)
- (str sb)))))
+ (loop [sb (StringBuilder. (str (first coll)))
+ more (next coll)
+ sep (str separator)]
+ (if more
+ (recur (-> sb (.append sep) (.append (str (first more))))
+ (next more)
+ sep)
+ (str sb)))))
(defn ^String capitalize
"Converts first character of the string to upper-case, all other
@@ -221,9 +221,9 @@ Design notes for clojure.string:
the maximum number of splits. Not lazy. Returns vector of the splits."
{:added "1.2"}
([^CharSequence s ^Pattern re]
- (LazilyPersistentVector/createOwning (.split re s)))
+ (LazilyPersistentVector/createOwning (.split re s)))
([ ^CharSequence s ^Pattern re limit]
- (LazilyPersistentVector/createOwning (.split re s limit))))
+ (LazilyPersistentVector/createOwning (.split re s limit))))
(defn split-lines
"Splits s on \\n or \\r\\n."
@@ -320,42 +320,42 @@ Design notes for clojure.string:
forward from from-index. Return nil if value not found."
{:added "1.8"}
([^CharSequence s value]
- (let [result ^long
- (if (instance? Character value)
- (.indexOf (.toString s) ^int (.charValue ^Character value))
- (.indexOf (.toString s) ^String value))]
- (if (= result -1)
- nil
- result)))
+ (let [result ^long
+ (if (instance? Character value)
+ (.indexOf (.toString s) ^int (.charValue ^Character value))
+ (.indexOf (.toString s) ^String value))]
+ (if (= result -1)
+ nil
+ result)))
([^CharSequence s value ^long from-index]
- (let [result ^long
- (if (instance? Character value)
- (.indexOf (.toString s) ^int (.charValue ^Character value) (unchecked-int from-index))
- (.indexOf (.toString s) ^String value (unchecked-int from-index)))]
- (if (= result -1)
- nil
- result))))
+ (let [result ^long
+ (if (instance? Character value)
+ (.indexOf (.toString s) ^int (.charValue ^Character value) (unchecked-int from-index))
+ (.indexOf (.toString s) ^String value (unchecked-int from-index)))]
+ (if (= result -1)
+ nil
+ result))))
(defn last-index-of
"Return last index of value (string or char) in s, optionally
searching backward from from-index. Return nil if value not found."
{:added "1.8"}
([^CharSequence s value]
- (let [result ^long
- (if (instance? Character value)
- (.lastIndexOf (.toString s) ^int (.charValue ^Character value))
- (.lastIndexOf (.toString s) ^String value))]
- (if (= result -1)
- nil
- result)))
+ (let [result ^long
+ (if (instance? Character value)
+ (.lastIndexOf (.toString s) ^int (.charValue ^Character value))
+ (.lastIndexOf (.toString s) ^String value))]
+ (if (= result -1)
+ nil
+ result)))
([^CharSequence s value ^long from-index]
- (let [result ^long
- (if (instance? Character value)
- (.lastIndexOf (.toString s) ^int (.charValue ^Character value) (unchecked-int from-index))
- (.lastIndexOf (.toString s) ^String value (unchecked-int from-index)))]
- (if (= result -1)
- nil
- result))))
+ (let [result ^long
+ (if (instance? Character value)
+ (.lastIndexOf (.toString s) ^int (.charValue ^Character value) (unchecked-int from-index))
+ (.lastIndexOf (.toString s) ^String value (unchecked-int from-index)))]
+ (if (= result -1)
+ nil
+ result))))
(defn starts-with?
"True if s starts with substr."
diff --git a/src/clj/clojure/template.clj b/src/clj/clojure/template.clj
index bda8eae4..f3d79a3e 100644
--- a/src/clj/clojure/template.clj
+++ b/src/clj/clojure/template.clj
@@ -23,7 +23,7 @@
(ns ^{:doc "Macros that expand to repeated copies of a template expression."
- :author "Stuart Sierra"}
+ :author "Stuart Sierra"}
clojure.template
(:require [clojure.walk :as walk]))
diff --git a/src/clj/clojure/test.clj b/src/clj/clojure/test.clj
index fcb32248..5c4d1d69 100644
--- a/src/clj/clojure/test.clj
+++ b/src/clj/clojure/test.clj
@@ -17,7 +17,7 @@
(ns
^{:author "Stuart Sierra, with contributions and suggestions by
Chas Emerick, Allen Rohner, and Stuart Halloway",
- :doc "A unit testing framework.
+ :doc "A unit testing framework.
ASSERTIONS
@@ -233,8 +233,8 @@
"}
clojure.test
(:require [clojure.template :as temp]
- [clojure.stacktrace :as stack]
- [clojure.string :as str]))
+ [clojure.stacktrace :as stack]
+ [clojure.string :as str]))
;; Nothing is marked "private" here, so you can rebind things to plug
;; in your own testing or reporting frameworks.
@@ -250,11 +250,11 @@
*load-tests* true)
(def ^:dynamic
- ^{:doc "The maximum depth of stack traces to print when an Exception
+ ^{:doc "The maximum depth of stack traces to print when an Exception
is thrown during a test. Defaults to nil, which means print the
complete stack trace."
- :added "1.1"}
- *stack-trace-depth* nil)
+ :added "1.1"}
+ *stack-trace-depth* nil)
;;; GLOBALS USED BY THE REPORTING FUNCTIONS
@@ -299,10 +299,10 @@
[m]
(let [{:keys [file line]} m]
(str
- ;; Uncomment to include namespace in failure report:
- ;;(ns-name (:ns (meta (first *testing-vars*)))) "/ "
- (reverse (map #(:name (meta %)) *testing-vars*))
- " (" file ":" line ")")))
+ ;; Uncomment to include namespace in failure report:
+ ;;(ns-name (:ns (meta (first *testing-vars*)))) "/ "
+ (reverse (map #(:name (meta %)) *testing-vars*))
+ " (" file ":" line ")")))
(defn testing-contexts-str
"Returns a string representation of the current test context. Joins
@@ -328,8 +328,8 @@
'report' will be a map with a :type key. See the documentation at
the top of test_is.clj for more information on the types of
arguments for 'report'."
- :dynamic true
- :added "1.1"}
+ :dynamic true
+ :added "1.1"}
report :type)
(defn- file-and-line
@@ -355,16 +355,16 @@
{:added "1.2"}
[m]
(report
- (case
- (:type m)
- :fail (merge (stacktrace-file-and-line (drop-while
- #(let [cl-name (.getClassName ^StackTraceElement %)]
- (or (str/starts-with? cl-name "java.lang.")
- (str/starts-with? cl-name "clojure.test$")
- (str/starts-with? cl-name "clojure.core$ex_info")))
- (.getStackTrace (Thread/currentThread)))) m)
- :error (merge (stacktrace-file-and-line (.getStackTrace ^Throwable (:actual m))) m)
- m)))
+ (case
+ (:type m)
+ :fail (merge (stacktrace-file-and-line (drop-while
+ #(let [cl-name (.getClassName ^StackTraceElement %)]
+ (or (str/starts-with? cl-name "java.lang.")
+ (str/starts-with? cl-name "clojure.test$")
+ (str/starts-with? cl-name "clojure.core$ex_info")))
+ (.getStackTrace (Thread/currentThread)))) m)
+ :error (merge (stacktrace-file-and-line (.getStackTrace ^Throwable (:actual m))) m)
+ m)))
(defmethod report :default [m]
(with-test-out (prn m)))
@@ -383,26 +383,26 @@
(defmethod report :error [m]
(with-test-out
- (inc-report-counter :error)
- (println "\nERROR in" (testing-vars-str m))
- (when (seq *testing-contexts*) (println (testing-contexts-str)))
- (when-let [message (:message m)] (println message))
- (println "expected:" (pr-str (:expected m)))
- (print " actual: ")
- (let [actual (:actual m)]
- (if (instance? Throwable actual)
- (stack/print-cause-trace actual *stack-trace-depth*)
- (prn actual)))))
+ (inc-report-counter :error)
+ (println "\nERROR in" (testing-vars-str m))
+ (when (seq *testing-contexts*) (println (testing-contexts-str)))
+ (when-let [message (:message m)] (println message))
+ (println "expected:" (pr-str (:expected m)))
+ (print " actual: ")
+ (let [actual (:actual m)]
+ (if (instance? Throwable actual)
+ (stack/print-cause-trace actual *stack-trace-depth*)
+ (prn actual)))))
(defmethod report :summary [m]
(with-test-out
- (println "\nRan" (:test m) "tests containing"
- (+ (:pass m) (:fail m) (:error m)) "assertions.")
- (println (:fail m) "failures," (:error m) "errors.")))
+ (println "\nRan" (:test m) "tests containing"
+ (+ (:pass m) (:fail m) (:error m)) "assertions.")
+ (println (:fail m) "failures," (:error m) "errors.")))
(defmethod report :begin-test-ns [m]
(with-test-out
- (println "\nTesting" (ns-name (:ns m)))))
+ (println "\nTesting" (ns-name (:ns m)))))
;; Ignore these message types:
(defmethod report :end-test-ns [m])
@@ -447,9 +447,9 @@
result# (apply ~pred values#)]
(if result#
(do-report {:type :pass, :message ~msg,
- :expected '~form, :actual (cons ~pred values#)})
+ :expected '~form, :actual (cons ~pred values#)})
(do-report {:type :fail, :message ~msg,
- :expected '~form, :actual (list '~'not (cons '~pred values#))}))
+ :expected '~form, :actual (list '~'not (cons '~pred values#))}))
result#)))
(defn assert-any
@@ -460,9 +460,9 @@
`(let [value# ~form]
(if value#
(do-report {:type :pass, :message ~msg,
- :expected '~form, :actual value#})
+ :expected '~form, :actual value#})
(do-report {:type :fail, :message ~msg,
- :expected '~form, :actual value#}))
+ :expected '~form, :actual value#}))
value#))
@@ -496,9 +496,9 @@
(let [result# (instance? klass# object#)]
(if result#
(do-report {:type :pass, :message ~msg,
- :expected '~form, :actual (class object#)})
+ :expected '~form, :actual (class object#)})
(do-report {:type :fail, :message ~msg,
- :expected '~form, :actual (class object#)}))
+ :expected '~form, :actual (class object#)}))
result#)))
(defmethod assert-expr 'thrown? [msg form]
@@ -509,10 +509,10 @@
body (nthnext form 2)]
`(try ~@body
(do-report {:type :fail, :message ~msg,
- :expected '~form, :actual nil})
+ :expected '~form, :actual nil})
(catch ~klass e#
(do-report {:type :pass, :message ~msg,
- :expected '~form, :actual e#})
+ :expected '~form, :actual e#})
e#))))
(defmethod assert-expr 'thrown-with-msg? [msg form]
@@ -529,9 +529,9 @@
(let [m# (.getMessage e#)]
(if (re-find ~re m#)
(do-report {:type :pass, :message ~msg,
- :expected '~form, :actual e#})
+ :expected '~form, :actual e#})
(do-report {:type :fail, :message ~msg,
- :expected '~form, :actual e#})))
+ :expected '~form, :actual e#})))
e#))))
@@ -585,12 +585,12 @@
{:added "1.1"}
[argv expr & args]
(if (or
- ;; (are [] true) is meaningless but ok
- (and (empty? argv) (empty? args))
- ;; Catch wrong number of args
- (and (pos? (count argv))
- (pos? (count args))
- (zero? (mod (count args) (count argv)))))
+ ;; (are [] true) is meaningless but ok
+ (and (empty? argv) (empty? args))
+ ;; Catch wrong number of args
+ (and (pos? (count argv))
+ (pos? (count args))
+ (zero? (mod (count args) (count argv)))))
`(temp/do-template ~argv (is ~expr) ~@args)
(throw (IllegalArgumentException. "The number of args doesn't match are's argv."))))
@@ -717,7 +717,7 @@
(try (t)
(catch Throwable e
(do-report {:type :error, :message "Uncaught exception, not in assertion."
- :expected nil, :actual e})))
+ :expected nil, :actual e})))
(do-report {:type :end-test-var, :var v}))))
(defn test-vars
@@ -729,10 +729,10 @@
(let [once-fixture-fn (join-fixtures (::once-fixtures (meta ns)))
each-fixture-fn (join-fixtures (::each-fixtures (meta ns)))]
(once-fixture-fn
- (fn []
- (doseq [v vars]
- (when (:test (meta v))
- (each-fixture-fn (fn [] (test-var v))))))))))
+ (fn []
+ (doseq [v vars]
+ (when (:test (meta v))
+ (each-fixture-fn (fn [] (test-var v))))))))))
(defn test-all-vars
"Calls test-vars on every var interned in the namespace, with fixtures."
@@ -755,7 +755,7 @@
(do-report {:type :begin-test-ns, :ns ns-obj})
;; If the namespace has a test-ns-hook function, call that:
(if-let [v (find-var (symbol (str (ns-name ns-obj)) "test-ns-hook"))]
- ((var-get v))
+ ((var-get v))
;; Otherwise, just test every var in the namespace.
(test-all-vars ns-obj))
(do-report {:type :end-test-ns, :ns ns-obj}))
@@ -772,10 +772,10 @@
{:added "1.1"}
([] (run-tests *ns*))
([& namespaces]
- (let [summary (assoc (apply merge-with + (map test-ns namespaces))
- :type :summary)]
- (do-report summary)
- summary)))
+ (let [summary (assoc (apply merge-with + (map test-ns namespaces))
+ :type :summary)]
+ (do-report summary)
+ summary)))
(defn run-all-tests
"Runs all tests in all namespaces; prints results.
diff --git a/src/clj/clojure/test/junit.clj b/src/clj/clojure/test/junit.clj
index 3d129b18..db0a292c 100644
--- a/src/clj/clojure/test/junit.clj
+++ b/src/clj/clojure/test/junit.clj
@@ -33,10 +33,10 @@
To write the output to a file, rebind clojure.test/*test-out* to
your own PrintWriter (perhaps opened using
clojure.java.io/writer)."
- :author "Jason Sankey"}
+ :author "Jason Sankey"}
clojure.test.junit
(:require [clojure.stacktrace :as stack]
- [clojure.test :as t]))
+ [clojure.test :as t]))
;; copied from clojure.contrib.lazy-xml
(def ^{:private true}
@@ -115,13 +115,13 @@
(indent)
(start-element tag false (if message {:message message} {}))
(element-content
- (let [[file line] (t/file-position 5)
- detail (apply str (interpose
- "\n"
- [(str "expected: " expected-str)
- (str " actual: " actual-str)
- (str " at: " file ":" line)]))]
- (if message (str message "\n" detail) detail)))
+ (let [[file line] (t/file-position 5)
+ detail (apply str (interpose
+ "\n"
+ [(str "expected: " expected-str)
+ (str " actual: " actual-str)
+ (str " at: " file ":" line)]))]
+ (if message (str message "\n" detail) detail)))
(finish-element tag false)
(println))
@@ -143,39 +143,39 @@
(defmethod junit-report :begin-test-ns [m]
(t/with-test-out
- (start-suite (name (ns-name (:ns m))))))
+ (start-suite (name (ns-name (:ns m))))))
(defmethod junit-report :end-test-ns [_]
(t/with-test-out
- (finish-suite)))
+ (finish-suite)))
(defmethod junit-report :begin-test-var [m]
(t/with-test-out
- (let [var (:var m)]
- (binding [*var-context* (conj *var-context* var)]
- (start-case (test-name *var-context*) (name (ns-name (:ns (meta var)))))))))
+ (let [var (:var m)]
+ (binding [*var-context* (conj *var-context* var)]
+ (start-case (test-name *var-context*) (name (ns-name (:ns (meta var)))))))))
(defmethod junit-report :end-test-var [m]
(t/with-test-out
- (finish-case)))
+ (finish-case)))
(defmethod junit-report :pass [m]
(t/with-test-out
- (t/inc-report-counter :pass)))
+ (t/inc-report-counter :pass)))
(defmethod junit-report :fail [m]
(t/with-test-out
- (t/inc-report-counter :fail)
- (failure-el (:message m)
- (:expected m)
- (:actual m))))
+ (t/inc-report-counter :fail)
+ (failure-el (:message m)
+ (:expected m)
+ (:actual m))))
(defmethod junit-report :error [m]
(t/with-test-out
- (t/inc-report-counter :error)
- (error-el (:message m)
- (:expected m)
- (:actual m))))
+ (t/inc-report-counter :error)
+ (error-el (:message m)
+ (:expected m)
+ (:actual m))))
(defmethod junit-report :default [_])
diff --git a/src/clj/clojure/test/tap.clj b/src/clj/clojure/test/tap.clj
index c3a3a820..838526e4 100644
--- a/src/clj/clojure/test/tap.clj
+++ b/src/clj/clojure/test/tap.clj
@@ -37,10 +37,10 @@
(with-tap-output
(run-tests 'my.cool.library))"
- :author "Stuart Sierra"}
+ :author "Stuart Sierra"}
clojure.test.tap
(:require [clojure.test :as t]
- [clojure.stacktrace :as stack]))
+ [clojure.stacktrace :as stack]))
(defn print-tap-plan
"Prints a TAP plan line like '1..n'. n is the number of tests"
@@ -73,7 +73,7 @@
(defmethod tap-report :default [data]
(t/with-test-out
- (print-tap-diagnostic (pr-str data))))
+ (print-tap-diagnostic (pr-str data))))
(defn print-diagnostics [data]
(when (seq t/*testing-contexts*)
@@ -85,33 +85,33 @@
(print-tap-diagnostic (str " actual:" (pr-str (:actual data))))
(do
(print-tap-diagnostic
- (str " actual:"
- (with-out-str
- (if (instance? Throwable (:actual data))
- (stack/print-cause-trace (:actual data) t/*stack-trace-depth*)
- (prn (:actual data)))))))))
+ (str " actual:"
+ (with-out-str
+ (if (instance? Throwable (:actual data))
+ (stack/print-cause-trace (:actual data) t/*stack-trace-depth*)
+ (prn (:actual data)))))))))
(defmethod tap-report :pass [data]
(t/with-test-out
- (t/inc-report-counter :pass)
- (print-tap-pass (t/testing-vars-str data))
- (print-diagnostics data)))
+ (t/inc-report-counter :pass)
+ (print-tap-pass (t/testing-vars-str data))
+ (print-diagnostics data)))
(defmethod tap-report :error [data]
(t/with-test-out
- (t/inc-report-counter :error)
- (print-tap-fail (t/testing-vars-str data))
- (print-diagnostics data)))
+ (t/inc-report-counter :error)
+ (print-tap-fail (t/testing-vars-str data))
+ (print-diagnostics data)))
(defmethod tap-report :fail [data]
(t/with-test-out
- (t/inc-report-counter :fail)
- (print-tap-fail (t/testing-vars-str data))
- (print-diagnostics data)))
+ (t/inc-report-counter :fail)
+ (print-tap-fail (t/testing-vars-str data))
+ (print-diagnostics data)))
(defmethod tap-report :summary [data]
(t/with-test-out
- (print-tap-plan (+ (:pass data) (:fail data) (:error data)))))
+ (print-tap-plan (+ (:pass data) (:fail data) (:error data)))))
(defmacro with-tap-output
diff --git a/src/clj/clojure/walk.clj b/src/clj/clojure/walk.clj
index fe8fb631..d1208b74 100644
--- a/src/clj/clojure/walk.clj
+++ b/src/clj/clojure/walk.clj
@@ -20,7 +20,7 @@
(ns
^{:author "Stuart Sierra",
- :doc "This file defines a generic tree walker for Clojure data
+ :doc "This file defines a generic tree walker for Clojure data
structures. It takes any data structure (list, vector, map, set,
seq), calls a function on every element, and uses the return value
of the function in place of the original. This makes it fairly
@@ -41,14 +41,14 @@ the sorting function."}
{:added "1.1"}
[inner outer form]
(cond
- (list? form) (outer (apply list (map inner form)))
- (instance? clojure.lang.IMapEntry form)
- (outer (clojure.lang.MapEntry/create (inner (key form)) (inner (val form))))
- (seq? form) (outer (doall (map inner 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)))
- :else (outer form)))
+ (list? form) (outer (apply list (map inner form)))
+ (instance? clojure.lang.IMapEntry form)
+ (outer (clojure.lang.MapEntry/create (inner (key form)) (inner (val form))))
+ (seq? form) (outer (doall (map inner 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)))
+ :else (outer form)))
(defn postwalk
"Performs a depth-first, post-order traversal of form. Calls f on
diff --git a/src/clj/clojure/xml.clj b/src/clj/clojure/xml.clj
index 4e4220f2..6d42684c 100644
--- a/src/clj/clojure/xml.clj
+++ b/src/clj/clojure/xml.clj
@@ -7,10 +7,10 @@
; You must not remove this notice, or any other, from this software.
(ns ^{:doc "XML reading/writing."
- :author "Rich Hickey"}
+ :author "Rich Hickey"}
clojure.xml
(:import (org.xml.sax ContentHandler Attributes SAXException)
- (javax.xml.parsers SAXParser SAXParserFactory)))
+ (javax.xml.parsers SAXParser SAXParserFactory)))
(def ^:dynamic *stack*)
(def ^:dynamic *current*)
@@ -85,12 +85,12 @@
{:added "1.0"}
([s] (parse s startparse-sax))
([s startparse]
- (binding [*stack* nil
- *current* (struct element)
- *state* :between
- *sb* nil]
- (startparse s content-handler)
- ((:content *current*) 0))))
+ (binding [*stack* nil
+ *current* (struct element)
+ *state* :between
+ *sb* nil]
+ (startparse s content-handler)
+ ((:content *current*) 0))))
(defn emit-element [e]
(if (instance? String e)
@@ -98,15 +98,15 @@
(do
(print (str "<" (name (:tag e))))
(when (:attrs e)
- (doseq [attr (:attrs e)]
- (print (str " " (name (key attr)) "='" (val attr)"'"))))
+ (doseq [attr (:attrs e)]
+ (print (str " " (name (key attr)) "='" (val attr)"'"))))
(if (:content e)
- (do
- (println ">")
- (doseq [c (:content e)]
- (emit-element c))
- (println (str "</" (name (:tag e)) ">")))
- (println "/>")))))
+ (do
+ (println ">")
+ (doseq [c (:content e)]
+ (emit-element c))
+ (println (str "</" (name (:tag e)) ">")))
+ (println "/>")))))
(defn emit [x]
(println "<?xml version='1.0' encoding='UTF-8'?>")
diff --git a/src/clj/clojure/zip.clj b/src/clj/clojure/zip.clj
index 7848ab06..16e10765 100644
--- a/src/clj/clojure/zip.clj
+++ b/src/clj/clojure/zip.clj
@@ -11,7 +11,7 @@
(ns ^{:doc "Functional hierarchical zipper, with navigation, editing,
and enumeration. See Huet"
- :author "Rich Hickey"}
+ :author "Rich Hickey"}
clojure.zip
(:refer-clojure :exclude (replace remove next)))
@@ -29,37 +29,37 @@
root is the root node."
{:added "1.0"}
[branch? children make-node root]
- ^{:zip/branch? branch? :zip/children children :zip/make-node make-node}
- [root nil])
+ ^{:zip/branch? branch? :zip/children children :zip/make-node make-node}
+ [root nil])
(defn seq-zip
"Returns a zipper for nested sequences, given a root sequence"
{:added "1.0"}
[root]
- (zipper seq?
- identity
- (fn [node children] (with-meta children (meta node)))
- root))
+ (zipper seq?
+ identity
+ (fn [node children] (with-meta children (meta node)))
+ root))
(defn vector-zip
"Returns a zipper for nested vectors, given a root vector"
{:added "1.0"}
[root]
- (zipper vector?
- seq
- (fn [node children] (with-meta (vec children) (meta node)))
- root))
+ (zipper vector?
+ seq
+ (fn [node children] (with-meta (vec children) (meta node)))
+ root))
(defn xml-zip
"Returns a zipper for xml elements (as from xml/parse),
given a root element"
{:added "1.0"}
[root]
- (zipper (complement string?)
- (comp seq :content)
- (fn [node children]
- (assoc node :content (and children (apply vector children))))
- root))
+ (zipper (complement string?)
+ (comp seq :content)
+ (fn [node children]
+ (assoc node :content (and children (apply vector children))))
+ root))
(defn node
"Returns the node at loc"
@@ -70,40 +70,40 @@
"Returns true if the node at loc is a branch"
{:added "1.0"}
[loc]
- ((:zip/branch? (meta loc)) (node loc)))
+ ((:zip/branch? (meta loc)) (node loc)))
(defn children
"Returns a seq of the children of node at loc, which must be a branch"
{:added "1.0"}
[loc]
- (if (branch? loc)
- ((:zip/children (meta loc)) (node loc))
- (throw (Exception. "called children on a leaf node"))))
+ (if (branch? loc)
+ ((:zip/children (meta loc)) (node loc))
+ (throw (Exception. "called children on a leaf node"))))
(defn make-node
"Returns a new branch node, given an existing node and new
children. The loc is only used to supply the constructor."
{:added "1.0"}
[loc node children]
- ((:zip/make-node (meta loc)) node children))
+ ((:zip/make-node (meta loc)) node children))
(defn path
"Returns a seq of nodes leading to this loc"
{:added "1.0"}
[loc]
- (:pnodes (loc 1)))
+ (:pnodes (loc 1)))
(defn lefts
"Returns a seq of the left siblings of this loc"
{:added "1.0"}
[loc]
- (seq (:l (loc 1))))
+ (seq (:l (loc 1))))
(defn rights
"Returns a seq of the right siblings of this loc"
{:added "1.0"}
[loc]
- (:r (loc 1)))
+ (:r (loc 1)))
(defn down
@@ -111,121 +111,121 @@
nil if no children"
{:added "1.0"}
[loc]
- (when (branch? loc)
- (let [[node path] loc
- [c & cnext :as cs] (children loc)]
- (when cs
- (with-meta [c {:l []
- :pnodes (if path (conj (:pnodes path) node) [node])
- :ppath path
- :r cnext}] (meta loc))))))
+ (when (branch? loc)
+ (let [[node path] loc
+ [c & cnext :as cs] (children loc)]
+ (when cs
+ (with-meta [c {:l []
+ :pnodes (if path (conj (:pnodes path) node) [node])
+ :ppath path
+ :r cnext}] (meta loc))))))
(defn up
"Returns the loc of the parent of the node at this loc, or nil if at
the top"
{:added "1.0"}
[loc]
- (let [[node {l :l, ppath :ppath, pnodes :pnodes r :r, changed? :changed?, :as path}] loc]
- (when pnodes
- (let [pnode (peek pnodes)]
- (with-meta (if changed?
- [(make-node loc pnode (concat l (cons node r)))
- (and ppath (assoc ppath :changed? true))]
- [pnode ppath])
- (meta loc))))))
+ (let [[node {l :l, ppath :ppath, pnodes :pnodes r :r, changed? :changed?, :as path}] loc]
+ (when pnodes
+ (let [pnode (peek pnodes)]
+ (with-meta (if changed?
+ [(make-node loc pnode (concat l (cons node r)))
+ (and ppath (assoc ppath :changed? true))]
+ [pnode ppath])
+ (meta loc))))))
(defn root
"zips all the way up and returns the root node, reflecting any
changes."
{:added "1.0"}
[loc]
- (if (= :end (loc 1))
- (node loc)
- (let [p (up loc)]
- (if p
- (recur p)
- (node loc)))))
+ (if (= :end (loc 1))
+ (node loc)
+ (let [p (up loc)]
+ (if p
+ (recur p)
+ (node loc)))))
(defn right
"Returns the loc of the right sibling of the node at this loc, or nil"
{:added "1.0"}
[loc]
- (let [[node {l :l [r & rnext :as rs] :r :as path}] loc]
- (when (and path rs)
- (with-meta [r (assoc path :l (conj l node) :r rnext)] (meta loc)))))
+ (let [[node {l :l [r & rnext :as rs] :r :as path}] loc]
+ (when (and path rs)
+ (with-meta [r (assoc path :l (conj l node) :r rnext)] (meta loc)))))
(defn rightmost
"Returns the loc of the rightmost sibling of the node at this loc, or self"
{:added "1.0"}
[loc]
- (let [[node {l :l r :r :as path}] loc]
- (if (and path r)
- (with-meta [(last r) (assoc path :l (apply conj l node (butlast r)) :r nil)] (meta loc))
- loc)))
+ (let [[node {l :l r :r :as path}] loc]
+ (if (and path r)
+ (with-meta [(last r) (assoc path :l (apply conj l node (butlast r)) :r nil)] (meta loc))
+ loc)))
(defn left
"Returns the loc of the left sibling of the node at this loc, or nil"
{:added "1.0"}
[loc]
- (let [[node {l :l r :r :as path}] loc]
- (when (and path (seq l))
- (with-meta [(peek l) (assoc path :l (pop l) :r (cons node r))] (meta loc)))))
+ (let [[node {l :l r :r :as path}] loc]
+ (when (and path (seq l))
+ (with-meta [(peek l) (assoc path :l (pop l) :r (cons node r))] (meta loc)))))
(defn leftmost
"Returns the loc of the leftmost sibling of the node at this loc, or self"
{:added "1.0"}
[loc]
- (let [[node {l :l r :r :as path}] loc]
- (if (and path (seq l))
- (with-meta [(first l) (assoc path :l [] :r (concat (rest l) [node] r))] (meta loc))
- loc)))
+ (let [[node {l :l r :r :as path}] loc]
+ (if (and path (seq l))
+ (with-meta [(first l) (assoc path :l [] :r (concat (rest l) [node] r))] (meta loc))
+ loc)))
(defn insert-left
"Inserts the item as the left sibling of the node at this loc,
without moving"
{:added "1.0"}
[loc item]
- (let [[node {l :l :as path}] loc]
- (if (nil? path)
- (throw (new Exception "Insert at top"))
- (with-meta [node (assoc path :l (conj l item) :changed? true)] (meta loc)))))
+ (let [[node {l :l :as path}] loc]
+ (if (nil? path)
+ (throw (new Exception "Insert at top"))
+ (with-meta [node (assoc path :l (conj l item) :changed? true)] (meta loc)))))
(defn insert-right
"Inserts the item as the right sibling of the node at this loc,
without moving"
{:added "1.0"}
[loc item]
- (let [[node {r :r :as path}] loc]
- (if (nil? path)
- (throw (new Exception "Insert at top"))
- (with-meta [node (assoc path :r (cons item r) :changed? true)] (meta loc)))))
+ (let [[node {r :r :as path}] loc]
+ (if (nil? path)
+ (throw (new Exception "Insert at top"))
+ (with-meta [node (assoc path :r (cons item r) :changed? true)] (meta loc)))))
(defn replace
"Replaces the node at this loc, without moving"
{:added "1.0"}
[loc node]
- (let [[_ path] loc]
- (with-meta [node (assoc path :changed? true)] (meta loc))))
+ (let [[_ path] loc]
+ (with-meta [node (assoc path :changed? true)] (meta loc))))
(defn edit
"Replaces the node at this loc with the value of (f node args)"
{:added "1.0"}
[loc f & args]
- (replace loc (apply f (node loc) args)))
+ (replace loc (apply f (node loc) args)))
(defn insert-child
"Inserts the item as the leftmost child of the node at this loc,
without moving"
{:added "1.0"}
[loc item]
- (replace loc (make-node loc (node loc) (cons item (children loc)))))
+ (replace loc (make-node loc (node loc) (cons item (children loc)))))
(defn append-child
"Inserts the item as the rightmost child of the node at this loc,
without moving"
{:added "1.0"}
[loc item]
- (replace loc (make-node loc (node loc) (concat (children loc) [item]))))
+ (replace loc (make-node loc (node loc) (concat (children loc) [item]))))
(defn next
"Moves to the next loc in the hierarchy, depth-first. When reaching
@@ -233,86 +233,86 @@
at the end, stays there."
{:added "1.0"}
[loc]
- (if (= :end (loc 1))
- loc
- (or
- (and (branch? loc) (down loc))
- (right loc)
- (loop [p loc]
- (if (up p)
- (or (right (up p)) (recur (up p)))
- [(node p) :end])))))
+ (if (= :end (loc 1))
+ loc
+ (or
+ (and (branch? loc) (down loc))
+ (right loc)
+ (loop [p loc]
+ (if (up p)
+ (or (right (up p)) (recur (up p)))
+ [(node p) :end])))))
(defn prev
"Moves to the previous loc in the hierarchy, depth-first. If already
at the root, returns nil."
{:added "1.0"}
[loc]
- (if-let [lloc (left loc)]
- (loop [loc lloc]
- (if-let [child (and (branch? loc) (down loc))]
- (recur (rightmost child))
- loc))
- (up loc)))
+ (if-let [lloc (left loc)]
+ (loop [loc lloc]
+ (if-let [child (and (branch? loc) (down loc))]
+ (recur (rightmost child))
+ loc))
+ (up loc)))
(defn end?
"Returns true if loc represents the end of a depth-first walk"
{:added "1.0"}
[loc]
- (= :end (loc 1)))
+ (= :end (loc 1)))
(defn remove
"Removes the node at loc, returning the loc that would have preceded
it in a depth-first walk."
{:added "1.0"}
[loc]
- (let [[node {l :l, ppath :ppath, pnodes :pnodes, rs :r, :as path}] loc]
- (if (nil? path)
- (throw (new Exception "Remove at top"))
- (if (pos? (count l))
- (loop [loc (with-meta [(peek l) (assoc path :l (pop l) :changed? true)] (meta loc))]
- (if-let [child (and (branch? loc) (down loc))]
- (recur (rightmost child))
- loc))
- (with-meta [(make-node loc (peek pnodes) rs)
- (and ppath (assoc ppath :changed? true))]
- (meta loc))))))
+ (let [[node {l :l, ppath :ppath, pnodes :pnodes, rs :r, :as path}] loc]
+ (if (nil? path)
+ (throw (new Exception "Remove at top"))
+ (if (pos? (count l))
+ (loop [loc (with-meta [(peek l) (assoc path :l (pop l) :changed? true)] (meta loc))]
+ (if-let [child (and (branch? loc) (down loc))]
+ (recur (rightmost child))
+ loc))
+ (with-meta [(make-node loc (peek pnodes) rs)
+ (and ppath (assoc ppath :changed? true))]
+ (meta loc))))))
(comment
-(load-file "/Users/rich/dev/clojure/src/zip.clj")
-(refer 'zip)
-(def data '[[a * b] + [c * d]])
-(def dz (vector-zip data))
-
-(right (down (right (right (down dz)))))
-(lefts (right (down (right (right (down dz))))))
-(rights (right (down (right (right (down dz))))))
-(up (up (right (down (right (right (down dz)))))))
-(path (right (down (right (right (down dz))))))
-
-(-> dz down right right down right)
-(-> dz down right right down right (replace '/) root)
-(-> dz next next (edit str) next next next (replace '/) root)
-(-> dz next next next next next next next next next remove root)
-(-> dz next next next next next next next next next remove (insert-right 'e) root)
-(-> dz next next next next next next next next next remove up (append-child 'e) root)
-
-(end? (-> dz next next next next next next next next next remove next))
-
-(-> dz next remove next remove root)
-
-(loop [loc dz]
- (if (end? loc)
- (root loc)
- (recur (next (if (= '* (node loc))
- (replace loc '/)
- loc)))))
-
-(loop [loc dz]
- (if (end? loc)
- (root loc)
- (recur (next (if (= '* (node loc))
- (remove loc)
- loc)))))
-)
+ (load-file "/Users/rich/dev/clojure/src/zip.clj")
+ (refer 'zip)
+ (def data '[[a * b] + [c * d]])
+ (def dz (vector-zip data))
+
+ (right (down (right (right (down dz)))))
+ (lefts (right (down (right (right (down dz))))))
+ (rights (right (down (right (right (down dz))))))
+ (up (up (right (down (right (right (down dz)))))))
+ (path (right (down (right (right (down dz))))))
+
+ (-> dz down right right down right)
+ (-> dz down right right down right (replace '/) root)
+ (-> dz next next (edit str) next next next (replace '/) root)
+ (-> dz next next next next next next next next next remove root)
+ (-> dz next next next next next next next next next remove (insert-right 'e) root)
+ (-> dz next next next next next next next next next remove up (append-child 'e) root)
+
+ (end? (-> dz next next next next next next next next next remove next))
+
+ (-> dz next remove next remove root)
+
+ (loop [loc dz]
+ (if (end? loc)
+ (root loc)
+ (recur (next (if (= '* (node loc))
+ (replace loc '/)
+ loc)))))
+
+ (loop [loc dz]
+ (if (end? loc)
+ (root loc)
+ (recur (next (if (= '* (node loc))
+ (remove loc)
+ loc)))))
+ )
diff --git a/src/script/run_test.clj b/src/script/run_test.clj
index 4ff2b163..a651656a 100755
--- a/src/script/run_test.clj
+++ b/src/script/run_test.clj
@@ -1,7 +1,7 @@
(System/setProperty "java.awt.headless" "true")
(require
- '[clojure.test :as test]
- '[clojure.tools.namespace.find :as ns])
+ '[clojure.test :as test]
+ '[clojure.tools.namespace.find :as ns])
(def namespaces (remove (read-string (System/getProperty "clojure.test-clojure.exclude-namespaces"))
(ns/find-namespaces-in-dir (java.io.File. "test"))))
(doseq [ns namespaces] (require ns))
diff --git a/test/clojure/test_clojure/agents.clj b/test/clojure/test_clojure/agents.clj
index 0fb85d09..1319cbf5 100644
--- a/test/clojure/test_clojure/agents.clj
+++ b/test/clojure/test_clojure/agents.clj
@@ -22,9 +22,9 @@
(let [agt (agent nil)]
(send agt (fn [state] (throw (Throwable. "just testing Throwables"))))
(try
- ;; Let the action finish; eat the "agent has errors" error that bubbles up
- (await-for fragile-wait agt)
- (catch RuntimeException _))
+ ;; Let the action finish; eat the "agent has errors" error that bubbles up
+ (await-for fragile-wait agt)
+ (catch RuntimeException _))
(is (instance? Throwable (first (agent-errors agt))))
(is (= 1 (count (agent-errors agt))))
@@ -47,21 +47,21 @@
(is (= 0 @agt))
(is (nil? (agent-error agt)))
(is (= agt (first @err)))
- (is (true? (instance? ArithmeticException (second @err))))))
+ (is (true? (instance? ArithmeticException (second @err))))))
;; TODO: make these tests deterministic (i.e. not sleep and hope)
#_(deftest fail-handler
- (let [err (atom nil)
- agt (agent 0 :error-mode :fail :error-handler #(reset! err %&))]
- (send agt /)
- (Thread/sleep 100)
- (is (true? (instance? ArithmeticException (agent-error agt))))
- (is (= 0 @agt))
- (is (= agt (first @err)))
- (is (true? (instance? ArithmeticException (second @err))))
- (is (thrown? RuntimeException (send agt inc)))))
+ (let [err (atom nil)
+ agt (agent 0 :error-mode :fail :error-handler #(reset! err %&))]
+ (send agt /)
+ (Thread/sleep 100)
+ (is (true? (instance? ArithmeticException (agent-error agt))))
+ (is (= 0 @agt))
+ (is (= agt (first @err)))
+ (is (true? (instance? ArithmeticException (second @err))))
+ (is (thrown? RuntimeException (send agt inc)))))
(deftest can-send-from-error-handler-before-popping-action-that-caused-error
(let [latch (CountDownLatch. 1)
@@ -83,57 +83,57 @@
(is (.await latch 10 TimeUnit/SECONDS))))
#_(deftest restart-no-clear
- (let [p (promise)
- agt (agent 1 :error-mode :fail)]
- (send agt (fn [v] @p))
- (send agt /)
- (send agt inc)
- (send agt inc)
- (deliver p 0)
- (Thread/sleep 100)
- (is (= 0 @agt))
- (is (= ArithmeticException (class (agent-error agt))))
- (restart-agent agt 10)
- (is (true? (await-for fragile-wait agt)))
- (is (= 12 @agt))
- (is (nil? (agent-error agt)))))
+ (let [p (promise)
+ agt (agent 1 :error-mode :fail)]
+ (send agt (fn [v] @p))
+ (send agt /)
+ (send agt inc)
+ (send agt inc)
+ (deliver p 0)
+ (Thread/sleep 100)
+ (is (= 0 @agt))
+ (is (= ArithmeticException (class (agent-error agt))))
+ (restart-agent agt 10)
+ (is (true? (await-for fragile-wait agt)))
+ (is (= 12 @agt))
+ (is (nil? (agent-error agt)))))
#_(deftest restart-clear
- (let [p (promise)
- agt (agent 1 :error-mode :fail)]
- (send agt (fn [v] @p))
- (send agt /)
- (send agt inc)
- (send agt inc)
- (deliver p 0)
- (Thread/sleep 100)
- (is (= 0 @agt))
- (is (= ArithmeticException (class (agent-error agt))))
- (restart-agent agt 10 :clear-actions true)
- (is (true? (await-for fragile-wait agt)))
- (is (= 10 @agt))
- (is (nil? (agent-error agt)))
- (send agt inc)
- (is (true? (await-for fragile-wait agt)))
- (is (= 11 @agt))
- (is (nil? (agent-error agt)))))
+ (let [p (promise)
+ agt (agent 1 :error-mode :fail)]
+ (send agt (fn [v] @p))
+ (send agt /)
+ (send agt inc)
+ (send agt inc)
+ (deliver p 0)
+ (Thread/sleep 100)
+ (is (= 0 @agt))
+ (is (= ArithmeticException (class (agent-error agt))))
+ (restart-agent agt 10 :clear-actions true)
+ (is (true? (await-for fragile-wait agt)))
+ (is (= 10 @agt))
+ (is (nil? (agent-error agt)))
+ (send agt inc)
+ (is (true? (await-for fragile-wait agt)))
+ (is (= 11 @agt))
+ (is (nil? (agent-error agt)))))
#_(deftest invalid-restart
- (let [p (promise)
- agt (agent 2 :error-mode :fail :validator even?)]
- (is (thrown? RuntimeException (restart-agent agt 4)))
- (send agt (fn [v] @p))
- (send agt (partial + 2))
- (send agt (partial + 2))
- (deliver p 3)
- (Thread/sleep 100)
- (is (= 2 @agt))
- (is (= IllegalStateException (class (agent-error agt))))
- (is (thrown? RuntimeException (restart-agent agt 5)))
- (restart-agent agt 6)
- (is (true? (await-for fragile-wait agt)))
- (is (= 10 @agt))
- (is (nil? (agent-error agt)))))
+ (let [p (promise)
+ agt (agent 2 :error-mode :fail :validator even?)]
+ (is (thrown? RuntimeException (restart-agent agt 4)))
+ (send agt (fn [v] @p))
+ (send agt (partial + 2))
+ (send agt (partial + 2))
+ (deliver p 3)
+ (Thread/sleep 100)
+ (is (= 2 @agt))
+ (is (= IllegalStateException (class (agent-error agt))))
+ (is (thrown? RuntimeException (restart-agent agt 5)))
+ (restart-agent agt 6)
+ (is (true? (await-for fragile-wait agt)))
+ (is (= 10 @agt))
+ (is (nil? (agent-error agt)))))
(deftest earmuff-agent-bound
(let [a (agent 1)]
@@ -146,10 +146,10 @@
(deftest thread-conveyance-to-agents
(let [a (agent nil)]
(doto (Thread.
- (fn []
- (binding [*bind-me* :thread-binding]
- (send a (constantly *bind-me*)))
- (await a)))
+ (fn []
+ (binding [*bind-me* :thread-binding]
+ (send a (constantly *bind-me*)))
+ (await a)))
(.start)
(.join))
(is (= @a :thread-binding))))
diff --git a/test/clojure/test_clojure/annotations/java_8.clj b/test/clojure/test_clojure/annotations/java_8.clj
index a263b80b..75f8daae 100644
--- a/test/clojure/test_clojure/annotations/java_8.clj
+++ b/test/clojure/test_clojure/annotations/java_8.clj
@@ -17,9 +17,9 @@
Deprecated true
Retention RetentionPolicy/RUNTIME
javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
- javax.xml.ws.soap.Addressing {:enabled false :required true}
+ javax.xml.ws.soap.Addressing {:enabled false :required true}
WebServiceRefs [(WebServiceRef {:name "fred" :type String})
- (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
+ (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
b]
Foo (#^{Deprecated true
Retention RetentionPolicy/RUNTIME
@@ -35,18 +35,18 @@
Works recursively. Returns non-annotations unscathed."
[#^java.lang.annotation.Annotation o]
(cond
- (instance? Annotation o)
- (let [type (.annotationType o)
- itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation))
- data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))]
- (into
- {:annotationType (.annotationType o)}
- (map
- (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))])
- data-methods)))
- (or (sequential? o) (.isArray (class o)))
- (map annotation->map o)
- :else o))
+ (instance? Annotation o)
+ (let [type (.annotationType o)
+ itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation))
+ data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))]
+ (into
+ {:annotationType (.annotationType o)}
+ (map
+ (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))])
+ data-methods)))
+ (or (sequential? o) (.isArray (class o)))
+ (map annotation->map o)
+ :else o))
(def expected-annotations
#{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME}
@@ -59,18 +59,18 @@
(deftest test-annotations-on-type
(is (=
- expected-annotations
- (into #{} (map annotation->map (.getAnnotations Bar))))))
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations Bar))))))
(deftest test-annotations-on-field
(is (=
- expected-annotations
- (into #{} (map annotation->map (.getAnnotations (.getField Bar "b")))))))
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations (.getField Bar "b")))))))
(deftest test-annotations-on-method
(is (=
- expected-annotations
- (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil)))))))
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil)))))))
(gen-class :name foo.Bar
:extends clojure.lang.Box
diff --git a/test/clojure/test_clojure/annotations/java_9.clj b/test/clojure/test_clojure/annotations/java_9.clj
index 0e4f1c7e..5ce23c66 100644
--- a/test/clojure/test_clojure/annotations/java_9.clj
+++ b/test/clojure/test_clojure/annotations/java_9.clj
@@ -17,9 +17,9 @@
Deprecated true
Retention RetentionPolicy/RUNTIME
javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
- javax.xml.ws.soap.Addressing {:enabled false :required true}
+ javax.xml.ws.soap.Addressing {:enabled false :required true}
WebServiceRefs [(WebServiceRef {:name "fred" :type String})
- (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
+ (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
b]
Foo (#^{Deprecated true
Retention RetentionPolicy/RUNTIME
@@ -35,18 +35,18 @@
Works recursively. Returns non-annotations unscathed."
[#^java.lang.annotation.Annotation o]
(cond
- (instance? Annotation o)
- (let [type (.annotationType o)
- itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation))
- data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))]
- (into
- {:annotationType (.annotationType o)}
- (map
- (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))])
- data-methods)))
- (or (sequential? o) (.isArray (class o)))
- (map annotation->map o)
- :else o))
+ (instance? Annotation o)
+ (let [type (.annotationType o)
+ itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation))
+ data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))]
+ (into
+ {:annotationType (.annotationType o)}
+ (map
+ (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))])
+ data-methods)))
+ (or (sequential? o) (.isArray (class o)))
+ (map annotation->map o)
+ :else o))
(def expected-annotations
#{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME}
@@ -59,18 +59,18 @@
(deftest test-annotations-on-type
(is (=
- expected-annotations
- (into #{} (map annotation->map (.getAnnotations Bar))))))
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations Bar))))))
(deftest test-annotations-on-field
(is (=
- expected-annotations
- (into #{} (map annotation->map (.getAnnotations (.getField Bar "b")))))))
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations (.getField Bar "b")))))))
(deftest test-annotations-on-method
(is (=
- expected-annotations
- (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil)))))))
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil)))))))
(gen-class :name foo.Bar
:extends clojure.lang.Box
diff --git a/test/clojure/test_clojure/api.clj b/test/clojure/test_clojure/api.clj
index 9718e553..9e8d218e 100644
--- a/test/clojure/test_clojure/api.clj
+++ b/test/clojure/test_clojure/api.clj
@@ -8,10 +8,10 @@
(ns clojure.test-clojure.api
(:require [clojure.test.generative :refer (defspec)]
- [clojure.test-clojure.generators :as cgen])
+ [clojure.test-clojure.generators :as cgen])
(:import clojure.lang.IFn
- clojure.java.api.Clojure
- clojure.lang.Var))
+ clojure.java.api.Clojure
+ clojure.lang.Var))
(set! *warn-on-reflection* true)
diff --git a/test/clojure/test_clojure/clojure_set.clj b/test/clojure/test_clojure/clojure_set.clj
index 61a36b91..84944425 100644
--- a/test/clojure/test_clojure/clojure_set.clj
+++ b/test/clojure/test_clojure/clojure_set.clj
@@ -15,114 +15,114 @@
(deftest test-union
(are [x y] (= x y)
- (set/union) #{}
-
- ; identity
- (set/union #{}) #{}
- (set/union #{1}) #{1}
- (set/union #{1 2 3}) #{1 2 3}
-
- ; 2 sets, at least one is empty
- (set/union #{} #{}) #{}
- (set/union #{} #{1}) #{1}
- (set/union #{} #{1 2 3}) #{1 2 3}
- (set/union #{1} #{}) #{1}
- (set/union #{1 2 3} #{}) #{1 2 3}
-
- ; 2 sets
- (set/union #{1} #{2}) #{1 2}
- (set/union #{1} #{1 2}) #{1 2}
- (set/union #{2} #{1 2}) #{1 2}
- (set/union #{1 2} #{3}) #{1 2 3}
- (set/union #{1 2} #{2 3}) #{1 2 3}
-
- ; 3 sets, some are empty
- (set/union #{} #{} #{}) #{}
- (set/union #{1} #{} #{}) #{1}
- (set/union #{} #{1} #{}) #{1}
- (set/union #{} #{} #{1}) #{1}
- (set/union #{1 2} #{2 3} #{}) #{1 2 3}
-
- ; 3 sets
- (set/union #{1 2} #{3 4} #{5 6}) #{1 2 3 4 5 6}
- (set/union #{1 2} #{2 3} #{1 3 4}) #{1 2 3 4}
-
- ; different data types
- (set/union #{1 2} #{:a :b} #{nil} #{false true} #{\c "abc"} #{[] [1 2]}
- #{{} {:a 1}} #{#{} #{1 2}})
- #{1 2 :a :b nil false true \c "abc" [] [1 2] {} {:a 1} #{} #{1 2}}
-
- ; different types of sets
- (set/union (hash-set) (hash-set 1 2) (hash-set 2 3))
- (hash-set 1 2 3)
- (set/union (sorted-set) (sorted-set 1 2) (sorted-set 2 3))
- (sorted-set 1 2 3)
- (set/union (hash-set) (hash-set 1 2) (hash-set 2 3)
- (sorted-set) (sorted-set 4 5) (sorted-set 5 6))
- (hash-set 1 2 3 4 5 6) ; also equals (sorted-set 1 2 3 4 5 6)
-))
+ (set/union) #{}
+
+ ; identity
+ (set/union #{}) #{}
+ (set/union #{1}) #{1}
+ (set/union #{1 2 3}) #{1 2 3}
+
+ ; 2 sets, at least one is empty
+ (set/union #{} #{}) #{}
+ (set/union #{} #{1}) #{1}
+ (set/union #{} #{1 2 3}) #{1 2 3}
+ (set/union #{1} #{}) #{1}
+ (set/union #{1 2 3} #{}) #{1 2 3}
+
+ ; 2 sets
+ (set/union #{1} #{2}) #{1 2}
+ (set/union #{1} #{1 2}) #{1 2}
+ (set/union #{2} #{1 2}) #{1 2}
+ (set/union #{1 2} #{3}) #{1 2 3}
+ (set/union #{1 2} #{2 3}) #{1 2 3}
+
+ ; 3 sets, some are empty
+ (set/union #{} #{} #{}) #{}
+ (set/union #{1} #{} #{}) #{1}
+ (set/union #{} #{1} #{}) #{1}
+ (set/union #{} #{} #{1}) #{1}
+ (set/union #{1 2} #{2 3} #{}) #{1 2 3}
+
+ ; 3 sets
+ (set/union #{1 2} #{3 4} #{5 6}) #{1 2 3 4 5 6}
+ (set/union #{1 2} #{2 3} #{1 3 4}) #{1 2 3 4}
+
+ ; different data types
+ (set/union #{1 2} #{:a :b} #{nil} #{false true} #{\c "abc"} #{[] [1 2]}
+ #{{} {:a 1}} #{#{} #{1 2}})
+ #{1 2 :a :b nil false true \c "abc" [] [1 2] {} {:a 1} #{} #{1 2}}
+
+ ; different types of sets
+ (set/union (hash-set) (hash-set 1 2) (hash-set 2 3))
+ (hash-set 1 2 3)
+ (set/union (sorted-set) (sorted-set 1 2) (sorted-set 2 3))
+ (sorted-set 1 2 3)
+ (set/union (hash-set) (hash-set 1 2) (hash-set 2 3)
+ (sorted-set) (sorted-set 4 5) (sorted-set 5 6))
+ (hash-set 1 2 3 4 5 6) ; also equals (sorted-set 1 2 3 4 5 6)
+ ))
(deftest test-intersection
; at least one argument is needed
(is (thrown? IllegalArgumentException (set/intersection)))
(are [x y] (= x y)
- ; identity
- (set/intersection #{}) #{}
- (set/intersection #{1}) #{1}
- (set/intersection #{1 2 3}) #{1 2 3}
+ ; identity
+ (set/intersection #{}) #{}
+ (set/intersection #{1}) #{1}
+ (set/intersection #{1 2 3}) #{1 2 3}
- ; 2 sets, at least one is empty
- (set/intersection #{} #{}) #{}
- (set/intersection #{} #{1}) #{}
- (set/intersection #{} #{1 2 3}) #{}
- (set/intersection #{1} #{}) #{}
- (set/intersection #{1 2 3} #{}) #{}
-
- ; 2 sets
- (set/intersection #{1 2} #{1 2}) #{1 2}
- (set/intersection #{1 2} #{3 4}) #{}
- (set/intersection #{1 2} #{1}) #{1}
- (set/intersection #{1 2} #{2}) #{2}
- (set/intersection #{1 2 4} #{2 3 4 5}) #{2 4}
-
- ; 3 sets, some are empty
- (set/intersection #{} #{} #{}) #{}
- (set/intersection #{1} #{} #{}) #{}
- (set/intersection #{1} #{1} #{}) #{}
- (set/intersection #{1} #{} #{1}) #{}
- (set/intersection #{1 2} #{2 3} #{}) #{}
-
- ; 3 sets
- (set/intersection #{1 2} #{2 3} #{5 2}) #{2}
- (set/intersection #{1 2 3} #{1 3 4} #{1 3}) #{1 3}
- (set/intersection #{1 2 3} #{3 4 5} #{8 2 3}) #{3}
-
- ; different types of sets
- (set/intersection (hash-set 1 2) (hash-set 2 3)) #{2}
- (set/intersection (sorted-set 1 2) (sorted-set 2 3)) #{2}
- (set/intersection
- (hash-set 1 2) (hash-set 2 3)
- (sorted-set 1 2) (sorted-set 2 3)) #{2} ))
+ ; 2 sets, at least one is empty
+ (set/intersection #{} #{}) #{}
+ (set/intersection #{} #{1}) #{}
+ (set/intersection #{} #{1 2 3}) #{}
+ (set/intersection #{1} #{}) #{}
+ (set/intersection #{1 2 3} #{}) #{}
+
+ ; 2 sets
+ (set/intersection #{1 2} #{1 2}) #{1 2}
+ (set/intersection #{1 2} #{3 4}) #{}
+ (set/intersection #{1 2} #{1}) #{1}
+ (set/intersection #{1 2} #{2}) #{2}
+ (set/intersection #{1 2 4} #{2 3 4 5}) #{2 4}
+
+ ; 3 sets, some are empty
+ (set/intersection #{} #{} #{}) #{}
+ (set/intersection #{1} #{} #{}) #{}
+ (set/intersection #{1} #{1} #{}) #{}
+ (set/intersection #{1} #{} #{1}) #{}
+ (set/intersection #{1 2} #{2 3} #{}) #{}
+
+ ; 3 sets
+ (set/intersection #{1 2} #{2 3} #{5 2}) #{2}
+ (set/intersection #{1 2 3} #{1 3 4} #{1 3}) #{1 3}
+ (set/intersection #{1 2 3} #{3 4 5} #{8 2 3}) #{3}
+
+ ; different types of sets
+ (set/intersection (hash-set 1 2) (hash-set 2 3)) #{2}
+ (set/intersection (sorted-set 1 2) (sorted-set 2 3)) #{2}
+ (set/intersection
+ (hash-set 1 2) (hash-set 2 3)
+ (sorted-set 1 2) (sorted-set 2 3)) #{2} ))
(deftest test-difference
(are [x y] (= x y)
- ; identity
- (set/difference #{}) #{}
- (set/difference #{1}) #{1}
- (set/difference #{1 2 3}) #{1 2 3}
-
- ; 2 sets
- (set/difference #{1 2} #{1 2}) #{}
- (set/difference #{1 2} #{3 4}) #{1 2}
- (set/difference #{1 2} #{1}) #{2}
- (set/difference #{1 2} #{2}) #{1}
- (set/difference #{1 2 4} #{2 3 4 5}) #{1}
-
- ; 3 sets
- (set/difference #{1 2} #{2 3} #{5 2}) #{1}
- (set/difference #{1 2 3} #{1 3 4} #{1 3}) #{2}
- (set/difference #{1 2 3} #{3 4 5} #{8 2 3}) #{1} ))
+ ; identity
+ (set/difference #{}) #{}
+ (set/difference #{1}) #{1}
+ (set/difference #{1 2 3}) #{1 2 3}
+
+ ; 2 sets
+ (set/difference #{1 2} #{1 2}) #{}
+ (set/difference #{1 2} #{3 4}) #{1 2}
+ (set/difference #{1 2} #{1}) #{2}
+ (set/difference #{1 2} #{2}) #{1}
+ (set/difference #{1 2 4} #{2 3 4 5}) #{1}
+
+ ; 3 sets
+ (set/difference #{1 2} #{2 3} #{5 2}) #{1}
+ (set/difference #{1 2 3} #{1 3 4} #{1 3}) #{2}
+ (set/difference #{1 2 3} #{3 4 5} #{8 2 3}) #{1} ))
(deftest test-select
(are [x y] (= x y)
@@ -169,13 +169,13 @@
(deftest test-index
(are [x y] (= x y)
(set/index #{{:c 2} {:b 1} {:a 1 :b 2}} [:b]) {{:b 2} #{{:a 1 :b 2}}, {:b 1} #{{:b 1}} {} #{{:c 2}}}
- ))
+ ))
(deftest test-join
(are [x y] (= x y)
(set/join compositions compositions) compositions
(set/join compositions #{{:name "Art of the Fugue" :genre "Classical"}})
- #{{:name "Art of the Fugue" :composer "J. S. Bach" :genre "Classical"}}
+ #{{:name "Art of the Fugue" :composer "J. S. Bach" :genre "Classical"}}
))
(deftest test-map-invert
diff --git a/test/clojure/test_clojure/clojure_walk.clj b/test/clojure/test_clojure/clojure_walk.clj
index 6c6f8663..1f7afddb 100644
--- a/test/clojure/test_clojure/clojure_walk.clj
+++ b/test/clojure/test_clojure/clojure_walk.clj
@@ -26,7 +26,7 @@
(deftest t-postwalk-order
(is (= (let [a (atom [])]
(w/postwalk (fn [form] (swap! a conj form) form)
- [1 2 {:a 3} (list 4 [5])])
+ [1 2 {:a 3} (list 4 [5])])
@a)
[1 2
:a 3 [:a 3] {:a 3}
@@ -48,7 +48,7 @@
(doseq [c colls]
(let [walked (w/walk identity identity c)]
(is (= c walked))
- ;;(is (= (type c) (type walked)))
+ ;;(is (= (type c) (type walked)))
(if (map? c)
(is (= (w/walk #(update-in % [1] inc) #(reduce + (vals %)) c)
(reduce + (map (comp inc val) c))))
diff --git a/test/clojure/test_clojure/compilation.clj b/test/clojure/test_clojure/compilation.clj
index 642bff8f..9554820d 100644
--- a/test/clojure/test_clojure/compilation.clj
+++ b/test/clojure/test_clojure/compilation.clj
@@ -12,10 +12,10 @@
(ns clojure.test-clojure.compilation
(:import (clojure.lang Compiler Compiler$CompilerException))
(:require [clojure.test.generative :refer (defspec)]
- [clojure.data.generators :as gen]
- [clojure.test-clojure.compilation.line-number-examples :as line])
+ [clojure.data.generators :as gen]
+ [clojure.test-clojure.compilation.line-number-examples :as line])
(:use clojure.test
- [clojure.test-helper :only (should-not-reflect should-print-err-message)]))
+ [clojure.test-helper :only (should-not-reflect should-print-err-message)]))
; http://clojure.org/compilation
@@ -26,23 +26,23 @@
(deftest test-compiler-metadata
(let [m (meta #'when)]
(are [x y] (= x y)
- (list? (:arglists m)) true
- (> (count (:arglists m)) 0) true
+ (list? (:arglists m)) true
+ (> (count (:arglists m)) 0) true
- (string? (:doc m)) true
- (> (.length (:doc m)) 0) true
+ (string? (:doc m)) true
+ (> (.length (:doc m)) 0) true
- (string? (:file m)) true
- (> (.length (:file m)) 0) true
+ (string? (:file m)) true
+ (> (.length (:file m)) 0) true
- (integer? (:line m)) true
- (> (:line m) 0) true
+ (integer? (:line m)) true
+ (> (:line m) 0) true
- (integer? (:column m)) true
- (> (:column m) 0) true
+ (integer? (:column m)) true
+ (> (:column m) 0) true
- (:macro m) true
- (:name m) 'when )))
+ (:macro m) true
+ (:name m) 'when )))
(deftest test-embedded-constants
(testing "Embedded constants"
@@ -115,9 +115,9 @@
;; disabled until build box can call java from mvn
#_(deftest test-numeric-dispatch
- (is (= "(int, int)" (TestDispatch/someMethod (int 1) (int 1))))
- (is (= "(int, long)" (TestDispatch/someMethod (int 1) (long 1))))
- (is (= "(long, long)" (TestDispatch/someMethod (long 1) (long 1)))))
+ (is (= "(int, int)" (TestDispatch/someMethod (int 1) (int 1))))
+ (is (= "(int, long)" (TestDispatch/someMethod (int 1) (long 1))))
+ (is (= "(long, long)" (TestDispatch/someMethod (long 1) (long 1)))))
(deftest test-CLJ-671-regression
(testing "that the presence of hints does not cause the compiler to infinitely loop"
@@ -190,31 +190,31 @@
#(loop [k (clojure.test-clojure.compilation/primfn)] (recur :foo))))
#_(deftest CLJ-1154-use-out-after-compile
- ;; This test creates a dummy file to compile, sets up a dummy
- ;; compiled output directory, and a dummy output stream, and
- ;; verifies the stream is still usable after compiling.
- (spit "test/dummy.clj" "(ns dummy)")
- (try
- (let [compile-path (System/getProperty "clojure.compile.path")
- tmp (java.io.File. "tmp")
- new-out (java.io.OutputStreamWriter. (java.io.ByteArrayOutputStream.))]
- (binding [clojure.core/*out* new-out]
- (try
- (.mkdir tmp)
- (System/setProperty "clojure.compile.path" "tmp")
- (clojure.lang.Compile/main (into-array ["dummy"]))
- (println "this should still work without throwing an exception" )
- (finally
- (if compile-path
- (System/setProperty "clojure.compile.path" compile-path)
- (System/clearProperty "clojure.compile.path"))
- (doseq [f (.listFiles tmp)]
- (.delete f))
- (.delete tmp)))))
- (finally
- (doseq [f (.listFiles (java.io.File. "test"))
- :when (re-find #"dummy.clj" (str f))]
- (.delete f)))))
+ ;; This test creates a dummy file to compile, sets up a dummy
+ ;; compiled output directory, and a dummy output stream, and
+ ;; verifies the stream is still usable after compiling.
+ (spit "test/dummy.clj" "(ns dummy)")
+ (try
+ (let [compile-path (System/getProperty "clojure.compile.path")
+ tmp (java.io.File. "tmp")
+ new-out (java.io.OutputStreamWriter. (java.io.ByteArrayOutputStream.))]
+ (binding [clojure.core/*out* new-out]
+ (try
+ (.mkdir tmp)
+ (System/setProperty "clojure.compile.path" "tmp")
+ (clojure.lang.Compile/main (into-array ["dummy"]))
+ (println "this should still work without throwing an exception" )
+ (finally
+ (if compile-path
+ (System/setProperty "clojure.compile.path" compile-path)
+ (System/clearProperty "clojure.compile.path"))
+ (doseq [f (.listFiles tmp)]
+ (.delete f))
+ (.delete tmp)))))
+ (finally
+ (doseq [f (.listFiles (java.io.File. "test"))
+ :when (re-find #"dummy.clj" (str f))]
+ (.delete f)))))
(deftest CLJ-1184-do-in-non-list-test
(testing "do in a vector throws an exception"
@@ -229,12 +229,12 @@
(letfn [(compile [s]
(spit "test/clojure/bad_def_test.clj" (str "(ns clojure.bad-def-test)\n" s))
(try
- (binding [*compile-path* "test"]
- (clojure.core/compile 'clojure.bad-def-test))
- (finally
- (doseq [f (.listFiles (java.io.File. "test/clojure"))
- :when (re-find #"bad_def_test" (str f))]
- (.delete f)))))]
+ (binding [*compile-path* "test"]
+ (clojure.core/compile 'clojure.bad-def-test))
+ (finally
+ (doseq [f (.listFiles (java.io.File. "test/clojure"))
+ :when (re-find #"bad_def_test" (str f))]
+ (.delete f)))))]
(testing "do in a vector throws an exception in compilation"
(is (thrown? Compiler$CompilerException (compile "[do 1 2 3]"))))
(testing "do in a set throws an exception in compilation"
@@ -281,17 +281,17 @@
(deftest test-compiler-line-numbers
(let [fails-on-line-number? (fn [expected function]
- (try
- (function)
- nil
- (catch Throwable t
- (let [frames (filter #(= "line_number_examples.clj" (.getFileName %))
- (.getStackTrace t))
- _ (if (zero? (count frames))
- (.printStackTrace t)
- )
- actual (.getLineNumber ^StackTraceElement (first frames))]
- (= expected actual)))))]
+ (try
+ (function)
+ nil
+ (catch Throwable t
+ (let [frames (filter #(= "line_number_examples.clj" (.getFileName %))
+ (.getStackTrace t))
+ _ (if (zero? (count frames))
+ (.printStackTrace t)
+ )
+ actual (.getLineNumber ^StackTraceElement (first frames))]
+ (= expected actual)))))]
(is (fails-on-line-number? 13 line/instance-field))
(is (fails-on-line-number? 19 line/instance-field-reflected))
(is (fails-on-line-number? 25 line/instance-field-unboxed))
@@ -326,15 +326,15 @@
(deftest clj-1568
(let [compiler-fails-at?
- (fn [row col source]
- (let [path (name (gensym "clj-1568.example-"))]
- (try
- (Compiler/load (java.io.StringReader. source) path "clj-1568.example")
- nil
- (catch Compiler$CompilerException e
- (let [data (ex-data e)]
- (= [path row col]
- [(:clojure.error/source data) (:clojure.error/line data) (:clojure.error/column data)]))))))]
+ (fn [row col source]
+ (let [path (name (gensym "clj-1568.example-"))]
+ (try
+ (Compiler/load (java.io.StringReader. source) path "clj-1568.example")
+ nil
+ (catch Compiler$CompilerException e
+ (let [data (ex-data e)]
+ (= [path row col]
+ [(:clojure.error/source data) (:clojure.error/line data) (:clojure.error/column data)]))))))]
(testing "with error in the initial form"
(are [row col source] (compiler-fails-at? row col source)
;; note that the spacing of the following string is important
diff --git a/test/clojure/test_clojure/compilation/line_number_examples.clj b/test/clojure/test_clojure/compilation/line_number_examples.clj
index 57b6c1ad..cd317737 100644
--- a/test/clojure/test_clojure/compilation/line_number_examples.clj
+++ b/test/clojure/test_clojure/compilation/line_number_examples.clj
@@ -11,80 +11,80 @@
"I throw an exception in an instance field form."
[]
(.field
- ^Thing (identity nil)))
+ ^Thing (identity nil)))
(defn instance-field-reflected
"I throw an exception in an instance field form."
[]
(.field
- (identity nil)))
+ (identity nil)))
(defn instance-field-unboxed
"I throw an exception in an instance field form."
^long []
(.primitive
- ^Thing (identity nil)))
+ ^Thing (identity nil)))
(defn instance-field-assign
"I throw an exception in an instance field assignment form."
[]
(set!
- (.field
- ^Thing (identity nil))
- (identity nil)))
+ (.field
+ ^Thing (identity nil))
+ (identity nil)))
(defn instance-field-assign-reflected
"I throw an exception in an instance field assignment form."
[]
(set!
- (.field
- (identity nil))
- (identity nil)))
+ (.field
+ (identity nil))
+ (identity nil)))
(defn static-field-assign
"I throw an exception in a static field assignment form."
[]
(set!
- PersistentHashMap/EMPTY
- (identity nil)))
+ PersistentHashMap/EMPTY
+ (identity nil)))
(defn instance-method
"I throw an exception in an instance method form."
[]
(.without
- ^PersistentHashMap (identity nil)
- :key))
+ ^PersistentHashMap (identity nil)
+ :key))
(defn instance-method-reflected
"I throw an exception in an instance method form."
[]
(.without
- (identity nil)
- :key))
+ (identity nil)
+ :key))
(defn instance-method-unboxed
"I throw an exception in an instance method form."
^long []
(.count
- ^PersistentHashMap (identity nil)))
+ ^PersistentHashMap (identity nil)))
(defn static-method
"I throw an exception in a static method form."
[]
(PersistentHashMap/create
- ^java.util.Map (identity nil)))
+ ^java.util.Map (identity nil)))
(defn static-method-reflected
"I throw an exception in a static method form."
[]
(String/copyValueOf
- (identity nil)))
+ (identity nil)))
(defn static-method-unboxed
"I throw an exception in a static method form."
^long []
(Long/parseLong
- ^String (identity nil)))
+ ^String (identity nil)))
(defn invoke
"I throw an exception in an invoke form."
diff --git a/test/clojure/test_clojure/control.clj b/test/clojure/test_clojure/control.clj
index 92846ad3..57cd15f6 100644
--- a/test/clojure/test_clojure/control.clj
+++ b/test/clojure/test_clojure/control.clj
@@ -14,26 +14,26 @@
(ns clojure.test-clojure.control
(:use clojure.test
- clojure.test-helper))
+ clojure.test-helper))
;; *** Helper functions ***
(defn maintains-identity [f]
(are [x] (= (f x) x)
- nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- () '(1 2)
- [] [1 2]
- {} {:a 1 :b 2}
- #{} #{1 2} ))
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () '(1 2)
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2} ))
; http://clojure.org/special_forms
@@ -41,20 +41,20 @@
(deftest test-do
(are [x y] (= x y)
- ; no params => nil
- (do) nil
+ ; no params => nil
+ (do) nil
- ; return last
- (do 1) 1
- (do 1 2) 2
- (do 1 2 3 4 5) 5
+ ; return last
+ (do 1) 1
+ (do 1 2) 2
+ (do 1 2 3 4 5) 5
- ; evaluate and return last
- (let [a (atom 0)]
- (do (reset! a (+ @a 1)) ; 1
- (reset! a (+ @a 1)) ; 2
- (reset! a (+ @a 1)) ; 3
- @a)) 3 )
+ ; evaluate and return last
+ (let [a (atom 0)]
+ (do (reset! a (+ @a 1)) ; 1
+ (reset! a (+ @a 1)) ; 2
+ (reset! a (+ @a 1)) ; 3
+ @a)) 3 )
; identity (= (do x) x)
(maintains-identity (fn [_] (do _))) )
@@ -136,7 +136,7 @@
1 (if-let [a false]
a 1)
1 (if-let [[a b] nil]
- b 1)
+ b 1)
1 (if-let [a false]
(exception)
1)
@@ -170,39 +170,39 @@
(deftest test-cond
(are [x y] (= x y)
- (cond) nil
+ (cond) nil
- (cond nil true) nil
- (cond false true) nil
+ (cond nil true) nil
+ (cond false true) nil
- (cond true 1 true (exception)) 1
- (cond nil 1 false 2 true 3 true 4) 3
- (cond nil 1 false 2 true 3 true (exception)) 3 )
+ (cond true 1 true (exception)) 1
+ (cond nil 1 false 2 true 3 true 4) 3
+ (cond nil 1 false 2 true 3 true (exception)) 3 )
; false
(are [x] (= (cond x :a true :b) :b)
- nil false )
+ nil false )
; true
(are [x] (= (cond x :a true :b) :a)
- true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- () '(1 2)
- [] [1 2]
- {} {:a 1 :b 2}
- #{} #{1 2} )
+ true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () '(1 2)
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2} )
; evaluation
(are [x y] (= x y)
- (cond (> 3 2) (+ 1 2) true :result true (exception)) 3
- (cond (< 3 2) (+ 1 2) true :result true (exception)) :result )
+ (cond (> 3 2) (+ 1 2) true :result true (exception)) 3
+ (cond (< 3 2) (+ 1 2) true :result true (exception)) :result )
; identity (= (cond true x) x)
(maintains-identity (fn [_] (cond true _))) )
@@ -330,9 +330,9 @@
(testing "sorting doesn't matter"
(let [test-fn
#(case %
- {:b 2 :a 1} :map
- #{3 2 1} :set
- :default)]
+ {:b 2 :a 1} :map
+ #{3 2 1} :set
+ :default)]
(are [result input] (= result (test-fn input))
:map {:a 1 :b 2}
:map (sorted-map :a 1 :b 2)
@@ -424,8 +424,8 @@
:d 3))
(testing "test warn for hash collision"
(should-print-err-message
- #"Performance warning, .*:\d+ - hash collision of some case test constants; if selected, those entries will be tested sequentially..*\r?\n"
- (case 1 1 :long 9223372039002259457N :big 2)))
+ #"Performance warning, .*:\d+ - hash collision of some case test constants; if selected, those entries will be tested sequentially..*\r?\n"
+ (case 1 1 :long 9223372039002259457N :big 2)))
(testing "test constants are *not* evaluated"
(let [test-fn
;; never write code like this...
diff --git a/test/clojure/test_clojure/data_structures.clj b/test/clojure/test_clojure/data_structures.clj
index 580e30b0..2eb25fe0 100644
--- a/test/clojure/test_clojure/data_structures.clj
+++ b/test/clojure/test_clojure/data_structures.clj
@@ -11,10 +11,10 @@
(ns clojure.test-clojure.data-structures
(:use clojure.test
- [clojure.test.generative :exclude (is)])
+ [clojure.test.generative :exclude (is)])
(:require [clojure.test-clojure.generators :as cgen]
- [clojure.data.generators :as gen]
- [clojure.string :as string]))
+ [clojure.data.generators :as gen]
+ [clojure.string :as string]))
;; *** Helper functions ***
@@ -103,25 +103,25 @@
identity
[^{:tag clojure.test-clojure.data-structures/gen-transient-set-actions} actions]
(assert-same-collection
- (to-persistent (apply-actions #{} actions))
- (to-persistent (apply-actions #{} actions))))
+ (to-persistent (apply-actions #{} actions))
+ (to-persistent (apply-actions #{} actions))))
(defspec same-output-persistent-transient-vector
identity
[^{:tag clojure.test-clojure.data-structures/gen-transient-vector-actions} actions]
(assert-same-collection
- (to-persistent (apply-actions [] actions))
- (to-persistent (apply-actions [] actions))))
+ (to-persistent (apply-actions [] actions))
+ (to-persistent (apply-actions [] actions))))
(defspec same-output-persistent-transient-map
identity
[^{:tag clojure.test-clojure.data-structures/gen-transient-map-actions} actions]
(assert-same-collection
- (to-persistent (apply-actions clojure.lang.PersistentArrayMap/EMPTY actions))
- (to-persistent (apply-actions clojure.lang.PersistentArrayMap/EMPTY actions)))
+ (to-persistent (apply-actions clojure.lang.PersistentArrayMap/EMPTY actions))
+ (to-persistent (apply-actions clojure.lang.PersistentArrayMap/EMPTY actions)))
(assert-same-collection
- (to-persistent (apply-actions clojure.lang.PersistentHashMap/EMPTY actions))
- (to-persistent (apply-actions clojure.lang.PersistentHashMap/EMPTY actions))))
+ (to-persistent (apply-actions clojure.lang.PersistentHashMap/EMPTY actions))
+ (to-persistent (apply-actions clojure.lang.PersistentHashMap/EMPTY actions))))
;; *** General ***
@@ -130,19 +130,19 @@
(deftest test-equality
; nil is not equal to any other value
(are [x] (not (= nil x))
- true false
- 0 0.0
- \space
- "" #""
- () [] #{} {}
- (lazy-seq nil) ; SVN 1292: fixed (= (lazy-seq nil) nil)
- (lazy-seq ())
- (lazy-seq [])
- (lazy-seq {})
- (lazy-seq #{})
- (lazy-seq "")
- (lazy-seq (into-array []))
- (new Object) )
+ true false
+ 0 0.0
+ \space
+ "" #""
+ () [] #{} {}
+ (lazy-seq nil) ; SVN 1292: fixed (= (lazy-seq nil) nil)
+ (lazy-seq ())
+ (lazy-seq [])
+ (lazy-seq {})
+ (lazy-seq #{})
+ (lazy-seq "")
+ (lazy-seq (into-array []))
+ (new Object) )
; numbers equality across types (see tests below - NOT IMPLEMENTED YET)
@@ -153,66 +153,66 @@
; vectors equal other seqs by items equality
(are [x y] (= x y)
- '() [] ; regression fixed in r1208; was not equal
- '(1) [1]
- '(1 2) [1 2]
+ '() [] ; regression fixed in r1208; was not equal
+ '(1) [1]
+ '(1 2) [1 2]
- [] '() ; same again, but vectors first
- [1] '(1)
- [1 2] '(1 2) )
+ [] '() ; same again, but vectors first
+ [1] '(1)
+ [1 2] '(1 2) )
(is (not= [1 2] '(2 1))) ; order of items matters
; list and vector vs. set and map
(are [x y] (not= x y)
- ; only () equals []
- () #{}
- () {}
- [] #{}
- [] {}
- #{} {}
- ; only '(1) equals [1]
- '(1) #{1}
- [1] #{1} )
+ ; only () equals []
+ () #{}
+ () {}
+ [] #{}
+ [] {}
+ #{} {}
+ ; only '(1) equals [1]
+ '(1) #{1}
+ [1] #{1} )
; sorted-map, hash-map and array-map - classes differ, but content is equal
-;; TODO: reimplement all-are with new do-template?
-;; (all-are (not= (class _1) (class _2))
-;; (sorted-map :a 1)
-;; (hash-map :a 1)
-;; (array-map :a 1))
-;; (all-are (= _1 _2)
-;; (sorted-map)
-;; (hash-map)
-;; (array-map))
-;; (all-are (= _1 _2)
-;; (sorted-map :a 1)
-;; (hash-map :a 1)
-;; (array-map :a 1))
-;; (all-are (= _1 _2)
-;; (sorted-map :a 1 :z 3 :c 2)
-;; (hash-map :a 1 :z 3 :c 2)
-;; (array-map :a 1 :z 3 :c 2))
+ ;; TODO: reimplement all-are with new do-template?
+ ;; (all-are (not= (class _1) (class _2))
+ ;; (sorted-map :a 1)
+ ;; (hash-map :a 1)
+ ;; (array-map :a 1))
+ ;; (all-are (= _1 _2)
+ ;; (sorted-map)
+ ;; (hash-map)
+ ;; (array-map))
+ ;; (all-are (= _1 _2)
+ ;; (sorted-map :a 1)
+ ;; (hash-map :a 1)
+ ;; (array-map :a 1))
+ ;; (all-are (= _1 _2)
+ ;; (sorted-map :a 1 :z 3 :c 2)
+ ;; (hash-map :a 1 :z 3 :c 2)
+ ;; (array-map :a 1 :z 3 :c 2))
; struct-map vs. sorted-map, hash-map and array-map
(are [x] (and (not= (class (struct equality-struct 1 2)) (class x))
(= (struct equality-struct 1 2) x))
- (sorted-map-by compare :a 1 :b 2)
- (sorted-map :a 1 :b 2)
- (hash-map :a 1 :b 2)
- (array-map :a 1 :b 2))
+ (sorted-map-by compare :a 1 :b 2)
+ (sorted-map :a 1 :b 2)
+ (hash-map :a 1 :b 2)
+ (array-map :a 1 :b 2))
(is (not= (sorted-set :a) (sorted-set 1)))
; sorted-set vs. hash-set
(is (not= (class (sorted-set 1)) (class (hash-set 1))))
(are [x y] (= x y)
- (sorted-set-by <) (hash-set)
- (sorted-set-by < 1) (hash-set 1)
- (sorted-set-by < 3 2 1) (hash-set 3 2 1)
- (sorted-set) (hash-set)
- (sorted-set 1) (hash-set 1)
- (sorted-set 3 2 1) (hash-set 3 2 1) ))
+ (sorted-set-by <) (hash-set)
+ (sorted-set-by < 1) (hash-set 1)
+ (sorted-set-by < 3 2 1) (hash-set 3 2 1)
+ (sorted-set) (hash-set)
+ (sorted-set 1) (hash-set 1)
+ (sorted-set 3 2 1) (hash-set 3 2 1) ))
;; *** Collections ***
@@ -260,9 +260,9 @@
; different types
(are [x] (= (count [x]) 1)
- nil true false
- 0 0.0 "" \space
- () [] #{} {} ))
+ nil true false
+ 0 0.0 "" \space
+ () [] #{} {} ))
(deftest test-conj
@@ -271,76 +271,76 @@
(is (thrown? ClassCastException (conj (into-array []) 1)))
(are [x y] (= x y)
- (conj nil 1) '(1)
- (conj nil 3 2 1) '(1 2 3)
+ (conj nil 1) '(1)
+ (conj nil 3 2 1) '(1 2 3)
- (conj nil nil) '(nil)
- (conj nil nil nil) '(nil nil)
- (conj nil nil nil 1) '(1 nil nil)
+ (conj nil nil) '(nil)
+ (conj nil nil nil) '(nil nil)
+ (conj nil nil nil 1) '(1 nil nil)
- ; list -> conj puts the item at the front of the list
- (conj () 1) '(1)
- (conj () 1 2) '(2 1)
+ ; list -> conj puts the item at the front of the list
+ (conj () 1) '(1)
+ (conj () 1 2) '(2 1)
- (conj '(2 3) 1) '(1 2 3)
- (conj '(2 3) 1 4 3) '(3 4 1 2 3)
+ (conj '(2 3) 1) '(1 2 3)
+ (conj '(2 3) 1 4 3) '(3 4 1 2 3)
- (conj () nil) '(nil)
- (conj () ()) '(())
+ (conj () nil) '(nil)
+ (conj () ()) '(())
- ; vector -> conj puts the item at the end of the vector
- (conj [] 1) [1]
- (conj [] 1 2) [1 2]
+ ; vector -> conj puts the item at the end of the vector
+ (conj [] 1) [1]
+ (conj [] 1 2) [1 2]
- (conj [2 3] 1) [2 3 1]
- (conj [2 3] 1 4 3) [2 3 1 4 3]
+ (conj [2 3] 1) [2 3 1]
+ (conj [2 3] 1 4 3) [2 3 1 4 3]
- (conj [] nil) [nil]
- (conj [] []) [[]]
+ (conj [] nil) [nil]
+ (conj [] []) [[]]
- ; map -> conj expects another (possibly single entry) map as the item,
- ; and returns a new map which is the old map plus the entries
- ; from the new, which may overwrite entries of the old.
- ; conj also accepts a MapEntry or a vector of two items (key and value).
- (conj {} {}) {}
- (conj {} {:a 1}) {:a 1}
- (conj {} {:a 1 :b 2}) {:a 1 :b 2}
- (conj {} {:a 1 :b 2} {:c 3}) {:a 1 :b 2 :c 3}
- (conj {} {:a 1 :b 2} {:a 3 :c 4}) {:a 3 :b 2 :c 4}
+ ; map -> conj expects another (possibly single entry) map as the item,
+ ; and returns a new map which is the old map plus the entries
+ ; from the new, which may overwrite entries of the old.
+ ; conj also accepts a MapEntry or a vector of two items (key and value).
+ (conj {} {}) {}
+ (conj {} {:a 1}) {:a 1}
+ (conj {} {:a 1 :b 2}) {:a 1 :b 2}
+ (conj {} {:a 1 :b 2} {:c 3}) {:a 1 :b 2 :c 3}
+ (conj {} {:a 1 :b 2} {:a 3 :c 4}) {:a 3 :b 2 :c 4}
- (conj {:a 1} {:a 7}) {:a 7}
- (conj {:a 1} {:b 2}) {:a 1 :b 2}
- (conj {:a 1} {:a 7 :b 2}) {:a 7 :b 2}
- (conj {:a 1} {:a 7 :b 2} {:c 3}) {:a 7 :b 2 :c 3}
- (conj {:a 1} {:a 7 :b 2} {:b 4 :c 5}) {:a 7 :b 4 :c 5}
+ (conj {:a 1} {:a 7}) {:a 7}
+ (conj {:a 1} {:b 2}) {:a 1 :b 2}
+ (conj {:a 1} {:a 7 :b 2}) {:a 7 :b 2}
+ (conj {:a 1} {:a 7 :b 2} {:c 3}) {:a 7 :b 2 :c 3}
+ (conj {:a 1} {:a 7 :b 2} {:b 4 :c 5}) {:a 7 :b 4 :c 5}
- (conj {} (first {:a 1})) {:a 1} ; MapEntry
- (conj {:a 1} (first {:b 2})) {:a 1 :b 2}
- (conj {:a 1} (first {:a 7})) {:a 7}
- (conj {:a 1} (first {:b 2}) (first {:a 5})) {:a 5 :b 2}
+ (conj {} (first {:a 1})) {:a 1} ; MapEntry
+ (conj {:a 1} (first {:b 2})) {:a 1 :b 2}
+ (conj {:a 1} (first {:a 7})) {:a 7}
+ (conj {:a 1} (first {:b 2}) (first {:a 5})) {:a 5 :b 2}
- (conj {} [:a 1]) {:a 1} ; vector
- (conj {:a 1} [:b 2]) {:a 1 :b 2}
- (conj {:a 1} [:a 7]) {:a 7}
- (conj {:a 1} [:b 2] [:a 5]) {:a 5 :b 2}
+ (conj {} [:a 1]) {:a 1} ; vector
+ (conj {:a 1} [:b 2]) {:a 1 :b 2}
+ (conj {:a 1} [:a 7]) {:a 7}
+ (conj {:a 1} [:b 2] [:a 5]) {:a 5 :b 2}
- (conj {} {nil {}}) {nil {}}
- (conj {} {{} nil}) {{} nil}
- (conj {} {{} {}}) {{} {}}
+ (conj {} {nil {}}) {nil {}}
+ (conj {} {{} nil}) {{} nil}
+ (conj {} {{} {}}) {{} {}}
- ; set
- (conj #{} 1) #{1}
- (conj #{} 1 2 3) #{1 2 3}
+ ; set
+ (conj #{} 1) #{1}
+ (conj #{} 1 2 3) #{1 2 3}
- (conj #{2 3} 1) #{3 1 2}
- (conj #{3 2} 1) #{1 2 3}
+ (conj #{2 3} 1) #{3 1 2}
+ (conj #{3 2} 1) #{1 2 3}
- (conj #{2 3} 2) #{2 3}
- (conj #{2 3} 2 3) #{2 3}
- (conj #{2 3} 4 1 2 3) #{1 2 3 4}
+ (conj #{2 3} 2) #{2 3}
+ (conj #{2 3} 2 3) #{2 3}
+ (conj #{2 3} 4 1 2 3) #{1 2 3 4}
- (conj #{} nil) #{nil}
- (conj #{} #{}) #{#{}} ))
+ (conj #{} nil) #{nil}
+ (conj #{} #{}) #{#{}} ))
;; *** Lists and Vectors ***
@@ -351,31 +351,31 @@
(is (thrown? ClassCastException (peek {:a 1})))
(are [x y] (= x y)
- (peek nil) nil
+ (peek nil) nil
- ; list = first
- (peek ()) nil
- (peek '(1)) 1
- (peek '(1 2 3)) 1
+ ; list = first
+ (peek ()) nil
+ (peek '(1)) 1
+ (peek '(1 2 3)) 1
- (peek '(nil)) nil ; special cases
- (peek '(1 nil)) 1
- (peek '(nil 2)) nil
- (peek '(())) ()
- (peek '(() nil)) ()
- (peek '(() 2 nil)) ()
+ (peek '(nil)) nil ; special cases
+ (peek '(1 nil)) 1
+ (peek '(nil 2)) nil
+ (peek '(())) ()
+ (peek '(() nil)) ()
+ (peek '(() 2 nil)) ()
- ; vector = last
- (peek []) nil
- (peek [1]) 1
- (peek [1 2 3]) 3
+ ; vector = last
+ (peek []) nil
+ (peek [1]) 1
+ (peek [1 2 3]) 3
- (peek [nil]) nil ; special cases
- (peek [1 nil]) nil
- (peek [nil 2]) 2
- (peek [[]]) []
- (peek [[] nil]) nil
- (peek [[] 2 nil]) nil ))
+ (peek [nil]) nil ; special cases
+ (peek [1 nil]) nil
+ (peek [nil 2]) 2
+ (peek [[]]) []
+ (peek [[] nil]) nil
+ (peek [[] 2 nil]) nil ))
(deftest test-pop
@@ -388,180 +388,180 @@
(is (thrown? IllegalStateException (pop [])))
(are [x y] (= x y)
- (pop nil) nil
+ (pop nil) nil
- ; list - pop first
- (pop '(1)) ()
- (pop '(1 2 3)) '(2 3)
+ ; list - pop first
+ (pop '(1)) ()
+ (pop '(1 2 3)) '(2 3)
- (pop '(nil)) ()
- (pop '(1 nil)) '(nil)
- (pop '(nil 2)) '(2)
- (pop '(())) ()
- (pop '(() nil)) '(nil)
- (pop '(() 2 nil)) '(2 nil)
+ (pop '(nil)) ()
+ (pop '(1 nil)) '(nil)
+ (pop '(nil 2)) '(2)
+ (pop '(())) ()
+ (pop '(() nil)) '(nil)
+ (pop '(() 2 nil)) '(2 nil)
- ; vector - pop last
- (pop [1]) []
- (pop [1 2 3]) [1 2]
+ ; vector - pop last
+ (pop [1]) []
+ (pop [1 2 3]) [1 2]
- (pop [nil]) []
- (pop [1 nil]) [1]
- (pop [nil 2]) [nil]
- (pop [[]]) []
- (pop [[] nil]) [[]]
- (pop [[] 2 nil]) [[] 2] ))
+ (pop [nil]) []
+ (pop [1 nil]) [1]
+ (pop [nil 2]) [nil]
+ (pop [[]]) []
+ (pop [[] nil]) [[]]
+ (pop [[] 2 nil]) [[] 2] ))
;; *** Lists (IPersistentList) ***
(deftest test-list
(are [x] (list? x)
- ()
- '()
- (list)
- (list 1 2 3) )
+ ()
+ '()
+ (list)
+ (list 1 2 3) )
; order is important
(are [x y] (not (= x y))
- (list 1 2) (list 2 1)
- (list 3 1 2) (list 1 2 3) )
+ (list 1 2) (list 2 1)
+ (list 3 1 2) (list 1 2 3) )
(are [x y] (= x y)
- '() ()
- (list) '()
- (list 1) '(1)
- (list 1 2) '(1 2)
-
- ; nesting
- (list 1 (list 2 3) (list 3 (list 4 5 (list 6 (list 7)))))
- '(1 (2 3) (3 (4 5 (6 (7)))))
-
- ; different data structures
- (list true false nil)
- '(true false nil)
- (list 1 2.5 2/3 "ab" \x 'cd :kw)
- '(1 2.5 2/3 "ab" \x cd :kw)
- (list (list 1 2) [3 4] {:a 1 :b 2} #{:c :d})
- '((1 2) [3 4] {:a 1 :b 2} #{:c :d})
-
- ; evaluation
- (list (+ 1 2) [(+ 2 3) 'a] (list (* 2 3) 8))
- '(3 [5 a] (6 8))
-
- ; special cases
- (list nil) '(nil)
- (list 1 nil) '(1 nil)
- (list nil 2) '(nil 2)
- (list ()) '(())
- (list 1 ()) '(1 ())
- (list () 2) '(() 2) ))
+ '() ()
+ (list) '()
+ (list 1) '(1)
+ (list 1 2) '(1 2)
+
+ ; nesting
+ (list 1 (list 2 3) (list 3 (list 4 5 (list 6 (list 7)))))
+ '(1 (2 3) (3 (4 5 (6 (7)))))
+
+ ; different data structures
+ (list true false nil)
+ '(true false nil)
+ (list 1 2.5 2/3 "ab" \x 'cd :kw)
+ '(1 2.5 2/3 "ab" \x cd :kw)
+ (list (list 1 2) [3 4] {:a 1 :b 2} #{:c :d})
+ '((1 2) [3 4] {:a 1 :b 2} #{:c :d})
+
+ ; evaluation
+ (list (+ 1 2) [(+ 2 3) 'a] (list (* 2 3) 8))
+ '(3 [5 a] (6 8))
+
+ ; special cases
+ (list nil) '(nil)
+ (list 1 nil) '(1 nil)
+ (list nil 2) '(nil 2)
+ (list ()) '(())
+ (list 1 ()) '(1 ())
+ (list () 2) '(() 2) ))
;; *** Maps (IPersistentMap) ***
(deftest test-find
(are [x y] (= x y)
- (find {} :a) nil
+ (find {} :a) nil
- (find {:a 1} :a) [:a 1]
- (find {:a 1} :b) nil
- (find {nil 1} nil) [nil 1]
+ (find {:a 1} :a) [:a 1]
+ (find {:a 1} :b) nil
+ (find {nil 1} nil) [nil 1]
- (find {:a 1 :b 2} :a) [:a 1]
- (find {:a 1 :b 2} :b) [:b 2]
- (find {:a 1 :b 2} :c) nil
+ (find {:a 1 :b 2} :a) [:a 1]
+ (find {:a 1 :b 2} :b) [:b 2]
+ (find {:a 1 :b 2} :c) nil
- (find {} nil) nil
- (find {:a 1} nil) nil
- (find {:a 1 :b 2} nil) nil ))
+ (find {} nil) nil
+ (find {:a 1} nil) nil
+ (find {:a 1 :b 2} nil) nil ))
(deftest test-contains?
; contains? is designed to work preferably on maps and sets
(are [x y] (= x y)
- (contains? {} :a) false
- (contains? {} nil) false
+ (contains? {} :a) false
+ (contains? {} nil) false
- (contains? {:a 1} :a) true
- (contains? {:a 1} :b) false
- (contains? {:a 1} nil) false
- (contains? {nil 1} nil) true
+ (contains? {:a 1} :a) true
+ (contains? {:a 1} :b) false
+ (contains? {:a 1} nil) false
+ (contains? {nil 1} nil) true
- (contains? {:a 1 :b 2} :a) true
- (contains? {:a 1 :b 2} :b) true
- (contains? {:a 1 :b 2} :c) false
- (contains? {:a 1 :b 2} nil) false
+ (contains? {:a 1 :b 2} :a) true
+ (contains? {:a 1 :b 2} :b) true
+ (contains? {:a 1 :b 2} :c) false
+ (contains? {:a 1 :b 2} nil) false
- ; sets
- (contains? #{} 1) false
- (contains? #{} nil) false
+ ; sets
+ (contains? #{} 1) false
+ (contains? #{} nil) false
- (contains? #{1} 1) true
- (contains? #{1} 2) false
- (contains? #{1} nil) false
+ (contains? #{1} 1) true
+ (contains? #{1} 2) false
+ (contains? #{1} nil) false
- (contains? #{1 2 3} 1) true
- (contains? #{1 2 3} 3) true
- (contains? #{1 2 3} 10) false
- (contains? #{1 2 3} nil) false)
+ (contains? #{1 2 3} 1) true
+ (contains? #{1 2 3} 3) true
+ (contains? #{1 2 3} 10) false
+ (contains? #{1 2 3} nil) false)
; contains? also works on java.util.Map and java.util.Set.
(are [x y] (= x y)
- (contains? (java.util.HashMap. {}) :a) false
- (contains? (java.util.HashMap. {}) nil) false
+ (contains? (java.util.HashMap. {}) :a) false
+ (contains? (java.util.HashMap. {}) nil) false
- (contains? (java.util.HashMap. {:a 1}) :a) true
- (contains? (java.util.HashMap. {:a 1}) :b) false
- (contains? (java.util.HashMap. {:a 1}) nil) false
+ (contains? (java.util.HashMap. {:a 1}) :a) true
+ (contains? (java.util.HashMap. {:a 1}) :b) false
+ (contains? (java.util.HashMap. {:a 1}) nil) false
- (contains? (java.util.HashMap. {:a 1 :b 2}) :a) true
- (contains? (java.util.HashMap. {:a 1 :b 2}) :b) true
- (contains? (java.util.HashMap. {:a 1 :b 2}) :c) false
- (contains? (java.util.HashMap. {:a 1 :b 2}) nil) false
+ (contains? (java.util.HashMap. {:a 1 :b 2}) :a) true
+ (contains? (java.util.HashMap. {:a 1 :b 2}) :b) true
+ (contains? (java.util.HashMap. {:a 1 :b 2}) :c) false
+ (contains? (java.util.HashMap. {:a 1 :b 2}) nil) false
- ; sets
- (contains? (java.util.HashSet. #{}) 1) false
- (contains? (java.util.HashSet. #{}) nil) false
+ ; sets
+ (contains? (java.util.HashSet. #{}) 1) false
+ (contains? (java.util.HashSet. #{}) nil) false
- (contains? (java.util.HashSet. #{1}) 1) true
- (contains? (java.util.HashSet. #{1}) 2) false
- (contains? (java.util.HashSet. #{1}) nil) false
+ (contains? (java.util.HashSet. #{1}) 1) true
+ (contains? (java.util.HashSet. #{1}) 2) false
+ (contains? (java.util.HashSet. #{1}) nil) false
- (contains? (java.util.HashSet. #{1 2 3}) 1) true
- (contains? (java.util.HashSet. #{1 2 3}) 3) true
- (contains? (java.util.HashSet. #{1 2 3}) 10) false
- (contains? (java.util.HashSet. #{1 2 3}) nil) false)
+ (contains? (java.util.HashSet. #{1 2 3}) 1) true
+ (contains? (java.util.HashSet. #{1 2 3}) 3) true
+ (contains? (java.util.HashSet. #{1 2 3}) 10) false
+ (contains? (java.util.HashSet. #{1 2 3}) nil) false)
; numerically indexed collections (e.g. vectors and Java arrays)
; => test if the numeric key is WITHIN THE RANGE OF INDEXES
(are [x y] (= x y)
- (contains? [] 0) false
- (contains? [] -1) false
- (contains? [] 1) false
+ (contains? [] 0) false
+ (contains? [] -1) false
+ (contains? [] 1) false
- (contains? [1] 0) true
- (contains? [1] -1) false
- (contains? [1] 1) false
+ (contains? [1] 0) true
+ (contains? [1] -1) false
+ (contains? [1] 1) false
- (contains? [1 2 3] 0) true
- (contains? [1 2 3] 2) true
- (contains? [1 2 3] 3) false
- (contains? [1 2 3] -1) false
+ (contains? [1 2 3] 0) true
+ (contains? [1 2 3] 2) true
+ (contains? [1 2 3] 3) false
+ (contains? [1 2 3] -1) false
- ; arrays
- (contains? (into-array []) 0) false
- (contains? (into-array []) -1) false
- (contains? (into-array []) 1) false
+ ; arrays
+ (contains? (into-array []) 0) false
+ (contains? (into-array []) -1) false
+ (contains? (into-array []) 1) false
- (contains? (into-array [1]) 0) true
- (contains? (into-array [1]) -1) false
- (contains? (into-array [1]) 1) false
+ (contains? (into-array [1]) 0) true
+ (contains? (into-array [1]) -1) false
+ (contains? (into-array [1]) 1) false
- (contains? (into-array [1 2 3]) 0) true
- (contains? (into-array [1 2 3]) 2) true
- (contains? (into-array [1 2 3]) 3) false
- (contains? (into-array [1 2 3]) -1) false)
+ (contains? (into-array [1 2 3]) 0) true
+ (contains? (into-array [1 2 3]) 2) true
+ (contains? (into-array [1 2 3]) 3) false
+ (contains? (into-array [1 2 3]) -1) false)
; 'contains?' will not operate on non-associative things
(are [x] (is (thrown? Exception (contains? x 1)))
@@ -571,27 +571,27 @@
(deftest test-keys
(are [x y] (= x y) ; other than map data structures
- (keys ()) nil
- (keys []) nil
- (keys #{}) nil
- (keys "") nil )
+ (keys ()) nil
+ (keys []) nil
+ (keys #{}) nil
+ (keys "") nil )
(are [x y] (= x y)
- ; (class {:a 1}) => clojure.lang.PersistentArrayMap
- (keys {}) nil
- (keys {:a 1}) '(:a)
- (keys {nil 1}) '(nil)
- (diff (keys {:a 1 :b 2}) '(:a :b)) nil ; (keys {:a 1 :b 2}) '(:a :b)
-
- ; (class (sorted-map :a 1)) => clojure.lang.PersistentTreeMap
- (keys (sorted-map)) nil
- (keys (sorted-map :a 1)) '(:a)
- (diff (keys (sorted-map :a 1 :b 2)) '(:a :b)) nil ; (keys (sorted-map :a 1 :b 2)) '(:a :b)
-
- ; (class (hash-map :a 1)) => clojure.lang.PersistentHashMap
- (keys (hash-map)) nil
- (keys (hash-map :a 1)) '(:a)
- (diff (keys (hash-map :a 1 :b 2)) '(:a :b)) nil ) ; (keys (hash-map :a 1 :b 2)) '(:a :b)
+ ; (class {:a 1}) => clojure.lang.PersistentArrayMap
+ (keys {}) nil
+ (keys {:a 1}) '(:a)
+ (keys {nil 1}) '(nil)
+ (diff (keys {:a 1 :b 2}) '(:a :b)) nil ; (keys {:a 1 :b 2}) '(:a :b)
+
+ ; (class (sorted-map :a 1)) => clojure.lang.PersistentTreeMap
+ (keys (sorted-map)) nil
+ (keys (sorted-map :a 1)) '(:a)
+ (diff (keys (sorted-map :a 1 :b 2)) '(:a :b)) nil ; (keys (sorted-map :a 1 :b 2)) '(:a :b)
+
+ ; (class (hash-map :a 1)) => clojure.lang.PersistentHashMap
+ (keys (hash-map)) nil
+ (keys (hash-map :a 1)) '(:a)
+ (diff (keys (hash-map :a 1 :b 2)) '(:a :b)) nil ) ; (keys (hash-map :a 1 :b 2)) '(:a :b)
(let [m {:a 1 :b 2}
k (keys m)]
@@ -600,27 +600,27 @@
(deftest test-vals
(are [x y] (= x y) ; other than map data structures
- (vals ()) nil
- (vals []) nil
- (vals #{}) nil
- (vals "") nil )
+ (vals ()) nil
+ (vals []) nil
+ (vals #{}) nil
+ (vals "") nil )
(are [x y] (= x y)
- ; (class {:a 1}) => clojure.lang.PersistentArrayMap
- (vals {}) nil
- (vals {:a 1}) '(1)
- (vals {nil 1}) '(1)
- (diff (vals {:a 1 :b 2}) '(1 2)) nil ; (vals {:a 1 :b 2}) '(1 2)
-
- ; (class (sorted-map :a 1)) => clojure.lang.PersistentTreeMap
- (vals (sorted-map)) nil
- (vals (sorted-map :a 1)) '(1)
- (diff (vals (sorted-map :a 1 :b 2)) '(1 2)) nil ; (vals (sorted-map :a 1 :b 2)) '(1 2)
-
- ; (class (hash-map :a 1)) => clojure.lang.PersistentHashMap
- (vals (hash-map)) nil
- (vals (hash-map :a 1)) '(1)
- (diff (vals (hash-map :a 1 :b 2)) '(1 2)) nil ) ; (vals (hash-map :a 1 :b 2)) '(1 2)
+ ; (class {:a 1}) => clojure.lang.PersistentArrayMap
+ (vals {}) nil
+ (vals {:a 1}) '(1)
+ (vals {nil 1}) '(1)
+ (diff (vals {:a 1 :b 2}) '(1 2)) nil ; (vals {:a 1 :b 2}) '(1 2)
+
+ ; (class (sorted-map :a 1)) => clojure.lang.PersistentTreeMap
+ (vals (sorted-map)) nil
+ (vals (sorted-map :a 1)) '(1)
+ (diff (vals (sorted-map :a 1 :b 2)) '(1 2)) nil ; (vals (sorted-map :a 1 :b 2)) '(1 2)
+
+ ; (class (hash-map :a 1)) => clojure.lang.PersistentHashMap
+ (vals (hash-map)) nil
+ (vals (hash-map :a 1)) '(1)
+ (diff (vals (hash-map :a 1 :b 2)) '(1 2)) nil ) ; (vals (hash-map :a 1 :b 2)) '(1 2)
(let [m {:a 1 :b 2}
v (vals m)]
@@ -645,38 +645,38 @@
(deftest test-key
(are [x] (= (key (first (hash-map x :value))) x)
- nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- () '(1 2)
- [] [1 2]
- {} {:a 1 :b 2}
- #{} #{1 2} ))
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () '(1 2)
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2} ))
(deftest test-val
(are [x] (= (val (first (hash-map :key x))) x)
- nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- () '(1 2)
- [] [1 2]
- {} {:a 1 :b 2}
- #{} #{1 2} ))
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () '(1 2)
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2} ))
(deftest test-get
(let [m {:a 1, :b 2, :c {:d 3, :e 4}, :f nil, :g false, nil {:h 5}}]
@@ -736,53 +736,53 @@
(deftest test-hash-set
(are [x] (set? x)
- #{}
- #{1 2}
- (hash-set)
- (hash-set 1 2) )
+ #{}
+ #{1 2}
+ (hash-set)
+ (hash-set 1 2) )
; order isn't important
(are [x y] (= x y)
- #{1 2} #{2 1}
- #{3 1 2} #{1 2 3}
- (hash-set 1 2) (hash-set 2 1)
- (hash-set 3 1 2) (hash-set 1 2 3) )
+ #{1 2} #{2 1}
+ #{3 1 2} #{1 2 3}
+ (hash-set 1 2) (hash-set 2 1)
+ (hash-set 3 1 2) (hash-set 1 2 3) )
(are [x y] (= x y)
- ; equal classes
- (class #{}) (class (hash-set))
- (class #{1 2}) (class (hash-set 1 2))
-
- ; creating
- (hash-set) #{}
- (hash-set 1) #{1}
- (hash-set 1 2) #{1 2}
-
- ; nesting
- (hash-set 1 (hash-set 2 3) (hash-set 3 (hash-set 4 5 (hash-set 6 (hash-set 7)))))
- #{1 #{2 3} #{3 #{4 5 #{6 #{7}}}}}
-
- ; different data structures
- (hash-set true false nil)
- #{true false nil}
- (hash-set 1 2.5 2/3 "ab" \x 'cd :kw)
- #{1 2.5 2/3 "ab" \x 'cd :kw}
- (hash-set (list 1 2) [3 4] {:a 1 :b 2} #{:c :d})
- #{'(1 2) [3 4] {:a 1 :b 2} #{:c :d}}
-
- ; evaluation
- (hash-set (+ 1 2) [(+ 2 3) :a] (hash-set (* 2 3) 8))
- #{3 [5 :a] #{6 8}}
-
- ; special cases
- (hash-set nil) #{nil}
- (hash-set 1 nil) #{1 nil}
- (hash-set nil 2) #{nil 2}
- (hash-set #{}) #{#{}}
- (hash-set 1 #{}) #{1 #{}}
- (hash-set #{} 2) #{#{} 2}
- (hash-set (Integer. -1)) (hash-set (Long. -1))))
+ ; equal classes
+ (class #{}) (class (hash-set))
+ (class #{1 2}) (class (hash-set 1 2))
+
+ ; creating
+ (hash-set) #{}
+ (hash-set 1) #{1}
+ (hash-set 1 2) #{1 2}
+
+ ; nesting
+ (hash-set 1 (hash-set 2 3) (hash-set 3 (hash-set 4 5 (hash-set 6 (hash-set 7)))))
+ #{1 #{2 3} #{3 #{4 5 #{6 #{7}}}}}
+
+ ; different data structures
+ (hash-set true false nil)
+ #{true false nil}
+ (hash-set 1 2.5 2/3 "ab" \x 'cd :kw)
+ #{1 2.5 2/3 "ab" \x 'cd :kw}
+ (hash-set (list 1 2) [3 4] {:a 1 :b 2} #{:c :d})
+ #{'(1 2) [3 4] {:a 1 :b 2} #{:c :d}}
+
+ ; evaluation
+ (hash-set (+ 1 2) [(+ 2 3) :a] (hash-set (* 2 3) 8))
+ #{3 [5 :a] #{6 8}}
+
+ ; special cases
+ (hash-set nil) #{nil}
+ (hash-set 1 nil) #{1 nil}
+ (hash-set nil 2) #{nil 2}
+ (hash-set #{}) #{#{}}
+ (hash-set 1 #{}) #{1 #{}}
+ (hash-set #{} 2) #{#{} 2}
+ (hash-set (Integer. -1)) (hash-set (Long. -1))))
(deftest test-sorted-set
@@ -798,18 +798,18 @@
; equal and unique
(are [x] (and (= (sorted-set x) #{x})
(= (sorted-set x x) (sorted-set x)))
- nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- [] [1 2]
- )
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ [] [1 2]
+ )
; cannot be cast to java.lang.Comparable
(is (thrown? ClassCastException (sorted-set ())))
(is (thrown? ClassCastException (sorted-set {})))
@@ -819,19 +819,19 @@
(is (thrown? ClassCastException (sorted-set #{1 2} #{1 2})))
(are [x y] (= x y)
- ; generating
- (sorted-set) #{}
- (sorted-set 1) #{1}
- (sorted-set 1 2) #{1 2}
+ ; generating
+ (sorted-set) #{}
+ (sorted-set 1) #{1}
+ (sorted-set 1 2) #{1 2}
- ; sorting
- (seq (sorted-set 5 4 3 2 1)) '(1 2 3 4 5)
+ ; sorting
+ (seq (sorted-set 5 4 3 2 1)) '(1 2 3 4 5)
- ; special cases
- (sorted-set nil) #{nil}
- (sorted-set 1 nil) #{nil 1}
- (sorted-set nil 2) #{nil 2}
- (sorted-set []) #{[]} ))
+ ; special cases
+ (sorted-set nil) #{nil}
+ (sorted-set 1 nil) #{nil 1}
+ (sorted-set nil 2) #{nil 2}
+ (sorted-set []) #{[]} ))
(deftest test-sorted-set-by
@@ -849,21 +849,21 @@
; equal and unique
(are [x] (and (= (sorted-set-by compare x) #{x})
(= (sorted-set-by compare x x) (sorted-set-by compare x)))
- nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- () ; '(1 2)
- [] [1 2]
- {} ; {:a 1 :b 2}
- #{} ; #{1 2}
- )
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () ; '(1 2)
+ [] [1 2]
+ {} ; {:a 1 :b 2}
+ #{} ; #{1 2}
+ )
; cannot be cast to java.lang.Comparable
; NB: not a ClassCastException, but a RuntimeException is thrown,
; requires discussion on whether this should be symmetric with test-sorted-set
@@ -872,67 +872,67 @@
(is (thrown? Exception (sorted-set-by compare #{1 2} #{1 2})))
(are [x y] (= x y)
- ; generating
- (sorted-set-by >) #{}
- (sorted-set-by > 1) #{1}
- (sorted-set-by > 1 2) #{1 2}
+ ; generating
+ (sorted-set-by >) #{}
+ (sorted-set-by > 1) #{1}
+ (sorted-set-by > 1 2) #{1 2}
- ; sorting
- (seq (sorted-set-by < 5 4 3 2 1)) '(1 2 3 4 5)
+ ; sorting
+ (seq (sorted-set-by < 5 4 3 2 1)) '(1 2 3 4 5)
- ; special cases
- (sorted-set-by compare nil) #{nil}
- (sorted-set-by compare 1 nil) #{nil 1}
- (sorted-set-by compare nil 2) #{nil 2}
- (sorted-set-by compare #{}) #{#{}} ))
+ ; special cases
+ (sorted-set-by compare nil) #{nil}
+ (sorted-set-by compare 1 nil) #{nil 1}
+ (sorted-set-by compare nil 2) #{nil 2}
+ (sorted-set-by compare #{}) #{#{}} ))
(deftest test-set
; set?
(are [x] (set? (set x))
- () '(1 2)
- [] [1 2]
- #{} #{1 2}
- {} {:a 1 :b 2}
- (into-array []) (into-array [1 2])
- "" "abc" )
+ () '(1 2)
+ [] [1 2]
+ #{} #{1 2}
+ {} {:a 1 :b 2}
+ (into-array []) (into-array [1 2])
+ "" "abc" )
; unique
(are [x] (= (set [x x]) #{x})
- nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- () '(1 2)
- [] [1 2]
- {} {:a 1 :b 2}
- #{} #{1 2} )
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () '(1 2)
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2} )
; conversion
(are [x y] (= (set x) y)
- () #{}
- '(1 2) #{1 2}
+ () #{}
+ '(1 2) #{1 2}
- [] #{}
- [1 2] #{1 2}
+ [] #{}
+ [1 2] #{1 2}
- #{} #{} ; identity
- #{1 2} #{1 2} ; identity
+ #{} #{} ; identity
+ #{1 2} #{1 2} ; identity
- {} #{}
- {:a 1 :b 2} #{[:a 1] [:b 2]}
+ {} #{}
+ {:a 1 :b 2} #{[:a 1] [:b 2]}
- (into-array []) #{}
- (into-array [1 2]) #{1 2}
+ (into-array []) #{}
+ (into-array [1 2]) #{1 2}
- "" #{}
- "abc" #{\a \b \c} ))
+ "" #{}
+ "abc" #{\a \b \c} ))
(deftest test-disj
@@ -943,54 +943,54 @@
; identity
(are [x] (= (disj x) x)
- nil
- #{}
- #{1 2 3}
- ; different data types
- #{nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- [] [1 2]
- {} {:a 1 :b 2}
- #{} #{1 2}} )
+ nil
+ #{}
+ #{1 2 3}
+ ; different data types
+ #{nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2}} )
; type identity
(are [x] (= (class (disj x)) (class x))
- (hash-set)
- (hash-set 1 2)
- (sorted-set)
- (sorted-set 1 2) )
+ (hash-set)
+ (hash-set 1 2)
+ (sorted-set)
+ (sorted-set 1 2) )
(are [x y] (= x y)
- (disj nil :a) nil
- (disj nil :a :b) nil
+ (disj nil :a) nil
+ (disj nil :a :b) nil
- (disj #{} :a) #{}
- (disj #{} :a :b) #{}
+ (disj #{} :a) #{}
+ (disj #{} :a :b) #{}
- (disj #{:a} :a) #{}
- (disj #{:a} :a :b) #{}
- (disj #{:a} :c) #{:a}
+ (disj #{:a} :a) #{}
+ (disj #{:a} :a :b) #{}
+ (disj #{:a} :c) #{:a}
- (disj #{:a :b :c :d} :a) #{:b :c :d}
- (disj #{:a :b :c :d} :a :d) #{:b :c}
- (disj #{:a :b :c :d} :a :b :c) #{:d}
- (disj #{:a :b :c :d} :d :a :c :b) #{}
+ (disj #{:a :b :c :d} :a) #{:b :c :d}
+ (disj #{:a :b :c :d} :a :d) #{:b :c}
+ (disj #{:a :b :c :d} :a :b :c) #{:d}
+ (disj #{:a :b :c :d} :d :a :c :b) #{}
- (disj #{nil} :a) #{nil}
- (disj #{nil} #{}) #{nil}
- (disj #{nil} nil) #{}
+ (disj #{nil} :a) #{nil}
+ (disj #{nil} #{}) #{nil}
+ (disj #{nil} nil) #{}
- (disj #{#{}} nil) #{#{}}
- (disj #{#{}} #{}) #{}
- (disj #{#{nil}} #{nil}) #{} ))
+ (disj #{#{}} nil) #{#{}}
+ (disj #{#{}} #{}) #{}
+ (disj #{#{nil}} #{nil}) #{} ))
;; *** Queues ***
@@ -1117,20 +1117,20 @@
(deftest ordered-collection-equality-test
(let [empty-colls [ []
- '()
- (lazy-seq)
- clojure.lang.PersistentQueue/EMPTY
- (vector-of :long) ]]
+ '()
+ (lazy-seq)
+ clojure.lang.PersistentQueue/EMPTY
+ (vector-of :long) ]]
(doseq [c1 empty-colls, c2 empty-colls]
(is-same-collection c1 c2)))
(let [colls1 [ [-3 :a "7th"]
- '(-3 :a "7th")
- (lazy-seq (cons -3
- (lazy-seq (cons :a
- (lazy-seq (cons "7th" nil))))))
- (into clojure.lang.PersistentQueue/EMPTY
- [-3 :a "7th"])
- (sequence (map identity) [-3 :a "7th"]) ]]
+ '(-3 :a "7th")
+ (lazy-seq (cons -3
+ (lazy-seq (cons :a
+ (lazy-seq (cons "7th" nil))))))
+ (into clojure.lang.PersistentQueue/EMPTY
+ [-3 :a "7th"])
+ (sequence (map identity) [-3 :a "7th"]) ]]
(doseq [c1 colls1, c2 colls1]
(is-same-collection c1 c2)))
(is-same-collection [-3 1 7] (vector-of :long -3 1 7)))
@@ -1140,32 +1140,32 @@
(deftest set-equality-test
(let [empty-sets [ #{}
- (hash-set)
- (sorted-set)
- (sorted-set-by case-indendent-string-cmp) ]]
+ (hash-set)
+ (sorted-set)
+ (sorted-set-by case-indendent-string-cmp) ]]
(doseq [s1 empty-sets, s2 empty-sets]
(is-same-collection s1 s2)))
(let [sets1 [ #{"Banana" "apple" "7th"}
- (hash-set "Banana" "apple" "7th")
- (sorted-set "Banana" "apple" "7th")
- (sorted-set-by case-indendent-string-cmp "Banana" "apple" "7th") ]]
+ (hash-set "Banana" "apple" "7th")
+ (sorted-set "Banana" "apple" "7th")
+ (sorted-set-by case-indendent-string-cmp "Banana" "apple" "7th") ]]
(doseq [s1 sets1, s2 sets1]
(is-same-collection s1 s2))))
(deftest map-equality-test
(let [empty-maps [ {}
- (hash-map)
- (array-map)
- (sorted-map)
- (sorted-map-by case-indendent-string-cmp) ]]
+ (hash-map)
+ (array-map)
+ (sorted-map)
+ (sorted-map-by case-indendent-string-cmp) ]]
(doseq [m1 empty-maps, m2 empty-maps]
(is-same-collection m1 m2)))
(let [maps1 [ {"Banana" "like", "apple" "love", "7th" "indifferent"}
- (hash-map "Banana" "like", "apple" "love", "7th" "indifferent")
- (array-map "Banana" "like", "apple" "love", "7th" "indifferent")
- (sorted-map "Banana" "like", "apple" "love", "7th" "indifferent")
- (sorted-map-by case-indendent-string-cmp
- "Banana" "like", "apple" "love", "7th" "indifferent") ]]
+ (hash-map "Banana" "like", "apple" "love", "7th" "indifferent")
+ (array-map "Banana" "like", "apple" "love", "7th" "indifferent")
+ (sorted-map "Banana" "like", "apple" "love", "7th" "indifferent")
+ (sorted-map-by case-indendent-string-cmp
+ "Banana" "like", "apple" "love", "7th" "indifferent") ]]
(doseq [m1 maps1, m2 maps1]
(is-same-collection m1 m2))))
@@ -1223,10 +1223,10 @@
(when-not (.hasNext i)
(throw (ex-info "Iterator exhausted before seq"
{:pos n :seqable seqable :iterable iterable})))
- (when-not (= (.next i) (first s))
- (throw (ex-info "Iterator and seq did not match"
- {:pos n :seqable seqable :iterable iterable})))
- (recur (rest s) (inc n)))
+ (when-not (= (.next i) (first s))
+ (throw (ex-info "Iterator and seq did not match"
+ {:pos n :seqable seqable :iterable iterable})))
+ (recur (rest s) (inc n)))
(when (.hasNext i)
(throw (ex-info "Seq exhausted before iterator"
{:pos n :seqable seqable :iterable iterable}))))))))
diff --git a/test/clojure/test_clojure/data_structures_interop.clj b/test/clojure/test_clojure/data_structures_interop.clj
index 190530de..17e3293e 100644
--- a/test/clojure/test_clojure/data_structures_interop.clj
+++ b/test/clojure/test_clojure/data_structures_interop.clj
@@ -8,9 +8,9 @@
(ns clojure.test-clojure.data-structures-interop
(:require [clojure.test :refer :all]
- [clojure.test.check.generators :as gen]
- [clojure.test.check.properties :as prop]
- [clojure.test.check.clojure-test :refer (defspec)]))
+ [clojure.test.check.generators :as gen]
+ [clojure.test.check.properties :as prop]
+ [clojure.test.check.clojure-test :refer (defspec)]))
(defn gen-range [min max]
(gen/bind (gen/choose min max) (fn [n] (gen/tuple (gen/return n)
diff --git a/test/clojure/test_clojure/def.clj b/test/clojure/test_clojure/def.clj
index 7ea442ef..db5b3bbc 100644
--- a/test/clojure/test_clojure/def.clj
+++ b/test/clojure/test_clojure/def.clj
@@ -8,7 +8,7 @@
(ns clojure.test-clojure.def
(:use clojure.test clojure.test-helper
- clojure.test-clojure.protocols))
+ clojure.test-clojure.protocols))
(deftest defn-error-messages
(testing "multiarity syntax invalid parameter declaration"
diff --git a/test/clojure/test_clojure/delays.clj b/test/clojure/test_clojure/delays.clj
index 0a2a1c99..4bbebc4b 100644
--- a/test/clojure/test_clojure/delays.clj
+++ b/test/clojure/test_clojure/delays.clj
@@ -14,16 +14,16 @@
(let [a (atom 0)
d (delay (swap! a inc))
threads 100
- ^CyclicBarrier barrier (CyclicBarrier. (+ threads 1))]
+ ^CyclicBarrier barrier (CyclicBarrier. (+ threads 1))]
(is (= 0 @a))
(dotimes [_ threads]
- (->
- (Thread.
- (fn []
- (.await barrier)
- (dotimes [_ 10000]
- (is (= 1 @d)))
- (.await barrier)))
+ (->
+ (Thread.
+ (fn []
+ (.await barrier)
+ (dotimes [_ 10000]
+ (is (= 1 @d)))
+ (.await barrier)))
(.start)))
(.await barrier)
(.await barrier)
@@ -50,18 +50,18 @@
@d
(catch Exception e e))
threads 100
- ^CyclicBarrier barrier (CyclicBarrier. (+ threads 1))]
+ ^CyclicBarrier barrier (CyclicBarrier. (+ threads 1))]
(dotimes [_ threads]
- (->
- (Thread.
- (fn []
- (.await barrier)
- (let [first-result (try-call)]
- (dotimes [_ 10000]
- (is (instance? Exception (try-call)))
- (is (identical? first-result (try-call)))))
- (.await barrier)))
- (.start)))
+ (->
+ (Thread.
+ (fn []
+ (.await barrier)
+ (let [first-result (try-call)]
+ (dotimes [_ 10000]
+ (is (instance? Exception (try-call)))
+ (is (identical? first-result (try-call)))))
+ (.await barrier)))
+ (.start)))
(.await barrier)
(.await barrier)
(is (instance? Exception (try-call)))
diff --git a/test/clojure/test_clojure/edn.clj b/test/clojure/test_clojure/edn.clj
index 4d5996c4..919dfb01 100644
--- a/test/clojure/test_clojure/edn.clj
+++ b/test/clojure/test_clojure/edn.clj
@@ -11,8 +11,8 @@
(ns clojure.test-clojure.edn
(:require [clojure.test.generative :refer (defspec)]
- [clojure.test-clojure.generators :as cgen]
- [clojure.edn :as edn]))
+ [clojure.test-clojure.generators :as cgen]
+ [clojure.edn :as edn]))
(defn roundtrip
"Print an object and read it back as edn. Returns rather than throws
@@ -22,8 +22,8 @@
*print-dup* nil
*print-level* nil]
(try
- (-> o pr-str edn/read-string)
- (catch Throwable t t))))
+ (-> o pr-str edn/read-string)
+ (catch Throwable t t))))
(defspec types-that-should-roundtrip
roundtrip
diff --git a/test/clojure/test_clojure/errors.clj b/test/clojure/test_clojure/errors.clj
index cebe0392..8dafbfc9 100644
--- a/test/clojure/test_clojure/errors.clj
+++ b/test/clojure/test_clojure/errors.clj
@@ -43,11 +43,11 @@
(throw (RuntimeException. "fail"))
(catch ArityException e
(is (= 0 (.-actual e))))))
- (is (try
- (macroexpand `(m2 5))
- (throw (RuntimeException. "fail"))
- (catch ArityException e
- (is (= 1 (.-actual e)))))))
+ (is (try
+ (macroexpand `(m2 5))
+ (throw (RuntimeException. "fail"))
+ (catch ArityException e
+ (is (= 1 (.-actual e)))))))
(deftest compile-error-examples
(are [form errtype re] (thrown-with-cause-msg? errtype re (eval form))
@@ -68,23 +68,23 @@
(deftest extract-ex-data
(try
- (throw (ex-info "example error" {:foo 1}))
- (catch Throwable t
- (is (= {:foo 1} (ex-data t)))))
+ (throw (ex-info "example error" {:foo 1}))
+ (catch Throwable t
+ (is (= {:foo 1} (ex-data t)))))
(is (nil? (ex-data (RuntimeException. "example non ex-data")))))
(deftest Throwable->map-test
(testing "base functionality"
(let [{:keys [cause via trace]} (Throwable->map
- (Exception. "I am a string literal"))]
+ (Exception. "I am a string literal"))]
(is (= cause "I am a string literal"))
(is (= 1 (count via)))
(is (vector? via))
(is (= ["I am a string literal"] (map :message via)))))
(testing "causes"
(let [{:keys [cause via trace]} (Throwable->map
- (Exception. "I am not a number"
- (Exception. "double two")))]
+ (Exception. "I am not a number"
+ (Exception. "double two")))]
(is (= cause "double two"))
(is (= ["I am not a number" "double two"]
(map :message via)))))
diff --git a/test/clojure/test_clojure/evaluation.clj b/test/clojure/test_clojure/evaluation.clj
index 7f8cc10a..a4c78030 100644
--- a/test/clojure/test_clojure/evaluation.clj
+++ b/test/clojure/test_clojure/evaluation.clj
@@ -97,16 +97,16 @@
~(if (instance? Exception x) x Exception)
~(if (instance? String x) x nil)))
([re form class msg]
- `(let [ex# (try
- ~form
- (catch ~class e# e#)
- (catch Exception e#
- (let [cause# (.getCause e#)]
- (if (= ~class (class cause#)) cause# (throw e#)))))]
- (is (a-match? ~re (.toString ex#))
- (or ~msg
- (str "Expected exception that matched " (pr-str ~re)
- ", but got exception with message: \"" ex#))))))
+ `(let [ex# (try
+ ~form
+ (catch ~class e# e#)
+ (catch Exception e#
+ (let [cause# (.getCause e#)]
+ (if (= ~class (class cause#)) cause# (throw e#)))))]
+ (is (a-match? ~re (.toString ex#))
+ (or ~msg
+ (str "Expected exception that matched " (pr-str ~re)
+ ", but got exception with message: \"" ex#))))))
(deftest SymbolResolution
(test-that
@@ -164,7 +164,7 @@
(let [if "foo"]
(is (thrown? Compiler$CompilerException (eval 'if)))
- ; Second
+ ; Second
(is (= (eval 'Boolean) (class-for-name "java.lang.Boolean"))))
(let [Boolean "foo"]
(is (= (eval 'Boolean) (class-for-name "java.lang.Boolean"))))
@@ -218,8 +218,8 @@
;aargh, fragile tests, please fix
#_(test-that
- "Non-empty lists are considered calls"
- (is (thrown? Compiler$CompilerException (eval '(1 2 3))))))
+ "Non-empty lists are considered calls"
+ (is (thrown? Compiler$CompilerException (eval '(1 2 3))))))
(deftest Macros)
diff --git a/test/clojure/test_clojure/for.clj b/test/clojure/test_clojure/for.clj
index 6d9dc59e..d15cecc2 100644
--- a/test/clojure/test_clojure/for.clj
+++ b/test/clojure/test_clojure/for.clj
@@ -26,11 +26,11 @@
[9 0] [9 1] [9 2] [9 3] [9 4] [9 5] [9 6] [9 7] [9 8]
[10 0] [10 1] [10 2] [10 3] [10 4] [10 5] [10 6] [10 7] [10 8] [10 9]
[11 0] [11 1] [11 2] [11 3] [11 4] [11 5] [11 6] [11 7] [11 8] [11 9]
- [11 10]
+ [11 10]
[12 0] [12 1] [12 2] [12 3] [12 4] [12 5] [12 6] [12 7] [12 8] [12 9]
- [12 10] [12 11]
+ [12 10] [12 11]
[13 0] [13 1] [13 2] [13 3] [13 4] [13 5] [13 6] [13 7] [13 8] [13 9]
- [13 10] [13 11] [13 12]
+ [13 10] [13 11] [13 12]
[14 0] [14 1] [14 2] [14 3] [14 4] [14 5] [14 6] [14 7] [14 8]))))
(defmacro deftest-both [txt & ises]
diff --git a/test/clojure/test_clojure/genclass.clj b/test/clojure/test_clojure/genclass.clj
index 18e808dc..72325021 100644
--- a/test/clojure/test_clojure/genclass.clj
+++ b/test/clojure/test_clojure/genclass.clj
@@ -18,10 +18,10 @@
ArrayDefInterface
ArrayGenInterface]
- [java.lang.annotation ElementType
- Retention
- RetentionPolicy
- Target]))
+ [java.lang.annotation ElementType
+ Retention
+ RetentionPolicy
+ Target]))
(deftest arg-support
(let [example (ExampleClass.)
@@ -39,33 +39,33 @@
;todo - fix this, it depends on the order of things out of a hash-map
#_(deftest test-annotations
- (let [annot-class ExampleAnnotationClass
- foo-method (.getDeclaredMethod annot-class "foo" (into-array [String]))]
- (testing "Class annotations:"
- (is (= 2 (count (.getDeclaredAnnotations annot-class))))
- (testing "@Deprecated"
- (let [deprecated (.getAnnotation annot-class Deprecated)]
- (is deprecated)))
- (testing "@Target([])"
- (let [resource (.getAnnotation annot-class Target)]
- (is (= 0 (count (.value resource)))))))
- (testing "Method annotations:"
- (testing "@Deprecated void foo(String):"
- (is (= 1 (count (.getDeclaredAnnotations foo-method))))
- (is (.getAnnotation foo-method Deprecated))))
- (testing "Parameter annotations:"
- (let [param-annots (.getParameterAnnotations foo-method)]
- (is (= 1 (alength param-annots)))
- (let [first-param-annots (aget param-annots 0)]
- (is (= 2 (alength first-param-annots)))
- (testing "void foo(@Retention(…) String)"
- (let [retention (aget first-param-annots 0)]
- (is (instance? Retention retention))
- (= RetentionPolicy/SOURCE (.value retention))))
- (testing "void foo(@Target(…) String)"
- (let [target (aget first-param-annots 1)]
- (is (instance? Target target))
- (is (= [ElementType/TYPE ElementType/PARAMETER] (seq (.value target)))))))))))
+ (let [annot-class ExampleAnnotationClass
+ foo-method (.getDeclaredMethod annot-class "foo" (into-array [String]))]
+ (testing "Class annotations:"
+ (is (= 2 (count (.getDeclaredAnnotations annot-class))))
+ (testing "@Deprecated"
+ (let [deprecated (.getAnnotation annot-class Deprecated)]
+ (is deprecated)))
+ (testing "@Target([])"
+ (let [resource (.getAnnotation annot-class Target)]
+ (is (= 0 (count (.value resource)))))))
+ (testing "Method annotations:"
+ (testing "@Deprecated void foo(String):"
+ (is (= 1 (count (.getDeclaredAnnotations foo-method))))
+ (is (.getAnnotation foo-method Deprecated))))
+ (testing "Parameter annotations:"
+ (let [param-annots (.getParameterAnnotations foo-method)]
+ (is (= 1 (alength param-annots)))
+ (let [first-param-annots (aget param-annots 0)]
+ (is (= 2 (alength first-param-annots)))
+ (testing "void foo(@Retention(…) String)"
+ (let [retention (aget first-param-annots 0)]
+ (is (instance? Retention retention))
+ (= RetentionPolicy/SOURCE (.value retention))))
+ (testing "void foo(@Target(…) String)"
+ (let [target (aget first-param-annots 1)]
+ (is (instance? Target target))
+ (is (= [ElementType/TYPE ElementType/PARAMETER] (seq (.value target)))))))))))
(deftest genclass-option-validation
(is (fails-with-cause? IllegalArgumentException #"Not a valid method name: has-hyphen"
diff --git a/test/clojure/test_clojure/genclass/examples.clj b/test/clojure/test_clojure/genclass/examples.clj
index f30c38a0..3df15b10 100644
--- a/test/clojure/test_clojure/genclass/examples.clj
+++ b/test/clojure/test_clojure/genclass/examples.clj
@@ -34,14 +34,14 @@
(gen-class :name ^{Deprecated {}
SuppressWarnings ["Warning1"] ; discarded
java.lang.annotation.Target []}
- clojure.test_clojure.genclass.examples.ExampleAnnotationClass
- :prefix "annot-"
- :methods [[^{Deprecated {}
- Override {}} ;discarded
- foo [^{java.lang.annotation.Retention java.lang.annotation.RetentionPolicy/SOURCE
- java.lang.annotation.Target [java.lang.annotation.ElementType/TYPE
- java.lang.annotation.ElementType/PARAMETER]}
- String] void]])
+ clojure.test_clojure.genclass.examples.ExampleAnnotationClass
+ :prefix "annot-"
+ :methods [[^{Deprecated {}
+ Override {}} ;discarded
+ foo [^{java.lang.annotation.Retention java.lang.annotation.RetentionPolicy/SOURCE
+ java.lang.annotation.Target [java.lang.annotation.ElementType/TYPE
+ java.lang.annotation.ElementType/PARAMETER]}
+ String] void]])
(gen-class :name clojure.test_clojure.genclass.examples.ProtectedFinalTester
:extends java.lang.ClassLoader
diff --git a/test/clojure/test_clojure/generators.clj b/test/clojure/test_clojure/generators.clj
index ea319748..44293482 100644
--- a/test/clojure/test_clojure/generators.clj
+++ b/test/clojure/test_clojure/generators.clj
@@ -29,18 +29,18 @@
_ (doseq [ns nses] (binding [*ns* ns] (refer 'clojure.core)))
make-in-ns (fn [ns src] (binding [*ns* ns] (eval src)))
vars (->> (mapcat
- (fn [ns]
- (map
- #(make-in-ns ns (var-source %))
- (range vars-per-ns)))
- nses)
+ (fn [ns]
+ (map
+ #(make-in-ns ns (var-source %))
+ (range vars-per-ns)))
+ nses)
(into []))
records (->> (mapcat
- (fn [ns]
- (map
- #(make-in-ns ns (record-source %))
- (range records-per-ns)))
- nses)
+ (fn [ns]
+ (map
+ #(make-in-ns ns (record-source %))
+ (range records-per-ns)))
+ nses)
(into []))]
{:nses nses
:vars vars
@@ -63,8 +63,8 @@
(def keyword-pool
(delay
- (binding [gen/*rnd* (java.util.Random. 42)]
- (into [] (repeatedly 1000 gen/keyword)))))
+ (binding [gen/*rnd* (java.util.Random. 42)]
+ (into [] (repeatedly 1000 gen/keyword)))))
(defn keyword-from-pool
[]
@@ -72,8 +72,8 @@
(def symbol-pool
(delay
- (binding [gen/*rnd* (java.util.Random. 42)]
- (into [] (repeatedly 1000 gen/symbol)))))
+ (binding [gen/*rnd* (java.util.Random. 42)]
+ (into [] (repeatedly 1000 gen/symbol)))))
(defn symbol-from-pool
[]
diff --git a/test/clojure/test_clojure/java/io.clj b/test/clojure/test_clojure/java/io.clj
index b83c63d3..ce59e2c6 100644
--- a/test/clojure/test_clojure/java/io.clj
+++ b/test/clojure/test_clojure/java/io.clj
@@ -8,12 +8,12 @@
(ns clojure.test-clojure.java.io
(:use clojure.test clojure.java.io
- [clojure.test-helper :only [platform-newlines]])
+ [clojure.test-helper :only [platform-newlines]])
(:import (java.io File BufferedInputStream
FileInputStream InputStreamReader InputStream
FileOutputStream OutputStreamWriter OutputStream
ByteArrayInputStream ByteArrayOutputStream)
- (java.net URL URI Socket ServerSocket)))
+ (java.net URL URI Socket ServerSocket)))
(defn temp-file
[prefix suffix]
@@ -22,19 +22,19 @@
;; does not work on IBM JDK
#_(deftest test-spit-and-slurp
- (let [f (temp-file "clojure.java.io" "test")
- content (apply str (concat "a" (repeat 500 "\u226a\ud83d\ude03")))]
- (spit f content)
- (is (= content (slurp f)))
- ;; UTF-16 must be last for the following test
- (doseq [enc [ "UTF-8" "UTF-16BE" "UTF-16LE" "UTF-16" ]]
- (spit f content :encoding enc)
- (is (= content (slurp f :encoding enc))))
- (testing "deprecated arity"
- (is (=
- (platform-newlines "WARNING: (slurp f enc) is deprecated, use (slurp f :encoding enc).\n")
- (with-out-str
- (is (= content (slurp f "UTF-16")))))))))
+ (let [f (temp-file "clojure.java.io" "test")
+ content (apply str (concat "a" (repeat 500 "\u226a\ud83d\ude03")))]
+ (spit f content)
+ (is (= content (slurp f)))
+ ;; UTF-16 must be last for the following test
+ (doseq [enc [ "UTF-8" "UTF-16BE" "UTF-16LE" "UTF-16" ]]
+ (spit f content :encoding enc)
+ (is (= content (slurp f :encoding enc))))
+ (testing "deprecated arity"
+ (is (=
+ (platform-newlines "WARNING: (slurp f enc) is deprecated, use (slurp f :encoding enc).\n")
+ (with-out-str
+ (is (= content (slurp f "UTF-16")))))))))
(deftest test-streams-defaults
(let [f (temp-file "clojure.java.io" "test-reader-writer")
@@ -58,7 +58,7 @@
(is (= content (slurp (.getBytes content "UTF-8"))))
(is (= content (slurp (.toCharArray content))))
(finally
- (.delete f)))))
+ (.delete f)))))
(deftest test-streams-nil
(is (thrown-with-msg? IllegalArgumentException #"Cannot open.*nil" (reader nil)))
@@ -93,37 +93,37 @@
(deftest test-copy
(dorun
- (for [{:keys [in out flush] :as test}
- [{:in :i :out :o}
- {:in :i :out :w}
- {:in :r :out :o}
- {:in :r :out :w}
- {:in :cs :out :o}
- {:in :cs :out :w}
- {:in :bs :out :o}
- {:in :bs :out :w}]
+ (for [{:keys [in out flush] :as test}
+ [{:in :i :out :o}
+ {:in :i :out :w}
+ {:in :r :out :o}
+ {:in :r :out :w}
+ {:in :cs :out :o}
+ {:in :cs :out :w}
+ {:in :bs :out :o}
+ {:in :bs :out :w}]
- opts
- [{} {:buffer-size 16} {:buffer-size 256}]]
- (let [{:keys [s o] :as d} (data-fixture "UTF-8")]
- (apply copy (in d) (out d) (flatten (vec opts)))
- #_(when (= out :w) (.flush (:w d)))
- (.flush (out d))
- (bytes-should-equal (.getBytes s "UTF-8")
- (.toByteArray o)
- (str "combination " test opts))))))
+ opts
+ [{} {:buffer-size 16} {:buffer-size 256}]]
+ (let [{:keys [s o] :as d} (data-fixture "UTF-8")]
+ (apply copy (in d) (out d) (flatten (vec opts)))
+ #_(when (= out :w) (.flush (:w d)))
+ (.flush (out d))
+ (bytes-should-equal (.getBytes s "UTF-8")
+ (.toByteArray o)
+ (str "combination " test opts))))))
;; does not work on IBM JDK
#_(deftest test-copy-encodings
- (doseq [enc [ "UTF-8" "UTF-16" "UTF-16BE" "UTF-16LE" ]]
- (testing (str "from inputstream " enc " to writer UTF-8")
- (let [{:keys [i s o w bs]} (data-fixture enc)]
- (copy i w :encoding enc :buffer-size 16)
- (.flush w)
- (bytes-should-equal (.getBytes s "UTF-8") (.toByteArray o) "")))
- (testing (str "from reader UTF-8 to output-stream " enc)
- (let [{:keys [r o s]} (data-fixture "UTF-8")]
- (copy r o :encoding enc :buffer-size 16)
- (bytes-should-equal (.getBytes s enc) (.toByteArray o) "")))))
+ (doseq [enc [ "UTF-8" "UTF-16" "UTF-16BE" "UTF-16LE" ]]
+ (testing (str "from inputstream " enc " to writer UTF-8")
+ (let [{:keys [i s o w bs]} (data-fixture enc)]
+ (copy i w :encoding enc :buffer-size 16)
+ (.flush w)
+ (bytes-should-equal (.getBytes s "UTF-8") (.toByteArray o) "")))
+ (testing (str "from reader UTF-8 to output-stream " enc)
+ (let [{:keys [r o s]} (data-fixture "UTF-8")]
+ (copy r o :encoding enc :buffer-size 16)
+ (bytes-should-equal (.getBytes s enc) (.toByteArray o) "")))))
(deftest test-as-file
(are [result input] (= result (as-file input))
diff --git a/test/clojure/test_clojure/java/javadoc.clj b/test/clojure/test_clojure/java/javadoc.clj
index 575314cf..095553c9 100644
--- a/test/clojure/test_clojure/java/javadoc.clj
+++ b/test/clojure/test_clojure/java/javadoc.clj
@@ -8,7 +8,7 @@
(ns clojure.test-clojure.java.javadoc
(:use clojure.test
- [clojure.java.javadoc :as j])
+ [clojure.java.javadoc :as j])
(:import (java.io File)))
(deftest javadoc-url-test
diff --git a/test/clojure/test_clojure/java/shell.clj b/test/clojure/test_clojure/java/shell.clj
index 56e3ff04..15fdd852 100644
--- a/test/clojure/test_clojure/java/shell.clj
+++ b/test/clojure/test_clojure/java/shell.clj
@@ -8,7 +8,7 @@
(ns clojure.test-clojure.java.shell
(:use clojure.test
- [clojure.java.shell :as sh])
+ [clojure.java.shell :as sh])
(:import (java.io File)))
(def platform-enc (.name (java.nio.charset.Charset/defaultCharset)))
diff --git a/test/clojure/test_clojure/java_interop.clj b/test/clojure/test_clojure/java_interop.clj
index d36ffc1e..cd7ce429 100644
--- a/test/clojure/test_clojure/java_interop.clj
+++ b/test/clojure/test_clojure/java_interop.clj
@@ -21,41 +21,41 @@
(deftest test-dot
; (.instanceMember instance args*)
(are [x] (= x "FRED")
- (.toUpperCase "fred")
- (. "fred" toUpperCase)
- (. "fred" (toUpperCase)) )
+ (.toUpperCase "fred")
+ (. "fred" toUpperCase)
+ (. "fred" (toUpperCase)) )
(are [x] (= x true)
- (.startsWith "abcde" "ab")
- (. "abcde" startsWith "ab")
- (. "abcde" (startsWith "ab")) )
+ (.startsWith "abcde" "ab")
+ (. "abcde" startsWith "ab")
+ (. "abcde" (startsWith "ab")) )
; (.instanceMember Classname args*)
(are [x] (= x "java.lang.String")
- (.getName String)
- (. (identity String) getName)
- (. (identity String) (getName)) )
+ (.getName String)
+ (. (identity String) getName)
+ (. (identity String) (getName)) )
; (Classname/staticMethod args*)
(are [x] (= x 7)
- (Math/abs -7)
- (. Math abs -7)
- (. Math (abs -7)) )
+ (Math/abs -7)
+ (. Math abs -7)
+ (. Math (abs -7)) )
; (. target -prop)
(let [p (java.awt.Point. 1 2)]
(are [x y] (= x y)
- 1 (.-x p)
- 2 (.-y p)
- 1 (. p -x)
- 2 (. p -y)
- 1 (. (java.awt.Point. 1 2) -x)
- 2 (. (java.awt.Point. 1 2) -y)))
+ 1 (.-x p)
+ 2 (.-y p)
+ 1 (. p -x)
+ 2 (. p -y)
+ 1 (. (java.awt.Point. 1 2) -x)
+ 2 (. (java.awt.Point. 1 2) -y)))
; Classname/staticField
(are [x] (= x 2147483647)
- Integer/MAX_VALUE
- (. Integer MAX_VALUE) ))
+ Integer/MAX_VALUE
+ (. Integer MAX_VALUE) ))
(definterface I (a []))
(deftype T [a] I (a [_] "method"))
@@ -78,43 +78,43 @@
(.put "a" 1)
(.put "b" 2))]
(are [x y] (= x y)
- (class m) java.util.HashMap
- m {"a" 1 "b" 2} )))
+ (class m) java.util.HashMap
+ m {"a" 1 "b" 2} )))
(deftest test-new
; Integer
(are [expr cls value] (and (= (class expr) cls)
- (= expr value))
- (new java.lang.Integer 42) java.lang.Integer 42
- (java.lang.Integer. 123) java.lang.Integer 123 )
+ (= expr value))
+ (new java.lang.Integer 42) java.lang.Integer 42
+ (java.lang.Integer. 123) java.lang.Integer 123 )
; Date
(are [x] (= (class x) java.util.Date)
- (new java.util.Date)
- (java.util.Date.) ))
+ (new java.util.Date)
+ (java.util.Date.) ))
(deftest test-instance?
; evaluation
(are [x y] (= x y)
- (instance? java.lang.Integer (+ 1 2)) false
- (instance? java.lang.Long (+ 1 2)) true )
+ (instance? java.lang.Integer (+ 1 2)) false
+ (instance? java.lang.Long (+ 1 2)) true )
; different types
(are [type literal] (instance? literal type)
- 1 java.lang.Long
- 1.0 java.lang.Double
- 1M java.math.BigDecimal
- \a java.lang.Character
- "a" java.lang.String )
+ 1 java.lang.Long
+ 1.0 java.lang.Double
+ 1M java.math.BigDecimal
+ \a java.lang.Character
+ "a" java.lang.String )
; it is a Long, nothing else
(are [x y] (= (instance? x 42) y)
- java.lang.Integer false
- java.lang.Long true
- java.lang.Character false
- java.lang.String false )
+ java.lang.Integer false
+ java.lang.Long true
+ java.lang.Character false
+ java.lang.String false )
; test compiler macro
(is (let [Long String] (instance? Long "abc")))
@@ -134,22 +134,22 @@
(deftest test-bean
(let [b (bean java.awt.Color/black)]
(are [x y] (= x y)
- (map? b) true
+ (map? b) true
- (:red b) 0
- (:green b) 0
- (:blue b) 0
- (:RGB b) -16777216
+ (:red b) 0
+ (:green b) 0
+ (:blue b) 0
+ (:RGB b) -16777216
- (:alpha b) 255
- (:transparency b) 1
+ (:alpha b) 255
+ (:transparency b) 1
- (:missing b) nil
- (:missing b :default) :default
- (get b :missing) nil
- (get b :missing :default) :default
+ (:missing b) nil
+ (:missing b :default) :default
+ (get b :missing) nil
+ (get b :missing :default) :default
- (:class b) java.awt.Color )))
+ (:class b) java.awt.Color )))
(deftest test-iterable-bean
(let [b (bean (java.util.Date.))]
@@ -162,17 +162,17 @@
(deftest test-proxy-chain
(testing "That the proxy functions can chain"
(are [x y] (= x y)
- (-> (get-proxy-class Object)
- construct-proxy
- (init-proxy {})
- (update-proxy {"toString" (fn [_] "chain chain chain")})
- str)
- "chain chain chain"
+ (-> (get-proxy-class Object)
+ construct-proxy
+ (init-proxy {})
+ (update-proxy {"toString" (fn [_] "chain chain chain")})
+ str)
+ "chain chain chain"
- (-> (proxy [Object] [] (toString [] "superfuzz bigmuff"))
- (update-proxy {"toString" (fn [_] "chain chain chain")})
- str)
- "chain chain chain")))
+ (-> (proxy [Object] [] (toString [] "superfuzz bigmuff"))
+ (update-proxy {"toString" (fn [_] "chain chain chain")})
+ str)
+ "chain chain chain")))
;; serialized-proxy can be regenerated using a modified version of
@@ -189,9 +189,9 @@
(def serialized-proxies
{"1.8" "rO0ABXNyAEVjbG9qdXJlLmluc3BlY3Rvci5wcm94eSRqYXZheC5zd2luZy50YWJsZS5BYnN0cmFjdFRhYmxlTW9kZWwkZmYxOTI3NGFydNi2XwhNRQIAAUwADl9fY2xvanVyZUZuTWFwdAAdTGNsb2p1cmUvbGFuZy9JUGVyc2lzdGVudE1hcDt4cgAkamF2YXguc3dpbmcudGFibGUuQWJzdHJhY3RUYWJsZU1vZGVscsvrOK4B/74CAAFMAAxsaXN0ZW5lckxpc3R0ACVMamF2YXgvc3dpbmcvZXZlbnQvRXZlbnRMaXN0ZW5lckxpc3Q7eHBzcgAjamF2YXguc3dpbmcuZXZlbnQuRXZlbnRMaXN0ZW5lckxpc3SxNsZ9hOrWRAMAAHhwcHhzcgAfY2xvanVyZS5sYW5nLlBlcnNpc3RlbnRBcnJheU1hcOM3cA+YxfTfAgACTAAFX21ldGFxAH4AAVsABWFycmF5dAATW0xqYXZhL2xhbmcvT2JqZWN0O3hyABtjbG9qdXJlLmxhbmcuQVBlcnNpc3RlbnRNYXBdfC8DdCByewIAAkkABV9oYXNoSQAHX2hhc2hlcXhwAAAAAAAAAABwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABnQADmdldENvbHVtbkNvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTbQ1M9FYoOj9wIAAHhyABZjbG9qdXJlLmxhbmcuQUZ1bmN0aW9uPgZwnJ5G/csCAAFMABFfX21ldGhvZEltcGxDYWNoZXQAHkxjbG9qdXJlL2xhbmcvTWV0aG9kSW1wbENhY2hlO3hwcHQAC2dldFJvd0NvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTgf1DHD2//pRAIAAUwABW5yb3dzdAASTGphdmEvbGFuZy9PYmplY3Q7eHEAfgAPcHB0AApnZXRWYWx1ZUF0c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNjBYQ6uzEwbd+gIAAkwACWdldF9sYWJlbHEAfgAUTAAJZ2V0X3ZhbHVlcQB+ABR4cQB+AA9wcHA="
- "9" "rO0ABXNyAEVjbG9qdXJlLmluc3BlY3Rvci5wcm94eSRqYXZheC5zd2luZy50YWJsZS5BYnN0cmFjdFRhYmxlTW9kZWwkZmYxOTI3NGFydNi2XwhNRQIAAUwADl9fY2xvanVyZUZuTWFwdAAdTGNsb2p1cmUvbGFuZy9JUGVyc2lzdGVudE1hcDt4cgAkamF2YXguc3dpbmcudGFibGUuQWJzdHJhY3RUYWJsZU1vZGVscsvrOK4B/74CAAFMAAxsaXN0ZW5lckxpc3R0ACVMamF2YXgvc3dpbmcvZXZlbnQvRXZlbnRMaXN0ZW5lckxpc3Q7eHBzcgAjamF2YXguc3dpbmcuZXZlbnQuRXZlbnRMaXN0ZW5lckxpc3SxNsZ9hOrWRAMAAHhwcHhzcgAfY2xvanVyZS5sYW5nLlBlcnNpc3RlbnRBcnJheU1hcOM3cA+YxfTfAgACTAAFX21ldGFxAH4AAVsABWFycmF5dAATW0xqYXZhL2xhbmcvT2JqZWN0O3hyABtjbG9qdXJlLmxhbmcuQVBlcnNpc3RlbnRNYXBdfC8DdCByewIAAkkABV9oYXNoSQAHX2hhc2hlcXhwAAAAAAAAAABwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABnQADmdldENvbHVtbkNvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTbQ1M9FYoOj9wIAAHhyABZjbG9qdXJlLmxhbmcuQUZ1bmN0aW9uPgZwnJ5G/csCAAFMABFfX21ldGhvZEltcGxDYWNoZXQAHkxjbG9qdXJlL2xhbmcvTWV0aG9kSW1wbENhY2hlO3hwcHQAC2dldFJvd0NvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTgf1DHD2//pRAIAAUwABW5yb3dzdAASTGphdmEvbGFuZy9PYmplY3Q7eHEAfgAPcHB0AApnZXRWYWx1ZUF0c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNjBYQ6uzEwbd+gIAAkwACWdldF9sYWJlbHEAfgAUTAAJZ2V0X3ZhbHVlcQB+ABR4cQB+AA9wcHA="
- "10" "rO0ABXNyAEVjbG9qdXJlLmluc3BlY3Rvci5wcm94eSRqYXZheC5zd2luZy50YWJsZS5BYnN0cmFjdFRhYmxlTW9kZWwkZmYxOTI3NGFydNi2XwhNRQIAAUwADl9fY2xvanVyZUZuTWFwdAAdTGNsb2p1cmUvbGFuZy9JUGVyc2lzdGVudE1hcDt4cgAkamF2YXguc3dpbmcudGFibGUuQWJzdHJhY3RUYWJsZU1vZGVscsvrOK4B/74CAAFMAAxsaXN0ZW5lckxpc3R0ACVMamF2YXgvc3dpbmcvZXZlbnQvRXZlbnRMaXN0ZW5lckxpc3Q7eHBzcgAjamF2YXguc3dpbmcuZXZlbnQuRXZlbnRMaXN0ZW5lckxpc3SRSMwtc98O3gMAAHhwcHhzcgAfY2xvanVyZS5sYW5nLlBlcnNpc3RlbnRBcnJheU1hcOM3cA+YxfTfAgACTAAFX21ldGFxAH4AAVsABWFycmF5dAATW0xqYXZhL2xhbmcvT2JqZWN0O3hyABtjbG9qdXJlLmxhbmcuQVBlcnNpc3RlbnRNYXBdfC8DdCByewIAAkkABV9oYXNoSQAHX2hhc2hlcXhwAAAAAAAAAABwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABnQADmdldENvbHVtbkNvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTbQ1M9FYoOj9wIAAHhyABZjbG9qdXJlLmxhbmcuQUZ1bmN0aW9uPgZwnJ5G/csCAAFMABFfX21ldGhvZEltcGxDYWNoZXQAHkxjbG9qdXJlL2xhbmcvTWV0aG9kSW1wbENhY2hlO3hwcHQAC2dldFJvd0NvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTgf1DHD2//pRAIAAUwABW5yb3dzdAASTGphdmEvbGFuZy9PYmplY3Q7eHEAfgAPcHB0AApnZXRWYWx1ZUF0c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNjBYQ6uzEwbd+gIAAkwACWdldF9sYWJlbHEAfgAUTAAJZ2V0X3ZhbHVlcQB+ABR4cQB+AA9wcHA="
- "11" "rO0ABXNyAEVjbG9qdXJlLmluc3BlY3Rvci5wcm94eSRqYXZheC5zd2luZy50YWJsZS5BYnN0cmFjdFRhYmxlTW9kZWwkZmYxOTI3NGFydNi2XwhNRQIAAUwADl9fY2xvanVyZUZuTWFwdAAdTGNsb2p1cmUvbGFuZy9JUGVyc2lzdGVudE1hcDt4cgAkamF2YXguc3dpbmcudGFibGUuQWJzdHJhY3RUYWJsZU1vZGVscsvrOK4B/74CAAFMAAxsaXN0ZW5lckxpc3R0ACVMamF2YXgvc3dpbmcvZXZlbnQvRXZlbnRMaXN0ZW5lckxpc3Q7eHBzcgAjamF2YXguc3dpbmcuZXZlbnQuRXZlbnRMaXN0ZW5lckxpc3SRSMwtc98O3gMAAHhwcHhzcgAfY2xvanVyZS5sYW5nLlBlcnNpc3RlbnRBcnJheU1hcOM3cA+YxfTfAgACTAAFX21ldGFxAH4AAVsABWFycmF5dAATW0xqYXZhL2xhbmcvT2JqZWN0O3hyABtjbG9qdXJlLmxhbmcuQVBlcnNpc3RlbnRNYXBdfC8DdCByewIAAkkABV9oYXNoSQAHX2hhc2hlcXhwAAAAAAAAAABwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABnQADmdldENvbHVtbkNvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTbQ1M9FYoOj9wIAAHhyABZjbG9qdXJlLmxhbmcuQUZ1bmN0aW9uPgZwnJ5G/csCAAFMABFfX21ldGhvZEltcGxDYWNoZXQAHkxjbG9qdXJlL2xhbmcvTWV0aG9kSW1wbENhY2hlO3hwcHQAC2dldFJvd0NvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTgf1DHD2//pRAIAAUwABW5yb3dzdAASTGphdmEvbGFuZy9PYmplY3Q7eHEAfgAPcHB0AApnZXRWYWx1ZUF0c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNjBYQ6uzEwbd+gIAAkwACWdldF9sYWJlbHEAfgAUTAAJZ2V0X3ZhbHVlcQB+ABR4cQB+AA9wcHA="})
+ "9" "rO0ABXNyAEVjbG9qdXJlLmluc3BlY3Rvci5wcm94eSRqYXZheC5zd2luZy50YWJsZS5BYnN0cmFjdFRhYmxlTW9kZWwkZmYxOTI3NGFydNi2XwhNRQIAAUwADl9fY2xvanVyZUZuTWFwdAAdTGNsb2p1cmUvbGFuZy9JUGVyc2lzdGVudE1hcDt4cgAkamF2YXguc3dpbmcudGFibGUuQWJzdHJhY3RUYWJsZU1vZGVscsvrOK4B/74CAAFMAAxsaXN0ZW5lckxpc3R0ACVMamF2YXgvc3dpbmcvZXZlbnQvRXZlbnRMaXN0ZW5lckxpc3Q7eHBzcgAjamF2YXguc3dpbmcuZXZlbnQuRXZlbnRMaXN0ZW5lckxpc3SxNsZ9hOrWRAMAAHhwcHhzcgAfY2xvanVyZS5sYW5nLlBlcnNpc3RlbnRBcnJheU1hcOM3cA+YxfTfAgACTAAFX21ldGFxAH4AAVsABWFycmF5dAATW0xqYXZhL2xhbmcvT2JqZWN0O3hyABtjbG9qdXJlLmxhbmcuQVBlcnNpc3RlbnRNYXBdfC8DdCByewIAAkkABV9oYXNoSQAHX2hhc2hlcXhwAAAAAAAAAABwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABnQADmdldENvbHVtbkNvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTbQ1M9FYoOj9wIAAHhyABZjbG9qdXJlLmxhbmcuQUZ1bmN0aW9uPgZwnJ5G/csCAAFMABFfX21ldGhvZEltcGxDYWNoZXQAHkxjbG9qdXJlL2xhbmcvTWV0aG9kSW1wbENhY2hlO3hwcHQAC2dldFJvd0NvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTgf1DHD2//pRAIAAUwABW5yb3dzdAASTGphdmEvbGFuZy9PYmplY3Q7eHEAfgAPcHB0AApnZXRWYWx1ZUF0c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNjBYQ6uzEwbd+gIAAkwACWdldF9sYWJlbHEAfgAUTAAJZ2V0X3ZhbHVlcQB+ABR4cQB+AA9wcHA="
+ "10" "rO0ABXNyAEVjbG9qdXJlLmluc3BlY3Rvci5wcm94eSRqYXZheC5zd2luZy50YWJsZS5BYnN0cmFjdFRhYmxlTW9kZWwkZmYxOTI3NGFydNi2XwhNRQIAAUwADl9fY2xvanVyZUZuTWFwdAAdTGNsb2p1cmUvbGFuZy9JUGVyc2lzdGVudE1hcDt4cgAkamF2YXguc3dpbmcudGFibGUuQWJzdHJhY3RUYWJsZU1vZGVscsvrOK4B/74CAAFMAAxsaXN0ZW5lckxpc3R0ACVMamF2YXgvc3dpbmcvZXZlbnQvRXZlbnRMaXN0ZW5lckxpc3Q7eHBzcgAjamF2YXguc3dpbmcuZXZlbnQuRXZlbnRMaXN0ZW5lckxpc3SRSMwtc98O3gMAAHhwcHhzcgAfY2xvanVyZS5sYW5nLlBlcnNpc3RlbnRBcnJheU1hcOM3cA+YxfTfAgACTAAFX21ldGFxAH4AAVsABWFycmF5dAATW0xqYXZhL2xhbmcvT2JqZWN0O3hyABtjbG9qdXJlLmxhbmcuQVBlcnNpc3RlbnRNYXBdfC8DdCByewIAAkkABV9oYXNoSQAHX2hhc2hlcXhwAAAAAAAAAABwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABnQADmdldENvbHVtbkNvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTbQ1M9FYoOj9wIAAHhyABZjbG9qdXJlLmxhbmcuQUZ1bmN0aW9uPgZwnJ5G/csCAAFMABFfX21ldGhvZEltcGxDYWNoZXQAHkxjbG9qdXJlL2xhbmcvTWV0aG9kSW1wbENhY2hlO3hwcHQAC2dldFJvd0NvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTgf1DHD2//pRAIAAUwABW5yb3dzdAASTGphdmEvbGFuZy9PYmplY3Q7eHEAfgAPcHB0AApnZXRWYWx1ZUF0c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNjBYQ6uzEwbd+gIAAkwACWdldF9sYWJlbHEAfgAUTAAJZ2V0X3ZhbHVlcQB+ABR4cQB+AA9wcHA="
+ "11" "rO0ABXNyAEVjbG9qdXJlLmluc3BlY3Rvci5wcm94eSRqYXZheC5zd2luZy50YWJsZS5BYnN0cmFjdFRhYmxlTW9kZWwkZmYxOTI3NGFydNi2XwhNRQIAAUwADl9fY2xvanVyZUZuTWFwdAAdTGNsb2p1cmUvbGFuZy9JUGVyc2lzdGVudE1hcDt4cgAkamF2YXguc3dpbmcudGFibGUuQWJzdHJhY3RUYWJsZU1vZGVscsvrOK4B/74CAAFMAAxsaXN0ZW5lckxpc3R0ACVMamF2YXgvc3dpbmcvZXZlbnQvRXZlbnRMaXN0ZW5lckxpc3Q7eHBzcgAjamF2YXguc3dpbmcuZXZlbnQuRXZlbnRMaXN0ZW5lckxpc3SRSMwtc98O3gMAAHhwcHhzcgAfY2xvanVyZS5sYW5nLlBlcnNpc3RlbnRBcnJheU1hcOM3cA+YxfTfAgACTAAFX21ldGFxAH4AAVsABWFycmF5dAATW0xqYXZhL2xhbmcvT2JqZWN0O3hyABtjbG9qdXJlLmxhbmcuQVBlcnNpc3RlbnRNYXBdfC8DdCByewIAAkkABV9oYXNoSQAHX2hhc2hlcXhwAAAAAAAAAABwdXIAE1tMamF2YS5sYW5nLk9iamVjdDuQzlifEHMpbAIAAHhwAAAABnQADmdldENvbHVtbkNvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTbQ1M9FYoOj9wIAAHhyABZjbG9qdXJlLmxhbmcuQUZ1bmN0aW9uPgZwnJ5G/csCAAFMABFfX21ldGhvZEltcGxDYWNoZXQAHkxjbG9qdXJlL2xhbmcvTWV0aG9kSW1wbENhY2hlO3hwcHQAC2dldFJvd0NvdW50c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNTgf1DHD2//pRAIAAUwABW5yb3dzdAASTGphdmEvbGFuZy9PYmplY3Q7eHEAfgAPcHB0AApnZXRWYWx1ZUF0c3IAJWNsb2p1cmUuaW5zcGVjdG9yJGxpc3RfbW9kZWwkZm5fXzkxNjBYQ6uzEwbd+gIAAkwACWdldF9sYWJlbHEAfgAUTAAJZ2V0X3ZhbHVlcQB+ABR4cQB+AA9wcHA="})
(defn- decode-base64
[^String s]
@@ -219,24 +219,24 @@
(deftest test-bases
(are [x y] (= x y)
- (bases java.lang.Math)
- (list java.lang.Object)
- (bases java.util.Collection)
- (list java.lang.Iterable)
- (bases java.lang.Object)
- nil
- (bases java.lang.Comparable)
- nil
- (bases java.lang.Integer)
- (list java.lang.Number java.lang.Comparable) ))
+ (bases java.lang.Math)
+ (list java.lang.Object)
+ (bases java.util.Collection)
+ (list java.lang.Iterable)
+ (bases java.lang.Object)
+ nil
+ (bases java.lang.Comparable)
+ nil
+ (bases java.lang.Integer)
+ (list java.lang.Number java.lang.Comparable) ))
(deftest test-supers
(are [x y] (= x y)
- (supers java.lang.Math)
- #{java.lang.Object}
- (supers java.lang.Integer)
- #{java.lang.Number java.lang.Object
- java.lang.Comparable java.io.Serializable} ))
+ (supers java.lang.Math)
+ #{java.lang.Object}
+ (supers java.lang.Integer)
+ #{java.lang.Number java.lang.Object
+ java.lang.Comparable java.io.Serializable} ))
(deftest test-proxy-super
(let [d (proxy [java.util.BitSet] []
@@ -263,40 +263,40 @@
(defmacro deftest-type-array [type-array type]
`(deftest ~(symbol (str "test-" type-array))
- ; correct type
- #_(is (= (class (first (~type-array [1 2]))) (class (~type 1))))
-
- ; given size (and empty)
- (are [x] (and (= (alength (~type-array x)) x)
- (= (vec (~type-array x)) (repeat x 0)))
- 0 1 5 )
-
- ; copy of a sequence
- (are [x] (and (= (alength (~type-array x)) (count x))
- (= (vec (~type-array x)) x))
- []
- [1]
- [1 -2 3 0 5] )
-
- ; given size and init-value
- (are [x] (and (= (alength (~type-array x 42)) x)
- (= (vec (~type-array x 42)) (repeat x 42)))
- 0 1 5 )
-
- ; given size and init-seq
- (are [x y z] (and (= (alength (~type-array x y)) x)
- (= (vec (~type-array x y)) z))
- 0 [] []
- 0 [1] []
- 0 [1 2 3] []
- 1 [] [0]
- 1 [1] [1]
- 1 [1 2 3] [1]
- 5 [] [0 0 0 0 0]
- 5 [1] [1 0 0 0 0]
- 5 [1 2 3] [1 2 3 0 0]
- 5 [1 2 3 4 5] [1 2 3 4 5]
- 5 [1 2 3 4 5 6 7] [1 2 3 4 5] )))
+ ; correct type
+ #_(is (= (class (first (~type-array [1 2]))) (class (~type 1))))
+
+ ; given size (and empty)
+ (are [x] (and (= (alength (~type-array x)) x)
+ (= (vec (~type-array x)) (repeat x 0)))
+ 0 1 5 )
+
+ ; copy of a sequence
+ (are [x] (and (= (alength (~type-array x)) (count x))
+ (= (vec (~type-array x)) x))
+ []
+ [1]
+ [1 -2 3 0 5] )
+
+ ; given size and init-value
+ (are [x] (and (= (alength (~type-array x 42)) x)
+ (= (vec (~type-array x 42)) (repeat x 42)))
+ 0 1 5 )
+
+ ; given size and init-seq
+ (are [x y z] (and (= (alength (~type-array x y)) x)
+ (= (vec (~type-array x y)) z))
+ 0 [] []
+ 0 [1] []
+ 0 [1 2 3] []
+ 1 [] [0]
+ 1 [1] [1]
+ 1 [1 2 3] [1]
+ 5 [] [0 0 0 0 0]
+ 5 [1] [1 0 0 0 0]
+ 5 [1 2 3] [1 2 3 0 0]
+ 5 [1 2 3 4 5] [1 2 3 4 5]
+ 5 [1 2 3 4 5 6 7] [1 2 3 4 5] )))
(deftest-type-array int-array int)
(deftest-type-array long-array long)
@@ -319,56 +319,56 @@
; one-dimensional
(are [x] (= (alength (make-array Integer x)) x)
- 0 1 5 )
+ 0 1 5 )
(let [a (make-array Long 5)]
(aset a 3 42)
(are [x y] (= x y)
- (aget a 3) 42
- (class (aget a 3)) Long ))
+ (aget a 3) 42
+ (class (aget a 3)) Long ))
; multi-dimensional
(let [a (make-array Long 3 2 4)]
(aset a 0 1 2 987)
(are [x y] (= x y)
- (alength a) 3
- (alength (first a)) 2
- (alength (first (first a))) 4
+ (alength a) 3
+ (alength (first a)) 2
+ (alength (first (first a))) 4
- (aget a 0 1 2) 987
- (class (aget a 0 1 2)) Long )))
+ (aget a 0 1 2) 987
+ (class (aget a 0 1 2)) Long )))
(deftest test-to-array
(let [v [1 "abc" :kw \c []]
a (to-array v)]
(are [x y] (= x y)
- ; length
- (alength a) (count v)
+ ; length
+ (alength a) (count v)
- ; content
- (vec a) v
- (class (aget a 0)) (class (nth v 0))
- (class (aget a 1)) (class (nth v 1))
- (class (aget a 2)) (class (nth v 2))
- (class (aget a 3)) (class (nth v 3))
- (class (aget a 4)) (class (nth v 4)) ))
+ ; content
+ (vec a) v
+ (class (aget a 0)) (class (nth v 0))
+ (class (aget a 1)) (class (nth v 1))
+ (class (aget a 2)) (class (nth v 2))
+ (class (aget a 3)) (class (nth v 3))
+ (class (aget a 4)) (class (nth v 4)) ))
; different kinds of collections
(are [x] (and (= (alength (to-array x)) (count x))
(= (vec (to-array x)) (vec x)))
- ()
- '(1 2)
- []
- [1 2]
- (sorted-set)
- (sorted-set 1 2)
+ ()
+ '(1 2)
+ []
+ [1 2]
+ (sorted-set)
+ (sorted-set 1 2)
- (int-array 0)
- (int-array [1 2 3])
+ (int-array 0)
+ (int-array [1 2 3])
- (to-array [])
- (to-array [1 2 3]) ))
+ (to-array [])
+ (to-array [1 2 3]) ))
(defn queue [& contents]
(apply conj (clojure.lang.PersistentQueue/EMPTY) contents))
@@ -405,9 +405,9 @@
(let [v [1 2 3 4 5]
a (into-array v)]
(are [x y] (= x y)
- (alength a) (count v)
- (vec a) v
- (class (first a)) (class (first v)) ))
+ (alength a) (count v)
+ (vec a) v
+ (class (first a)) (class (first v)) ))
(is (= \a (aget (into-array Character/TYPE [\a \b \c]) 0)))
@@ -432,18 +432,18 @@
(= (vec (into-array x)) (vec x))
(= (alength (into-array Long/TYPE x)) (count x))
(= (vec (into-array Long/TYPE x)) (vec x)))
- ()
- '(1 2)
- []
- [1 2]
- (sorted-set)
- (sorted-set 1 2)
+ ()
+ '(1 2)
+ []
+ [1 2]
+ (sorted-set)
+ (sorted-set 1 2)
- (int-array 0)
- (int-array [1 2 3])
+ (int-array 0)
+ (int-array [1 2 3])
- (to-array [])
- (to-array [1 2 3]) ))
+ (to-array [])
+ (to-array [1 2 3]) ))
(deftest test-to-array-2d
@@ -454,104 +454,104 @@
(let [v [[1] [2 3] [4 5 6]]
a (to-array-2d v)]
(are [x y] (= x y)
- (alength a) (count v)
- (alength (aget a 0)) (count (nth v 0))
- (alength (aget a 1)) (count (nth v 1))
- (alength (aget a 2)) (count (nth v 2))
+ (alength a) (count v)
+ (alength (aget a 0)) (count (nth v 0))
+ (alength (aget a 1)) (count (nth v 1))
+ (alength (aget a 2)) (count (nth v 2))
- (vec (aget a 0)) (nth v 0)
- (vec (aget a 1)) (nth v 1)
- (vec (aget a 2)) (nth v 2) ))
+ (vec (aget a 0)) (nth v 0)
+ (vec (aget a 1)) (nth v 1)
+ (vec (aget a 2)) (nth v 2) ))
; empty array
(let [a (to-array-2d [])]
(are [x y] (= x y)
- (alength a) 0
- (vec a) [] )))
+ (alength a) 0
+ (vec a) [] )))
(deftest test-alength
(are [x] (= (alength x) 0)
- (int-array 0)
- (long-array 0)
- (float-array 0)
- (double-array 0)
- (boolean-array 0)
- (byte-array 0)
- (char-array 0)
- (short-array 0)
- (make-array Integer/TYPE 0)
- (to-array [])
- (into-array [])
- (to-array-2d []) )
+ (int-array 0)
+ (long-array 0)
+ (float-array 0)
+ (double-array 0)
+ (boolean-array 0)
+ (byte-array 0)
+ (char-array 0)
+ (short-array 0)
+ (make-array Integer/TYPE 0)
+ (to-array [])
+ (into-array [])
+ (to-array-2d []) )
(are [x] (= (alength x) 1)
- (int-array 1)
- (long-array 1)
- (float-array 1)
- (double-array 1)
- (boolean-array 1)
- (byte-array 1)
- (char-array 1)
- (short-array 1)
- (make-array Integer/TYPE 1)
- (to-array [1])
- (into-array [1])
- (to-array-2d [[1]]) )
+ (int-array 1)
+ (long-array 1)
+ (float-array 1)
+ (double-array 1)
+ (boolean-array 1)
+ (byte-array 1)
+ (char-array 1)
+ (short-array 1)
+ (make-array Integer/TYPE 1)
+ (to-array [1])
+ (into-array [1])
+ (to-array-2d [[1]]) )
(are [x] (= (alength x) 3)
- (int-array 3)
- (long-array 3)
- (float-array 3)
- (double-array 3)
- (boolean-array 3)
- (byte-array 3)
- (char-array 3)
- (short-array 3)
- (make-array Integer/TYPE 3)
- (to-array [1 "a" :k])
- (into-array [1 2 3])
- (to-array-2d [[1] [2 3] [4 5 6]]) ))
+ (int-array 3)
+ (long-array 3)
+ (float-array 3)
+ (double-array 3)
+ (boolean-array 3)
+ (byte-array 3)
+ (char-array 3)
+ (short-array 3)
+ (make-array Integer/TYPE 3)
+ (to-array [1 "a" :k])
+ (into-array [1 2 3])
+ (to-array-2d [[1] [2 3] [4 5 6]]) ))
(deftest test-aclone
; clone all arrays except 2D
(are [x] (and (= (alength (aclone x)) (alength x))
(= (vec (aclone x)) (vec x)))
- (int-array 0)
- (long-array 0)
- (float-array 0)
- (double-array 0)
- (boolean-array 0)
- (byte-array 0)
- (char-array 0)
- (short-array 0)
- (make-array Integer/TYPE 0)
- (to-array [])
- (into-array [])
-
- (int-array [1 2 3])
- (long-array [1 2 3])
- (float-array [1 2 3])
- (double-array [1 2 3])
- (boolean-array [true false])
- (byte-array [(byte 1) (byte 2)])
- (byte-array [1 2])
- (byte-array 2 [1 2])
- (char-array [\a \b \c])
- (short-array [(short 1) (short 2)])
- (short-array [1 2])
- (short-array 2 [1 2])
- (make-array Integer/TYPE 3)
- (to-array [1 "a" :k])
- (into-array [1 2 3]) )
+ (int-array 0)
+ (long-array 0)
+ (float-array 0)
+ (double-array 0)
+ (boolean-array 0)
+ (byte-array 0)
+ (char-array 0)
+ (short-array 0)
+ (make-array Integer/TYPE 0)
+ (to-array [])
+ (into-array [])
+
+ (int-array [1 2 3])
+ (long-array [1 2 3])
+ (float-array [1 2 3])
+ (double-array [1 2 3])
+ (boolean-array [true false])
+ (byte-array [(byte 1) (byte 2)])
+ (byte-array [1 2])
+ (byte-array 2 [1 2])
+ (char-array [\a \b \c])
+ (short-array [(short 1) (short 2)])
+ (short-array [1 2])
+ (short-array 2 [1 2])
+ (make-array Integer/TYPE 3)
+ (to-array [1 "a" :k])
+ (into-array [1 2 3]) )
; clone 2D
(are [x] (and (= (alength (aclone x)) (alength x))
(= (map alength (aclone x)) (map alength x))
(= (map vec (aclone x)) (map vec x)))
- (to-array-2d [])
- (to-array-2d [[1] [2 3] [4 5 6]]) ))
+ (to-array-2d [])
+ (to-array-2d [[1] [2 3] [4 5 6]]) ))
; Type Hints, *warn-on-reflection*
@@ -564,18 +564,18 @@
(deftest test-boolean
(are [x y] (and (instance? java.lang.Boolean (boolean x))
(= (boolean x) y))
- nil false
- false false
- true true
-
- 0 true
- 1 true
- () true
- [1] true
-
- "" true
- \space true
- :kw true ))
+ nil false
+ false false
+ true true
+
+ 0 true
+ 1 true
+ () true
+ [1] true
+
+ "" true
+ \space true
+ :kw true ))
(deftest test-char
diff --git a/test/clojure/test_clojure/logic.clj b/test/clojure/test_clojure/logic.clj
index c85855cb..fbe3e0b4 100644
--- a/test/clojure/test_clojure/logic.clj
+++ b/test/clojure/test_clojure/logic.clj
@@ -13,7 +13,7 @@
(ns clojure.test-clojure.logic
(:use clojure.test
- [clojure.test-helper :only (exception)]))
+ [clojure.test-helper :only (exception)]))
;; *** Tests ***
@@ -21,65 +21,65 @@
(deftest test-if
; true/false/nil
(are [x y] (= x y)
- (if true :t) :t
- (if true :t :f) :t
- (if true :t (exception)) :t
+ (if true :t) :t
+ (if true :t :f) :t
+ (if true :t (exception)) :t
- (if false :t) nil
- (if false :t :f) :f
- (if false (exception) :f) :f
+ (if false :t) nil
+ (if false :t :f) :f
+ (if false (exception) :f) :f
- (if nil :t) nil
- (if nil :t :f) :f
- (if nil (exception) :f) :f )
+ (if nil :t) nil
+ (if nil :t :f) :f
+ (if nil (exception) :f) :f )
; zero/empty is true
(are [x] (= (if x :t :f) :t)
- (byte 0)
- (short 0)
- (int 0)
- (long 0)
- (bigint 0)
- (float 0)
- (double 0)
- (bigdec 0)
-
- 0/2
- ""
- #""
- (symbol "")
-
- ()
- []
- {}
- #{}
- (into-array []) )
+ (byte 0)
+ (short 0)
+ (int 0)
+ (long 0)
+ (bigint 0)
+ (float 0)
+ (double 0)
+ (bigdec 0)
+
+ 0/2
+ ""
+ #""
+ (symbol "")
+
+ ()
+ []
+ {}
+ #{}
+ (into-array []) )
; anything except nil/false is true
(are [x] (= (if x :t :f) :t)
- (byte 2)
- (short 2)
- (int 2)
- (long 2)
- (bigint 2)
- (float 2)
- (double 2)
- (bigdec 2)
-
- 2/3
- \a
- "abc"
- #"a*b"
- 'abc
- :kw
-
- '(1 2)
- [1 2]
- {:a 1 :b 2}
- #{1 2}
- (into-array [1 2])
-
- (new java.util.Date) ))
+ (byte 2)
+ (short 2)
+ (int 2)
+ (long 2)
+ (bigint 2)
+ (float 2)
+ (double 2)
+ (bigdec 2)
+
+ 2/3
+ \a
+ "abc"
+ #"a*b"
+ 'abc
+ :kw
+
+ '(1 2)
+ [1 2]
+ {:a 1 :b 2}
+ #{1 2}
+ (into-array [1 2])
+
+ (new java.util.Date) ))
(deftest test-nil-punning
@@ -115,93 +115,93 @@
(deftest test-and
(are [x y] (= x y)
- (and) true
- (and true) true
- (and nil) nil
- (and false) false
+ (and) true
+ (and true) true
+ (and nil) nil
+ (and false) false
- (and true nil) nil
- (and true false) false
+ (and true nil) nil
+ (and true false) false
- (and 1 true :kw 'abc "abc") "abc"
+ (and 1 true :kw 'abc "abc") "abc"
- (and 1 true :kw nil 'abc "abc") nil
- (and 1 true :kw nil (exception) 'abc "abc") nil
+ (and 1 true :kw nil 'abc "abc") nil
+ (and 1 true :kw nil (exception) 'abc "abc") nil
- (and 1 true :kw 'abc "abc" false) false
- (and 1 true :kw 'abc "abc" false (exception)) false ))
+ (and 1 true :kw 'abc "abc" false) false
+ (and 1 true :kw 'abc "abc" false (exception)) false ))
(deftest test-or
(are [x y] (= x y)
- (or) nil
- (or true) true
- (or nil) nil
- (or false) false
+ (or) nil
+ (or true) true
+ (or nil) nil
+ (or false) false
- (or nil false true) true
- (or nil false 1 2) 1
- (or nil false "abc" :kw) "abc"
+ (or nil false true) true
+ (or nil false 1 2) 1
+ (or nil false "abc" :kw) "abc"
- (or false nil) nil
- (or nil false) false
- (or nil nil nil false) false
+ (or false nil) nil
+ (or nil false) false
+ (or nil nil nil false) false
- (or nil true false) true
- (or nil true (exception) false) true
- (or nil false "abc" (exception)) "abc" ))
+ (or nil true false) true
+ (or nil true (exception) false) true
+ (or nil false "abc" (exception)) "abc" ))
(deftest test-not
-; (is (thrown? IllegalArgumentException (not)))
+ ; (is (thrown? IllegalArgumentException (not)))
(are [x] (= (not x) true)
- nil
- false )
+ nil
+ false )
(are [x] (= (not x) false)
- true
-
- ; numbers
- 0
- 0.0
- 42
- 1.2
- 0/2
- 2/3
-
- ; characters
- \space
- \tab
- \a
-
- ; strings
- ""
- "abc"
-
- ; regexes
- #""
- #"a*b"
-
- ; symbols
- (symbol "")
- 'abc
-
- ; keywords
- :kw
-
- ; collections/arrays
- ()
- '(1 2)
- []
- [1 2]
- {}
- {:a 1 :b 2}
- #{}
- #{1 2}
- (into-array [])
- (into-array [1 2])
-
- ; Java objects
- (new java.util.Date) ))
+ true
+
+ ; numbers
+ 0
+ 0.0
+ 42
+ 1.2
+ 0/2
+ 2/3
+
+ ; characters
+ \space
+ \tab
+ \a
+
+ ; strings
+ ""
+ "abc"
+
+ ; regexes
+ #""
+ #"a*b"
+
+ ; symbols
+ (symbol "")
+ 'abc
+
+ ; keywords
+ :kw
+
+ ; collections/arrays
+ ()
+ '(1 2)
+ []
+ [1 2]
+ {}
+ {:a 1 :b 2}
+ #{}
+ #{1 2}
+ (into-array [])
+ (into-array [1 2])
+
+ ; Java objects
+ (new java.util.Date) ))
(deftest test-some?
(are [expected x] (= expected (some? x))
diff --git a/test/clojure/test_clojure/main.clj b/test/clojure/test_clojure/main.clj
index 31bec966..00dfb030 100644
--- a/test/clojure/test_clojure/main.clj
+++ b/test/clojure/test_clojure/main.clj
@@ -11,7 +11,7 @@
(ns clojure.test-clojure.main
(:use clojure.test
- [clojure.test-helper :only [platform-newlines]])
+ [clojure.test-helper :only [platform-newlines]])
(:require [clojure.main :as main]))
(deftest eval-opt
@@ -46,10 +46,10 @@
;argh - test fragility, please fix
#_(deftest repl-exception-safety
- (testing "catches and prints exception on bad equals"
- (is (re-matches #"java\.lang\.NullPointerException\r?\n"
- (run-repl-and-return-err
- "(proxy [Object] [] (equals [o] (.toString nil)))")))))
+ (testing "catches and prints exception on bad equals"
+ (is (re-matches #"java\.lang\.NullPointerException\r?\n"
+ (run-repl-and-return-err
+ "(proxy [Object] [] (equals [o] (.toString nil)))")))))
(deftest null-stack-error-reporting
(let [e (doto (Error. "xyz")
diff --git a/test/clojure/test_clojure/metadata.clj b/test/clojure/test_clojure/metadata.clj
index d0158ab2..99d8fcc2 100644
--- a/test/clojure/test_clojure/metadata.clj
+++ b/test/clojure/test_clojure/metadata.clj
@@ -10,7 +10,7 @@
(ns clojure.test-clojure.metadata
(:use clojure.test
- [clojure.test-helper :only (eval-in-temp-ns)])
+ [clojure.test-helper :only (eval-in-temp-ns)])
(:require [clojure.set :as set]))
(def public-namespaces
@@ -48,185 +48,185 @@
(deftest interaction-of-def-with-metadata
(testing "initial def sets metadata"
(let [v (eval-in-temp-ns
- (def ^{:a 1} foo 0)
- #'foo)]
+ (def ^{:a 1} foo 0)
+ #'foo)]
(is (= 1 (-> v meta :a)))))
#_(testing "subsequent declare doesn't overwrite metadata"
- (let [v (eval-in-temp-ns
- (def ^{:b 2} bar 0)
- (declare bar)
- #'bar)]
- (is (= 2 (-> v meta :b))))
- (testing "when compiled"
(let [v (eval-in-temp-ns
- (def ^{:c 3} bar 0)
- (defn declare-bar []
- (declare bar))
- (declare-bar)
- #'bar)]
- (is (= 3 (-> v meta :c))))))
+ (def ^{:b 2} bar 0)
+ (declare bar)
+ #'bar)]
+ (is (= 2 (-> v meta :b))))
+ (testing "when compiled"
+ (let [v (eval-in-temp-ns
+ (def ^{:c 3} bar 0)
+ (defn declare-bar []
+ (declare bar))
+ (declare-bar)
+ #'bar)]
+ (is (= 3 (-> v meta :c))))))
(testing "subsequent def with init-expr *does* overwrite metadata"
(let [v (eval-in-temp-ns
- (def ^{:d 4} quux 0)
- (def quux 1)
- #'quux)]
+ (def ^{:d 4} quux 0)
+ (def quux 1)
+ #'quux)]
(is (nil? (-> v meta :d))))
(testing "when compiled"
(let [v (eval-in-temp-ns
- (def ^{:e 5} quux 0)
- (defn def-quux []
- (def quux 1))
- (def-quux)
- #'quux)]
+ (def ^{:e 5} quux 0)
+ (defn def-quux []
+ (def quux 1))
+ (def-quux)
+ #'quux)]
(is (nil? (-> v meta :e))))))
(testing "IllegalArgumentException should not be thrown"
(testing "when defining var whose value is calculated with a primitive fn."
(testing "This case fails without a fix for CLJ-852"
(is (eval-in-temp-ns
- (defn foo ^long [^long x] x)
- (def x (inc (foo 10))))))
+ (defn foo ^long [^long x] x)
+ (def x (inc (foo 10))))))
(testing "This case should pass even without a fix for CLJ-852"
(is (eval-in-temp-ns
- (defn foo ^long [^long x] x)
- (def x (foo (inc 10)))))))))
-
- (deftest fns-preserve-metadata-on-maps
- (let [xm {:a 1 :b -7}
- x (with-meta {:foo 1 :bar 2} xm)
- ym {:c "foo"}
- y (with-meta {:baz 4 :guh x} ym)]
-
- (is (= xm (meta (:guh y))))
- (is (= xm (meta (reduce #(assoc %1 %2 (inc %2)) x (range 1000)))))
- (is (= xm (meta (-> x (dissoc :foo) (dissoc :bar)))))
- (let [z (assoc-in y [:guh :la] 18)]
- (is (= ym (meta z)))
- (is (= xm (meta (:guh z)))))
- (let [z (update-in y [:guh :bar] inc)]
- (is (= ym (meta z)))
- (is (= xm (meta (:guh z)))))
- (is (= xm (meta (get-in y [:guh]))))
- (is (= xm (meta (into x y))))
- (is (= ym (meta (into y x))))
+ (defn foo ^long [^long x] x)
+ (def x (foo (inc 10)))))))))
+
+(deftest fns-preserve-metadata-on-maps
+ (let [xm {:a 1 :b -7}
+ x (with-meta {:foo 1 :bar 2} xm)
+ ym {:c "foo"}
+ y (with-meta {:baz 4 :guh x} ym)]
+
+ (is (= xm (meta (:guh y))))
+ (is (= xm (meta (reduce #(assoc %1 %2 (inc %2)) x (range 1000)))))
+ (is (= xm (meta (-> x (dissoc :foo) (dissoc :bar)))))
+ (let [z (assoc-in y [:guh :la] 18)]
+ (is (= ym (meta z)))
+ (is (= xm (meta (:guh z)))))
+ (let [z (update-in y [:guh :bar] inc)]
+ (is (= ym (meta z)))
+ (is (= xm (meta (:guh z)))))
+ (is (= xm (meta (get-in y [:guh]))))
+ (is (= xm (meta (into x y))))
+ (is (= ym (meta (into y x))))
- (is (= xm (meta (merge x y))))
- (is (= ym (meta (merge y x))))
- (is (= xm (meta (merge-with + x y))))
- (is (= ym (meta (merge-with + y x))))
+ (is (= xm (meta (merge x y))))
+ (is (= ym (meta (merge y x))))
+ (is (= xm (meta (merge-with + x y))))
+ (is (= ym (meta (merge-with + y x))))
- (is (= xm (meta (select-keys x [:bar]))))
- (is (= xm (meta (set/rename-keys x {:foo :new-foo}))))
+ (is (= xm (meta (select-keys x [:bar]))))
+ (is (= xm (meta (set/rename-keys x {:foo :new-foo}))))
- ;; replace returns a seq when given a set. Can seqs have
- ;; metadata?
+ ;; replace returns a seq when given a set. Can seqs have
+ ;; metadata?
- ;; TBD: rseq, subseq, and rsubseq returns seqs. If it is even
- ;; possible to put metadata on a seq, does it make sense that the
- ;; seqs returned by these functions should have the same metadata
- ;; as the sorted collection on which they are called?
- ))
-
- (deftest fns-preserve-metadata-on-vectors
- (let [xm {:a 1 :b -7}
- x (with-meta [1 2 3] xm)
- ym {:c "foo"}
- y (with-meta [4 x 6] ym)]
-
- (is (= xm (meta (y 1))))
- (is (= xm (meta (assoc x 1 "one"))))
- (is (= xm (meta (reduce #(conj %1 %2) x (range 1000)))))
- (is (= xm (meta (pop (pop (pop x))))))
- (let [z (assoc-in y [1 2] 18)]
- (is (= ym (meta z)))
- (is (= xm (meta (z 1)))))
- (let [z (update-in y [1 2] inc)]
- (is (= ym (meta z)))
- (is (= xm (meta (z 1)))))
- (is (= xm (meta (get-in y [1]))))
- (is (= xm (meta (into x y))))
- (is (= ym (meta (into y x))))
-
- (is (= xm (meta (replace {2 "two"} x))))
- (is (= [1 "two" 3] (replace {2 "two"} x)))
-
- ;; TBD: Currently subvec drops metadata. Should it preserve it?
- ;;(is (= xm (meta (subvec x 2 3))))
-
- ;; TBD: rseq returns a seq. If it is even possible to put
- ;; metadata on a seq, does it make sense that the seqs returned by
- ;; these functions should have the same metadata as the sorted
- ;; collection on which they are called?
- ))
-
- (deftest fns-preserve-metadata-on-sets
- ;; TBD: Do tests independently for set, hash-set, and sorted-set,
- ;; perhaps with a loop here.
- (let [xm {:a 1 :b -7}
- x (with-meta #{1 2 3} xm)
- ym {:c "foo"}
- y (with-meta #{4 x 6} ym)]
-
- (is (= xm (meta (y #{3 2 1}))))
- (is (= xm (meta (reduce #(conj %1 %2) x (range 1000)))))
- (is (= xm (meta (-> x (disj 1) (disj 2) (disj 3)))))
- (is (= xm (meta (into x y))))
- (is (= ym (meta (into y x))))
-
- (is (= xm (meta (set/select even? x))))
- (let [cow1m {:what "betsy cow"}
- cow1 (with-meta {:name "betsy" :id 33} cow1m)
- cow2m {:what "panda cow"}
- cow2 (with-meta {:name "panda" :id 34} cow2m)
- cowsm {:what "all the cows"}
- cows (with-meta #{cow1 cow2} cowsm)
- cow-names (set/project cows [:name])
- renamed (set/rename cows {:id :number})]
- (is (= cowsm (meta cow-names)))
- (is (= cow1m (meta (first (filter #(= "betsy" (:name %)) cow-names)))))
- (is (= cow2m (meta (first (filter #(= "panda" (:name %)) cow-names)))))
- (is (= cowsm (meta renamed)))
- (is (= cow1m (meta (first (filter #(= "betsy" (:name %)) renamed)))))
- (is (= cow2m (meta (first (filter #(= "panda" (:name %)) renamed))))))
-
- ;; replace returns a seq when given a set. Can seqs have
- ;; metadata?
-
- ;; union: Currently returns the metadata of the largest input set.
- ;; This is an artifact of union's current implementation. I doubt
- ;; any explicit design decision was made to do so. Like join,
- ;; there doesn't seem to be much reason to prefer the metadata of
- ;; one input set over another, if at least two input sets are
- ;; given, but perhaps defining it to always return a set with the
- ;; metadata of the first input set would be reasonable?
-
- ;; intersection: Returns metadata of the smallest input set.
- ;; Otherwise similar to union.
-
- ;; difference: Seems to always return a set with metadata of first
- ;; input set. Seems reasonable. Not sure we want to add a test
- ;; for it, if it is an accident of the current implementation.
-
- ;; join, index, map-invert: Currently always returns a value with
- ;; no metadata. This seems reasonable.
- ))
+ ;; TBD: rseq, subseq, and rsubseq returns seqs. If it is even
+ ;; possible to put metadata on a seq, does it make sense that the
+ ;; seqs returned by these functions should have the same metadata
+ ;; as the sorted collection on which they are called?
+ ))
+
+(deftest fns-preserve-metadata-on-vectors
+ (let [xm {:a 1 :b -7}
+ x (with-meta [1 2 3] xm)
+ ym {:c "foo"}
+ y (with-meta [4 x 6] ym)]
+
+ (is (= xm (meta (y 1))))
+ (is (= xm (meta (assoc x 1 "one"))))
+ (is (= xm (meta (reduce #(conj %1 %2) x (range 1000)))))
+ (is (= xm (meta (pop (pop (pop x))))))
+ (let [z (assoc-in y [1 2] 18)]
+ (is (= ym (meta z)))
+ (is (= xm (meta (z 1)))))
+ (let [z (update-in y [1 2] inc)]
+ (is (= ym (meta z)))
+ (is (= xm (meta (z 1)))))
+ (is (= xm (meta (get-in y [1]))))
+ (is (= xm (meta (into x y))))
+ (is (= ym (meta (into y x))))
+
+ (is (= xm (meta (replace {2 "two"} x))))
+ (is (= [1 "two" 3] (replace {2 "two"} x)))
+
+ ;; TBD: Currently subvec drops metadata. Should it preserve it?
+ ;;(is (= xm (meta (subvec x 2 3))))
+
+ ;; TBD: rseq returns a seq. If it is even possible to put
+ ;; metadata on a seq, does it make sense that the seqs returned by
+ ;; these functions should have the same metadata as the sorted
+ ;; collection on which they are called?
+ ))
+
+(deftest fns-preserve-metadata-on-sets
+ ;; TBD: Do tests independently for set, hash-set, and sorted-set,
+ ;; perhaps with a loop here.
+ (let [xm {:a 1 :b -7}
+ x (with-meta #{1 2 3} xm)
+ ym {:c "foo"}
+ y (with-meta #{4 x 6} ym)]
+
+ (is (= xm (meta (y #{3 2 1}))))
+ (is (= xm (meta (reduce #(conj %1 %2) x (range 1000)))))
+ (is (= xm (meta (-> x (disj 1) (disj 2) (disj 3)))))
+ (is (= xm (meta (into x y))))
+ (is (= ym (meta (into y x))))
+
+ (is (= xm (meta (set/select even? x))))
+ (let [cow1m {:what "betsy cow"}
+ cow1 (with-meta {:name "betsy" :id 33} cow1m)
+ cow2m {:what "panda cow"}
+ cow2 (with-meta {:name "panda" :id 34} cow2m)
+ cowsm {:what "all the cows"}
+ cows (with-meta #{cow1 cow2} cowsm)
+ cow-names (set/project cows [:name])
+ renamed (set/rename cows {:id :number})]
+ (is (= cowsm (meta cow-names)))
+ (is (= cow1m (meta (first (filter #(= "betsy" (:name %)) cow-names)))))
+ (is (= cow2m (meta (first (filter #(= "panda" (:name %)) cow-names)))))
+ (is (= cowsm (meta renamed)))
+ (is (= cow1m (meta (first (filter #(= "betsy" (:name %)) renamed)))))
+ (is (= cow2m (meta (first (filter #(= "panda" (:name %)) renamed))))))
+
+ ;; replace returns a seq when given a set. Can seqs have
+ ;; metadata?
+
+ ;; union: Currently returns the metadata of the largest input set.
+ ;; This is an artifact of union's current implementation. I doubt
+ ;; any explicit design decision was made to do so. Like join,
+ ;; there doesn't seem to be much reason to prefer the metadata of
+ ;; one input set over another, if at least two input sets are
+ ;; given, but perhaps defining it to always return a set with the
+ ;; metadata of the first input set would be reasonable?
+
+ ;; intersection: Returns metadata of the smallest input set.
+ ;; Otherwise similar to union.
+
+ ;; difference: Seems to always return a set with metadata of first
+ ;; input set. Seems reasonable. Not sure we want to add a test
+ ;; for it, if it is an accident of the current implementation.
+
+ ;; join, index, map-invert: Currently always returns a value with
+ ;; no metadata. This seems reasonable.
+ ))
(deftest defn-primitive-args
(testing "Hinting the arg vector of a primitive-taking fn with a non-primitive type should not result in AbstractMethodError when invoked."
(testing "CLJ-850 is fixed when this case passes."
(is (= "foo"
(eval-in-temp-ns
- (defn f ^String [^String s ^long i] s)
- (f "foo" 1)))))
+ (defn f ^String [^String s ^long i] s)
+ (f "foo" 1)))))
(testing "These cases should pass, even without a fix for CLJ-850."
(is (= "foo"
(eval-in-temp-ns
- (defn f ^String [^String s] s)
- (f "foo"))))
+ (defn f ^String [^String s] s)
+ (f "foo"))))
(is (= 1
(eval-in-temp-ns
- (defn f ^long [^String s ^long i] i)
- (f "foo" 1))))
+ (defn f ^long [^String s ^long i] i)
+ (f "foo" 1))))
(is (= 1
(eval-in-temp-ns
- (defn f ^long [^long i] i)
- (f 1)))))))
+ (defn f ^long [^long i] i)
+ (f 1)))))))
diff --git a/test/clojure/test_clojure/multimethods.clj b/test/clojure/test_clojure/multimethods.clj
index 924b0bcb..728eccee 100644
--- a/test/clojure/test_clojure/multimethods.clj
+++ b/test/clojure/test_clojure/multimethods.clj
@@ -29,8 +29,8 @@
"Return all tags in a derivation hierarchy"
[h]
(set/select
- #(instance? clojure.lang.Named %)
- (reduce into #{} (map keys (vals h)))))
+ #(instance? clojure.lang.Named %)
+ (reduce into #{} (map keys (vals h)))))
(defn transitive-closure
"Return all objects reachable by calling f starting with o,
@@ -47,8 +47,8 @@
"Set of descedants which are tags (i.e. Named)."
[& args]
(set/select
- #(instance? clojure.lang.Named %)
- (or (apply descendants args) #{})))
+ #(instance? clojure.lang.Named %)
+ (or (apply descendants args) #{})))
(defn assert-valid-hierarchy
[h]
@@ -67,17 +67,17 @@
(or (tag-descendants h tag) #{})))))
(testing "a tag isa? all of its parents"
(for-all [tag tags
- :let [parents (parents h tag)]
- parent parents]
+ :let [parents (parents h tag)]
+ parent parents]
(is (isa? h tag parent))))
(testing "a tag isa? all of its ancestors"
(for-all [tag tags
- :let [ancestors (ancestors h tag)]
- ancestor ancestors]
+ :let [ancestors (ancestors h tag)]
+ ancestor ancestors]
(is (isa? h tag ancestor))))
(testing "all my descendants have me as an ancestor"
(for-all [tag tags
- :let [descendants (descendants h tag)]
+ :let [descendants (descendants h tag)]
descendant descendants]
(is (isa? h descendant tag))))
(testing "there are no cycles in parents"
@@ -152,11 +152,11 @@
(is (nil? (ancestors ::manx))))))
#_(defmacro for-all
- "Better than the actual for-all, if only it worked."
- [& args]
- `(reduce
- #(and %1 %2)
- (map true? (for ~@args))))
+ "Better than the actual for-all, if only it worked."
+ [& args]
+ `(reduce
+ #(and %1 %2)
+ (map true? (for ~@args))))
(deftest basic-multimethod-test
(testing "Check basic dispatch"
@@ -187,7 +187,7 @@
(is (= :a-string (foo "bar")))))
(deftest preferences-multimethod-test
- (testing "Multiple method match dispatch error is caught"
+ (testing "Multiple method match dispatch error is caught"
;; Example from the multimethod docs.
(derive ::rect ::shape)
(defmulti bar (fn [x y] [x y]))
@@ -195,13 +195,13 @@
(defmethod bar [::shape ::rect] [x y] :shape-rect)
(is (thrown? java.lang.IllegalArgumentException
(bar ::rect ::rect))))
- (testing "The prefers method returns empty table w/ no prefs"
- (is (= {} (prefers bar))))
- (testing "Adding a preference to resolve it dispatches correctly"
- (prefer-method bar [::rect ::shape] [::shape ::rect])
- (is (= :rect-shape (bar ::rect ::rect))))
- (testing "The prefers method now returns the correct table"
- (is (= {[::rect ::shape] #{[::shape ::rect]}} (prefers bar)))))
+ (testing "The prefers method returns empty table w/ no prefs"
+ (is (= {} (prefers bar))))
+ (testing "Adding a preference to resolve it dispatches correctly"
+ (prefer-method bar [::rect ::shape] [::shape ::rect])
+ (is (= :rect-shape (bar ::rect ::rect))))
+ (testing "The prefers method now returns the correct table"
+ (is (= {[::rect ::shape] #{[::shape ::rect]}} (prefers bar)))))
(deftest remove-all-methods-test
(testing "Core function remove-all-methods works"
diff --git a/test/clojure/test_clojure/ns_libs.clj b/test/clojure/test_clojure/ns_libs.clj
index 0e470d73..29f3e8f1 100644
--- a/test/clojure/test_clojure/ns_libs.clj
+++ b/test/clojure/test_clojure/ns_libs.clj
@@ -27,7 +27,7 @@
; loaded-libs
(deftest test-alias
- (is (thrown-with-msg? Exception #"No namespace: epicfail found" (alias 'bogus 'epicfail))))
+ (is (thrown-with-msg? Exception #"No namespace: epicfail found" (alias 'bogus 'epicfail))))
(deftest test-require
(is (thrown? Exception (require :foo)))
@@ -55,14 +55,14 @@
(is (= [:a :b] (keys inst2))))
;fragile tests, please fix
#_(testing "you cannot import same local name from a different namespace"
- (is (thrown? clojure.lang.Compiler$CompilerException
- #"ReimportMe already refers to: class exporter.ReimportMe in namespace: importer"
- (binding [*ns* *ns*]
- (eval '(do (ns exporter-2)
- (defrecord ReimportMe [a b])
- (ns importer)
- (import exporter-2.ReimportMe)
- (ReimportMe. 1 2)))))))))
+ (is (thrown? clojure.lang.Compiler$CompilerException
+ #"ReimportMe already refers to: class exporter.ReimportMe in namespace: importer"
+ (binding [*ns* *ns*]
+ (eval '(do (ns exporter-2)
+ (defrecord ReimportMe [a b])
+ (ns importer)
+ (import exporter-2.ReimportMe)
+ (ReimportMe. 1 2)))))))))
(deftest naming-types
(testing "you cannot use a name already referred from another namespace"
@@ -98,8 +98,8 @@
(deftest test-defrecord-deftype-err-msg
(is (thrown-with-cause-msg? clojure.lang.Compiler$CompilerException
- #"defrecord and deftype fields must be symbols, user\.MyRecord had: :shutdown-fn"
- (eval '(defrecord MyRecord [:shutdown-fn]))))
+ #"defrecord and deftype fields must be symbols, user\.MyRecord had: :shutdown-fn"
+ (eval '(defrecord MyRecord [:shutdown-fn]))))
(is (thrown-with-cause-msg? clojure.lang.Compiler$CompilerException
- #"defrecord and deftype fields must be symbols, user\.MyType had: :key1"
- (eval '(deftype MyType [:key1])))))
+ #"defrecord and deftype fields must be symbols, user\.MyType had: :key1"
+ (eval '(deftype MyType [:key1])))))
diff --git a/test/clojure/test_clojure/numbers.clj b/test/clojure/test_clojure/numbers.clj
index 26140a7c..55f01044 100644
--- a/test/clojure/test_clojure/numbers.clj
+++ b/test/clojure/test_clojure/numbers.clj
@@ -13,10 +13,10 @@
(ns clojure.test-clojure.numbers
(:use clojure.test
- [clojure.test.generative :exclude (is)]
- clojure.template)
+ [clojure.test.generative :exclude (is)]
+ clojure.template)
(:require [clojure.data.generators :as gen]
- [clojure.test-helper :as helper]))
+ [clojure.test-helper :as helper]))
; TODO:
@@ -30,10 +30,10 @@
(deftest Coerced-BigDecimal
(doseq [v [(bigdec 3) (bigdec (inc (bigint Long/MAX_VALUE)))]]
(are [x] (true? x)
- (instance? BigDecimal v)
- (number? v)
- (decimal? v)
- (not (float? v)))))
+ (instance? BigDecimal v)
+ (number? v)
+ (decimal? v)
+ (not (float? v)))))
(deftest BigInteger-conversions
(doseq [coerce-fn [bigint biginteger]]
@@ -169,7 +169,7 @@
[unchecked-int [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE -1 Integer/MAX_VALUE Integer/MAX_VALUE]]
[long [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE Long/MAX_VALUE :error :error]]
[unchecked-long [-1 0 1 Byte/MAX_VALUE Short/MAX_VALUE Integer/MAX_VALUE Long/MAX_VALUE Long/MAX_VALUE Long/MAX_VALUE]]
- ;; 2.14748365E9 if when float/double conversion is avoided...
+ ;; 2.14748365E9 if when float/double conversion is avoided...
[float [-1.0 0.0 1.0 127.0 32767.0 2.147483648E9 9.223372036854776E18 Float/MAX_VALUE :error]]
[unchecked-float [-1.0 0.0 1.0 127.0 32767.0 2.147483648E9 9.223372036854776E18 Float/MAX_VALUE Float/POSITIVE_INFINITY]]
[double [-1.0 0.0 1.0 127.0 32767.0 2.147483647E9 9.223372036854776E18 Float/MAX_VALUE Double/MAX_VALUE]]
@@ -180,8 +180,8 @@
(doseq [[f vals] expectations]
(let [wrapped (fn [x]
(try
- (f x)
- (catch IllegalArgumentException e :error)))]
+ (f x)
+ (catch IllegalArgumentException e :error)))]
(is (= vals (map wrapped inputs)))))))
;; *** Functions ***
@@ -190,26 +190,26 @@
(deftest test-add
(are [x y] (= x y)
- (+) 0
- (+ 1) 1
- (+ 1 2) 3
- (+ 1 2 3) 6
+ (+) 0
+ (+ 1) 1
+ (+ 1 2) 3
+ (+ 1 2 3) 6
- (+ -1) -1
- (+ -1 -2) -3
- (+ -1 +2 -3) -2
+ (+ -1) -1
+ (+ -1 -2) -3
+ (+ -1 +2 -3) -2
- (+ 1 -1) 0
- (+ -1 1) 0
+ (+ 1 -1) 0
+ (+ -1 1) 0
- (+ 2/3) 2/3
- (+ 2/3 1) 5/3
- (+ 2/3 1/3) 1 )
+ (+ 2/3) 2/3
+ (+ 2/3 1) 5/3
+ (+ 2/3 1/3) 1 )
(are [x y] (< (- x y) DELTA)
- (+ 1.2) 1.2
- (+ 1.1 2.4) 3.5
- (+ 1.1 2.2 3.3) 6.6 )
+ (+ 1.2) 1.2
+ (+ 1.1 2.4) 3.5
+ (+ 1.1 2.2 3.3) 6.6 )
(is (> (+ Integer/MAX_VALUE 10) Integer/MAX_VALUE)) ; no overflow
(is (thrown? ClassCastException (+ "ab" "cd"))) ) ; no string concatenation
@@ -218,48 +218,48 @@
(deftest test-subtract
(is (thrown? IllegalArgumentException (-)))
(are [x y] (= x y)
- (- 1) -1
- (- 1 2) -1
- (- 1 2 3) -4
+ (- 1) -1
+ (- 1 2) -1
+ (- 1 2 3) -4
- (- -2) 2
- (- 1 -2) 3
- (- 1 -2 -3) 6
+ (- -2) 2
+ (- 1 -2) 3
+ (- 1 -2 -3) 6
- (- 1 1) 0
- (- -1 -1) 0
+ (- 1 1) 0
+ (- -1 -1) 0
- (- 2/3) -2/3
- (- 2/3 1) -1/3
- (- 2/3 1/3) 1/3 )
+ (- 2/3) -2/3
+ (- 2/3 1) -1/3
+ (- 2/3 1/3) 1/3 )
(are [x y] (< (- x y) DELTA)
- (- 1.2) -1.2
- (- 2.2 1.1) 1.1
- (- 6.6 2.2 1.1) 3.3 )
+ (- 1.2) -1.2
+ (- 2.2 1.1) 1.1
+ (- 6.6 2.2 1.1) 3.3 )
(is (< (- Integer/MIN_VALUE 10) Integer/MIN_VALUE)) ) ; no underflow
(deftest test-multiply
(are [x y] (= x y)
- (*) 1
- (* 2) 2
- (* 2 3) 6
- (* 2 3 4) 24
+ (*) 1
+ (* 2) 2
+ (* 2 3) 6
+ (* 2 3 4) 24
- (* -2) -2
- (* 2 -3) -6
- (* 2 -3 -1) 6
+ (* -2) -2
+ (* 2 -3) -6
+ (* 2 -3 -1) 6
- (* 1/2) 1/2
- (* 1/2 1/3) 1/6
- (* 1/2 1/3 -1/4) -1/24 )
+ (* 1/2) 1/2
+ (* 1/2 1/3) 1/6
+ (* 1/2 1/3 -1/4) -1/24 )
(are [x y] (< (- x y) DELTA)
- (* 1.2) 1.2
- (* 2.0 1.2) 2.4
- (* 3.5 2.0 1.2) 8.4 )
+ (* 1.2) 1.2
+ (* 2.0 1.2) 2.4
+ (* 3.5 2.0 1.2) 8.4 )
(is (> (* 3 (int (/ Integer/MAX_VALUE 2.0))) Integer/MAX_VALUE)) ) ; no overflow
@@ -281,22 +281,22 @@
(deftest test-divide
(are [x y] (= x y)
- (/ 1) 1
- (/ 2) 1/2
- (/ 3 2) 3/2
- (/ 4 2) 2
- (/ 24 3 2) 4
- (/ 24 3 2 -1) -4
-
- (/ -1) -1
- (/ -2) -1/2
- (/ -3 -2) 3/2
- (/ -4 -2) 2
- (/ -4 2) -2 )
+ (/ 1) 1
+ (/ 2) 1/2
+ (/ 3 2) 3/2
+ (/ 4 2) 2
+ (/ 24 3 2) 4
+ (/ 24 3 2 -1) -4
+
+ (/ -1) -1
+ (/ -2) -1/2
+ (/ -3 -2) 3/2
+ (/ -4 -2) 2
+ (/ -4 2) -2 )
(are [x y] (< (- x y) DELTA)
- (/ 4.5 3) 1.5
- (/ 4.5 3.0 3.0) 0.5 )
+ (/ 4.5 3) 1.5
+ (/ 4.5 3.0 3.0) 0.5 )
(is (thrown? ArithmeticException (/ 0)))
(is (thrown? ArithmeticException (/ 2 0)))
@@ -323,9 +323,9 @@
(deftest test-mod
; wrong number of args
-; (is (thrown? IllegalArgumentException (mod)))
-; (is (thrown? IllegalArgumentException (mod 1)))
-; (is (thrown? IllegalArgumentException (mod 3 2 1)))
+ ; (is (thrown? IllegalArgumentException (mod)))
+ ; (is (thrown? IllegalArgumentException (mod 1)))
+ ; (is (thrown? IllegalArgumentException (mod 3 2 1)))
; divide by zero
(is (thrown? ArithmeticException (mod 9 0)))
@@ -368,17 +368,17 @@
; large args
(mod 3216478362187432 432143214) 120355456
+ )
)
-)
;; rem & quot
;; http://en.wikipedia.org/wiki/Remainder
(deftest test-rem
; wrong number of args
-; (is (thrown? IllegalArgumentException (rem)))
-; (is (thrown? IllegalArgumentException (rem 1)))
-; (is (thrown? IllegalArgumentException (rem 3 2 1)))
+ ; (is (thrown? IllegalArgumentException (rem)))
+ ; (is (thrown? IllegalArgumentException (rem 1)))
+ ; (is (thrown? IllegalArgumentException (rem 3 2 1)))
; divide by zero
(is (thrown? ArithmeticException (rem 9 0)))
@@ -418,14 +418,14 @@
; num = 0, div != 0
(rem 0 3) 0
(rem 0 -3) 0
+ )
)
-)
(deftest test-quot
; wrong number of args
-; (is (thrown? IllegalArgumentException (quot)))
-; (is (thrown? IllegalArgumentException (quot 1)))
-; (is (thrown? IllegalArgumentException (quot 3 2 1)))
+ ; (is (thrown? IllegalArgumentException (quot)))
+ ; (is (thrown? IllegalArgumentException (quot 1)))
+ ; (is (thrown? IllegalArgumentException (quot 3 2 1)))
; divide by zero
(is (thrown? ArithmeticException (quot 9 0)))
@@ -465,8 +465,8 @@
; num = 0, div != 0
(quot 0 3) 0
(quot 0 -3) 0
+ )
)
-)
;; *** Predicates ***
@@ -668,9 +668,9 @@ Math/pow overflows to Infinity."
(defn longable?
[n]
(try
- (long n)
- true
- (catch Exception _)))
+ (long n)
+ true
+ (catch Exception _)))
(defspec integer-commutative-laws
(partial map identity)
@@ -866,67 +866,67 @@ Math/pow overflows to Infinity."
(let [nan Double/NaN
onan (cast Object Double/NaN)]
(are [x] (Double/isNaN x)
- (+ nan 1)
- (+ nan 0)
- (+ nan 0.0)
- (+ 1 nan)
- (+ 0 nan)
- (+ 0.0 nan)
- (+ nan nan)
- (- nan 1)
- (- nan 0)
- (- nan 0.0)
- (- 1 nan)
- (- 0 nan)
- (- 0.0 nan)
- (- nan nan)
- (* nan 1)
- (* nan 0)
- (* nan 0.0)
- (* 1 nan)
- (* 0 nan)
- (* 0.0 nan)
- (* nan nan)
- (/ nan 1)
- (/ nan 0)
- (/ nan 0.0)
- (/ 1 nan)
- (/ 0 nan)
- (/ 0.0 nan)
- (/ nan nan)
- (+ onan 1)
- (+ onan 0)
- (+ onan 0.0)
- (+ 1 onan)
- (+ 0 onan)
- (+ 0.0 onan)
- (+ onan onan)
- (- onan 1)
- (- onan 0)
- (- onan 0.0)
- (- 1 onan)
- (- 0 onan)
- (- 0.0 onan)
- (- onan onan)
- (* onan 1)
- (* onan 0)
- (* onan 0.0)
- (* 1 onan)
- (* 0 onan)
- (* 0.0 onan)
- (* onan onan)
- (/ onan 1)
- (/ onan 0)
- (/ onan 0.0)
- (/ 1 onan)
- (/ 0 onan)
- (/ 0.0 onan)
- (/ onan onan)
- (+ nan onan)
- (+ onan nan)
- (- nan onan)
- (- onan nan)
- (* nan onan)
- (* onan nan)
- (/ nan onan)
- (/ onan nan) ))))
+ (+ nan 1)
+ (+ nan 0)
+ (+ nan 0.0)
+ (+ 1 nan)
+ (+ 0 nan)
+ (+ 0.0 nan)
+ (+ nan nan)
+ (- nan 1)
+ (- nan 0)
+ (- nan 0.0)
+ (- 1 nan)
+ (- 0 nan)
+ (- 0.0 nan)
+ (- nan nan)
+ (* nan 1)
+ (* nan 0)
+ (* nan 0.0)
+ (* 1 nan)
+ (* 0 nan)
+ (* 0.0 nan)
+ (* nan nan)
+ (/ nan 1)
+ (/ nan 0)
+ (/ nan 0.0)
+ (/ 1 nan)
+ (/ 0 nan)
+ (/ 0.0 nan)
+ (/ nan nan)
+ (+ onan 1)
+ (+ onan 0)
+ (+ onan 0.0)
+ (+ 1 onan)
+ (+ 0 onan)
+ (+ 0.0 onan)
+ (+ onan onan)
+ (- onan 1)
+ (- onan 0)
+ (- onan 0.0)
+ (- 1 onan)
+ (- 0 onan)
+ (- 0.0 onan)
+ (- onan onan)
+ (* onan 1)
+ (* onan 0)
+ (* onan 0.0)
+ (* 1 onan)
+ (* 0 onan)
+ (* 0.0 onan)
+ (* onan onan)
+ (/ onan 1)
+ (/ onan 0)
+ (/ onan 0.0)
+ (/ 1 onan)
+ (/ 0 onan)
+ (/ 0.0 onan)
+ (/ onan onan)
+ (+ nan onan)
+ (+ onan nan)
+ (- nan onan)
+ (- onan nan)
+ (* nan onan)
+ (* onan nan)
+ (/ nan onan)
+ (/ onan nan) ))))
diff --git a/test/clojure/test_clojure/other_functions.clj b/test/clojure/test_clojure/other_functions.clj
index 958df5ec..8ce2bb5f 100644
--- a/test/clojure/test_clojure/other_functions.clj
+++ b/test/clojure/test_clojure/other_functions.clj
@@ -19,29 +19,29 @@
(deftest test-identity
; exactly 1 argument needed
-; (is (thrown? IllegalArgumentException (identity)))
-; (is (thrown? IllegalArgumentException (identity 1 2)))
+ ; (is (thrown? IllegalArgumentException (identity)))
+ ; (is (thrown? IllegalArgumentException (identity 1 2)))
(are [x] (= (identity x) x)
- nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- () '(1 2)
- [] [1 2]
- {} {:a 1 :b 2}
- #{} #{1 2} )
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () '(1 2)
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2} )
; evaluation
(are [x y] (= (identity x) y)
- (+ 1 2) 3
- (> 5 0) true ))
+ (+ 1 2) 3
+ (> 5 0) true ))
(deftest test-name
@@ -131,202 +131,202 @@
; every-pred
(deftest test-every-pred
(are [result expr] (= result expr)
- ;; 1 pred
- true ((every-pred even?))
- true ((every-pred even?) 2)
- true ((every-pred even?) 2 4)
- true ((every-pred even?) 2 4 6)
- true ((every-pred even?) 2 4 6 8)
- true ((every-pred even?) 2 4 6 8 10)
- false ((every-pred odd?) 2)
- false ((every-pred odd?) 2 4)
- false ((every-pred odd?) 2 4 6)
- false ((every-pred odd?) 2 4 6 8)
- false ((every-pred odd?) 2 4 6 8 10)
- ;; 2 preds
- true ((every-pred even? number?))
- true ((every-pred even? number?) 2)
- true ((every-pred even? number?) 2 4)
- true ((every-pred even? number?) 2 4 6)
- true ((every-pred even? number?) 2 4 6 8)
- true ((every-pred even? number?) 2 4 6 8 10)
- false ((every-pred number? odd?) 2)
- false ((every-pred number? odd?) 2 4)
- false ((every-pred number? odd?) 2 4 6)
- false ((every-pred number? odd?) 2 4 6 8)
- false ((every-pred number? odd?) 2 4 6 8 10)
- ;; 2 preds, short-circuiting
- false ((every-pred number? odd?) 1 :a)
- false ((every-pred number? odd?) 1 3 :a)
- false ((every-pred number? odd?) 1 3 5 :a)
- false ((every-pred number? odd?) 1 3 5 7 :a)
- false ((every-pred number? odd?) 1 :a 3 5 7)
- ;; 3 preds
- true ((every-pred even? number? #(> % 0)))
- true ((every-pred even? number? #(> % 0)) 2)
- true ((every-pred even? number? #(> % 0)) 2 4)
- true ((every-pred even? number? #(> % 0)) 2 4 6)
- true ((every-pred even? number? #(> % 0)) 2 4 6 8)
- true ((every-pred even? number? #(> % 0)) 2 4 6 8 10)
- true ((every-pred number? even? #(> % 0)) 2 4 6 8 10 12)
- false ((every-pred number? odd? #(> % 0)) 2)
- false ((every-pred number? odd? #(> % 0)) 2 4)
- false ((every-pred number? odd? #(> % 0)) 2 4 6)
- false ((every-pred number? odd? #(> % 0)) 2 4 6 8)
- false ((every-pred number? odd? #(> % 0)) 2 4 6 8 10)
- false ((every-pred number? odd? #(> % 0)) 2 4 6 8 -10)
- ;; 3 preds, short-circuiting
- false ((every-pred number? odd? #(> % 0)) 1 :a)
- false ((every-pred number? odd? #(> % 0)) 1 3 :a)
- false ((every-pred number? odd? #(> % 0)) 1 3 5 :a)
- false ((every-pred number? odd? #(> % 0)) 1 3 5 7 :a)
- false ((every-pred number? odd? #(> % 0)) 1 :a 3 5 7)
- ;; 4 preds
- true ((every-pred even? number? #(> % 0) #(<= % 12)))
- true ((every-pred even? number? #(> % 0) #(<= % 12)) 2)
- true ((every-pred even? number? #(> % 0) #(<= % 12)) 2 4)
- true ((every-pred even? number? #(> % 0) #(<= % 12)) 2 4 6)
- true ((every-pred even? number? #(> % 0) #(<= % 12)) 2 4 6 8)
- true ((every-pred even? number? #(> % 0) #(<= % 12)) 2 4 6 8 10)
- true ((every-pred number? even? #(> % 0) #(<= % 12)) 2 4 6 8 10 12)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4 6)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4 6 8)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4 6 8 10)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4 6 8 14)
- ;; 4 preds, short-circuiting
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 :a)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 3 :a)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 3 5 :a)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 3 5 7 :a)
- false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 :a 3 5 7)
- ;; 5 preds
- true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))))
- true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2)
- true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4)
- true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6)
- true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8)
- true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10)
- true ((every-pred number? even? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10 12)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 13)
- ;; 5 preds, short-circuiting
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 :a)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 :a)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 5 :a)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 5 7 :a)
- false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 :a 3 5 7)
- ;; truthiness
- true (reduce #(and % %2)
- (for [i (range 1 25)]
- (apply (apply every-pred (repeat i identity))
- (range i))))))
+ ;; 1 pred
+ true ((every-pred even?))
+ true ((every-pred even?) 2)
+ true ((every-pred even?) 2 4)
+ true ((every-pred even?) 2 4 6)
+ true ((every-pred even?) 2 4 6 8)
+ true ((every-pred even?) 2 4 6 8 10)
+ false ((every-pred odd?) 2)
+ false ((every-pred odd?) 2 4)
+ false ((every-pred odd?) 2 4 6)
+ false ((every-pred odd?) 2 4 6 8)
+ false ((every-pred odd?) 2 4 6 8 10)
+ ;; 2 preds
+ true ((every-pred even? number?))
+ true ((every-pred even? number?) 2)
+ true ((every-pred even? number?) 2 4)
+ true ((every-pred even? number?) 2 4 6)
+ true ((every-pred even? number?) 2 4 6 8)
+ true ((every-pred even? number?) 2 4 6 8 10)
+ false ((every-pred number? odd?) 2)
+ false ((every-pred number? odd?) 2 4)
+ false ((every-pred number? odd?) 2 4 6)
+ false ((every-pred number? odd?) 2 4 6 8)
+ false ((every-pred number? odd?) 2 4 6 8 10)
+ ;; 2 preds, short-circuiting
+ false ((every-pred number? odd?) 1 :a)
+ false ((every-pred number? odd?) 1 3 :a)
+ false ((every-pred number? odd?) 1 3 5 :a)
+ false ((every-pred number? odd?) 1 3 5 7 :a)
+ false ((every-pred number? odd?) 1 :a 3 5 7)
+ ;; 3 preds
+ true ((every-pred even? number? #(> % 0)))
+ true ((every-pred even? number? #(> % 0)) 2)
+ true ((every-pred even? number? #(> % 0)) 2 4)
+ true ((every-pred even? number? #(> % 0)) 2 4 6)
+ true ((every-pred even? number? #(> % 0)) 2 4 6 8)
+ true ((every-pred even? number? #(> % 0)) 2 4 6 8 10)
+ true ((every-pred number? even? #(> % 0)) 2 4 6 8 10 12)
+ false ((every-pred number? odd? #(> % 0)) 2)
+ false ((every-pred number? odd? #(> % 0)) 2 4)
+ false ((every-pred number? odd? #(> % 0)) 2 4 6)
+ false ((every-pred number? odd? #(> % 0)) 2 4 6 8)
+ false ((every-pred number? odd? #(> % 0)) 2 4 6 8 10)
+ false ((every-pred number? odd? #(> % 0)) 2 4 6 8 -10)
+ ;; 3 preds, short-circuiting
+ false ((every-pred number? odd? #(> % 0)) 1 :a)
+ false ((every-pred number? odd? #(> % 0)) 1 3 :a)
+ false ((every-pred number? odd? #(> % 0)) 1 3 5 :a)
+ false ((every-pred number? odd? #(> % 0)) 1 3 5 7 :a)
+ false ((every-pred number? odd? #(> % 0)) 1 :a 3 5 7)
+ ;; 4 preds
+ true ((every-pred even? number? #(> % 0) #(<= % 12)))
+ true ((every-pred even? number? #(> % 0) #(<= % 12)) 2)
+ true ((every-pred even? number? #(> % 0) #(<= % 12)) 2 4)
+ true ((every-pred even? number? #(> % 0) #(<= % 12)) 2 4 6)
+ true ((every-pred even? number? #(> % 0) #(<= % 12)) 2 4 6 8)
+ true ((every-pred even? number? #(> % 0) #(<= % 12)) 2 4 6 8 10)
+ true ((every-pred number? even? #(> % 0) #(<= % 12)) 2 4 6 8 10 12)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4 6)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4 6 8)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4 6 8 10)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 2 4 6 8 14)
+ ;; 4 preds, short-circuiting
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 :a)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 3 :a)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 3 5 :a)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 3 5 7 :a)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12)) 1 :a 3 5 7)
+ ;; 5 preds
+ true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))))
+ true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2)
+ true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4)
+ true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6)
+ true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8)
+ true ((every-pred even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10)
+ true ((every-pred number? even? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10 12)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 13)
+ ;; 5 preds, short-circuiting
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 :a)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 :a)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 5 :a)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 5 7 :a)
+ false ((every-pred number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 :a 3 5 7)
+ ;; truthiness
+ true (reduce #(and % %2)
+ (for [i (range 1 25)]
+ (apply (apply every-pred (repeat i identity))
+ (range i))))))
; some-fn
(deftest test-some-fn
(are [result] (identity result)
- ;; 1 pred
- (not ((some-fn even?)))
- ((some-fn even?) 2)
- ((some-fn even?) 2 4)
- ((some-fn even?) 2 4 6)
- ((some-fn even?) 2 4 6 8)
- ((some-fn even?) 2 4 6 8 10)
- (not ((some-fn odd?) 2))
- (not ((some-fn odd?) 2 4))
- (not ((some-fn odd?) 2 4 6))
- (not ((some-fn odd?) 2 4 6 8))
- (not ((some-fn odd?) 2 4 6 8 10))
- ;; 2 preds
- (not ((some-fn even? number?)))
- ((some-fn even? number?) 2)
- ((some-fn even? number?) 2 4)
- ((some-fn even? number?) 2 4 6)
- ((some-fn even? number?) 2 4 6 8)
- ((some-fn even? number?) 2 4 6 8 10)
- ((some-fn number? odd?) 2)
- ((some-fn number? odd?) 2 4)
- ((some-fn number? odd?) 2 4 6)
- ((some-fn number? odd?) 2 4 6 8)
- ((some-fn number? odd?) 2 4 6 8 10)
- ;; 2 preds, short-circuiting
- ((some-fn number? odd?) 1 :a)
- ((some-fn number? odd?) 1 3 :a)
- ((some-fn number? odd?) 1 3 5 :a)
- ((some-fn number? odd?) 1 3 5 7 :a)
- ((some-fn number? odd?) 1 :a 3 5 7)
- ;; 3 preds
- (not ((some-fn even? number? #(> % 0))))
- ((some-fn even? number? #(> % 0)) 2)
- ((some-fn even? number? #(> % 0)) 2 4)
- ((some-fn even? number? #(> % 0)) 2 4 6)
- ((some-fn even? number? #(> % 0)) 2 4 6 8)
- ((some-fn even? number? #(> % 0)) 2 4 6 8 10)
- ((some-fn number? even? #(> % 0)) 2 4 6 8 10 12)
- ((some-fn number? odd? #(> % 0)) 2)
- ((some-fn number? odd? #(> % 0)) 2 4)
- ((some-fn number? odd? #(> % 0)) 2 4 6)
- ((some-fn number? odd? #(> % 0)) 2 4 6 8)
- ((some-fn number? odd? #(> % 0)) 2 4 6 8 10)
- ((some-fn number? odd? #(> % 0)) 2 4 6 8 -10)
- ;; 3 preds, short-circuiting
- ((some-fn number? odd? #(> % 0)) 1 :a)
- ((some-fn number? odd? #(> % 0)) 1 3 :a)
- ((some-fn number? odd? #(> % 0)) 1 3 5 :a)
- ((some-fn number? odd? #(> % 0)) 1 :a 3 5 7)
- ;; 4 preds
- (not ((some-fn even? number? #(> % 0) #(<= % 12))))
- ((some-fn even? number? #(> % 0) #(<= % 12)) 2)
- ((some-fn even? number? #(> % 0) #(<= % 12)) 2 4)
- ((some-fn even? number? #(> % 0) #(<= % 12)) 2 4 6)
- ((some-fn even? number? #(> % 0) #(<= % 12)) 2 4 6 8)
- ((some-fn even? number? #(> % 0) #(<= % 12)) 2 4 6 8 10)
- ((some-fn number? even? #(> % 0) #(<= % 12)) 2 4 6 8 10 12)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 2)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4 6)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4 6 8)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4 6 8 10)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4 6 8 14)
- ;; 4 preds, short-circuiting
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 :a)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 3 :a)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 3 5 :a)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 3 5 7 :a)
- ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 :a 3 5 7)
- ;; 5 preds
- (not ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2)))))
- ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2)
- ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4)
- ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6)
- ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8)
- ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10)
- ((some-fn number? even? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10 12)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 13)
- ;; 5 preds, short-circuiting
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 :a)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 :a)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 5 :a)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 5 7 :a)
- ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 :a 3 5 7)
- ;; truthiness
- (reduce #(or % %2)
- (conj
- (vec
- (for [i (range 1 25)]
- (apply (apply some-fn (repeat i (comp not boolean))) (range i))))
- true))))
+ ;; 1 pred
+ (not ((some-fn even?)))
+ ((some-fn even?) 2)
+ ((some-fn even?) 2 4)
+ ((some-fn even?) 2 4 6)
+ ((some-fn even?) 2 4 6 8)
+ ((some-fn even?) 2 4 6 8 10)
+ (not ((some-fn odd?) 2))
+ (not ((some-fn odd?) 2 4))
+ (not ((some-fn odd?) 2 4 6))
+ (not ((some-fn odd?) 2 4 6 8))
+ (not ((some-fn odd?) 2 4 6 8 10))
+ ;; 2 preds
+ (not ((some-fn even? number?)))
+ ((some-fn even? number?) 2)
+ ((some-fn even? number?) 2 4)
+ ((some-fn even? number?) 2 4 6)
+ ((some-fn even? number?) 2 4 6 8)
+ ((some-fn even? number?) 2 4 6 8 10)
+ ((some-fn number? odd?) 2)
+ ((some-fn number? odd?) 2 4)
+ ((some-fn number? odd?) 2 4 6)
+ ((some-fn number? odd?) 2 4 6 8)
+ ((some-fn number? odd?) 2 4 6 8 10)
+ ;; 2 preds, short-circuiting
+ ((some-fn number? odd?) 1 :a)
+ ((some-fn number? odd?) 1 3 :a)
+ ((some-fn number? odd?) 1 3 5 :a)
+ ((some-fn number? odd?) 1 3 5 7 :a)
+ ((some-fn number? odd?) 1 :a 3 5 7)
+ ;; 3 preds
+ (not ((some-fn even? number? #(> % 0))))
+ ((some-fn even? number? #(> % 0)) 2)
+ ((some-fn even? number? #(> % 0)) 2 4)
+ ((some-fn even? number? #(> % 0)) 2 4 6)
+ ((some-fn even? number? #(> % 0)) 2 4 6 8)
+ ((some-fn even? number? #(> % 0)) 2 4 6 8 10)
+ ((some-fn number? even? #(> % 0)) 2 4 6 8 10 12)
+ ((some-fn number? odd? #(> % 0)) 2)
+ ((some-fn number? odd? #(> % 0)) 2 4)
+ ((some-fn number? odd? #(> % 0)) 2 4 6)
+ ((some-fn number? odd? #(> % 0)) 2 4 6 8)
+ ((some-fn number? odd? #(> % 0)) 2 4 6 8 10)
+ ((some-fn number? odd? #(> % 0)) 2 4 6 8 -10)
+ ;; 3 preds, short-circuiting
+ ((some-fn number? odd? #(> % 0)) 1 :a)
+ ((some-fn number? odd? #(> % 0)) 1 3 :a)
+ ((some-fn number? odd? #(> % 0)) 1 3 5 :a)
+ ((some-fn number? odd? #(> % 0)) 1 :a 3 5 7)
+ ;; 4 preds
+ (not ((some-fn even? number? #(> % 0) #(<= % 12))))
+ ((some-fn even? number? #(> % 0) #(<= % 12)) 2)
+ ((some-fn even? number? #(> % 0) #(<= % 12)) 2 4)
+ ((some-fn even? number? #(> % 0) #(<= % 12)) 2 4 6)
+ ((some-fn even? number? #(> % 0) #(<= % 12)) 2 4 6 8)
+ ((some-fn even? number? #(> % 0) #(<= % 12)) 2 4 6 8 10)
+ ((some-fn number? even? #(> % 0) #(<= % 12)) 2 4 6 8 10 12)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 2)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4 6)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4 6 8)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4 6 8 10)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 2 4 6 8 14)
+ ;; 4 preds, short-circuiting
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 :a)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 3 :a)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 3 5 :a)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 3 5 7 :a)
+ ((some-fn number? odd? #(> % 0) #(<= % 12)) 1 :a 3 5 7)
+ ;; 5 preds
+ (not ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2)))))
+ ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2)
+ ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4)
+ ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6)
+ ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8)
+ ((some-fn even? number? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10)
+ ((some-fn number? even? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10 12)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 10)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 2 4 6 8 13)
+ ;; 5 preds, short-circuiting
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 :a)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 :a)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 5 :a)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 3 5 7 :a)
+ ((some-fn number? odd? #(> % 0) #(<= % 12) #(zero? (rem % 2))) 1 :a 3 5 7)
+ ;; truthiness
+ (reduce #(or % %2)
+ (conj
+ (vec
+ (for [i (range 1 25)]
+ (apply (apply some-fn (repeat i (comp not boolean))) (range i))))
+ true))))
(deftest test-max-min-key
diff --git a/test/clojure/test_clojure/pprint.clj b/test/clojure/test_clojure/pprint.clj
index 819c23d6..26fb9f6c 100644
--- a/test/clojure/test_clojure/pprint.clj
+++ b/test/clojure/test_clojure/pprint.clj
@@ -12,9 +12,9 @@
(:refer-clojure :exclude [format])
(:require [clojure.string :as str])
(:use [clojure.test :only (deftest is are run-tests)]
- [clojure.test-helper :only [platform-newlines]]
- clojure.test-clojure.pprint.test-helper
- clojure.pprint))
+ [clojure.test-helper :only [platform-newlines]]
+ clojure.test-clojure.pprint.test-helper
+ clojure.pprint))
(load "pprint/test_cl_format")
(load "pprint/test_pretty")
diff --git a/test/clojure/test_clojure/pprint/test_cl_format.clj b/test/clojure/test_clojure/pprint/test_cl_format.clj
index a8cc134f..0d7083ba 100644
--- a/test/clojure/test_clojure/pprint/test_cl_format.clj
+++ b/test/clojure/test_clojure/pprint/test_cl_format.clj
@@ -28,7 +28,7 @@
(cl-format nil "~:D" 2000000) "2,000,000"
(cl-format nil "~D" 1/2) "1/2"
(cl-format nil "~D" 'fred) "fred"
-)
+ )
(simple-tests base-tests
(cl-format nil "~{~2r~^ ~}~%" (range 10))
@@ -46,7 +46,7 @@
(with-out-str
(doseq [pb [2 3 8 10 16]]
(binding [*print-radix* true ;print the integer 10 and
- *print-base* pb] ;the ratio 1/10 in bases 2,
+ *print-base* pb] ;the ratio 1/10 in bases 2,
(cl-format true "~&~S ~S~%" 10 1/10)))) ;3, 8, 10, 16
"#b1010 #b1/1010\n#3r101 #3r1/101\n#o12 #o1/12\n10. #10r1/10\n#xa #x1/a\n")
@@ -313,7 +313,7 @@
"a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa"
(cl-format nil "~@{~&~A~2,6@T~:*~A~}" 'a 'aa 'aaa 'aaaa 'aaaaa 'aaaaaa 'aaaaaaa 'aaaaaaaa 'aaaaaaaaa 'aaaaaaaaaa)
"a a\naa aa\naaa aaa\naaaa aaaa\naaaaa aaaaa\naaaaaa aaaaaa\naaaaaaa aaaaaaa\naaaaaaaa aaaaaaaa\naaaaaaaaa aaaaaaaaa\naaaaaaaaaa aaaaaaaaaa"
-)
+ )
(simple-tests paren-tests
(cl-format nil "~(PLEASE SPEAK QUIETLY IN HERE~)") "please speak quietly in here"
@@ -331,7 +331,7 @@
(cl-format nil "~:(~A~)" "pipe 13a, foo16c") "Pipe 13a, Foo16c"
(cl-format nil "~:(~A~)" nil) "Nil"
(cl-format nil "~:(~A~)" "") ""
-)
+ )
(simple-tests square-bracket-tests
;; Tests for format without modifiers
@@ -383,7 +383,7 @@
"The answer is 7 out of 22."
(cl-format nil "The answer is ~#[nothing~;~D~;~D out of ~D~:;something crazy~]." 1 2 3 4)
"The answer is something crazy."
-)
+ )
(simple-tests curly-brace-plain-tests
;; Iteration from sublist
@@ -410,7 +410,7 @@
(cl-format nil "Coordinates are~{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [ ])
"Coordinates are none\n"
-)
+ )
(simple-tests curly-brace-colon-tests
@@ -441,7 +441,7 @@
(cl-format nil "Coordinates are~:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]" [ ])
"Coordinates are none\n"
-)
+ )
(simple-tests curly-brace-at-tests
;; Iteration from main list
@@ -468,7 +468,7 @@
(cl-format nil "Coordinates are~@{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]")
"Coordinates are none\n"
-)
+ )
(simple-tests curly-brace-colon-at-tests
;; Iteration from sublists on the main arg list
@@ -498,7 +498,7 @@
(cl-format nil "Coordinates are~@:{~:}~%" " ~#[none~;<~D>~:;[~D,~D]~]")
"Coordinates are none\n"
-)
+ )
;; TODO tests for ~^ in ~[ constructs and other brackets
;; TODO test ~:^ generates an error when used improperly
@@ -511,7 +511,7 @@
(cl-format nil "~{~a~#,3^, ~}" aseq) "a, quick, brown, fox, jumped, over"
(cl-format nil "~{~a~v,3^, ~}" lseq) "a, quick, brown, fox"
(cl-format nil "~{~a~3,v,4^, ~}" lseq) "a, quick, brown, fox"
-))
+ ))
(simple-tests angle-bracket-tests
(cl-format nil "~<foo~;bar~;baz~>") "foobarbaz"
@@ -528,20 +528,20 @@
(cl-format nil "~20<~A~;~^~A~;~^~A~>" "foo" "bar") "foo bar"
(cl-format nil "~20@<~A~;~^~A~;~^~A~>" "foo") "foo "
(cl-format nil "~20:<~A~;~^~A~;~^~A~>" "foo") " foo"
-)
+ )
(simple-tests angle-bracket-max-column-tests
(cl-format nil "~%;; ~{~<~%;; ~1,50:; ~A~>~}.~%" (into [] (.split "This function computes the circular thermodynamic coefficient of the thrombulator angle for use in determining the reaction distance" "\\s")))
"\n;; This function computes the circular\n;; thermodynamic coefficient of the thrombulator\n;; angle for use in determining the reaction\n;; distance.\n"
-(cl-format true "~%;; ~{~<~%;; ~:; ~A~>~}.~%" (into [] (.split "This function computes the circular thermodynamic coefficient of the thrombulator angle for use in determining the reaction distance." "\\s"))))
+ (cl-format true "~%;; ~{~<~%;; ~:; ~A~>~}.~%" (into [] (.split "This function computes the circular thermodynamic coefficient of the thrombulator angle for use in determining the reaction distance." "\\s"))))
(defn list-to-table [aseq column-width]
(let [stream (get-pretty-writer (java.io.StringWriter.))]
(binding [*out* stream]
- (doseq [row aseq]
- (doseq [col row]
- (cl-format true "~4D~7,vT" col column-width))
- (prn)))
+ (doseq [row aseq]
+ (doseq [col row]
+ (cl-format true "~4D~7,vT" col column-width))
+ (prn)))
(.flush stream)
(.toString (:base @@(:base @@stream)))))
@@ -557,18 +557,18 @@
(let [x 5, y "elephant", n 3]
(simple-tests cltl-intro-tests
- (format nil "foo") "foo"
- (format nil "The answer is ~D." x) "The answer is 5."
- (format nil "The answer is ~3D." x) "The answer is 5."
- (format nil "The answer is ~3,'0D." x) "The answer is 005."
- (format nil "The answer is ~:D." (expt 47 x)) "The answer is 229,345,007."
- (format nil "Look at the ~A!" y) "Look at the elephant!"
- (format nil "Type ~:C to ~A." (char 4) "delete all your files")
- "Type Control-D to delete all your files."
- (format nil "~D item~:P found." n) "3 items found."
- (format nil "~R dog~:[s are~; is~] here." n (= n 1)) "three dogs are here."
- (format nil "~R dog~:*~[s are~; is~:;s are~] here." n) "three dogs are here."
- (format nil "Here ~[are~;is~:;are~] ~:*~R pupp~:@P." n) "Here are three puppies."))
+ (format nil "foo") "foo"
+ (format nil "The answer is ~D." x) "The answer is 5."
+ (format nil "The answer is ~3D." x) "The answer is 5."
+ (format nil "The answer is ~3,'0D." x) "The answer is 005."
+ (format nil "The answer is ~:D." (expt 47 x)) "The answer is 229,345,007."
+ (format nil "Look at the ~A!" y) "Look at the elephant!"
+ (format nil "Type ~:C to ~A." (char 4) "delete all your files")
+ "Type Control-D to delete all your files."
+ (format nil "~D item~:P found." n) "3 items found."
+ (format nil "~R dog~:[s are~; is~] here." n (= n 1)) "three dogs are here."
+ (format nil "~R dog~:*~[s are~; is~:;s are~] here." n) "three dogs are here."
+ (format nil "Here ~[are~;is~:;are~] ~:*~R pupp~:@P." n) "Here are three puppies."))
(simple-tests cltl-B-tests
;; CLtL didn't have the colons here, but the spec requires them
@@ -610,7 +610,7 @@
(cl-format false "~10,3f" tiny-neg-ratio)) " -0.000"
(foo 3.14159) " 3.14| 31.42| 3.14|3.1416|3.14|3.14159"
(foo 314159/100000)
- " 3.14| 31.42| 3.14|3.1416|3.14|3.14159"
+ " 3.14| 31.42| 3.14|3.1416|3.14|3.14159"
(foo -3.14159) " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159"
(foo 100.0) "100.00|******|100.00| 100.0|100.00|100.0"
(foo 1234.0) "1234.00|******|??????|1234.0|1234.00|1234.0"
@@ -634,17 +634,17 @@
(cl-format false "~10,3e" tiny-neg-ratio)) "-1.000E-340"
(foo-e 0.0314159) " 3.14E-2| 31.42$-03|+.003E+01| 3.14E-2" ; Added this one
(foo-e 314159/10000000)
- " 3.14E-2| 31.42$-03|+.003E+01| 3.14E-2"
+ " 3.14E-2| 31.42$-03|+.003E+01| 3.14E-2"
(foo-e 3.14159) " 3.14E+0| 31.42$-01|+.003E+03| 3.14E+0"
(foo-e -3.14159) " -3.14E+0|-31.42$-01|-.003E+03| -3.14E+0"
(foo-e 1100.0) " 1.10E+3| 11.00$+02|+.001E+06| 1.10E+3"
-; In Clojure, this is identical to the above
-; (foo-e 1100.0L0) " 1.10L+3| 11.00$+02|+.001L+06| 1.10L+3"
+ ; In Clojure, this is identical to the above
+ ; (foo-e 1100.0L0) " 1.10L+3| 11.00$+02|+.001L+06| 1.10L+3"
(foo-e 1.1E13) "*********| 11.00$+12|+.001E+16| 1.10E+13"
(foo-e 1.1E120) "*********|??????????|%%%%%%%%%|1.10E+120"
-; Clojure doesn't support real numbers this large
-; (foo-e 1.1L1200) "*********|??????????|%%%%%%%%%|1.10L+1200"
-)
+ ; Clojure doesn't support real numbers this large
+ ; (foo-e 1.1L1200) "*********|??????????|%%%%%%%%%|1.10L+1200"
+ )
(simple-tests cltl-E-scale-tests
(map
@@ -683,19 +683,19 @@
(cl-format false "~10,3g" tiny-neg-ratio)) "-1.000E-340"
(foo-g 0.0314159) " 3.14E-2|314.2$-04|0.314E-01| 3.14E-2"
(foo-g 314159/10000000)
- " 3.14E-2|314.2$-04|0.314E-01| 3.14E-2"
+ " 3.14E-2|314.2$-04|0.314E-01| 3.14E-2"
(foo-g 0.314159) " 0.31 |0.314 |0.314 | 0.31 "
(foo-g 3.14159) " 3.1 | 3.14 | 3.14 | 3.1 "
(foo-g 31.4159) " 31. | 31.4 | 31.4 | 31. "
(foo-g 314.159) " 3.14E+2| 314. | 314. | 3.14E+2"
(foo-g 3141.59) " 3.14E+3|314.2$+01|0.314E+04| 3.14E+3"
-; In Clojure, this is identical to the above
-; (foo-g 3141.59L0) " 3.14L+3|314.2$+01|0.314L+04| 3.14L+3"
+ ; In Clojure, this is identical to the above
+ ; (foo-g 3141.59L0) " 3.14L+3|314.2$+01|0.314L+04| 3.14L+3"
(foo-g 3.14E12) "*********|314.0$+10|0.314E+13| 3.14E+12"
(foo-g 3.14E120) "*********|?????????|%%%%%%%%%|3.14E+120"
-; Clojure doesn't support real numbers this large
-; (foo-g 3.14L1200) "*********|?????????|%%%%%%%%%|3.14L+1200"
-)
+ ; Clojure doesn't support real numbers this large
+ ; (foo-g 3.14L1200) "*********|?????????|%%%%%%%%%|3.14L+1200"
+ )
(defn type-clash-error [fun nargs argnum right-type wrong-type]
(format nil ;; CLtL has this format string slightly wrong
@@ -706,10 +706,10 @@
(simple-tests cltl-Newline-tests
(type-clash-error 'aref nil 2 'integer 'vector)
-"Function aref requires its second argument to be of type integer,
+ "Function aref requires its second argument to be of type integer,
but it was called with an argument of type vector.\n"
(type-clash-error 'car 1 1 'list 'short-float)
-"Function car requires its argument to be of type list,
+ "Function car requires its argument to be of type list,
but it was called with an argument of type short-float.\n")
(simple-tests cltl-?-tests
@@ -744,8 +744,8 @@ but it was called with an argument of type short-float.\n")
(simple-tests cltl-curly-bracket-tests
(format nil
- "The winners are:~{ ~S~}."
- '(fred harry jill))
+ "The winners are:~{ ~S~}."
+ '(fred harry jill))
"The winners are: fred harry jill."
(format nil "Pairs:~{ <~S,~S>~}." '(a 1 b 2 c 3))
@@ -829,15 +829,15 @@ but it was called with an argument of type short-float.\n")
'first \n 0 'back)
"n defaults to 0, so ~@* goes back to the first arg."
(format nil "~~n@* is an ~1@*~A ~0@*~A rather than a ~2@*~A ~0@*~A."
- 'goto 'absolute 'relative)
+ 'goto 'absolute 'relative)
"~n@* is an absolute goto rather than a relative goto."
(format nil "We will see no numbers: ~6@*~S"
- 0 1 2 3 4 5 :see?) "We will see no numbers: :see?"
+ 0 1 2 3 4 5 :see?) "We will see no numbers: :see?"
(format nil "~4@*~D ~3@*~D ~2@*~D ~1@*~D ~0@*~D"
- 0 1 2 3 4) "4 3 2 1 0"
+ 0 1 2 3 4) "4 3 2 1 0"
(format nil "~{~A a ~~{ ~3@*~A, the ~1@*~A is ~A to the ~4@*~A of ~A~}[...]"
- '("Within" goto relative construct list arguments))
+ '("Within" goto relative construct list arguments))
"Within a ~{ construct, the goto is relative to the list of arguments[...]"
(format nil "~{~2@*~S ~1@*~S ~4@*~S ~3@*~S ~S~}"
'(:a :b :c :d :e)) ":c :b :e :d :e"
- )
+ )
diff --git a/test/clojure/test_clojure/pprint/test_helper.clj b/test/clojure/test_clojure/pprint/test_helper.clj
index a7edd74e..4514b955 100644
--- a/test/clojure/test_clojure/pprint/test_helper.clj
+++ b/test/clojure/test_clojure/pprint/test_helper.clj
@@ -16,7 +16,7 @@
(ns clojure.test-clojure.pprint.test-helper
(:use [clojure.test :only (deftest is)]
- [clojure.test-helper :only [platform-newlines]]))
+ [clojure.test-helper :only [platform-newlines]]))
(defn- back-match [x y] (re-matches y x))
@@ -24,8 +24,8 @@
`(deftest ~name
~@(for [[x y] (partition 2 test-pairs)]
(cond
- (instance? java.util.regex.Pattern y)
- `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y))
- (instance? java.lang.String y) `(is (= ~x (platform-newlines ~y)))
- :else `(is (= ~x ~y))))))
+ (instance? java.util.regex.Pattern y)
+ `(is (#'clojure.test-clojure.pprint.test-helper/back-match ~x ~y))
+ (instance? java.lang.String y) `(is (= ~x (platform-newlines ~y)))
+ :else `(is (= ~x ~y))))))
diff --git a/test/clojure/test_clojure/pprint/test_pretty.clj b/test/clojure/test_clojure/pprint/test_pretty.clj
index c9b321fd..ac710293 100644
--- a/test/clojure/test_clojure/pprint/test_pretty.clj
+++ b/test/clojure/test_clojure/pprint/test_pretty.clj
@@ -102,33 +102,33 @@ Usage: *hello*
(with-pprint-dispatch code-dispatch
(binding [*print-right-margin* 52]
(write
- '(add-to-buffer this (make-buffer-blob (str (char c)) nil))
- :stream nil)))
+ '(add-to-buffer this (make-buffer-blob (str (char c)) nil))
+ :stream nil)))
"(add-to-buffer\n this\n (make-buffer-blob (str (char c)) nil))"
(binding [*print-pprint-dispatch* simple-dispatch]
(write (var Foo) :stream nil))
"#'clojure.test-clojure.pprint/Foo"
-)
+ )
(simple-tests pprint-reader-macro-test
(with-pprint-dispatch code-dispatch
(write (read-string "(map #(first %) [[1 2 3] [4 5 6] [7]])")
- :stream nil))
+ :stream nil))
"(map #(first %) [[1 2 3] [4 5 6] [7]])"
(with-pprint-dispatch code-dispatch
(write (read-string "@@(ref (ref 1))")
- :stream nil))
+ :stream nil))
"@@(ref (ref 1))"
(with-pprint-dispatch code-dispatch
(write (read-string "'foo")
- :stream nil))
+ :stream nil))
"'foo"
-)
+ )
(defmacro code-block
"Read a string then print it with code-dispatch and succeed if it comes out the same"
@@ -137,9 +137,9 @@ Usage: *hello*
~@(apply concat
(for [block blocks]
`[(str/split-lines
- (with-out-str
- (with-pprint-dispatch code-dispatch
- (pprint (read-string ~block)))))
+ (with-out-str
+ (with-pprint-dispatch code-dispatch
+ (pprint (read-string ~block)))))
(str/split-lines ~block)]))))
(code-block code-block-tests
@@ -152,7 +152,7 @@ Usage: *hello*
navigator (init-navigator args)]
(execute-format stream compiled-format navigator)))"
- "(defn pprint-defn [writer alis]
+ "(defn pprint-defn [writer alis]
(if (next alis)
(let [[defn-sym defn-name & stuff] alis
[doc-str stuff] (if (string? (first stuff))
@@ -235,24 +235,24 @@ It is implemented with a number of custom enlive templates.\"
(defrecord pprint-test-rec [a b c])
(simple-tests pprint-datastructures-tests
- (tst-pprint 20 future-filled) #"#<Future@[0-9a-f]+: \r?\n 100>"
- (tst-pprint 20 future-unfilled) #"#<Future@[0-9a-f]+: \r?\n :pending>"
- (tst-pprint 20 promise-filled) #"#<Promise@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
- ;; This hangs currently, cause we can't figure out whether a promise is filled
- ;;(tst-pprint 20 promise-unfilled) #"#<Promise@[0-9a-f]+: \r?\n :pending>"
- (tst-pprint 20 basic-agent) #"#<Agent@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
- (tst-pprint 20 basic-atom) #"#<Atom@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\r?\)>"
- (tst-pprint 20 basic-ref) #"#<Ref@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
- (tst-pprint 20 delay-forced) #"#<Delay@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
- ;; Currently no way not to force the delay
- ;;(tst-pprint 20 delay-unforced) #"#<Delay@[0-9a-f]+: \n :pending>"
- (tst-pprint 20 (pprint-test-rec. 'first 'second 'third)) "{:a first,\n :b second,\n :c third}"
-
- ;; basic java arrays: fails owing to assembla ticket #346
- ;;(tst-pprint 10 (int-array (range 7))) "[0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6]"
- (tst-pprint 15 (reduce conj clojure.lang.PersistentQueue/EMPTY (range 10)))
- "<-(0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9)-<"
- )
+ (tst-pprint 20 future-filled) #"#<Future@[0-9a-f]+: \r?\n 100>"
+ (tst-pprint 20 future-unfilled) #"#<Future@[0-9a-f]+: \r?\n :pending>"
+ (tst-pprint 20 promise-filled) #"#<Promise@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
+ ;; This hangs currently, cause we can't figure out whether a promise is filled
+ ;;(tst-pprint 20 promise-unfilled) #"#<Promise@[0-9a-f]+: \r?\n :pending>"
+ (tst-pprint 20 basic-agent) #"#<Agent@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
+ (tst-pprint 20 basic-atom) #"#<Atom@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\r?\)>"
+ (tst-pprint 20 basic-ref) #"#<Ref@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
+ (tst-pprint 20 delay-forced) #"#<Delay@[0-9a-f]+: \r?\n \(first\r?\n second\r?\n third\)>"
+ ;; Currently no way not to force the delay
+ ;;(tst-pprint 20 delay-unforced) #"#<Delay@[0-9a-f]+: \n :pending>"
+ (tst-pprint 20 (pprint-test-rec. 'first 'second 'third)) "{:a first,\n :b second,\n :c third}"
+
+ ;; basic java arrays: fails owing to assembla ticket #346
+ ;;(tst-pprint 10 (int-array (range 7))) "[0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6]"
+ (tst-pprint 15 (reduce conj clojure.lang.PersistentQueue/EMPTY (range 10)))
+ "<-(0\n 1\n 2\n 3\n 4\n 5\n 6\n 7\n 8\n 9)-<"
+ )
;;; Some simple tests of dispatch
@@ -267,11 +267,11 @@ It is implemented with a number of custom enlive templates.\"
(pprint-logical-block :prefix "[" :suffix "]"
(loop [aseq (seq avec)]
(when aseq
- (write-out (first aseq))
- (when (next aseq)
- (.write ^java.io.Writer *out* " ")
- (pprint-newline :linear)
- (recur (next aseq)))))))
+ (write-out (first aseq))
+ (when (next aseq)
+ (.write ^java.io.Writer *out* " ")
+ (pprint-newline :linear)
+ (recur (next aseq)))))))
(defmethod test-dispatch false [aval] (pr aval))
@@ -280,7 +280,7 @@ It is implemented with a number of custom enlive templates.\"
(with-out-str
(pprint '("hello" "there"))))
"[\"hello\" \"there\"]\n"
-)
+ )
(simple-tests print-length-tests
(binding [*print-length* 1] (with-out-str (pprint '(a b c d e f))))
@@ -334,11 +334,11 @@ It is implemented with a number of custom enlive templates.\"
[o]
(let [flush-count-atom (atom 0)]
[
- (proxy [java.io.BufferedWriter] [o]
- (flush []
- (proxy-super flush)
- (swap! flush-count-atom inc)))
- flush-count-atom]))
+ (proxy [java.io.BufferedWriter] [o]
+ (flush []
+ (proxy-super flush)
+ (swap! flush-count-atom inc)))
+ flush-count-atom]))
(deftest test-flush-underlying-prn
[]
diff --git a/test/clojure/test_clojure/predicates.clj b/test/clojure/test_clojure/predicates.clj
index 7efdc6fe..9014c128 100644
--- a/test/clojure/test_clojure/predicates.clj
+++ b/test/clojure/test_clojure/predicates.clj
@@ -20,99 +20,99 @@
(def myvar 42)
(def sample-data {
- :nil nil
-
- :bool-true true
- :bool-false false
-
- :byte (byte 7)
- :short (short 7)
- :int (int 7)
- :long (long 7)
- :bigint (bigint 7)
- :float (float 7)
- :double (double 7)
- :bigdec (bigdec 7)
-
- :ratio 2/3
-
- :character \a
- :symbol 'abc
- :keyword :kw
-
- :empty-string ""
- :empty-regex #""
- :empty-list ()
- :empty-lazy-seq (lazy-seq nil)
- :empty-vector []
- :empty-map {}
- :empty-set #{}
- :empty-array (into-array [])
-
- :string "abc"
- :regex #"a*b"
- :list '(1 2 3)
- :lazy-seq (lazy-seq [1 2 3])
- :vector [1 2 3]
- :map {:a 1 :b 2 :c 3}
- :set #{1 2 3}
- :array (into-array [1 2 3])
-
- :fn (fn [x] (* 2 x))
-
- :class java.util.Date
- :object (new java.util.Date)
-
- :var (var myvar)
- :delay (delay (+ 1 2))
-})
+ :nil nil
+
+ :bool-true true
+ :bool-false false
+
+ :byte (byte 7)
+ :short (short 7)
+ :int (int 7)
+ :long (long 7)
+ :bigint (bigint 7)
+ :float (float 7)
+ :double (double 7)
+ :bigdec (bigdec 7)
+
+ :ratio 2/3
+
+ :character \a
+ :symbol 'abc
+ :keyword :kw
+
+ :empty-string ""
+ :empty-regex #""
+ :empty-list ()
+ :empty-lazy-seq (lazy-seq nil)
+ :empty-vector []
+ :empty-map {}
+ :empty-set #{}
+ :empty-array (into-array [])
+
+ :string "abc"
+ :regex #"a*b"
+ :list '(1 2 3)
+ :lazy-seq (lazy-seq [1 2 3])
+ :vector [1 2 3]
+ :map {:a 1 :b 2 :c 3}
+ :set #{1 2 3}
+ :array (into-array [1 2 3])
+
+ :fn (fn [x] (* 2 x))
+
+ :class java.util.Date
+ :object (new java.util.Date)
+
+ :var (var myvar)
+ :delay (delay (+ 1 2))
+ })
(def type-preds {
- nil? [:nil]
-
- true? [:bool-true]
- false? [:bool-false]
- ; boolean?
-
- integer? [:byte :short :int :long :bigint]
- float? [:float :double]
- decimal? [:bigdec]
- ratio? [:ratio]
- rational? [:byte :short :int :long :bigint :ratio :bigdec]
- number? [:byte :short :int :long :bigint :ratio :bigdec :float :double]
-
- ; character?
- symbol? [:symbol]
- keyword? [:keyword]
-
- string? [:empty-string :string]
- ; regex?
-
- list? [:empty-list :list]
- vector? [:empty-vector :vector]
- map? [:empty-map :map]
- set? [:empty-set :set]
-
- coll? [:empty-list :list
- :empty-lazy-seq :lazy-seq
- :empty-vector :vector
- :empty-map :map
- :empty-set :set]
-
- seq? [:empty-list :list
- :empty-lazy-seq :lazy-seq]
- ; array?
-
- fn? [:fn]
- ifn? [:fn
- :empty-vector :vector :empty-map :map :empty-set :set
- :keyword :symbol :var]
-
- class? [:class]
- var? [:var]
- delay? [:delay]
-})
+ nil? [:nil]
+
+ true? [:bool-true]
+ false? [:bool-false]
+ ; boolean?
+
+ integer? [:byte :short :int :long :bigint]
+ float? [:float :double]
+ decimal? [:bigdec]
+ ratio? [:ratio]
+ rational? [:byte :short :int :long :bigint :ratio :bigdec]
+ number? [:byte :short :int :long :bigint :ratio :bigdec :float :double]
+
+ ; character?
+ symbol? [:symbol]
+ keyword? [:keyword]
+
+ string? [:empty-string :string]
+ ; regex?
+
+ list? [:empty-list :list]
+ vector? [:empty-vector :vector]
+ map? [:empty-map :map]
+ set? [:empty-set :set]
+
+ coll? [:empty-list :list
+ :empty-lazy-seq :lazy-seq
+ :empty-vector :vector
+ :empty-map :map
+ :empty-set :set]
+
+ seq? [:empty-list :list
+ :empty-lazy-seq :lazy-seq]
+ ; array?
+
+ fn? [:fn]
+ ifn? [:fn
+ :empty-vector :vector :empty-map :map :empty-set :set
+ :keyword :symbol :var]
+
+ class? [:class]
+ var? [:var]
+ delay? [:delay]
+ })
;; Test all type predicates against all data types
diff --git a/test/clojure/test_clojure/printer.clj b/test/clojure/test_clojure/printer.clj
index 3d9cc65f..dfbcadd6 100644
--- a/test/clojure/test_clojure/printer.clj
+++ b/test/clojure/test_clojure/printer.clj
@@ -143,9 +143,9 @@
(deftest print-symbol-values
(are [s v] (= s (pr-str v))
- "##Inf" Double/POSITIVE_INFINITY
- "##-Inf" Double/NEGATIVE_INFINITY
- "##NaN" Double/NaN
- "##Inf" Float/POSITIVE_INFINITY
- "##-Inf" Float/NEGATIVE_INFINITY
- "##NaN" Float/NaN))
+ "##Inf" Double/POSITIVE_INFINITY
+ "##-Inf" Double/NEGATIVE_INFINITY
+ "##NaN" Double/NaN
+ "##Inf" Float/POSITIVE_INFINITY
+ "##-Inf" Float/NEGATIVE_INFINITY
+ "##NaN" Float/NaN))
diff --git a/test/clojure/test_clojure/protocols.clj b/test/clojure/test_clojure/protocols.clj
index 30729154..6c01df57 100644
--- a/test/clojure/test_clojure/protocols.clj
+++ b/test/clojure/test_clojure/protocols.clj
@@ -11,8 +11,8 @@
(ns clojure.test-clojure.protocols
(:use clojure.test clojure.test-clojure.protocols.examples)
(:require [clojure.test-clojure.protocols.more-examples :as other]
- [clojure.set :as set]
- clojure.test-helper)
+ [clojure.set :as set]
+ clojure.test-helper)
(:import [clojure.test_clojure.protocols.examples ExampleInterface]))
;; temporary hack until I decide how to cleanly reload protocol
@@ -31,8 +31,8 @@
"return sorted list of method names on a class"
[c]
(->> (.getMethods c)
- (map #(.getName %))
- (sort)))
+ (map #(.getName %))
+ (sort)))
(defrecord EmptyRecord [])
(defrecord TestRecord [a b])
@@ -73,13 +73,13 @@
(is (thrown? AbstractMethodError (baz obj)))))
(testing "error conditions checked when defining protocols"
(is (thrown-with-cause-msg?
- Exception
- #"Definition of function m in protocol badprotdef must take at least one arg."
- (eval '(defprotocol badprotdef (m [])))))
+ Exception
+ #"Definition of function m in protocol badprotdef must take at least one arg."
+ (eval '(defprotocol badprotdef (m [])))))
(is (thrown-with-cause-msg?
- Exception
- #"Function m in protocol badprotdef was redefined. Specify all arities in single definition."
- (eval '(defprotocol badprotdef (m [this arg]) (m [this arg1 arg2]))))))
+ Exception
+ #"Function m in protocol badprotdef was redefined. Specify all arities in single definition."
+ (eval '(defprotocol badprotdef (m [this arg]) (m [this arg1 arg2]))))))
(testing "you can redefine a protocol with different methods"
(eval '(defprotocol Elusive (old-method [x])))
(eval '(defprotocol Elusive (new-method [x])))
@@ -120,13 +120,13 @@
(is (= "pow" (foo "pow"))))
(testing "you can have two methods with the same name. Just use namespaces!"
(extend String other/SimpleProtocol
- {:foo (fn [s] (.toUpperCase s))})
+ {:foo (fn [s] (.toUpperCase s))})
(is (= "POW" (other/foo "pow"))))
(testing "you can extend deftype types"
(extend
- ExtendTestWidget
- ExampleProtocol
- {:foo (fn [this] (str "widget " (.name this)))})
+ ExtendTestWidget
+ ExampleProtocol
+ {:foo (fn [this] (str "widget " (.name this)))})
(is (= "widget z" (foo (ExtendTestWidget. "z"))))))
(deftest record-marker-interfaces
@@ -149,65 +149,65 @@
(deftype ExtendsTestWidget []
ExampleProtocol)
#_(deftest extends?-test
- (reload-example-protocols)
- (testing "returns false if a type does not implement the protocol at all"
- (is (false? (extends? other/SimpleProtocol ExtendsTestWidget))))
- (testing "returns true if a type implements the protocol directly" ;; semantics changed 4/15/2010
- (is (true? (extends? ExampleProtocol ExtendsTestWidget))))
- (testing "returns true if a type explicitly extends protocol"
- (extend
- ExtendsTestWidget
- other/SimpleProtocol
- {:foo identity})
- (is (true? (extends? other/SimpleProtocol ExtendsTestWidget)))))
+ (reload-example-protocols)
+ (testing "returns false if a type does not implement the protocol at all"
+ (is (false? (extends? other/SimpleProtocol ExtendsTestWidget))))
+ (testing "returns true if a type implements the protocol directly" ;; semantics changed 4/15/2010
+ (is (true? (extends? ExampleProtocol ExtendsTestWidget))))
+ (testing "returns true if a type explicitly extends protocol"
+ (extend
+ ExtendsTestWidget
+ other/SimpleProtocol
+ {:foo identity})
+ (is (true? (extends? other/SimpleProtocol ExtendsTestWidget)))))
(deftype ExtendersTestWidget [])
#_(deftest extenders-test
- (reload-example-protocols)
- (testing "a fresh protocol has no extenders"
- (is (nil? (extenders ExampleProtocol))))
- (testing "extending with no methods doesn't count!"
- (deftype Something [])
- (extend ::Something ExampleProtocol)
- (is (nil? (extenders ExampleProtocol))))
- (testing "extending a protocol (and including an impl) adds an entry to extenders"
- (extend ExtendersTestWidget ExampleProtocol {:foo identity})
- (is (= [ExtendersTestWidget] (extenders ExampleProtocol)))))
+ (reload-example-protocols)
+ (testing "a fresh protocol has no extenders"
+ (is (nil? (extenders ExampleProtocol))))
+ (testing "extending with no methods doesn't count!"
+ (deftype Something [])
+ (extend ::Something ExampleProtocol)
+ (is (nil? (extenders ExampleProtocol))))
+ (testing "extending a protocol (and including an impl) adds an entry to extenders"
+ (extend ExtendersTestWidget ExampleProtocol {:foo identity})
+ (is (= [ExtendersTestWidget] (extenders ExampleProtocol)))))
(deftype SatisfiesTestWidget []
ExampleProtocol)
#_(deftest satisifies?-test
- (reload-example-protocols)
- (let [whatzit (SatisfiesTestWidget.)]
- (testing "returns false if a type does not implement the protocol at all"
- (is (false? (satisfies? other/SimpleProtocol whatzit))))
- (testing "returns true if a type implements the protocol directly"
- (is (true? (satisfies? ExampleProtocol whatzit))))
- (testing "returns true if a type explicitly extends protocol"
- (extend
- SatisfiesTestWidget
- other/SimpleProtocol
- {:foo identity})
- (is (true? (satisfies? other/SimpleProtocol whatzit))))) )
+ (reload-example-protocols)
+ (let [whatzit (SatisfiesTestWidget.)]
+ (testing "returns false if a type does not implement the protocol at all"
+ (is (false? (satisfies? other/SimpleProtocol whatzit))))
+ (testing "returns true if a type implements the protocol directly"
+ (is (true? (satisfies? ExampleProtocol whatzit))))
+ (testing "returns true if a type explicitly extends protocol"
+ (extend
+ SatisfiesTestWidget
+ other/SimpleProtocol
+ {:foo identity})
+ (is (true? (satisfies? other/SimpleProtocol whatzit))))) )
(deftype ReExtendingTestWidget [])
#_(deftest re-extending-test
- (reload-example-protocols)
- (extend
- ReExtendingTestWidget
- ExampleProtocol
- {:foo (fn [_] "first foo")
- :baz (fn [_] "first baz")})
- (testing "if you re-extend, the old implementation is replaced (not merged!)"
+ (reload-example-protocols)
(extend
- ReExtendingTestWidget
- ExampleProtocol
- {:baz (fn [_] "second baz")
- :bar (fn [_ _] "second bar")})
- (let [whatzit (ReExtendingTestWidget.)]
- (is (thrown? IllegalArgumentException (foo whatzit)))
- (is (= "second bar" (bar whatzit nil)))
- (is (= "second baz" (baz whatzit))))))
+ ReExtendingTestWidget
+ ExampleProtocol
+ {:foo (fn [_] "first foo")
+ :baz (fn [_] "first baz")})
+ (testing "if you re-extend, the old implementation is replaced (not merged!)"
+ (extend
+ ReExtendingTestWidget
+ ExampleProtocol
+ {:baz (fn [_] "second baz")
+ :bar (fn [_ _] "second bar")})
+ (let [whatzit (ReExtendingTestWidget.)]
+ (is (thrown? IllegalArgumentException (foo whatzit)))
+ (is (= "second bar" (bar whatzit nil)))
+ (is (= "second baz" (baz whatzit))))))
(defrecord DefrecordObjectMethodsWidgetA [a])
(defrecord DefrecordObjectMethodsWidgetB [a])
@@ -335,17 +335,17 @@
(is (= r-n (map->RecordToTestFactories (map->RecordToTestFactories {}))))
(is (= r-d (map->RecordToTestDegenerateFactories {})))
(is (= r-d (map->RecordToTestDegenerateFactories
- (map->RecordToTestDegenerateFactories {})))))
+ (map->RecordToTestDegenerateFactories {})))))
(testing "that ext maps work correctly"
(is (= (assoc r :xxx 42) (map->RecordToTestFactories {:a 1 :b 2 :c 3 :xxx 42})))
(is (= (assoc r :xxx 42) (map->RecordToTestFactories (map->RecordToTestFactories
- {:a 1 :b 2 :c 3 :xxx 42}))))
+ {:a 1 :b 2 :c 3 :xxx 42}))))
(is (= (assoc r-n :xxx 42) (map->RecordToTestFactories {:xxx 42})))
(is (= (assoc r-n :xxx 42) (map->RecordToTestFactories (map->RecordToTestFactories
- {:xxx 42}))))
+ {:xxx 42}))))
(is (= (assoc r-d :xxx 42) (map->RecordToTestDegenerateFactories {:xxx 42})))
(is (= (assoc r-d :xxx 42) (map->RecordToTestDegenerateFactories
- (map->RecordToTestDegenerateFactories {:xxx 42})))))
+ (map->RecordToTestDegenerateFactories {:xxx 42})))))
(testing "record equality"
(is (not= r-a r-b))
(is (= (into {} r-a) (into {} r-b)))
@@ -381,32 +381,32 @@
(defn compare-huge-types
[hugeL hugeR]
(and
- (= (.a hugeL) (.a hugeR))
- (= (.b hugeL) (.b hugeR))
- (= (.c hugeL) (.c hugeR))
- (= (.d hugeL) (.d hugeR))
- (= (.e hugeL) (.e hugeR))
- (= (.f hugeL) (.f hugeR))
- (= (.g hugeL) (.g hugeR))
- (= (.h hugeL) (.h hugeR))
- (= (.i hugeL) (.i hugeR))
- (= (.j hugeL) (.j hugeR))
- (= (.k hugeL) (.k hugeR))
- (= (.l hugeL) (.l hugeR))
- (= (.m hugeL) (.m hugeR))
- (= (.n hugeL) (.n hugeR))
- (= (.o hugeL) (.o hugeR))
- (= (.p hugeL) (.p hugeR))
- (= (.q hugeL) (.q hugeR))
- (= (.r hugeL) (.r hugeR))
- (= (.s hugeL) (.s hugeR))
- (= (.t hugeL) (.t hugeR))
- (= (.u hugeL) (.u hugeR))
- (= (.v hugeL) (.v hugeR))
- (= (.w hugeL) (.w hugeR))
- (= (.x hugeL) (.x hugeR))
- (= (.y hugeL) (.y hugeR))
- (= (.z hugeL) (.z hugeR))))
+ (= (.a hugeL) (.a hugeR))
+ (= (.b hugeL) (.b hugeR))
+ (= (.c hugeL) (.c hugeR))
+ (= (.d hugeL) (.d hugeR))
+ (= (.e hugeL) (.e hugeR))
+ (= (.f hugeL) (.f hugeR))
+ (= (.g hugeL) (.g hugeR))
+ (= (.h hugeL) (.h hugeR))
+ (= (.i hugeL) (.i hugeR))
+ (= (.j hugeL) (.j hugeR))
+ (= (.k hugeL) (.k hugeR))
+ (= (.l hugeL) (.l hugeR))
+ (= (.m hugeL) (.m hugeR))
+ (= (.n hugeL) (.n hugeR))
+ (= (.o hugeL) (.o hugeR))
+ (= (.p hugeL) (.p hugeR))
+ (= (.q hugeL) (.q hugeR))
+ (= (.r hugeL) (.r hugeR))
+ (= (.s hugeL) (.s hugeR))
+ (= (.t hugeL) (.t hugeR))
+ (= (.u hugeL) (.u hugeR))
+ (= (.v hugeL) (.v hugeR))
+ (= (.w hugeL) (.w hugeR))
+ (= (.x hugeL) (.x hugeR))
+ (= (.y hugeL) (.y hugeR))
+ (= (.z hugeL) (.z hugeR))))
(deftype TypeToTestFactory [a])
(defrecord TypeToTestHugeFactories [a b c d e f g h i j k l m n o p q r s t u v w x y z])
@@ -415,8 +415,8 @@
(testing "that the ->T factory is gen'd for a deftype and that it works"
(is (= (.a (TypeToTestFactory. 42)) (.a (->TypeToTestFactory 42))))
(is (compare-huge-types
- (TypeToTestHugeFactories. 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)
- (->TypeToTestHugeFactories 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))))
+ (TypeToTestHugeFactories. 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)
+ (->TypeToTestHugeFactories 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))))
(testing "that the generated factory checks arity constraints"
(is (thrown? clojure.lang.ArityException (->TypeToTestHugeFactories 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)))
(is (thrown? clojure.lang.ArityException (->TypeToTestHugeFactories 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)))))
@@ -432,8 +432,8 @@
(testing "that constructor literals work for deftypes too"
(is (= (.a (TypeToTestFactory. 42)) (.a #clojure.test_clojure.protocols.TypeToTestFactory[42])))
(is (compare-huge-types
- (TypeToTestHugeFactories. 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)
- #clojure.test_clojure.protocols.TypeToTestHugeFactories[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]))))
+ (TypeToTestHugeFactories. 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)
+ #clojure.test_clojure.protocols.TypeToTestHugeFactories[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]))))
(defrecord RecordToTestLiterals [a])
(defrecord TestNode [v l r])
@@ -581,8 +581,8 @@
(testing "of an interface"
(let [s :foo
r (reify
- java.util.List
- (contains [_ o] (= s o)))]
+ java.util.List
+ (contains [_ o] (= s o)))]
(testing "implemented methods"
(is (true? (.contains r :foo)))
(is (false? (.contains r :bar))))
@@ -590,44 +590,44 @@
(is (thrown? AbstractMethodError (.add r :baz))))))
(testing "of two interfaces"
(let [r (reify
- java.util.List
- (contains [_ o] (= :foo o))
- java.util.Collection
- (isEmpty [_] false))]
+ java.util.List
+ (contains [_ o] (= :foo o))
+ java.util.Collection
+ (isEmpty [_] false))]
(is (true? (.contains r :foo)))
(is (false? (.contains r :bar)))
(is (false? (.isEmpty r)))))
(testing "you can't define a method twice"
(is (thrown? Exception
- (eval '(reify
- java.util.List
- (size [_] 10)
- java.util.Collection
- (size [_] 20))))))
+ (eval '(reify
+ java.util.List
+ (size [_] 10)
+ java.util.Collection
+ (size [_] 20))))))
(testing "you can't define a method not on an interface/protocol/j.l.Object"
(is (thrown? Exception
- (eval '(reify java.util.List (foo [_]))))))
+ (eval '(reify java.util.List (foo [_]))))))
(testing "of a protocol"
(let [r (reify
- ExampleProtocol
- (bar [this o] o)
- (baz [this] 1)
- (baz [this o] 2))]
+ ExampleProtocol
+ (bar [this o] o)
+ (baz [this] 1)
+ (baz [this o] 2))]
(is (= :foo (.bar r :foo)))
(is (= 1 (.baz r)))
(is (= 2 (.baz r nil)))))
(testing "destructuring in method def"
(let [r (reify
- ExampleProtocol
- (bar [this [_ _ item]] item))]
+ ExampleProtocol
+ (bar [this [_ _ item]] item))]
(is (= :c (.bar r [:a :b :c])))))
(testing "methods can recur"
(let [r (reify
- java.util.List
- (get [_ index]
- (if (zero? index)
- :done
- (recur (dec index)))))]
+ java.util.List
+ (get [_ index]
+ (if (zero? index)
+ :done
+ (recur (dec index)))))]
(is (= :done (.get r 0)))
(is (= :done (.get r 1)))))
(testing "disambiguating with type hints"
@@ -636,9 +636,9 @@
(eval '(reify clojure.test_clojure.protocols.examples.ExampleInterface (hinted [_ o]))))))
(testing "hinting"
(let [r (reify
- ExampleInterface
- (hinted [_ ^int i] (inc i))
- (hinted [_ ^String s] (str s s)))]
+ ExampleInterface
+ (hinted [_ ^int i] (inc i))
+ (hinted [_ ^String s] (str s s)))]
(is (= 2 (.hinted r 1)))
(is (= "xoxo" (.hinted r "xo")))))))
diff --git a/test/clojure/test_clojure/protocols/hash_collisions.clj b/test/clojure/test_clojure/protocols/hash_collisions.clj
index 8c5bb5ad..5f2b5e61 100644
--- a/test/clojure/test_clojure/protocols/hash_collisions.clj
+++ b/test/clojure/test_clojure/protocols/hash_collisions.clj
@@ -47,22 +47,22 @@
else."
[x]
(cond
- (= x TestType1) 1
- (= x TestType2) 2
- (= x TestType3) 4
- (= x TestType4) 8
- (= x TestType5) 16
- (= x TestType6) 32
- (= x TestType7) 64
- (= x TestType8) 128
- (= x TestType9) 256
- (= x TestType10) 512
- (= x TestType11) 1024
- (= x TestType12) 2048
- (= x TestType13) 4096
- (= x TestType14) 8192
- (= x TestType15) 16384
- :else (original-hash x)))
+ (= x TestType1) 1
+ (= x TestType2) 2
+ (= x TestType3) 4
+ (= x TestType4) 8
+ (= x TestType5) 16
+ (= x TestType6) 32
+ (= x TestType7) 64
+ (= x TestType8) 128
+ (= x TestType9) 256
+ (= x TestType10) 512
+ (= x TestType11) 1024
+ (= x TestType12) 2048
+ (= x TestType13) 4096
+ (= x TestType14) 8192
+ (= x TestType15) 16384
+ :else (original-hash x)))
(deftest protocols-with-no-min-hash-in-13-bits
(with-redefs [hash no-min-hash-in-13-bits]
diff --git a/test/clojure/test_clojure/reader.cljc b/test/clojure/test_clojure/reader.cljc
index 522a2792..b026c037 100644
--- a/test/clojure/test_clojure/reader.cljc
+++ b/test/clojure/test_clojure/reader.cljc
@@ -22,13 +22,13 @@
read-instant-calendar
read-instant-timestamp]])
(:require clojure.walk
- [clojure.edn :as edn]
- [clojure.test.generative :refer (defspec)]
- [clojure.test-clojure.generators :as cgen]
- [clojure.edn :as edn])
+ [clojure.edn :as edn]
+ [clojure.test.generative :refer (defspec)]
+ [clojure.test-clojure.generators :as cgen]
+ [clojure.edn :as edn])
(:import [clojure.lang BigInt Ratio]
- java.io.File
- java.util.TimeZone))
+ java.io.File
+ java.util.TimeZone))
;; Symbols
@@ -78,7 +78,7 @@
(doseq [source [:string :file]]
(testing (str "Valid string literals read from " (name source))
(are [x form] (= x (code-units
- (read-from source f (str "\"" form "\""))))
+ (read-from source f (str "\"" form "\""))))
[] ""
[34] "\\\""
[10] "\\n"
@@ -286,7 +286,7 @@
(is (instance? Ratio 1/2))
(is (instance? Ratio -1/2))
(is (instance? Ratio +1/2))
-)
+ )
;; Characters
@@ -460,8 +460,8 @@
(deftest t-Syntax-quote
(are [x y] (= x y)
- `() () ; was NPE before SVN r1337
- ))
+ `() () ; was NPE before SVN r1337
+ ))
;; (read)
;; (read stream)
@@ -602,8 +602,8 @@
*print-dup* nil
*print-level* nil]
(try
- (-> o pr-str read-string)
- (catch Throwable t t))))
+ (-> o pr-str read-string)
+ (catch Throwable t t))))
(defn roundtrip-dup
"Print an object with print-dup and read it back.
@@ -613,8 +613,8 @@
*print-dup* true
*print-level* nil]
(try
- (-> o pr-str read-string)
- (catch Throwable t t))))
+ (-> o pr-str read-string)
+ (catch Throwable t t))))
(defspec types-that-should-roundtrip
roundtrip
@@ -718,7 +718,7 @@
(deftest eof-option
(is (= 23 (read-string {:eof 23} "")))
(is (= 23 (read {:eof 23} (clojure.lang.LineNumberingPushbackReader.
- (java.io.StringReader. ""))))))
+ (java.io.StringReader. ""))))))
(require '[clojure.string :as s])
(deftest namespaced-maps
@@ -737,13 +737,13 @@
(deftest namespaced-map-errors
(are [err msg form] (thrown-with-msg? err msg (read-string form))
- Exception #"Invalid token" "#:::"
- Exception #"Namespaced map literal must contain an even number of forms" "#:s{1}"
- Exception #"Namespaced map must specify a valid namespace" "#:s/t{1 2}"
- Exception #"Unknown auto-resolved namespace alias" "#::BOGUS{1 2}"
- Exception #"Namespaced map must specify a namespace" "#: s{:a 1}"
- Exception #"Duplicate key: :user/a" "#::{:a 1 :a 2}"
- Exception #"Duplicate key: user/a" "#::{a 1 a 2}"))
+ Exception #"Invalid token" "#:::"
+ Exception #"Namespaced map literal must contain an even number of forms" "#:s{1}"
+ Exception #"Namespaced map must specify a valid namespace" "#:s/t{1 2}"
+ Exception #"Unknown auto-resolved namespace alias" "#::BOGUS{1 2}"
+ Exception #"Namespaced map must specify a namespace" "#: s{:a 1}"
+ Exception #"Duplicate key: :user/a" "#::{:a 1 :a 2}"
+ Exception #"Duplicate key: user/a" "#::{a 1 a 2}"))
(deftest namespaced-map-edn
(is (= {1 1, :a/b 2, :b/c 3, :d 4}
diff --git a/test/clojure/test_clojure/reducers.clj b/test/clojure/test_clojure/reducers.clj
index a884c851..2d871952 100644
--- a/test/clojure/test_clojure/reducers.clj
+++ b/test/clojure/test_clojure/reducers.clj
@@ -10,8 +10,8 @@
(ns clojure.test-clojure.reducers
(:require [clojure.core.reducers :as r]
- [clojure.test.generative :refer (defspec)]
- [clojure.data.generators :as gen])
+ [clojure.test.generative :refer (defspec)]
+ [clojure.data.generators :as gen])
(:use clojure.test))
(defmacro defequivtest
diff --git a/test/clojure/test_clojure/reflect.clj b/test/clojure/test_clojure/reflect.clj
index 36ea6817..516c763f 100644
--- a/test/clojure/test_clojure/reflect.clj
+++ b/test/clojure/test_clojure/reflect.clj
@@ -1,7 +1,7 @@
(ns clojure.test-clojure.reflect
(:use clojure.data [clojure.reflect :as reflect] clojure.test clojure.pprint)
(:import [clojure.reflect AsmReflector JavaReflector]
- [reflector IBar$Factory]))
+ [reflector IBar$Factory]))
(defn nodiff
[x y]
@@ -12,17 +12,17 @@
:common common}))))))
#_(deftest compare-reflect-and-asm
- (let [cl (.getContextClassLoader (Thread/currentThread))
- asm-reflector (AsmReflector. cl)
- java-reflector (JavaReflector. cl)]
- (doseq [classname '[java.lang.Runnable
- java.lang.Object
- java.io.FileInputStream
- clojure.lang.Compiler
- clojure.lang.PersistentVector
- java.lang.SuppressWarnings]]
- (nodiff (type-reflect classname :reflector asm-reflector)
- (type-reflect classname :reflector java-reflector)))))
+ (let [cl (.getContextClassLoader (Thread/currentThread))
+ asm-reflector (AsmReflector. cl)
+ java-reflector (JavaReflector. cl)]
+ (doseq [classname '[java.lang.Runnable
+ java.lang.Object
+ java.io.FileInputStream
+ clojure.lang.Compiler
+ clojure.lang.PersistentVector
+ java.lang.SuppressWarnings]]
+ (nodiff (type-reflect classname :reflector asm-reflector)
+ (type-reflect classname :reflector java-reflector)))))
(deftest field-descriptor->class-symbol-test
(are [s d] (= s (@#'reflect/field-descriptor->class-symbol d))
diff --git a/test/clojure/test_clojure/repl.clj b/test/clojure/test_clojure/repl.clj
index c7a0c41b..678246a2 100644
--- a/test/clojure/test_clojure/repl.clj
+++ b/test/clojure/test_clojure/repl.clj
@@ -1,8 +1,8 @@
(ns clojure.test-clojure.repl
(:use clojure.test
- clojure.repl
- [clojure.test-helper :only [platform-newlines]]
- clojure.test-clojure.repl.example)
+ clojure.repl
+ [clojure.test-helper :only [platform-newlines]]
+ clojure.test-clojure.repl.example)
(:require [clojure.string :as str]))
(deftest test-doc
@@ -56,6 +56,6 @@
(deftest test-dynamic-ns
(testing "a call to ns returns nil"
- (is (= nil (call-ns))))
+ (is (= nil (call-ns))))
(testing "requiring a dynamically created ns should not throw an exception"
(is (= nil (let [a (call-ns-sym)] (require a))))))
diff --git a/test/clojure/test_clojure/rt.clj b/test/clojure/test_clojure/rt.clj
index 39526975..dd8678c6 100644
--- a/test/clojure/test_clojure/rt.clj
+++ b/test/clojure/test_clojure/rt.clj
@@ -17,10 +17,10 @@
[x]
(with-out-str
(try
- (push-thread-bindings {#'clojure.core/print-initialized false})
- (clojure.lang.RT/print x *out*)
- (finally
- (pop-thread-bindings)))))
+ (push-thread-bindings {#'clojure.core/print-initialized false})
+ (clojure.lang.RT/print x *out*)
+ (finally
+ (pop-thread-bindings)))))
(deftest rt-print-prior-to-print-initialize
(testing "pattern literals"
@@ -29,44 +29,44 @@
(deftest error-messages
(testing "binding a core var that already refers to something"
(should-print-err-message
- #"WARNING: prefers already refers to: #'clojure.core/prefers in namespace: .*\r?\n"
- (defn prefers [] (throw (RuntimeException. "rebound!")))))
+ #"WARNING: prefers already refers to: #'clojure.core/prefers in namespace: .*\r?\n"
+ (defn prefers [] (throw (RuntimeException. "rebound!")))))
(testing "reflection cannot resolve field"
(should-print-err-message
- #"Reflection warning, .*:\d+:\d+ - reference to field blah can't be resolved\.\r?\n"
- (defn foo [x] (.blah x))))
+ #"Reflection warning, .*:\d+:\d+ - reference to field blah can't be resolved\.\r?\n"
+ (defn foo [x] (.blah x))))
(testing "reflection cannot resolve field on known class"
(should-print-err-message
- #"Reflection warning, .*:\d+:\d+ - reference to field blah on java\.lang\.String can't be resolved\.\r?\n"
- (defn foo [^String x] (.blah x))))
+ #"Reflection warning, .*:\d+:\d+ - reference to field blah on java\.lang\.String can't be resolved\.\r?\n"
+ (defn foo [^String x] (.blah x))))
(testing "reflection cannot resolve instance method because it is missing"
(should-print-err-message
- #"Reflection warning, .*:\d+:\d+ - call to method zap on java\.lang\.String can't be resolved \(no such method\)\.\r?\n"
- (defn foo [^String x] (.zap x 1))))
+ #"Reflection warning, .*:\d+:\d+ - call to method zap on java\.lang\.String can't be resolved \(no such method\)\.\r?\n"
+ (defn foo [^String x] (.zap x 1))))
(testing "reflection cannot resolve instance method because it has incompatible argument types"
(should-print-err-message
- #"Reflection warning, .*:\d+:\d+ - call to method getBytes on java\.lang\.String can't be resolved \(argument types: java\.util\.regex\.Pattern\)\.\r?\n"
- (defn foo [^String x] (.getBytes x #"boom"))))
+ #"Reflection warning, .*:\d+:\d+ - call to method getBytes on java\.lang\.String can't be resolved \(argument types: java\.util\.regex\.Pattern\)\.\r?\n"
+ (defn foo [^String x] (.getBytes x #"boom"))))
(testing "reflection cannot resolve instance method because it has unknown argument types"
(should-print-err-message
- #"Reflection warning, .*:\d+:\d+ - call to method getBytes on java\.lang\.String can't be resolved \(argument types: unknown\)\.\r?\n"
- (defn foo [^String x y] (.getBytes x y))))
+ #"Reflection warning, .*:\d+:\d+ - call to method getBytes on java\.lang\.String can't be resolved \(argument types: unknown\)\.\r?\n"
+ (defn foo [^String x y] (.getBytes x y))))
(testing "reflection error prints correctly for nil arguments"
(should-print-err-message
- #"Reflection warning, .*:\d+:\d+ - call to method divide on java\.math\.BigDecimal can't be resolved \(argument types: unknown, unknown\)\.\r?\n"
- (defn foo [a] (.divide 1M a nil))))
+ #"Reflection warning, .*:\d+:\d+ - call to method divide on java\.math\.BigDecimal can't be resolved \(argument types: unknown, unknown\)\.\r?\n"
+ (defn foo [a] (.divide 1M a nil))))
(testing "reflection cannot resolve instance method because target class is unknown"
(should-print-err-message
- #"Reflection warning, .*:\d+:\d+ - call to method zap can't be resolved \(target class is unknown\)\.\r?\n"
- (defn foo [x] (.zap x 1))))
+ #"Reflection warning, .*:\d+:\d+ - call to method zap can't be resolved \(target class is unknown\)\.\r?\n"
+ (defn foo [x] (.zap x 1))))
(testing "reflection cannot resolve static method"
(should-print-err-message
- #"Reflection warning, .*:\d+:\d+ - call to static method valueOf on java\.lang\.Integer can't be resolved \(argument types: java\.util\.regex\.Pattern\)\.\r?\n"
- (defn foo [] (Integer/valueOf #"boom"))))
+ #"Reflection warning, .*:\d+:\d+ - call to static method valueOf on java\.lang\.Integer can't be resolved \(argument types: java\.util\.regex\.Pattern\)\.\r?\n"
+ (defn foo [] (Integer/valueOf #"boom"))))
(testing "reflection cannot resolve constructor"
(should-print-err-message
- #"Reflection warning, .*:\d+:\d+ - call to java\.lang\.String ctor can't be resolved\.\r?\n"
- (defn foo [] (String. 1 2 3)))))
+ #"Reflection warning, .*:\d+:\d+ - call to java\.lang\.String ctor can't be resolved\.\r?\n"
+ (defn foo [] (String. 1 2 3)))))
(def example-var)
(deftest binding-root-clears-macro-metadata
@@ -78,7 +78,7 @@
(deftest last-var-wins-for-core
(testing "you can replace a core name, with warning"
(let [ns (temp-ns)
- replacement (gensym)]
+ replacement (gensym)]
(with-err-string-writer (intern ns 'prefers replacement))
(is (= replacement @('prefers (ns-publics ns))))))
(testing "you can replace a name you defined before"
diff --git a/test/clojure/test_clojure/sequences.clj b/test/clojure/test_clojure/sequences.clj
index e568b525..a11bd5ea 100644
--- a/test/clojure/test_clojure/sequences.clj
+++ b/test/clojure/test_clojure/sequences.clj
@@ -11,9 +11,9 @@
(ns clojure.test-clojure.sequences
(:require [clojure.test :refer :all]
- [clojure.test.check.generators :as gen]
- [clojure.test.check.properties :as prop]
- [clojure.test.check.clojure-test :refer (defspec)])
+ [clojure.test.check.generators :as gen]
+ [clojure.test.check.properties :as prop]
+ [clojure.test.check.clojure-test :refer (defspec)])
(:import clojure.lang.IReduce))
;; *** Tests ***
@@ -45,41 +45,41 @@
byte-vec (into (vector-of :byte) (map byte arange))
all-true (into-array Boolean/TYPE (repeat 10 true))]
(is (== 4950
- (reduce + arange)
- (reduce + avec)
- (.reduce ^IReduce avec +)
- (reduce + alist)
- (reduce + obj-array)
- (reduce + int-array)
- (reduce + long-array)
- (reduce + float-array)
- (reduce int+ char-array)
- (reduce + double-array)
- (reduce int+ byte-array)
- (reduce + int-vec)
- (reduce + long-vec)
- (reduce + float-vec)
- (reduce int+ char-vec)
- (reduce + double-vec)
- (reduce int+ byte-vec)))
+ (reduce + arange)
+ (reduce + avec)
+ (.reduce ^IReduce avec +)
+ (reduce + alist)
+ (reduce + obj-array)
+ (reduce + int-array)
+ (reduce + long-array)
+ (reduce + float-array)
+ (reduce int+ char-array)
+ (reduce + double-array)
+ (reduce int+ byte-array)
+ (reduce + int-vec)
+ (reduce + long-vec)
+ (reduce + float-vec)
+ (reduce int+ char-vec)
+ (reduce + double-vec)
+ (reduce int+ byte-vec)))
(is (== 4951
- (reduce + 1 arange)
- (reduce + 1 avec)
- (.reduce ^IReduce avec + 1)
- (reduce + 1 alist)
- (reduce + 1 obj-array)
- (reduce + 1 int-array)
- (reduce + 1 long-array)
- (reduce + 1 float-array)
- (reduce int+ 1 char-array)
- (reduce + 1 double-array)
- (reduce int+ 1 byte-array)
- (reduce + 1 int-vec)
- (reduce + 1 long-vec)
- (reduce + 1 float-vec)
- (reduce int+ 1 char-vec)
- (reduce + 1 double-vec)
- (reduce int+ 1 byte-vec)))
+ (reduce + 1 arange)
+ (reduce + 1 avec)
+ (.reduce ^IReduce avec + 1)
+ (reduce + 1 alist)
+ (reduce + 1 obj-array)
+ (reduce + 1 int-array)
+ (reduce + 1 long-array)
+ (reduce + 1 float-array)
+ (reduce int+ 1 char-array)
+ (reduce + 1 double-array)
+ (reduce int+ 1 byte-array)
+ (reduce + 1 int-vec)
+ (reduce + 1 long-vec)
+ (reduce + 1 float-vec)
+ (reduce int+ 1 char-vec)
+ (reduce + 1 double-vec)
+ (reduce int+ 1 byte-vec)))
(is (= true
(reduce #(and %1 %2) all-true)
(reduce #(and %1 %2) true all-true)))))
@@ -105,43 +105,43 @@
(deftest test-equality
; lazy sequences
(are [x y] (= x y)
- ; fixed SVN 1288 - LazySeq and EmptyList equals/equiv
- ; http://groups.google.com/group/clojure/browse_frm/thread/286d807be9cae2a5#
- (map inc nil) ()
- (map inc ()) ()
- (map inc []) ()
- (map inc #{}) ()
- (map inc {}) ()
- (sequence (map inc) (range 10)) (range 1 11)
- (range 1 11) (sequence (map inc) (range 10))))
+ ; fixed SVN 1288 - LazySeq and EmptyList equals/equiv
+ ; http://groups.google.com/group/clojure/browse_frm/thread/286d807be9cae2a5#
+ (map inc nil) ()
+ (map inc ()) ()
+ (map inc []) ()
+ (map inc #{}) ()
+ (map inc {}) ()
+ (sequence (map inc) (range 10)) (range 1 11)
+ (range 1 11) (sequence (map inc) (range 10))))
(deftest test-lazy-seq
(are [x] (seq? x)
- (lazy-seq nil)
- (lazy-seq [])
- (lazy-seq [1 2]))
+ (lazy-seq nil)
+ (lazy-seq [])
+ (lazy-seq [1 2]))
(is (not (.equals (lazy-seq [3]) (lazy-seq [3N]))))
(are [x y] (= x y)
- (lazy-seq nil) ()
- (lazy-seq [nil]) '(nil)
+ (lazy-seq nil) ()
+ (lazy-seq [nil]) '(nil)
- (lazy-seq ()) ()
- (lazy-seq []) ()
- (lazy-seq #{}) ()
- (lazy-seq {}) ()
- (lazy-seq "") ()
- (lazy-seq (into-array [])) ()
+ (lazy-seq ()) ()
+ (lazy-seq []) ()
+ (lazy-seq #{}) ()
+ (lazy-seq {}) ()
+ (lazy-seq "") ()
+ (lazy-seq (into-array [])) ()
- (lazy-seq [3]) [3N]
- (lazy-seq (list 1 2)) '(1 2)
- (lazy-seq [1 2]) '(1 2)
- (lazy-seq (sorted-set 1 2)) '(1 2)
- (lazy-seq (sorted-map :a 1 :b 2)) '([:a 1] [:b 2])
- (lazy-seq "abc") '(\a \b \c)
- (lazy-seq (into-array [1 2])) '(1 2) ))
+ (lazy-seq [3]) [3N]
+ (lazy-seq (list 1 2)) '(1 2)
+ (lazy-seq [1 2]) '(1 2)
+ (lazy-seq (sorted-set 1 2)) '(1 2)
+ (lazy-seq (sorted-map :a 1 :b 2)) '([:a 1] [:b 2])
+ (lazy-seq "abc") '(\a \b \c)
+ (lazy-seq (into-array [1 2])) '(1 2) ))
(deftest test-seq
@@ -195,82 +195,82 @@
(deftest test-empty
(are [x y] (and (= (empty x) y)
#_(= (class (empty x)) (class y)))
- nil nil
+ nil nil
- () ()
- '(1 2) ()
+ () ()
+ '(1 2) ()
- [] []
- [1 2] []
+ [] []
+ [1 2] []
- {} {}
- {:a 1 :b 2} {}
+ {} {}
+ {:a 1 :b 2} {}
- (sorted-map) (sorted-map)
- (sorted-map :a 1 :b 2) (sorted-map)
+ (sorted-map) (sorted-map)
+ (sorted-map :a 1 :b 2) (sorted-map)
- #{} #{}
- #{1 2} #{}
+ #{} #{}
+ #{1 2} #{}
- (sorted-set) (sorted-set)
- (sorted-set 1 2) (sorted-set)
+ (sorted-set) (sorted-set)
+ (sorted-set 1 2) (sorted-set)
- (seq ()) nil ; (seq ()) => nil
- (seq '(1 2)) ()
+ (seq ()) nil ; (seq ()) => nil
+ (seq '(1 2)) ()
- (seq []) nil ; (seq []) => nil
- (seq [1 2]) ()
+ (seq []) nil ; (seq []) => nil
+ (seq [1 2]) ()
- (seq "") nil ; (seq "") => nil
- (seq "ab") ()
+ (seq "") nil ; (seq "") => nil
+ (seq "ab") ()
- (lazy-seq ()) ()
- (lazy-seq '(1 2)) ()
+ (lazy-seq ()) ()
+ (lazy-seq '(1 2)) ()
- (lazy-seq []) ()
- (lazy-seq [1 2]) ()
+ (lazy-seq []) ()
+ (lazy-seq [1 2]) ()
- ; non-coll, non-seq => nil
- 42 nil
- 1.2 nil
- "abc" nil ))
+ ; non-coll, non-seq => nil
+ 42 nil
+ 1.2 nil
+ "abc" nil ))
;Tests that the comparator is preserved
;The first element should be the same in each set if preserved.
(deftest test-empty-sorted
(let [inv-compare (comp - compare)]
(are [x y] (= (first (into (empty x) x))
- (first y))
- (sorted-set 1 2 3) (sorted-set 1 2 3)
- (sorted-set-by inv-compare 1 2 3) (sorted-set-by inv-compare 1 2 3)
+ (first y))
+ (sorted-set 1 2 3) (sorted-set 1 2 3)
+ (sorted-set-by inv-compare 1 2 3) (sorted-set-by inv-compare 1 2 3)
- (sorted-map 1 :a 2 :b 3 :c) (sorted-map 1 :a 2 :b 3 :c)
- (sorted-map-by inv-compare 1 :a 2 :b 3 :c) (sorted-map-by inv-compare 1 :a 2 :b 3 :c))))
+ (sorted-map 1 :a 2 :b 3 :c) (sorted-map 1 :a 2 :b 3 :c)
+ (sorted-map-by inv-compare 1 :a 2 :b 3 :c) (sorted-map-by inv-compare 1 :a 2 :b 3 :c))))
(deftest test-not-empty
; empty coll/seq => nil
(are [x] (= (not-empty x) nil)
- ()
- []
- {}
- #{}
- (seq ())
- (seq [])
- (lazy-seq ())
- (lazy-seq []) )
+ ()
+ []
+ {}
+ #{}
+ (seq ())
+ (seq [])
+ (lazy-seq ())
+ (lazy-seq []) )
; non-empty coll/seq => identity
(are [x] (and (= (not-empty x) x)
(= (class (not-empty x)) (class x)))
- '(1 2)
- [1 2]
- {:a 1}
- #{1 2}
- (seq '(1 2))
- (seq [1 2])
- (lazy-seq '(1 2))
- (lazy-seq [1 2]) ))
+ '(1 2)
+ [1 2]
+ {:a 1}
+ #{1 2}
+ (seq '(1 2))
+ (seq [1 2])
+ (lazy-seq '(1 2))
+ (lazy-seq [1 2]) ))
(deftest test-first
@@ -341,7 +341,7 @@
(deftest test-next
- ; (is (thrown? IllegalArgumentException (next)))
+ ; (is (thrown? IllegalArgumentException (next)))
(is (thrown? IllegalArgumentException (next true)))
(is (thrown? IllegalArgumentException (next false)))
(is (thrown? IllegalArgumentException (next 1)))
@@ -416,67 +416,67 @@
(deftest test-last
(are [x y] (= x y)
- (last nil) nil
-
- ; list
- (last ()) nil
- (last '(1)) 1
- (last '(1 2 3)) 3
-
- (last '(nil)) nil
- (last '(1 nil)) nil
- (last '(nil 2)) 2
- (last '(())) ()
- (last '(() nil)) nil
- (last '(() 2 nil)) nil
-
- ; vector
- (last []) nil
- (last [1]) 1
- (last [1 2 3]) 3
-
- (last [nil]) nil
- (last [1 nil]) nil
- (last [nil 2]) 2
- (last [[]]) []
- (last [[] nil]) nil
- (last [[] 2 nil]) nil
-
- ; set
- (last #{}) nil
- (last #{1}) 1
- (last (sorted-set 1 2 3)) 3
-
- (last #{nil}) nil
- (last (sorted-set 1 nil)) 1
- (last (sorted-set nil 2)) 2
- (last #{#{}}) #{}
- (last (sorted-set [] nil)) []
- ;(last (sorted-set #{} 2 nil)) nil
-
- ; map
- (last {}) nil
- (last (sorted-map :a 1)) [:a 1]
- (last (sorted-map :a 1 :b 2 :c 3)) [:c 3]
-
- ; string
- (last "") nil
- (last "a") \a
- (last "abc") \c
-
- ; array
- (last (into-array [])) nil
- (last (into-array [1])) 1
- (last (into-array [1 2 3])) 3
- (last (to-array [nil])) nil
- (last (to-array [1 nil])) nil
- (last (to-array [nil 2])) 2 ))
+ (last nil) nil
+
+ ; list
+ (last ()) nil
+ (last '(1)) 1
+ (last '(1 2 3)) 3
+
+ (last '(nil)) nil
+ (last '(1 nil)) nil
+ (last '(nil 2)) 2
+ (last '(())) ()
+ (last '(() nil)) nil
+ (last '(() 2 nil)) nil
+
+ ; vector
+ (last []) nil
+ (last [1]) 1
+ (last [1 2 3]) 3
+
+ (last [nil]) nil
+ (last [1 nil]) nil
+ (last [nil 2]) 2
+ (last [[]]) []
+ (last [[] nil]) nil
+ (last [[] 2 nil]) nil
+
+ ; set
+ (last #{}) nil
+ (last #{1}) 1
+ (last (sorted-set 1 2 3)) 3
+
+ (last #{nil}) nil
+ (last (sorted-set 1 nil)) 1
+ (last (sorted-set nil 2)) 2
+ (last #{#{}}) #{}
+ (last (sorted-set [] nil)) []
+ ;(last (sorted-set #{} 2 nil)) nil
+
+ ; map
+ (last {}) nil
+ (last (sorted-map :a 1)) [:a 1]
+ (last (sorted-map :a 1 :b 2 :c 3)) [:c 3]
+
+ ; string
+ (last "") nil
+ (last "a") \a
+ (last "abc") \c
+
+ ; array
+ (last (into-array [])) nil
+ (last (into-array [1])) 1
+ (last (into-array [1 2 3])) 3
+ (last (to-array [nil])) nil
+ (last (to-array [1 nil])) nil
+ (last (to-array [nil 2])) 2 ))
;; (ffirst coll) = (first (first coll))
;;
(deftest test-ffirst
-; (is (thrown? IllegalArgumentException (ffirst)))
+ ; (is (thrown? IllegalArgumentException (ffirst)))
(are [x y] (= x y)
(ffirst nil) nil
@@ -496,7 +496,7 @@
;; (fnext coll) = (first (next coll)) = (second coll)
;;
(deftest test-fnext
-; (is (thrown? IllegalArgumentException (fnext)))
+ ; (is (thrown? IllegalArgumentException (fnext)))
(are [x y] (= x y)
(fnext nil) nil
@@ -520,7 +520,7 @@
;; (nfirst coll) = (next (first coll))
;;
(deftest test-nfirst
-; (is (thrown? IllegalArgumentException (nfirst)))
+ ; (is (thrown? IllegalArgumentException (nfirst)))
(are [x y] (= x y)
(nfirst nil) nil
@@ -540,7 +540,7 @@
;; (nnext coll) = (next (next coll))
;;
(deftest test-nnext
-; (is (thrown? IllegalArgumentException (nnext)))
+ ; (is (thrown? IllegalArgumentException (nnext)))
(are [x y] (= x y)
(nnext nil) nil
@@ -599,54 +599,54 @@
(is (thrown? IndexOutOfBoundsException (nth (java.util.ArrayList. [1 2 3]) -1))) ; ???
(are [x y] (= x y)
- (nth '(1) 0) 1
- (nth '(1 2 3) 0) 1
- (nth '(1 2 3 4 5) 1) 2
- (nth '(1 2 3 4 5) 4) 5
- (nth '(1 2 3) 5 :not-found) :not-found
-
- (nth [1] 0) 1
- (nth [1 2 3] 0) 1
- (nth [1 2 3 4 5] 1) 2
- (nth [1 2 3 4 5] 4) 5
- (nth [1 2 3] 5 :not-found) :not-found
-
- (nth (into-array [1]) 0) 1
- (nth (into-array [1 2 3]) 0) 1
- (nth (into-array [1 2 3 4 5]) 1) 2
- (nth (into-array [1 2 3 4 5]) 4) 5
- (nth (into-array [1 2 3]) 5 :not-found) :not-found
-
- (nth "a" 0) \a
- (nth "abc" 0) \a
- (nth "abcde" 1) \b
- (nth "abcde" 4) \e
- (nth "abc" 5 :not-found) :not-found
-
- (nth (java.util.ArrayList. [1]) 0) 1
- (nth (java.util.ArrayList. [1 2 3]) 0) 1
- (nth (java.util.ArrayList. [1 2 3 4 5]) 1) 2
- (nth (java.util.ArrayList. [1 2 3 4 5]) 4) 5
- (nth (java.util.ArrayList. [1 2 3]) 5 :not-found) :not-found )
+ (nth '(1) 0) 1
+ (nth '(1 2 3) 0) 1
+ (nth '(1 2 3 4 5) 1) 2
+ (nth '(1 2 3 4 5) 4) 5
+ (nth '(1 2 3) 5 :not-found) :not-found
+
+ (nth [1] 0) 1
+ (nth [1 2 3] 0) 1
+ (nth [1 2 3 4 5] 1) 2
+ (nth [1 2 3 4 5] 4) 5
+ (nth [1 2 3] 5 :not-found) :not-found
+
+ (nth (into-array [1]) 0) 1
+ (nth (into-array [1 2 3]) 0) 1
+ (nth (into-array [1 2 3 4 5]) 1) 2
+ (nth (into-array [1 2 3 4 5]) 4) 5
+ (nth (into-array [1 2 3]) 5 :not-found) :not-found
+
+ (nth "a" 0) \a
+ (nth "abc" 0) \a
+ (nth "abcde" 1) \b
+ (nth "abcde" 4) \e
+ (nth "abc" 5 :not-found) :not-found
+
+ (nth (java.util.ArrayList. [1]) 0) 1
+ (nth (java.util.ArrayList. [1 2 3]) 0) 1
+ (nth (java.util.ArrayList. [1 2 3 4 5]) 1) 2
+ (nth (java.util.ArrayList. [1 2 3 4 5]) 4) 5
+ (nth (java.util.ArrayList. [1 2 3]) 5 :not-found) :not-found )
; regex Matchers
(let [m (re-matcher #"(a)(b)" "ababaa")]
(re-find m) ; => ["ab" "a" "b"]
(are [x y] (= x y)
- (nth m 0) "ab"
- (nth m 1) "a"
- (nth m 2) "b"
- (nth m 3 :not-found) :not-found
- (nth m -1 :not-found) :not-found )
+ (nth m 0) "ab"
+ (nth m 1) "a"
+ (nth m 2) "b"
+ (nth m 3 :not-found) :not-found
+ (nth m -1 :not-found) :not-found )
(is (thrown? IndexOutOfBoundsException (nth m 3)))
(is (thrown? IndexOutOfBoundsException (nth m -1))))
(let [m (re-matcher #"c" "ababaa")]
(re-find m) ; => nil
(are [x y] (= x y)
- (nth m 0 :not-found) :not-found
- (nth m 2 :not-found) :not-found
- (nth m -1 :not-found) :not-found )
+ (nth m 0 :not-found) :not-found
+ (nth m 2 :not-found) :not-found
+ (nth m -1 :not-found) :not-found )
(is (thrown? IllegalStateException (nth m 0)))
(is (thrown? IllegalStateException (nth m 2)))
(is (thrown? IllegalStateException (nth m -1)))))
@@ -658,42 +658,42 @@
;
(deftest test-distinct
(are [x y] (= x y)
- (distinct ()) ()
- (distinct '(1)) '(1)
- (distinct '(1 2 3)) '(1 2 3)
- (distinct '(1 2 3 1 1 1)) '(1 2 3)
- (distinct '(1 1 1 2)) '(1 2)
- (distinct '(1 2 1 2)) '(1 2)
-
- (distinct []) ()
- (distinct [1]) '(1)
- (distinct [1 2 3]) '(1 2 3)
- (distinct [1 2 3 1 2 2 1 1]) '(1 2 3)
- (distinct [1 1 1 2]) '(1 2)
- (distinct [1 2 1 2]) '(1 2)
-
- (distinct "") ()
- (distinct "a") '(\a)
- (distinct "abc") '(\a \b \c)
- (distinct "abcabab") '(\a \b \c)
- (distinct "aaab") '(\a \b)
- (distinct "abab") '(\a \b) )
+ (distinct ()) ()
+ (distinct '(1)) '(1)
+ (distinct '(1 2 3)) '(1 2 3)
+ (distinct '(1 2 3 1 1 1)) '(1 2 3)
+ (distinct '(1 1 1 2)) '(1 2)
+ (distinct '(1 2 1 2)) '(1 2)
+
+ (distinct []) ()
+ (distinct [1]) '(1)
+ (distinct [1 2 3]) '(1 2 3)
+ (distinct [1 2 3 1 2 2 1 1]) '(1 2 3)
+ (distinct [1 1 1 2]) '(1 2)
+ (distinct [1 2 1 2]) '(1 2)
+
+ (distinct "") ()
+ (distinct "a") '(\a)
+ (distinct "abc") '(\a \b \c)
+ (distinct "abcabab") '(\a \b \c)
+ (distinct "aaab") '(\a \b)
+ (distinct "abab") '(\a \b) )
(are [x] (= (distinct [x x]) [x])
- nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- () '(1 2)
- [] [1 2]
- {} {:a 1 :b 2}
- #{} #{1 2} ))
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () '(1 2)
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2} ))
(deftest test-interpose
@@ -781,40 +781,40 @@
(partition 5 [1 2 3]) ()
-; (partition 0 [1 2 3]) (repeat nil) ; infinite sequence of nil
+ ; (partition 0 [1 2 3]) (repeat nil) ; infinite sequence of nil
(partition -1 [1 2 3]) ()
(partition -2 [1 2 3]) () )
- ;; reduce
- (is (= [1 2 4 8 16] (map #(reduce * (repeat % 2)) (range 5))))
- (is (= [3 6 12 24 48] (map #(reduce * 3 (repeat % 2)) (range 5))))
+ ;; reduce
+ (is (= [1 2 4 8 16] (map #(reduce * (repeat % 2)) (range 5))))
+ (is (= [3 6 12 24 48] (map #(reduce * 3 (repeat % 2)) (range 5))))
- ;; equality and hashing
- (is (= (repeat 5 :x) (repeat 5 :x)))
- (is (= (repeat 5 :x) '(:x :x :x :x :x)))
- (is (= (hash (repeat 5 :x)) (hash '(:x :x :x :x :x))))
- (is (= (assoc (array-map (repeat 1 :x) :y) '(:x) :z) {'(:x) :z}))
- (is (= (assoc (hash-map (repeat 1 :x) :y) '(:x) :z) {'(:x) :z})))
+ ;; equality and hashing
+ (is (= (repeat 5 :x) (repeat 5 :x)))
+ (is (= (repeat 5 :x) '(:x :x :x :x :x)))
+ (is (= (hash (repeat 5 :x)) (hash '(:x :x :x :x :x))))
+ (is (= (assoc (array-map (repeat 1 :x) :y) '(:x) :z) {'(:x) :z}))
+ (is (= (assoc (hash-map (repeat 1 :x) :y) '(:x) :z) {'(:x) :z})))
(deftest test-iterate
- (are [x y] (= x y)
- (take 0 (iterate inc 0)) ()
- (take 1 (iterate inc 0)) '(0)
- (take 2 (iterate inc 0)) '(0 1)
- (take 5 (iterate inc 0)) '(0 1 2 3 4) )
+ (are [x y] (= x y)
+ (take 0 (iterate inc 0)) ()
+ (take 1 (iterate inc 0)) '(0)
+ (take 2 (iterate inc 0)) '(0 1)
+ (take 5 (iterate inc 0)) '(0 1 2 3 4) )
- ;; test other fns
- (is (= '(:foo 42 :foo 42) (take 4 (iterate #(if (= % :foo) 42 :foo) :foo))))
- (is (= '(1 false true true) (take 4 (iterate #(instance? Boolean %) 1))))
- (is (= '(256 128 64 32 16 8 4 2 1 0) (take 10 (iterate #(quot % 2) 256))))
- (is (= '(0 true) (take 2 (iterate zero? 0))))
- (is (= 2 (first (next (next (iterate inc 0))))))
- (is (= [1 2 3] (into [] (take 3) (next (iterate inc 0)))))
+ ;; test other fns
+ (is (= '(:foo 42 :foo 42) (take 4 (iterate #(if (= % :foo) 42 :foo) :foo))))
+ (is (= '(1 false true true) (take 4 (iterate #(instance? Boolean %) 1))))
+ (is (= '(256 128 64 32 16 8 4 2 1 0) (take 10 (iterate #(quot % 2) 256))))
+ (is (= '(0 true) (take 2 (iterate zero? 0))))
+ (is (= 2 (first (next (next (iterate inc 0))))))
+ (is (= [1 2 3] (into [] (take 3) (next (iterate inc 0)))))
- ;; reduce via transduce
- (is (= (transduce (take 5) + (iterate #(* 2 %) 2)) 62))
- (is (= (transduce (take 5) + 1 (iterate #(* 2 %) 2)) 63)) )
+ ;; reduce via transduce
+ (is (= (transduce (take 5) + (iterate #(* 2 %) 2)) 62))
+ (is (= (transduce (take 5) + 1 (iterate #(* 2 %) 2)) 63)) )
(deftest test-reverse
@@ -851,18 +851,18 @@
(deftest test-take-nth
(are [x y] (= x y)
- (take-nth 1 [1 2 3 4 5]) '(1 2 3 4 5)
- (take-nth 2 [1 2 3 4 5]) '(1 3 5)
- (take-nth 3 [1 2 3 4 5]) '(1 4)
- (take-nth 4 [1 2 3 4 5]) '(1 5)
- (take-nth 5 [1 2 3 4 5]) '(1)
- (take-nth 9 [1 2 3 4 5]) '(1)
+ (take-nth 1 [1 2 3 4 5]) '(1 2 3 4 5)
+ (take-nth 2 [1 2 3 4 5]) '(1 3 5)
+ (take-nth 3 [1 2 3 4 5]) '(1 4)
+ (take-nth 4 [1 2 3 4 5]) '(1 5)
+ (take-nth 5 [1 2 3 4 5]) '(1)
+ (take-nth 9 [1 2 3 4 5]) '(1)
- ; infinite seq of 1s = (repeat 1)
- ;(take-nth 0 [1 2 3 4 5])
- ;(take-nth -1 [1 2 3 4 5])
- ;(take-nth -2 [1 2 3 4 5])
- ))
+ ; infinite seq of 1s = (repeat 1)
+ ;(take-nth 0 [1 2 3 4 5])
+ ;(take-nth -1 [1 2 3 4 5])
+ ;(take-nth -2 [1 2 3 4 5])
+ ))
(deftest test-take-while
@@ -956,37 +956,37 @@
; infinite sequence => use take
(are [x y] (= x y)
- (take 0 (repeat 7)) ()
- (take 1 (repeat 7)) '(7)
- (take 2 (repeat 7)) '(7 7)
- (take 5 (repeat 7)) '(7 7 7 7 7) )
+ (take 0 (repeat 7)) ()
+ (take 1 (repeat 7)) '(7)
+ (take 2 (repeat 7)) '(7 7)
+ (take 5 (repeat 7)) '(7 7 7 7 7) )
; limited sequence
(are [x y] (= x y)
- (repeat 0 7) ()
- (repeat 1 7) '(7)
- (repeat 2 7) '(7 7)
- (repeat 5 7) '(7 7 7 7 7)
+ (repeat 0 7) ()
+ (repeat 1 7) '(7)
+ (repeat 2 7) '(7 7)
+ (repeat 5 7) '(7 7 7 7 7)
- (repeat -1 7) ()
- (repeat -3 7) () )
+ (repeat -1 7) ()
+ (repeat -3 7) () )
; test different data types
(are [x] (= (repeat 3 x) (list x x x))
- nil
- false true
- 0 42
- 0.0 3.14
- 2/3
- 0M 1M
- \c
- "" "abc"
- 'sym
- :kw
- () '(1 2)
- [] [1 2]
- {} {:a 1 :b 2}
- #{} #{1 2} ))
+ nil
+ false true
+ 0 42
+ 0.0 3.14
+ 2/3
+ 0M 1M
+ \c
+ "" "abc"
+ 'sym
+ :kw
+ () '(1 2)
+ [] [1 2]
+ {} {:a 1 :b 2}
+ #{} #{1 2} ))
(defspec longrange-equals-range 100
(prop/for-all [start gen/int
@@ -997,66 +997,66 @@
(deftest test-range
(are [x y] (= x y)
- (take 100 (range)) (range 100)
-
- (range 0) () ; exclusive end!
- (range 1) '(0)
- (range 5) '(0 1 2 3 4)
-
- (range -1) ()
- (range -3) ()
-
- (range 2.5) '(0 1 2)
- (range 7/3) '(0 1 2)
-
- (range 0 3) '(0 1 2)
- (range 0 1) '(0)
- (range 0 0) ()
- (range 0 -3) ()
-
- (range 3 6) '(3 4 5)
- (range 3 4) '(3)
- (range 3 3) ()
- (range 3 1) ()
- (range 3 0) ()
- (range 3 -2) ()
-
- (range -2 5) '(-2 -1 0 1 2 3 4)
- (range -2 0) '(-2 -1)
- (range -2 -1) '(-2)
- (range -2 -2) ()
- (range -2 -5) ()
-
- (take 3 (range 3 9 0)) '(3 3 3)
- (take 3 (range 9 3 0)) '(9 9 9)
- (range 0 0 0) ()
- (range 3 9 1) '(3 4 5 6 7 8)
- (range 3 9 2) '(3 5 7)
- (range 3 9 3) '(3 6)
- (range 3 9 10) '(3)
- (range 3 9 -1) ()
- (range 10 10 -1) ()
- (range 10 9 -1) '(10)
- (range 10 8 -1) '(10 9)
- (range 10 7 -1) '(10 9 8)
- (range 10 0 -2) '(10 8 6 4 2)
-
- (take 100 (range)) (take 100 (iterate inc 0))
-
- (range 1/2 5 1/3) '(1/2 5/6 7/6 3/2 11/6 13/6 5/2 17/6 19/6 7/2 23/6 25/6 9/2 29/6)
- (range 0.5 8 1.2) '(0.5 1.7 2.9 4.1 5.3 6.5 7.7)
- (range 0.5 -4 -2) '(0.5 -1.5 -3.5)
- (take 3 (range Long/MAX_VALUE Double/POSITIVE_INFINITY)) '(9223372036854775807 9223372036854775808N 9223372036854775809N)
-
- (reduce + (take 100 (range))) 4950
- (reduce + 0 (take 100 (range))) 4950
- (reduce + (range 100)) 4950
- (reduce + 0 (range 100)) 4950
- (reduce + (range 0.0 100.0)) 4950.0
- (reduce + 0 (range 0.0 100.0)) 4950.0
-
- (reduce + (iterator-seq (.iterator (range 100)))) 4950
- (reduce + (iterator-seq (.iterator (range 0.0 100.0 1.0)))) 4950.0 ))
+ (take 100 (range)) (range 100)
+
+ (range 0) () ; exclusive end!
+ (range 1) '(0)
+ (range 5) '(0 1 2 3 4)
+
+ (range -1) ()
+ (range -3) ()
+
+ (range 2.5) '(0 1 2)
+ (range 7/3) '(0 1 2)
+
+ (range 0 3) '(0 1 2)
+ (range 0 1) '(0)
+ (range 0 0) ()
+ (range 0 -3) ()
+
+ (range 3 6) '(3 4 5)
+ (range 3 4) '(3)
+ (range 3 3) ()
+ (range 3 1) ()
+ (range 3 0) ()
+ (range 3 -2) ()
+
+ (range -2 5) '(-2 -1 0 1 2 3 4)
+ (range -2 0) '(-2 -1)
+ (range -2 -1) '(-2)
+ (range -2 -2) ()
+ (range -2 -5) ()
+
+ (take 3 (range 3 9 0)) '(3 3 3)
+ (take 3 (range 9 3 0)) '(9 9 9)
+ (range 0 0 0) ()
+ (range 3 9 1) '(3 4 5 6 7 8)
+ (range 3 9 2) '(3 5 7)
+ (range 3 9 3) '(3 6)
+ (range 3 9 10) '(3)
+ (range 3 9 -1) ()
+ (range 10 10 -1) ()
+ (range 10 9 -1) '(10)
+ (range 10 8 -1) '(10 9)
+ (range 10 7 -1) '(10 9 8)
+ (range 10 0 -2) '(10 8 6 4 2)
+
+ (take 100 (range)) (take 100 (iterate inc 0))
+
+ (range 1/2 5 1/3) '(1/2 5/6 7/6 3/2 11/6 13/6 5/2 17/6 19/6 7/2 23/6 25/6 9/2 29/6)
+ (range 0.5 8 1.2) '(0.5 1.7 2.9 4.1 5.3 6.5 7.7)
+ (range 0.5 -4 -2) '(0.5 -1.5 -3.5)
+ (take 3 (range Long/MAX_VALUE Double/POSITIVE_INFINITY)) '(9223372036854775807 9223372036854775808N 9223372036854775809N)
+
+ (reduce + (take 100 (range))) 4950
+ (reduce + 0 (take 100 (range))) 4950
+ (reduce + (range 100)) 4950
+ (reduce + 0 (range 100)) 4950
+ (reduce + (range 0.0 100.0)) 4950.0
+ (reduce + 0 (range 0.0 100.0)) 4950.0
+
+ (reduce + (iterator-seq (.iterator (range 100)))) 4950
+ (reduce + (iterator-seq (.iterator (range 0.0 100.0 1.0)))) 4950.0 ))
(deftest range-test
(let [threads 10
@@ -1097,18 +1097,18 @@
lmin+32 (+ Long/MIN_VALUE 32)
lmin+33 (+ Long/MIN_VALUE 33)]
(doseq [range-args [ [lmax-2 lmax]
- [lmax-33 lmax]
- [lmax-33 lmax-31]
- [lmin+2 lmin -1]
- [lmin+33 lmin -1]
- [lmin+33 lmin+31 -1]
- [lmin lmax lmax]
- [lmax lmin lmin]
- [-1 lmax lmax]
- [1 lmin lmin]]]
- (is (= (apply unlimited-range-create range-args)
- (apply range range-args))
- (apply str "from (range " (concat (interpose " " range-args) ")"))))))
+ [lmax-33 lmax]
+ [lmax-33 lmax-31]
+ [lmin+2 lmin -1]
+ [lmin+33 lmin -1]
+ [lmin+33 lmin+31 -1]
+ [lmin lmax lmax]
+ [lmax lmin lmin]
+ [-1 lmax lmax]
+ [1 lmin lmin]]]
+ (is (= (apply unlimited-range-create range-args)
+ (apply range range-args))
+ (apply str "from (range " (concat (interpose " " range-args) ")"))))))
(deftest test-empty?
(are [x] (empty? x)
@@ -1134,84 +1134,84 @@
(deftest test-every?
; always true for nil or empty coll/seq
(are [x] (= (every? pos? x) true)
- nil
- () [] {} #{}
- (lazy-seq [])
- (into-array []) )
+ nil
+ () [] {} #{}
+ (lazy-seq [])
+ (into-array []) )
(are [x y] (= x y)
- true (every? pos? [1])
- true (every? pos? [1 2])
- true (every? pos? [1 2 3 4 5])
-
- false (every? pos? [-1])
- false (every? pos? [-1 -2])
- false (every? pos? [-1 -2 3])
- false (every? pos? [-1 2])
- false (every? pos? [1 -2])
- false (every? pos? [1 2 -3])
- false (every? pos? [1 2 -3 4]) )
+ true (every? pos? [1])
+ true (every? pos? [1 2])
+ true (every? pos? [1 2 3 4 5])
+
+ false (every? pos? [-1])
+ false (every? pos? [-1 -2])
+ false (every? pos? [-1 -2 3])
+ false (every? pos? [-1 2])
+ false (every? pos? [1 -2])
+ false (every? pos? [1 2 -3])
+ false (every? pos? [1 2 -3 4]) )
(are [x y] (= x y)
- true (every? #{:a} [:a :a])
-;! false (every? #{:a} [:a :b]) ; Issue 68: every? returns nil instead of false
-;! false (every? #{:a} [:b :b]) ; http://code.google.com/p/clojure/issues/detail?id=68
- ))
+ true (every? #{:a} [:a :a])
+ ;! false (every? #{:a} [:a :b]) ; Issue 68: every? returns nil instead of false
+ ;! false (every? #{:a} [:b :b]) ; http://code.google.com/p/clojure/issues/detail?id=68
+ ))
(deftest test-not-every?
; always false for nil or empty coll/seq
(are [x] (= (not-every? pos? x) false)
- nil
- () [] {} #{}
- (lazy-seq [])
- (into-array []) )
+ nil
+ () [] {} #{}
+ (lazy-seq [])
+ (into-array []) )
(are [x y] (= x y)
- false (not-every? pos? [1])
- false (not-every? pos? [1 2])
- false (not-every? pos? [1 2 3 4 5])
-
- true (not-every? pos? [-1])
- true (not-every? pos? [-1 -2])
- true (not-every? pos? [-1 -2 3])
- true (not-every? pos? [-1 2])
- true (not-every? pos? [1 -2])
- true (not-every? pos? [1 2 -3])
- true (not-every? pos? [1 2 -3 4]) )
+ false (not-every? pos? [1])
+ false (not-every? pos? [1 2])
+ false (not-every? pos? [1 2 3 4 5])
+
+ true (not-every? pos? [-1])
+ true (not-every? pos? [-1 -2])
+ true (not-every? pos? [-1 -2 3])
+ true (not-every? pos? [-1 2])
+ true (not-every? pos? [1 -2])
+ true (not-every? pos? [1 2 -3])
+ true (not-every? pos? [1 2 -3 4]) )
(are [x y] (= x y)
- false (not-every? #{:a} [:a :a])
- true (not-every? #{:a} [:a :b])
- true (not-every? #{:a} [:b :b]) ))
+ false (not-every? #{:a} [:a :a])
+ true (not-every? #{:a} [:a :b])
+ true (not-every? #{:a} [:b :b]) ))
(deftest test-not-any?
; always true for nil or empty coll/seq
(are [x] (= (not-any? pos? x) true)
- nil
- () [] {} #{}
- (lazy-seq [])
- (into-array []) )
+ nil
+ () [] {} #{}
+ (lazy-seq [])
+ (into-array []) )
(are [x y] (= x y)
- false (not-any? pos? [1])
- false (not-any? pos? [1 2])
- false (not-any? pos? [1 2 3 4 5])
+ false (not-any? pos? [1])
+ false (not-any? pos? [1 2])
+ false (not-any? pos? [1 2 3 4 5])
- true (not-any? pos? [-1])
- true (not-any? pos? [-1 -2])
+ true (not-any? pos? [-1])
+ true (not-any? pos? [-1 -2])
- false (not-any? pos? [-1 -2 3])
- false (not-any? pos? [-1 2])
- false (not-any? pos? [1 -2])
- false (not-any? pos? [1 2 -3])
- false (not-any? pos? [1 2 -3 4]) )
+ false (not-any? pos? [-1 -2 3])
+ false (not-any? pos? [-1 2])
+ false (not-any? pos? [1 -2])
+ false (not-any? pos? [1 2 -3])
+ false (not-any? pos? [1 2 -3 4]) )
(are [x y] (= x y)
- false (not-any? #{:a} [:a :a])
- false (not-any? #{:a} [:a :b])
- true (not-any? #{:a} [:b :b]) ))
+ false (not-any? #{:a} [:a :a])
+ false (not-any? #{:a} [:a :b])
+ true (not-any? #{:a} [:b :b]) ))
(deftest test-some
@@ -1279,11 +1279,11 @@
(deftest test-group-by
(is (= (group-by even? [1 2 3 4 5])
- {false [1 3 5], true [2 4]})))
+ {false [1 3 5], true [2 4]})))
(deftest test-partition-by
(are [test-seq] (= (partition-by (comp even? count) test-seq)
- [["a"] ["bb" "cccc" "dd"] ["eee" "f"] ["" "hh"]])
+ [["a"] ["bb" "cccc" "dd"] ["eee" "f"] ["" "hh"]])
["a" "bb" "cccc" "dd" "eee" "f" "" "hh"]
'("a" "bb" "cccc" "dd" "eee" "f" "" "hh"))
(is (=(partition-by #{\a \e \i \o \u} "abcdefghijklm")
@@ -1302,9 +1302,9 @@
(is (= (reductions + nil)
[0]))
(is (= (reductions + [1 2 3 4 5])
- [1 3 6 10 15]))
+ [1 3 6 10 15]))
(is (= (reductions + 10 [1 2 3 4 5])
- [10 11 13 16 20 25])))
+ [10 11 13 16 20 25])))
(deftest test-reductions-obeys-reduced
(is (= [0 :x]
@@ -1327,9 +1327,9 @@
(deftest test-partition-all
(is (= (partition-all 4 [1 2 3 4 5 6 7 8 9])
- [[1 2 3 4] [5 6 7 8] [9]]))
+ [[1 2 3 4] [5 6 7 8] [9]]))
(is (= (partition-all 4 2 [1 2 3 4 5 6 7 8 9])
- [[1 2 3 4] [3 4 5 6] [5 6 7 8] [7 8 9] [9]])))
+ [[1 2 3 4] [3 4 5 6] [5 6 7 8] [7 8 9] [9]])))
(deftest test-shuffle-invariants
(is (= (count (shuffle [1 2 3 4])) 4))
diff --git a/test/clojure/test_clojure/special.clj b/test/clojure/test_clojure/special.clj
index c4a04cff..86d86572 100644
--- a/test/clojure/test_clojure/special.clj
+++ b/test/clojure/test_clojure/special.clj
@@ -68,23 +68,23 @@
(deftest keywords-not-allowed-in-let-bindings
(is (thrown-with-cause-msg? Exception #"did not conform to spec"
- (eval '(let [:a 1] a))))
+ (eval '(let [:a 1] a))))
(is (thrown-with-cause-msg? Exception #"did not conform to spec"
- (eval '(let [:a/b 1] b))))
+ (eval '(let [:a/b 1] b))))
(is (thrown-with-cause-msg? Exception #"did not conform to spec"
- (eval '(let [[:a] [1]] a))))
+ (eval '(let [[:a] [1]] a))))
(is (thrown-with-cause-msg? Exception #"did not conform to spec"
- (eval '(let [[:a/b] [1]] b)))))
+ (eval '(let [[:a/b] [1]] b)))))
(deftest namespaced-syms-only-allowed-in-map-destructuring
(is (thrown-with-cause-msg? Exception #"did not conform to spec"
- (eval '(let [a/x 1, [y] [1]] x))))
+ (eval '(let [a/x 1, [y] [1]] x))))
(is (thrown-with-cause-msg? Exception #"did not conform to spec"
- (eval '(let [[a/x] [1]] x)))))
+ (eval '(let [[a/x] [1]] x)))))
(deftest or-doesnt-create-bindings
(is (thrown-with-cause-msg? Exception #"Unable to resolve symbol: b"
- (eval '(let [{:keys [a] :or {b 2}} {:a 1}] [a b])))))
+ (eval '(let [{:keys [a] :or {b 2}} {:a 1}] [a b])))))
(require '[clojure.string :as s])
(deftest resolve-keyword-ns-alias-in-destructuring
diff --git a/test/clojure/test_clojure/string.clj b/test/clojure/test_clojure/string.clj
index c9291902..66be8882 100644
--- a/test/clojure/test_clojure/string.clj
+++ b/test/clojure/test_clojure/string.clj
@@ -160,7 +160,7 @@
(is (= nil (s/index-of sb "z" 2)))
(is (= nil (s/index-of sb \z 2)))
(is (= nil (s/index-of sb "z" 100))
- (is (= nil (s/index-of sb "z" -10))))))
+ (is (= nil (s/index-of sb "z" -10))))))
(deftest t-last-index-of
(let [sb (StringBuffer. "banana")]
@@ -175,7 +175,7 @@
(is (= nil (s/last-index-of sb "z" 1)))
(is (= nil (s/last-index-of sb \z 1)))
(is (= nil (s/last-index-of sb "z" 100))
- (is (= nil (s/last-index-of sb "z" -10))))))
+ (is (= nil (s/last-index-of sb "z" -10))))))
(deftest t-starts-with?
(is (s/starts-with? (StringBuffer. "clojure west") "clojure"))
@@ -183,7 +183,7 @@
(deftest t-ends-with?
(is (s/ends-with? (StringBuffer. "Clojure West") "West")
- (is (not (s/ends-with? (StringBuffer. "Conj") "West")))))
+ (is (not (s/ends-with? (StringBuffer. "Conj") "West")))))
(deftest t-includes?
(let [sb (StringBuffer. "Clojure Applied Book")]
diff --git a/test/clojure/test_clojure/test.clj b/test/clojure/test_clojure/test.clj
index 498ddff9..21508bce 100644
--- a/test/clojure/test_clojure/test.clj
+++ b/test/clojure/test_clojure/test.clj
@@ -88,10 +88,10 @@
(declare does-not-exist)
#_(deftest can-test-unbound-symbol
- (is (= nil does-not-exist) "Should error"))
+ (is (= nil does-not-exist) "Should error"))
#_(deftest can-test-unbound-function
- (is (does-not-exist) "Should error"))
+ (is (does-not-exist) "Should error"))
;; Here, we create an alternate version of test/report, that
diff --git a/test/clojure/test_clojure/transducers.clj b/test/clojure/test_clojure/transducers.clj
index 76a0e978..65a678bc 100644
--- a/test/clojure/test_clojure/transducers.clj
+++ b/test/clojure/test_clojure/transducers.clj
@@ -10,11 +10,11 @@
(ns clojure.test-clojure.transducers
(:require [clojure.string :as s]
- [clojure.test :refer :all]
- [clojure.test.check :as chk]
- [clojure.test.check.generators :as gen]
- [clojure.test.check.properties :as prop]
- [clojure.test.check.clojure-test :as ctest]))
+ [clojure.test :refer :all]
+ [clojure.test.check :as chk]
+ [clojure.test.check.generators :as gen]
+ [clojure.test.check.properties :as prop]
+ [clojure.test.check.clojure-test :as ctest]))
(defmacro fbind [source-gen f]
`(gen/fmap
@@ -225,88 +225,88 @@
(deftest test-dedupe
(are [x y] (= (transduce (dedupe) conj x) y)
- [] []
- [1] [1]
- [1 2 3] [1 2 3]
- [1 2 3 1 2 2 1 1] [1 2 3 1 2 1]
- [1 1 1 2] [1 2]
- [1 1 1 1] [1]
-
- "" []
- "a" [\a]
- "aaaa" [\a]
- "aabaa" [\a \b \a]
- "abba" [\a \b \a]
-
- [nil nil nil] [nil]
- [1 1.0 1.0M 1N] [1 1.0 1.0M 1N]
- [0.5 0.5] [0.5]))
+ [] []
+ [1] [1]
+ [1 2 3] [1 2 3]
+ [1 2 3 1 2 2 1 1] [1 2 3 1 2 1]
+ [1 1 1 2] [1 2]
+ [1 1 1 1] [1]
+
+ "" []
+ "a" [\a]
+ "aaaa" [\a]
+ "aabaa" [\a \b \a]
+ "abba" [\a \b \a]
+
+ [nil nil nil] [nil]
+ [1 1.0 1.0M 1N] [1 1.0 1.0M 1N]
+ [0.5 0.5] [0.5]))
(deftest test-cat
(are [x y] (= (transduce cat conj x) y)
- [] []
- [[1 2]] [1 2]
- [[1 2] [3 4]] [1 2 3 4]
- [[] [3 4]] [3 4]
- [[1 2] []] [1 2]
- [[] []] []
- [[1 2] [3 4] [5 6]] [1 2 3 4 5 6]))
+ [] []
+ [[1 2]] [1 2]
+ [[1 2] [3 4]] [1 2 3 4]
+ [[] [3 4]] [3 4]
+ [[1 2] []] [1 2]
+ [[] []] []
+ [[1 2] [3 4] [5 6]] [1 2 3 4 5 6]))
(deftest test-partition-all
(are [n coll y] (= (transduce (partition-all n) conj coll) y)
- 2 [1 2 3] '((1 2) (3))
- 2 [1 2 3 4] '((1 2) (3 4))
- 2 [] ()
- 1 [] ()
- 1 [1 2 3] '((1) (2) (3))
- 5 [1 2 3] '((1 2 3))))
+ 2 [1 2 3] '((1 2) (3))
+ 2 [1 2 3 4] '((1 2) (3 4))
+ 2 [] ()
+ 1 [] ()
+ 1 [1 2 3] '((1) (2) (3))
+ 5 [1 2 3] '((1 2 3))))
(deftest test-take
(are [n y] (= (transduce (take n) conj [1 2 3 4 5]) y)
- 1 '(1)
- 3 '(1 2 3)
- 5 '(1 2 3 4 5)
- 9 '(1 2 3 4 5)
- 0 ()
- -1 ()
- -2 ()))
+ 1 '(1)
+ 3 '(1 2 3)
+ 5 '(1 2 3 4 5)
+ 9 '(1 2 3 4 5)
+ 0 ()
+ -1 ()
+ -2 ()))
(deftest test-drop
(are [n y] (= (transduce (drop n) conj [1 2 3 4 5]) y)
- 1 '(2 3 4 5)
- 3 '(4 5)
- 5 ()
- 9 ()
- 0 '(1 2 3 4 5)
- -1 '(1 2 3 4 5)
- -2 '(1 2 3 4 5)))
+ 1 '(2 3 4 5)
+ 3 '(4 5)
+ 5 ()
+ 9 ()
+ 0 '(1 2 3 4 5)
+ -1 '(1 2 3 4 5)
+ -2 '(1 2 3 4 5)))
(deftest test-take-nth
(are [n y] (= (transduce (take-nth n) conj [1 2 3 4 5]) y)
- 1 '(1 2 3 4 5)
- 2 '(1 3 5)
- 3 '(1 4)
- 4 '(1 5)
- 5 '(1)
- 9 '(1)))
+ 1 '(1 2 3 4 5)
+ 2 '(1 3 5)
+ 3 '(1 4)
+ 4 '(1 5)
+ 5 '(1)
+ 9 '(1)))
(deftest test-take-while
(are [coll y] (= (transduce (take-while pos?) conj coll) y)
- [] ()
- [1 2 3 4] '(1 2 3 4)
- [1 2 3 -1] '(1 2 3)
- [1 -1 2 3] '(1)
- [-1 1 2 3] ()
- [-1 -2 -3] ()))
+ [] ()
+ [1 2 3 4] '(1 2 3 4)
+ [1 2 3 -1] '(1 2 3)
+ [1 -1 2 3] '(1)
+ [-1 1 2 3] ()
+ [-1 -2 -3] ()))
(deftest test-drop-while
(are [coll y] (= (transduce (drop-while pos?) conj coll) y)
- [] ()
- [1 2 3 4] ()
- [1 2 3 -1] '(-1)
- [1 -1 2 3] '(-1 2 3)
- [-1 1 2 3] '(-1 1 2 3)
- [-1 -2 -3] '(-1 -2 -3)))
+ [] ()
+ [1 2 3 4] ()
+ [1 2 3 -1] '(-1)
+ [1 -1 2 3] '(-1 2 3)
+ [-1 1 2 3] '(-1 1 2 3)
+ [-1 -2 -3] '(-1 -2 -3)))
(deftest test-re-reduced
(is (= [:a] (transduce (take 1) conj [:a])))
@@ -390,8 +390,8 @@
(let [expected (interpose :s (range))]
(dotimes [i 10]
(is (= (take i expected)
- (sequence (comp (interpose :s) (take i))
- (range))))))))
+ (sequence (comp (interpose :s) (take i))
+ (range))))))))
(deftest test-map-indexed
(is (= []
diff --git a/test/clojure/test_clojure/transients.clj b/test/clojure/test_clojure/transients.clj
index f64ba926..24f61091 100644
--- a/test/clojure/test_clojure/transients.clj
+++ b/test/clojure/test_clojure/transients.clj
@@ -11,9 +11,9 @@
(is (thrown-with-msg? IllegalStateException #"Can't pop empty vector"
(-> [] transient pop!))))
(testing "copying array from a non-editable when put in tail position")
- (is (= 31 (let [pv (vec (range 34))]
- (-> pv transient pop! pop! pop! (conj! 42))
- (nth pv 31)))))
+ (is (= 31 (let [pv (vec (range 34))]
+ (-> pv transient pop! pop! pop! (conj! 42))
+ (nth pv 31)))))
(defn- hash-obj [hash]
(reify Object (hashCode [this] hash)))
diff --git a/test/clojure/test_clojure/try_catch.clj b/test/clojure/test_clojure/try_catch.clj
index d907d504..040856cd 100755
--- a/test/clojure/test_clojure/try_catch.clj
+++ b/test/clojure/test_clojure/try_catch.clj
@@ -11,7 +11,7 @@
(ns clojure.test-clojure.try-catch
(:use clojure.test)
(:import [clojure.test ReflectorTryCatchFixture
- ReflectorTryCatchFixture$Cookies]))
+ ReflectorTryCatchFixture$Cookies]))
(defn- get-exception [expression]
(try (eval expression)
diff --git a/test/clojure/test_clojure/vars.clj b/test/clojure/test_clojure/vars.clj
index 6b454d2b..9d23d398 100644
--- a/test/clojure/test_clojure/vars.clj
+++ b/test/clojure/test_clojure/vars.clj
@@ -22,8 +22,8 @@
(def ^:dynamic a)
(deftest test-binding
(are [x y] (= x y)
- (eval `(binding [a 4] a)) 4 ; regression in Clojure SVN r1370
- ))
+ (eval `(binding [a 4] a)) 4 ; regression in Clojure SVN r1370
+ ))
; var-get var-set alter-var-root [var? (predicates.clj)]
; with-in-str with-out-str
@@ -53,10 +53,10 @@
(deftest test-settable-math-context
(is (=
- (clojure.main/with-bindings
- (set! *math-context* (java.math.MathContext. 8))
- (+ 3.55555555555555M 1))
- 4.5555556M)))
+ (clojure.main/with-bindings
+ (set! *math-context* (java.math.MathContext. 8))
+ (+ 3.55555555555555M 1))
+ 4.5555556M)))
; set-validator get-validator
@@ -84,9 +84,9 @@
(deftest test-with-redefs-throw
(let [p (promise)]
(is (thrown? Exception
- (with-redefs [stub-me :temp]
- (deliver p stub-me)
- (throw (Exception. "simulated failure in with-redefs")))))
+ (with-redefs [stub-me :temp]
+ (deliver p stub-me)
+ (throw (Exception. "simulated failure in with-redefs")))))
(is (= :temp @p))
(is (= :original stub-me))))
diff --git a/test/clojure/test_clojure/vectors.clj b/test/clojure/test_clojure/vectors.clj
index 0bea3ff4..ee121ba9 100644
--- a/test/clojure/test_clojure/vectors.clj
+++ b/test/clojure/test_clojure/vectors.clj
@@ -59,13 +59,13 @@
;; can't manufacture this scenario: ASeq defers to Counted, but
;; LazySeq doesn't, so Counted never gets checked on reified seq below
#_(testing "hops to counted when available"
- (is (= 200
- (.count (concat
- (seq vs)
- (reify clojure.lang.ISeq
- (seq [this] this)
- clojure.lang.Counted
- (count [_] 100))))))))
+ (is (= 200
+ (.count (concat
+ (seq vs)
+ (reify clojure.lang.ISeq
+ (seq [this] this)
+ clojure.lang.Counted
+ (count [_] 100))))))))
(testing "IPersistentCollection.equiv"
(are [a b] (true? (.equiv a b))
vs vs
diff --git a/test/clojure/test_helper.clj b/test/clojure/test_helper.clj
index 4c89b899..6fd7a8a6 100644
--- a/test/clojure/test_helper.clj
+++ b/test/clojure/test_helper.clj
@@ -34,7 +34,7 @@
(in-ns (gensym))
(clojure.core/use 'clojure.core)
(eval
- '(do ~@forms))))
+ '(do ~@forms))))
(defn causes
[^Throwable throwable]
@@ -47,29 +47,29 @@
(defmethod assert-expr 'fails-with-cause?
[msg [_ exception-class msg-re & body :as form]]
`(try
- ~@body
- (report {:type :fail, :message ~msg, :expected '~form, :actual nil})
- (catch Throwable t#
- (if (some (fn [cause#]
- (and
- (= ~exception-class (class cause#))
- (re-find ~msg-re (.getMessage cause#))))
- (causes t#))
- (report {:type :pass, :message ~msg,
- :expected '~form, :actual t#})
- (report {:type :fail, :message ~msg,
- :expected '~form, :actual t#})))))
+ ~@body
+ (report {:type :fail, :message ~msg, :expected '~form, :actual nil})
+ (catch Throwable t#
+ (if (some (fn [cause#]
+ (and
+ (= ~exception-class (class cause#))
+ (re-find ~msg-re (.getMessage cause#))))
+ (causes t#))
+ (report {:type :pass, :message ~msg,
+ :expected '~form, :actual t#})
+ (report {:type :fail, :message ~msg,
+ :expected '~form, :actual t#})))))
(defn get-field
"Access to private or protected field. field-name is a symbol or
keyword."
([klass field-name]
- (get-field klass field-name nil))
+ (get-field klass field-name nil))
([klass field-name inst]
- (-> klass (.getDeclaredField (name field-name))
- (doto (.setAccessible true))
- (.get inst))))
+ (-> klass (.getDeclaredField (name field-name))
+ (doto (.setAccessible true))
+ (.get inst))))
(defn set-var-roots
[maplike]
@@ -82,9 +82,9 @@
(let [originals (doall (map (fn [[var _]] [var @var]) root-map))]
(set-var-roots root-map)
(try
- (apply f args)
- (finally
- (set-var-roots originals)))))
+ (apply f args)
+ (finally
+ (set-var-roots originals)))))
(defmacro with-var-roots
[root-map & body]
@@ -120,8 +120,8 @@
correctly for all semi-reasonable bindings of *err*."
[msg-re form]
`(binding [*warn-on-reflection* true]
- (is (re-matches ~msg-re (with-err-string-writer (eval-in-temp-ns ~form))))
- (is (re-matches ~msg-re (with-err-print-writer (eval-in-temp-ns ~form))))))
+ (is (re-matches ~msg-re (with-err-string-writer (eval-in-temp-ns ~form))))
+ (is (re-matches ~msg-re (with-err-print-writer (eval-in-temp-ns ~form))))))
(defmacro should-not-reflect
"Turn on all warning flags, and test that reflection does not occur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment