diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-04-29 18:48:50 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-05-03 16:06:02 -0400 |
commit | 59b65669860a1f33825775494809e5d500c19c63 (patch) | |
tree | 4ff16f1966e4d8debc7b32d6191ba3793d48d15d | |
parent | 7b4b8e18c0d28e03e7c66f54bc441ef355ceb5ed (diff) |
added 1.0, test all public doc-ed fns have :added
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | src/clj/clojure/core.clj | 785 | ||||
-rw-r--r-- | src/clj/clojure/core_print.clj | 12 | ||||
-rw-r--r-- | src/clj/clojure/core_proxy.clj | 12 | ||||
-rw-r--r-- | src/clj/clojure/genclass.clj | 3 | ||||
-rw-r--r-- | src/clj/clojure/gvec.clj | 3 | ||||
-rw-r--r-- | src/clj/clojure/inspector.clj | 3 | ||||
-rw-r--r-- | src/clj/clojure/set.clj | 10 | ||||
-rw-r--r-- | src/clj/clojure/test.clj | 1 | ||||
-rw-r--r-- | src/clj/clojure/xml.clj | 1 | ||||
-rw-r--r-- | src/clj/clojure/zip.clj | 30 | ||||
-rw-r--r-- | test/clojure/test_clojure/metadata.clj | 23 |
11 files changed, 693 insertions, 190 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 6b0fbbbf..2ee14a07 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -15,56 +15,65 @@ (def ^{:arglists '([& items]) - :doc "Creates a new list containing the items."} + :doc "Creates a new list containing the items." + :added "1.0"} list (. clojure.lang.PersistentList creator)) (def ^{:arglists '([x seq]) :doc "Returns a new seq where x is the first element and seq is - the rest."} + the rest." + :added "1.0"} cons (fn* cons [x seq] (. clojure.lang.RT (cons x seq)))) ;during bootstrap we don't have destructuring let, loop or fn, will redefine later (def - ^{:macro true} + ^{:macro true + :added "1.0"} let (fn* let [&form &env & decl] (cons 'let* decl))) (def - ^{:macro true} + ^{:macro true + :added "1.0"} loop (fn* loop [&form &env & decl] (cons 'loop* decl))) (def - ^{:macro true} + ^{: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 - argument. If coll is nil, returns nil."} + :doc "Returns the first item in the collection. Calls seq on its + argument. If coll is nil, returns nil." + :added "1.0"} first (fn 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 - argument. If there are no more items, returns nil."} + :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"} next (fn 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 - argument."} + :tag clojure.lang.ISeq + :doc "Returns a possibly empty seq of the items after the first. Calls seq on its + argument." + :added "1.0"} rest (fn rest [x] (. clojure.lang.RT (more x)))) (def ^{:arglists '([coll x] [coll x & xs]) - :doc "conj[oin]. Returns a new collection with the 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."} + happen at different 'places' depending on the concrete type." + :added "1.0"} conj (fn conj ([coll x] (. clojure.lang.RT (conj coll x))) ([coll x & xs] @@ -74,75 +83,88 @@ (def ^{:doc "Same as (first (next x))" - :arglists '([x])} + :arglists '([x]) + :added "1.0"} second (fn second [x] (first (next x)))) (def ^{:doc "Same as (first (first x))" - :arglists '([x])} + :arglists '([x]) + :added "1.0"} ffirst (fn ffirst [x] (first (first x)))) (def ^{:doc "Same as (next (first x))" - :arglists '([x])} + :arglists '([x]) + :added "1.0"} nfirst (fn nfirst [x] (next (first x)))) (def ^{:doc "Same as (first (next x))" - :arglists '([x])} + :arglists '([x]) + :added "1.0"} fnext (fn fnext [x] (first (next x)))) (def ^{:doc "Same as (next (next x))" - :arglists '([x])} + :arglists '([x]) + :added "1.0"} nnext (fn nnext [x] (next (next x)))) (def ^{:arglists '([coll]) - :doc "Returns a seq on the collection. If the collection is + :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." - :tag clojure.lang.ISeq} + :tag clojure.lang.ISeq + :added "1.0"} seq (fn seq [coll] (. clojure.lang.RT (seq coll)))) (def ^{:arglists '([^Class c x]) - :doc "Evaluates x and tests if it is an instance of the class - c. Returns true or false"} + :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)))) (def ^{:arglists '([x]) - :doc "Return true if x implements ISeq"} + :doc "Return true if x implements ISeq" + :added "1.0"} seq? (fn seq? [x] (instance? clojure.lang.ISeq x))) (def ^{:arglists '([x]) - :doc "Return true if x is a Character"} + :doc "Return true if x is a Character" + :added "1.0"} char? (fn char? [x] (instance? Character x))) (def ^{:arglists '([x]) - :doc "Return true if x is a String"} + :doc "Return true if x is a String" + :added "1.0"} string? (fn string? [x] (instance? String x))) (def ^{:arglists '([x]) - :doc "Return true if x implements IPersistentMap"} + :doc "Return true if x implements IPersistentMap" + :added "1.0"} map? (fn map? [x] (instance? clojure.lang.IPersistentMap x))) (def ^{:arglists '([x]) - :doc "Return true if x implements IPersistentVector "} + :doc "Return true if x implements IPersistentVector" + :added "1.0"} vector? (fn 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 + :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)."} + contains val at index. Note - index must be <= (count vector)." + :added "1.0"} assoc (fn assoc ([map key val] (. clojure.lang.RT (assoc map key val))) @@ -155,15 +177,17 @@ ;;;;;;;;;;;;;;;;; metadata ;;;;;;;;;;;;;;;;;;;;;;;;;;; (def ^{:arglists '([obj]) - :doc "Returns the metadata of obj, returns nil if there is no metadata."} + :doc "Returns the metadata of obj, returns nil if there is no metadata." + :added "1.0"} meta (fn 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 - map m as its metadata."} + :doc "Returns an object of the same type and value as obj, with + map m as its metadata." + :added "1.0"} with-meta (fn with-meta [^clojure.lang.IObj x m] (. x (withMeta m)))) @@ -194,7 +218,8 @@ (def ^{:arglists '([coll]) - :doc "Return the last item in coll, in linear time"} + :doc "Return the last item in coll, in linear time" + :added "1.0"} last (fn last [s] (if (next s) (recur (next s)) @@ -202,7 +227,8 @@ (def ^{:arglists '([coll]) - :doc "Return a seq of all but the last item in coll, in linear time"} + :doc "Return a seq of all but the last item in coll, in linear time" + :added "1.0"} butlast (fn butlast [s] (loop [ret [] s s] (if (next s) @@ -214,8 +240,9 @@ ^{: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" - :arglists '([name doc-string? attr-map? [params*] body] - [name doc-string? attr-map? ([params*] body)+ attr-map?])} + :arglists '([name doc-string? attr-map? [params*] body] + [name doc-string? attr-map? ([params*] body)+ attr-map?]) + :added "1.0"} defn (fn defn [&form &env name & fdecl] (let [m (if (string? (first fdecl)) {:doc (first fdecl)} @@ -256,17 +283,20 @@ (defn cast "Throws a ClassCastException if x is not a c, else returns x." + {:added "1.0"} [^Class c x] (. c (cast x))) (defn to-array "Returns an array of Objects containing the contents of coll, which can be any Collection. Maps to java.util.Collection.toArray()." - {:tag "[Ljava.lang.Object;"} + {:tag "[Ljava.lang.Object;" + :added "1.0"} [coll] (. clojure.lang.RT (toArray coll))) (defn vector "Creates a new vector containing the args." + {:added "1.0"} ([] []) ([a] [a]) ([a b] [a b]) @@ -277,6 +307,7 @@ (defn vec "Creates a new vector containing the contents of coll." + {:added "1.0"} ([coll] (if (instance? java.util.Collection coll) (clojure.lang.LazilyPersistentVector/create coll) @@ -285,12 +316,14 @@ (defn hash-map "keyval => key val Returns a new hash map with supplied mappings." + {:added "1.0"} ([] {}) ([& keyvals] (. clojure.lang.PersistentHashMap (createWithCheck keyvals)))) (defn hash-set "Returns a new hash set with supplied keys." + {:added "1.0"} ([] #{}) ([& keys] (clojure.lang.PersistentHashSet/createWithCheck keys))) @@ -298,17 +331,20 @@ (defn sorted-map "keyval => key val Returns a new sorted map with supplied mappings." + {:added "1.0"} ([& keyvals] (clojure.lang.PersistentTreeMap/create keyvals))) (defn sorted-map-by "keyval => key val Returns a new sorted map with supplied mappings, using the supplied comparator." + {:added "1.0"} ([comparator & keyvals] (clojure.lang.PersistentTreeMap/create comparator keyvals))) (defn sorted-set "Returns a new sorted set with supplied keys." + {:added "1.0"} ([& keys] (clojure.lang.PersistentTreeSet/create keys))) @@ -322,7 +358,8 @@ ;;;;;;;;;;;;;;;;;;;; (defn nil? "Returns true if x is nil, false otherwise." - {:tag Boolean} + {:tag Boolean + :added "1.0"} [x] (clojure.lang.Util/identical x nil)) (def @@ -330,8 +367,9 @@ ^{: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?])} + :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] @@ -375,34 +413,40 @@ (defmacro when "Evaluates test. If logical true, evaluates body in an implicit do." + {:added "1.0"} [test & body] (list 'if test (cons 'do body))) (defmacro when-not "Evaluates test. If logical false, evaluates body in an implicit do." + {:added "1.0"} [test & body] (list 'if test nil (cons 'do body))) (defn false? "Returns true if x is the value false, false otherwise." - {:tag Boolean} + {:tag Boolean, + :added "1.0"} [x] (clojure.lang.Util/identical x false)) (defn true? "Returns true if x is the value true, false otherwise." - {:tag Boolean} + {:tag Boolean, + :added "1.0"} [x] (clojure.lang.Util/identical x true)) (defn not "Returns true if x is logical false, false otherwise." - {:tag Boolean} + {:tag Boolean + :added "1.0"} [x] (if x false true)) (defn str "With no args, returns the empty string. With one arg x, returns x.toString(). (str nil) returns the empty string. With more than one arg, returns the concatenation of the str values of the args." - {:tag String} + {:tag String + :added "1.0"} ([] "") ([^Object x] (if (nil? x) "" (. x (toString)))) @@ -416,15 +460,18 @@ (defn symbol? "Return true if x is a Symbol" + {:added "1.0"} [x] (instance? clojure.lang.Symbol x)) (defn keyword? "Return true if x is a Keyword" + {:added "1.0"} [x] (instance? clojure.lang.Keyword x)) (defn symbol "Returns a Symbol with the given namespace and name." - {:tag clojure.lang.Symbol} + {:tag clojure.lang.Symbol + :added "1.0"} ([name] (if (symbol? name) name (clojure.lang.Symbol/intern name))) ([ns name] (clojure.lang.Symbol/intern ns name))) @@ -432,6 +479,7 @@ "Returns a new symbol with a unique name. If a prefix string is supplied, the name is prefix# where # is some unique number. If prefix is not supplied, the prefix is 'G__'." + {:added "1.0"} ([] (gensym "G__")) ([prefix-string] (. clojure.lang.Symbol (intern (str prefix-string (str (. clojure.lang.RT (nextID)))))))) @@ -440,6 +488,7 @@ time. If a test returns logical true, cond evaluates and returns the value of the corresponding expr and doesn't evaluate any of the other tests or exprs. (cond) returns nil." + {:added "1.0"} [& clauses] (when clauses (list 'if (first clauses) @@ -452,7 +501,8 @@ (defn keyword "Returns a Keyword with the given namespace and name. Do not use : in the keyword strings, it will be added automatically." - {:tag clojure.lang.Keyword} + {:tag clojure.lang.Keyword + :added "1.0"} ([name] (cond (keyword? name) name (symbol? name) (clojure.lang.Keyword/intern ^clojure.lang.Symbol name) (string? name) (clojure.lang.Keyword/intern ^String name))) @@ -469,6 +519,7 @@ (defn list* "Creates a new list containing the items prepended to the rest, the last of which will be treated as a sequence." + {:added "1.0"} ([args] (seq args)) ([a args] (cons a args)) ([a b args] (cons a (cons b args))) @@ -478,7 +529,8 @@ (defn apply "Applies fn f to the argument list formed by prepending args to argseq." - {:arglists '([f args* argseq])} + {:arglists '([f args* argseq]) + :added "1.0"} ([^clojure.lang.IFn f args] (. f (applyTo (seq args)))) ([^clojure.lang.IFn f x args] @@ -493,6 +545,7 @@ (defn vary-meta "Returns an object of the same type and value as obj, with (apply f (meta obj) args) as its metadata." + {:added "1.0"} [obj f & args] (with-meta obj (apply f (meta obj) args))) @@ -500,7 +553,8 @@ "Takes a body of expressions that returns an ISeq or nil, and yields a Seqable object that will invoke the body only the first time seq is called, and will cache the result and return it on all subsequent - seq calls." + seq calls." + {:added "1.0"} [& body] (list 'new 'clojure.lang.LazySeq (list* '^{:once true} fn* [] body))) @@ -532,6 +586,7 @@ (defn concat "Returns a lazy seq representing the concatenation of the elements in the supplied colls." + {:added "1.0"} ([] (lazy-seq nil)) ([x] (lazy-seq x)) ([x y] @@ -560,21 +615,25 @@ "Takes a body of expressions and yields a Delay object that will invoke the body only the first time it is forced (with force or deref/@), and will cache the result and return it on all subsequent force - calls." + calls." + {:added "1.0"} [& body] (list 'new 'clojure.lang.Delay (list* `^{:once true} fn* [] body))) (defn delay? "returns true if x is a Delay created with delay" + {:added "1.0"} [x] (instance? clojure.lang.Delay x)) (defn force "If x is a Delay, returns the (possibly cached) value of its expression, else returns x" + {:added "1.0"} [x] (. clojure.lang.Delay (force x))) (defmacro if-not "Evaluates test. If logical false, evaluates and returns then expr, otherwise else expr, if supplied, else nil." + {:added "1.0"} ([test then] `(if-not ~test ~then nil)) ([test then else] `(if (not ~test) ~then ~else))) @@ -583,7 +642,8 @@ "Tests if 2 arguments are the same object" {:tag Boolean :inline (fn [x y] `(. clojure.lang.Util identical ~x ~y)) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([x y] (clojure.lang.Util/identical x y))) (defn = @@ -594,7 +654,8 @@ comparison." {:tag Boolean :inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y)) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([x] true) ([x y] (clojure.lang.Util/equiv x y)) ([x y & more] @@ -606,7 +667,8 @@ (defn not= "Same as (not (= obj1 obj2))" - {:tag Boolean} + {:tag Boolean + :added "1.0"} ([x] false) ([x y] (not (= x y))) ([x y & more] @@ -621,7 +683,8 @@ compares numbers and collections in a type-independent manner. x must implement Comparable" {:tag Integer - :inline (fn [x y] `(. clojure.lang.Util compare ~x ~y))} + :inline (fn [x y] `(. clojure.lang.Util compare ~x ~y)) + :added "1.0"} [x y] (. clojure.lang.Util (compare x y))) (defmacro and @@ -629,6 +692,7 @@ returns logical false (nil or false), and returns that value and doesn't evaluate any of the other expressions, otherwise it returns the value of the last expr. (and) returns true." + {:added "1.0"} ([] true) ([x] x) ([x & next] @@ -640,6 +704,7 @@ returns a logical true value, or returns that value and doesn't evaluate any of the other expressions, otherwise it returns the value of the last expression. (or) returns nil." + {:added "1.0"} ([] nil) ([x] x) ([x & next] @@ -650,20 +715,23 @@ (defn zero? "Returns true if num is zero, else false" {:tag Boolean - :inline (fn [x] `(. clojure.lang.Numbers (isZero ~x)))} + :inline (fn [x] `(. clojure.lang.Numbers (isZero ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers (isZero x))) (defn count "Returns the number of items in the collection. (count nil) returns 0. Also works on strings, arrays, and Java Collections and Maps" {:tag Integer - :inline (fn [x] `(. clojure.lang.RT (count ~x)))} + :inline (fn [x] `(. clojure.lang.RT (count ~x))) + :added "1.0"} [coll] (clojure.lang.RT/count coll)) (defn int "Coerce to int" {:tag Integer - :inline (fn [x] `(. clojure.lang.RT (intCast ~x)))} + :inline (fn [x] `(. clojure.lang.RT (intCast ~x))) + :added "1.0"} [x] (. clojure.lang.RT (intCast x))) (defn nth @@ -672,7 +740,8 @@ also works for strings, Java arrays, regex Matchers and Lists, and, in O(n) time, for sequences." {:inline (fn [c i & nf] `(. clojure.lang.RT (nth ~c ~i ~@nf))) - :inline-arities #{2 3}} + :inline-arities #{2 3} + :added "1.0"} ([coll index] (. clojure.lang.RT (nth coll index))) ([coll index not-found] (. clojure.lang.RT (nth coll index not-found)))) @@ -680,7 +749,8 @@ "Returns non-nil if nums are in monotonically increasing order, otherwise false." {:inline (fn [x y] `(. clojure.lang.Numbers (lt ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([x] true) ([x y] (. clojure.lang.Numbers (lt x y))) ([x y & more] @@ -692,7 +762,8 @@ (defn inc "Returns a number one greater than num." - {:inline (fn [x] `(. clojure.lang.Numbers (inc ~x)))} + {:inline (fn [x] `(. clojure.lang.Numbers (inc ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers (inc x))) ;; reduce is defined again later after InternalReduce loads @@ -714,6 +785,7 @@ (defn reverse "Returns a seq of the items in coll in reverse order. Not lazy." + {:added "1.0"} [coll] (reduce conj () coll)) @@ -721,7 +793,8 @@ (defn + "Returns the sum of nums. (+) returns 0." {:inline (fn [x y] `(. clojure.lang.Numbers (add ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([] 0) ([x] (cast Number x)) ([x y] (. clojure.lang.Numbers (add x y))) @@ -731,7 +804,8 @@ (defn * "Returns the product of nums. (*) returns 1." {:inline (fn [x y] `(. clojure.lang.Numbers (multiply ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([] 1) ([x] (cast Number x)) ([x y] (. clojure.lang.Numbers (multiply x y))) @@ -742,7 +816,8 @@ "If no denominators are supplied, returns 1/numerator, else returns numerator divided by all of the denominators." {:inline (fn [x y] `(. clojure.lang.Numbers (divide ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([x] (/ 1 x)) ([x y] (. clojure.lang.Numbers (divide x y))) ([x y & more] @@ -752,7 +827,8 @@ "If no ys are supplied, returns the negation of x, else subtracts the ys from x and returns the result." {:inline (fn [& args] `(. clojure.lang.Numbers (minus ~@args))) - :inline-arities #{1 2}} + :inline-arities #{1 2} + :added "1.0"} ([x] (. clojure.lang.Numbers (minus x))) ([x y] (. clojure.lang.Numbers (minus x y))) ([x y & more] @@ -762,7 +838,8 @@ "Returns non-nil if nums are in monotonically non-decreasing order, otherwise false." {:inline (fn [x y] `(. clojure.lang.Numbers (lte ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([x] true) ([x y] (. clojure.lang.Numbers (lte x y))) ([x y & more] @@ -776,7 +853,8 @@ "Returns non-nil if nums are in monotonically decreasing order, otherwise false." {:inline (fn [x y] `(. clojure.lang.Numbers (gt ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([x] true) ([x y] (. clojure.lang.Numbers (gt x y))) ([x y & more] @@ -790,7 +868,8 @@ "Returns non-nil if nums are in monotonically non-increasing order, otherwise false." {:inline (fn [x y] `(. clojure.lang.Numbers (gte ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([x] true) ([x y] (. clojure.lang.Numbers (gte x y))) ([x y & more] @@ -803,7 +882,8 @@ (defn == "Returns non-nil if nums all have the same value, otherwise false" {:inline (fn [x y] `(. clojure.lang.Numbers (equiv ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([x] true) ([x y] (. clojure.lang.Numbers (equiv x y))) ([x y & more] @@ -815,6 +895,7 @@ (defn max "Returns the greatest of the nums." + {:added "1.0"} ([x] x) ([x y] (if (> x y) x y)) ([x y & more] @@ -822,6 +903,7 @@ (defn min "Returns the least of the nums." + {:added "1.0"} ([x] x) ([x y] (if (< x y) x y)) ([x y & more] @@ -829,81 +911,95 @@ (defn dec "Returns a number one less than num." - {:inline (fn [x] `(. clojure.lang.Numbers (dec ~x)))} + {:inline (fn [x] `(. clojure.lang.Numbers (dec ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers (dec x))) (defn unchecked-inc "Returns a number one greater than x, an int or long. Note - uses a primitive operator subject to overflow." - {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_inc ~x)))} + {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_inc ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers (unchecked_inc x))) (defn unchecked-dec "Returns a number one less than x, an int or long. Note - uses a primitive operator subject to overflow." - {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_dec ~x)))} + {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_dec ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers (unchecked_dec x))) (defn unchecked-negate "Returns the negation of x, an int or long. Note - uses a primitive operator subject to overflow." - {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_negate ~x)))} + {:inline (fn [x] `(. clojure.lang.Numbers (unchecked_negate ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers (unchecked_negate x))) (defn unchecked-add "Returns the sum of x and y, both int or long. Note - uses a primitive operator subject to overflow." - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_add ~x ~y)))} + {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_add ~x ~y))) + :added "1.0"} [x y] (. clojure.lang.Numbers (unchecked_add x y))) (defn unchecked-subtract "Returns the difference of x and y, both int or long. Note - uses a primitive operator subject to overflow." - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_subtract ~x ~y)))} + {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_subtract ~x ~y))) + :added "1.0"} [x y] (. clojure.lang.Numbers (unchecked_subtract x y))) (defn unchecked-multiply "Returns the product of x and y, both int or long. Note - uses a primitive operator subject to overflow." - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_multiply ~x ~y)))} + {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_multiply ~x ~y))) + :added "1.0"} [x y] (. clojure.lang.Numbers (unchecked_multiply x y))) (defn unchecked-divide "Returns the division of x by y, both int or long. Note - uses a primitive operator subject to truncation." - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_divide ~x ~y)))} + {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_divide ~x ~y))) + :added "1.0"} [x y] (. clojure.lang.Numbers (unchecked_divide x y))) (defn unchecked-remainder "Returns the remainder of division of x by y, both int or long. Note - uses a primitive operator subject to truncation." - {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_remainder ~x ~y)))} + {:inline (fn [x y] `(. clojure.lang.Numbers (unchecked_remainder ~x ~y))) + :added "1.0"} [x y] (. clojure.lang.Numbers (unchecked_remainder x y))) (defn pos? "Returns true if num is greater than zero, else false" {:tag Boolean - :inline (fn [x] `(. clojure.lang.Numbers (isPos ~x)))} + :inline (fn [x] `(. clojure.lang.Numbers (isPos ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers (isPos x))) (defn neg? "Returns true if num is less than zero, else false" {:tag Boolean - :inline (fn [x] `(. clojure.lang.Numbers (isNeg ~x)))} + :inline (fn [x] `(. clojure.lang.Numbers (isNeg ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers (isNeg x))) (defn quot "quot[ient] of dividing numerator by denominator." + {:added "1.0"} [num div] (. clojure.lang.Numbers (quotient num div))) (defn rem "remainder of dividing numerator by denominator." + {:added "1.0"} [num div] (. clojure.lang.Numbers (remainder num div))) (defn rationalize "returns the rational value of num" + {:added "1.0"} [num] (. clojure.lang.Numbers (rationalize num))) @@ -911,63 +1007,76 @@ (defn bit-not "Bitwise complement" - {:inline (fn [x] `(. clojure.lang.Numbers (not ~x)))} + {:inline (fn [x] `(. clojure.lang.Numbers (not ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers not x)) (defn bit-and "Bitwise and" - {:inline (fn [x y] `(. clojure.lang.Numbers (and ~x ~y)))} + {:inline (fn [x y] `(. clojure.lang.Numbers (and ~x ~y))) + :added "1.0"} [x y] (. clojure.lang.Numbers and x y)) (defn bit-or "Bitwise or" - {:inline (fn [x y] `(. clojure.lang.Numbers (or ~x ~y)))} + {:inline (fn [x y] `(. clojure.lang.Numbers (or ~x ~y))) + :added "1.0"} [x y] (. clojure.lang.Numbers or x y)) (defn bit-xor "Bitwise exclusive or" - {:inline (fn [x y] `(. clojure.lang.Numbers (xor ~x ~y)))} + {:inline (fn [x y] `(. clojure.lang.Numbers (xor ~x ~y))) + :added "1.0"} [x y] (. clojure.lang.Numbers xor x y)) (defn bit-and-not "Bitwise and with complement" + {:added "1.0"} [x y] (. clojure.lang.Numbers andNot x y)) (defn bit-clear "Clear bit at index n" + {:added "1.0"} [x n] (. clojure.lang.Numbers clearBit x n)) (defn bit-set "Set bit at index n" + {:added "1.0"} [x n] (. clojure.lang.Numbers setBit x n)) (defn bit-flip "Flip bit at index n" + {:added "1.0"} [x n] (. clojure.lang.Numbers flipBit x n)) (defn bit-test "Test bit at index n" + {:added "1.0"} [x n] (. clojure.lang.Numbers testBit x n)) (defn bit-shift-left "Bitwise shift left" - {:inline (fn [x n] `(. clojure.lang.Numbers (shiftLeft ~x ~n)))} + {:inline (fn [x n] `(. clojure.lang.Numbers (shiftLeft ~x ~n))) + :added "1.0"} [x n] (. clojure.lang.Numbers shiftLeft x n)) (defn bit-shift-right "Bitwise shift right" - {:inline (fn [x n] `(. clojure.lang.Numbers (shiftRight ~x ~n)))} + {:inline (fn [x n] `(. clojure.lang.Numbers (shiftRight ~x ~n))) + :added "1.0"} [x n] (. clojure.lang.Numbers shiftRight x n)) (defn even? "Returns true if n is even, throws an exception if n is not an integer" + {:added "1.0"} [n] (zero? (bit-and n 1))) (defn odd? "Returns true if n is odd, throws an exception if n is not an integer" + {:added "1.0"} [n] (not (even? n))) @@ -976,6 +1085,7 @@ (defn complement "Takes a fn f and returns a fn that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value." + {:added "1.0"} [f] (fn ([] (not (f))) @@ -985,10 +1095,12 @@ (defn constantly "Returns a function that takes any number of arguments and returns x." + {:added "1.0"} [x] (fn [& args] x)) (defn identity "Returns its argument." + {:added "1.0"} [x] x) ;;Collection stuff @@ -1001,6 +1113,7 @@ (defn peek "For a list or queue, same as first, for a vector, same as, but much more efficient than, last. If the collection is empty, returns nil." + {:added "1.0"} [coll] (. clojure.lang.RT (peek coll))) (defn pop @@ -1008,6 +1121,7 @@ item, for a vector, returns a new vector without the last item. If the collection is empty, throws an exception. Note - not the same as next/butlast." + {:added "1.0"} [coll] (. clojure.lang.RT (pop coll))) ;;map stuff @@ -1018,12 +1132,14 @@ vectors and Java arrays, this tests if the numeric key is within the range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'." + {:added "1.0"} [coll key] (. clojure.lang.RT (contains coll key))) (defn get "Returns the value mapped to key, not-found or nil if key not present." {:inline (fn [m k & nf] `(. clojure.lang.RT (get ~m ~k ~@nf))) - :inline-arities #{2 3}} + :inline-arities #{2 3} + :added "1.0"} ([map key] (. clojure.lang.RT (get map key))) ([map key not-found] @@ -1032,6 +1148,7 @@ (defn dissoc "dissoc[iate]. Returns a new map of the same (hashed/sorted) type, that does not contain a mapping for key(s)." + {:added "1.0"} ([map] map) ([map key] (. clojure.lang.RT (dissoc map key))) @@ -1044,6 +1161,7 @@ (defn disj "disj[oin]. Returns a new set of the same (hashed/sorted) type, that does not contain key(s)." + {:added "1.0"} ([set] set) ([^clojure.lang.IPersistentSet set key] (. set (disjoin key))) @@ -1055,10 +1173,12 @@ (defn find "Returns the map entry for key, or nil if key not present." + {:added "1.0"} [map key] (. clojure.lang.RT (find map key))) (defn select-keys "Returns a map containing only those entries in map whose key is in keys" + {:added "1.0"} [map keyseq] (loop [ret {} keys (seq keyseq)] (if keys @@ -1072,43 +1192,51 @@ (defn keys "Returns a sequence of the map's keys." + {:added "1.0"} [map] (. clojure.lang.RT (keys map))) (defn vals "Returns a sequence of the map's values." + {:added "1.0"} [map] (. clojure.lang.RT (vals map))) (defn key "Returns the key of the map entry." + {:added "1.0"} [^java.util.Map$Entry e] (. e (getKey))) (defn val "Returns the value in the map entry." + {:added "1.0"} [^java.util.Map$Entry e] (. e (getValue))) (defn rseq "Returns, in constant time, a seq of the items in rev (which can be a vector or sorted-map), in reverse order. If rev is empty returns nil" + {:added "1.0"} [^clojure.lang.Reversible rev] (. rev (rseq))) (defn name "Returns the name String of a symbol or keyword." - {:tag String} + {:tag String + :added "1.0"} [^clojure.lang.Named x] (. x (getName))) (defn namespace "Returns the namespace String of a symbol or keyword, or nil if not present." - {:tag String} + {:tag String + :added "1.0"} [^clojure.lang.Named x] (. x (getNamespace))) (defmacro locking "Executes exprs in an implicit do, while holding the monitor of x. Will release the monitor of x in all circumstances." + {:added "1.0"} [x & body] `(let [lockee# ~x] (try @@ -1131,6 +1259,7 @@ (. (. System (getProperties)) (get \"os.name\")) but is easier to write, read, and understand." + {:added "1.0"} ([x form] `(. ~x ~form)) ([x form & more] `(.. (. ~x ~form) ~@more))) @@ -1139,6 +1268,7 @@ second item in the first form, making a list of it if it is not a list already. If there are more forms, inserts the first form as the second item in second form, etc." + {:added "1.0"} ([x] x) ([x form] (if (seq? form) (with-meta `(~(first form) ~x ~@(next form)) (meta form)) @@ -1167,7 +1297,8 @@ :default the default dispatch value, defaults to :default :hierarchy the isa? hierarchy to use for dispatching defaults to the global hierarchy" - {:arglists '([name docstring? attr-map? dispatch-fn & options])} + {:arglists '([name docstring? attr-map? dispatch-fn & options]) + :added "1.0"} [mm-name & options] (let [docstring (if (string? (first options)) (first options) @@ -1202,6 +1333,7 @@ (defmacro defmethod "Creates and installs a new method of multimethod associated with dispatch-value. " + {:added "1.0"} [multifn dispatch-val & fn-tail] `(. ~(with-meta multifn {:tag 'clojure.lang.MultiFn}) addMethod ~dispatch-val (fn ~@fn-tail))) @@ -1213,26 +1345,31 @@ (defn remove-method "Removes the method of multimethod associated with dispatch-value." + {:added "1.0"} [^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 when there is a conflict" + {:added "1.0"} [^clojure.lang.MultiFn multifn dispatch-val-x dispatch-val-y] (. multifn preferMethod dispatch-val-x dispatch-val-y)) (defn methods "Given a multimethod, returns a map of dispatch values -> dispatch fns" + {:added "1.0"} [^clojure.lang.MultiFn multifn] (.getMethodTable multifn)) (defn get-method "Given a multimethod and a dispatch value, returns the dispatch fn that would apply to that value, or nil if none apply and no default" + {:added "1.0"} [^clojure.lang.MultiFn multifn dispatch-val] (.getMethod multifn dispatch-val)) (defn prefers "Given a multimethod, returns a map of preferred value -> set of other values" + {:added "1.0"} [^clojure.lang.MultiFn multifn] (.getPreferTable multifn)) ;;;;;;;;; var stuff @@ -1250,6 +1387,7 @@ If test is true, evaluates then with binding-form bound to the value of test, if not, yields else" + {:added "1.0"} ([bindings then] `(if-let ~bindings ~then nil)) ([bindings then else & oldform] @@ -1267,6 +1405,7 @@ "bindings => binding-form test When test is true, evaluates body with binding-form bound to the value of test" + {:added "1.0"} [bindings & body] (assert-args when-let (vector? bindings) "a vector for its binding" @@ -1316,6 +1455,7 @@ re-establishes the bindings that existed before. The new bindings are made in parallel (unlike let); all init-exprs are evaluated before the vars are bound to their new values." + {:added "1.0"} [bindings & body] (assert-args binding (vector? bindings) "a vector for its binding" @@ -1376,6 +1516,7 @@ (defn find-var "Returns the global var named by the namespace-qualified symbol, or nil if no var with that name." + {:added "1.0"} [sym] (. clojure.lang.Var (find sym))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Refs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1410,6 +1551,7 @@ :continue (the default if an error-handler is given) or :fail (the default if no error-handler is given) -- see set-error-mode! for details." + {:added "1.0"} ([state & options] (let [a (new clojure.lang.Agent state) opts (apply hash-map options)] @@ -1426,6 +1568,7 @@ will be set to the value of: (apply action-fn state-of-agent args)" + {:added "1.0"} [^clojure.lang.Agent a f & args] (. a (dispatch f args false))) @@ -1435,6 +1578,7 @@ the agent will be set to the value of: (apply action-fn state-of-agent args)" + {:added "1.0"} [^clojure.lang.Agent a f & args] (. a (dispatch f args true))) @@ -1445,6 +1589,7 @@ actions immediately. This has no impact on actions sent during a transaction, which are still held until commit. If no action is occurring, does nothing. Returns the number of actions dispatched." + {:added "1.0"} [] (clojure.lang.Agent/releasePendingSends)) (defn add-watch @@ -1462,11 +1607,13 @@ set!s. Keys must be unique per reference, and can be used to remove the watch with remove-watch, but are otherwise considered opaque by the watch mechanism." + {:added "1.0"} [^clojure.lang.IRef reference key fn] (.addWatch reference key fn)) (defn remove-watch "Alpha - subject to change. Removes a watch (set by add-watch) from a reference" + {:added "1.0"} [^clojure.lang.IRef reference key] (.removeWatch reference key)) @@ -1534,6 +1681,7 @@ "DEPRECATED: Use 'agent-error' instead. Returns a sequence of the exceptions thrown during asynchronous actions of the agent." + {:added "1.0"} [a] (when-let [e (agent-error a)] (list e))) @@ -1542,12 +1690,14 @@ "DEPRECATED: Use 'restart-agent' instead. Clears any exceptions thrown during asynchronous actions of the agent, allowing subsequent actions to occur." + {:added "1.0"} [^clojure.lang.Agent a] (restart-agent a (.deref a))) (defn shutdown-agents "Initiates a shutdown of the thread pools that back the agent system. Running actions will complete, but no new actions will be accepted" + {:added "1.0"} [] (. clojure.lang.Agent shutdown)) (defn ref @@ -1573,6 +1723,7 @@ set :min-history to ensure it will be available when first needed (instead of after a read fault). History is limited, and the limit can be set with :max-history." + {:added "1.0"} ([x] (new clojure.lang.Ref x)) ([x & options] (let [r ^clojure.lang.Ref (setup-reference (ref x) options) @@ -1589,7 +1740,8 @@ most-recently-committed value of ref. When applied to a var, agent or atom, returns its current state. When applied to a delay, forces it if not already forced. When applied to a future, will block if - computation not complete" + computation not complete" + {:added "1.0"} [^clojure.lang.IDeref ref] (.deref ref)) (defn atom @@ -1605,6 +1757,7 @@ argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the validate-fn should return false or throw an exception." + {:added "1.0"} ([x] (new clojure.lang.Atom x)) ([x & options] (setup-reference (atom x) options))) @@ -1613,6 +1766,7 @@ (apply f current-value-of-atom args). Note that f may be called multiple times, and thus should be free of side effects. Returns the value that was swapped in." + {:added "1.0"} ([^clojure.lang.Atom atom f] (.swap atom f)) ([^clojure.lang.Atom atom f x] (.swap atom f x)) ([^clojure.lang.Atom atom f x y] (.swap atom f x y)) @@ -1622,11 +1776,13 @@ "Atomically sets the value of atom to newval if and only if the current value of the atom is identical to oldval. Returns true if set happened, else false" + {:added "1.0"} [^clojure.lang.Atom atom oldval newval] (.compareAndSet atom oldval newval)) (defn reset! "Sets the value of atom to newval without regard for the current value. Returns newval." + {:added "1.0"} [^clojure.lang.Atom atom newval] (.reset atom newval)) (defn set-validator! @@ -1636,10 +1792,12 @@ validator-fn should return false or throw an exception. If the current state (root value if var) is not acceptable to the new validator, an exception will be thrown and the validator will not be changed." + {:added "1.0"} [^clojure.lang.IRef iref validator-fn] (. iref (setValidator validator-fn))) (defn get-validator "Gets the validator-fn for a var/ref/agent/atom." + {:added "1.0"} [^clojure.lang.IRef iref] (. iref (getValidator))) (defn alter-meta! @@ -1648,10 +1806,12 @@ (apply f its-current-meta args) f must be free of side-effects" + {:added "1.0"} [^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"} [^clojure.lang.IReference iref metadata-map] (.resetMeta iref metadata-map)) (defn commute @@ -1669,6 +1829,7 @@ Thus fun should be commutative, or, failing that, you must accept last-one-in-wins behavior. commute allows for more concurrency than ref-set." + {:added "1.0"} [^clojure.lang.Ref ref fun & args] (. ref (commute fun args))) @@ -1680,12 +1841,14 @@ (apply fun in-transaction-value-of-ref args) and returns the in-transaction-value of ref." + {:added "1.0"} [^clojure.lang.Ref ref fun & args] (. ref (alter fun args))) (defn ref-set "Must be called in a transaction. Sets the value of ref. Returns val." + {:added "1.0"} [^clojure.lang.Ref ref val] (. ref (set val))) @@ -1715,6 +1878,7 @@ "Must be called in a transaction. Protects the ref from modification by other transactions. Returns the in-transaction-value of ref. Allows for more concurrency than (ref-set ref @ref)" + {:added "1.0"} [^clojure.lang.Ref ref] (. ref (touch)) (. ref (deref))) @@ -1727,6 +1891,7 @@ running on this thread. Any uncaught exception will abort the transaction and flow out of sync. The exprs may be run more than once, but any effects on Refs will be atomic." + {:added "1.0"} [flags-ignored-for-now & body] `(. clojure.lang.LockingTransaction (runInTransaction (fn [] ~@body)))) @@ -1737,6 +1902,7 @@ IllegalStateException, else runs body in an implicit do. If the first expression in body is a literal string, will use that as the exception message." + {:added "1.0"} [& body] (let [message (when (string? (first body)) (first body)) body (if message (next body) body)] @@ -1752,6 +1918,7 @@ of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc." + {:added "1.0"} ([f] f) ([f g] (fn @@ -1817,6 +1984,7 @@ "Takes a function f and fewer than the normal arguments to f, and returns a fn that takes a variable number of additional args. When called, the returned function calls f with args + additional args." + {:added "1.0"} ([f arg1] (fn [& args] (apply f arg1 args))) ([f arg1 arg2] @@ -1829,7 +1997,8 @@ ;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;; (defn sequence "Coerces coll to a (possibly empty) sequence, if it is not already - one. Will not force a lazy seq. (sequence nil) yields ()" + one. Will not force a lazy seq. (sequence nil) yields ()" + {:added "1.0"} [coll] (if (seq? coll) coll (or (seq coll) ()))) @@ -1837,7 +2006,8 @@ (defn every? "Returns true if (pred x) is logical true for every x in coll, else false." - {:tag Boolean} + {:tag Boolean + :added "1.0"} [pred coll] (cond (nil? (seq coll)) true @@ -1846,9 +2016,10 @@ (def ^{:tag Boolean - :doc "Returns false if (pred x) is logical true for every x in + :doc "Returns false if (pred x) is logical true for every x in coll, else true." - :arglists '([pred coll])} + :arglists '([pred coll]) + :added "1.0"} not-every? (comp not every?)) (defn some @@ -1856,15 +2027,17 @@ else nil. One common idiom is to use a set as pred, for example this will return :fred if :fred is in the sequence, otherwise nil: (some #{:fred} coll)" + {:added "1.0"} [pred coll] (when (seq coll) (or (pred (first coll)) (recur pred (next coll))))) (def ^{:tag Boolean - :doc "Returns false if (pred x) is logical true for any x in coll, + :doc "Returns false if (pred x) is logical true for any x in coll, else true." - :arglists '([pred coll])} + :arglists '([pred coll]) + :added "1.0"} not-any? (comp not some)) ;will be redefed later with arg checks @@ -1873,6 +2046,7 @@ Repeatedly executes body (presumably for side-effects) with name bound to integers from 0 through n-1." + {:added "1.0"} [bindings & body] (let [i (first bindings) n (second bindings)] @@ -1888,6 +2062,7 @@ of second items in each coll, until any one of the colls is exhausted. Any remaining items in other colls are ignored. Function f should accept number-of-colls arguments." + {:added "1.0"} ([f coll] (lazy-seq (when-let [s (seq coll)] @@ -1922,12 +2097,14 @@ (defn mapcat "Returns the result of applying concat to the result of applying map to f and colls. Thus function f should return a collection." + {:added "1.0"} [f & colls] (apply concat (apply map f colls))) (defn filter "Returns a lazy sequence of the items in coll for which (pred item) returns true. pred must be free of side-effects." + {:added "1.0"} ([pred coll] (lazy-seq (when-let [s (seq coll)] @@ -1948,12 +2125,14 @@ (defn remove "Returns a lazy sequence of the items in coll for which (pred item) returns false. pred must be free of side-effects." + {:added "1.0"} [pred coll] (filter (complement pred) coll)) (defn take "Returns a lazy sequence of the first n items in coll, or all items if there are fewer than n." + {:added "1.0"} [n coll] (lazy-seq (when (pos? n) @@ -1963,6 +2142,7 @@ (defn take-while "Returns a lazy sequence of successive items from coll while (pred item) returns true. pred must be free of side-effects." + {:added "1.0"} [pred coll] (lazy-seq (when-let [s (seq coll)] @@ -1971,6 +2151,7 @@ (defn drop "Returns a lazy sequence of all but the first n items in coll." + {:added "1.0"} [n coll] (let [step (fn [n coll] (let [s (seq coll)] @@ -1981,6 +2162,7 @@ (defn drop-last "Return a lazy sequence of all but the last n (default 1) items in coll" + {:added "1.0"} ([s] (drop-last 1 s)) ([n s] (map (fn [x _] x) s (drop n s)))) @@ -1997,6 +2179,7 @@ (defn drop-while "Returns a lazy sequence of the items in coll starting from the first item for which (pred item) returns nil." + {:added "1.0"} [pred coll] (let [step (fn [pred coll] (let [s (seq coll)] @@ -2006,38 +2189,45 @@ (lazy-seq (step pred coll)))) (defn cycle - "Returns a lazy (infinite!) sequence of repetitions of the items in coll." + "Returns a lazy (infinite!) sequence of repetitions of the items in coll." + {:added "1.0"} [coll] (lazy-seq (when-let [s (seq coll)] (concat s (cycle s))))) (defn split-at "Returns a vector of [(take n coll) (drop n coll)]" + {:added "1.0"} [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"} [pred coll] [(take-while pred coll) (drop-while pred coll)]) (defn repeat "Returns a lazy (infinite!, or length n if supplied) sequence of xs." + {:added "1.0"} ([x] (lazy-seq (cons x (repeat x)))) ([n x] (take n (repeat x)))) (defn replicate "Returns a lazy seq of n xs." + {:added "1.0"} [n x] (take n (repeat x))) (defn iterate "Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects" + {:added "1.0"} [f x] (cons x (lazy-seq (iterate f (f x))))) (defn range "Returns a lazy seq of nums from start (inclusive) to end (exclusive), by step, where start defaults to 0, step to 1, and end to infinity." + {:added "1.0"} ([] (range 0 Double/POSITIVE_INFINITY 1)) ([end] (range 0 end 1)) ([start end] (range start end 1)) @@ -2059,6 +2249,7 @@ "Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping from the latter (left-to-right) will be the mapping in the result." + {:added "1.0"} [& maps] (when (some identity maps) (reduce #(conj (or %1 {}) %2) maps))) @@ -2068,6 +2259,7 @@ the first. If a key occurs in more than one map, the mapping(s) from the latter (left-to-right) will be combined with the mapping in the result by calling (f val-in-result val-in-latter)." + {:added "1.0"} [f & maps] (when (some identity maps) (let [merge-entry (fn [m e] @@ -2083,6 +2275,7 @@ (defn zipmap "Returns a map with the keys mapped to the corresponding vals." + {:added "1.0"} [keys vals] (loop [map {} ks (seq keys) @@ -2095,17 +2288,20 @@ (defmacro declare "defs the supplied var names with no bindings, useful for making forward declarations." + {:added "1.0"} [& names] `(do ~@(map #(list 'def (vary-meta % assoc :declared true)) names))) (defn line-seq "Returns the lines of text from rdr as a lazy sequence of strings. rdr must implement java.io.BufferedReader." + {:added "1.0"} [^java.io.BufferedReader rdr] (when-let [line (.readLine rdr)] (cons line (lazy-seq (line-seq rdr))))) (defn comparator "Returns an implementation of java.util.Comparator based upon pred." + {:added "1.0"} [pred] (fn [x y] (cond (pred x y) -1 (pred y x) 1 :else 0))) @@ -2114,6 +2310,7 @@ "Returns a sorted sequence of the items in coll. If no comparator is supplied, uses compare. comparator must implement java.util.Comparator." + {:added "1.0"} ([coll] (sort compare coll)) ([^java.util.Comparator comp coll] @@ -2128,6 +2325,7 @@ order is determined by comparing (keyfn item). If no comparator is supplied, uses compare. comparator must implement java.util.Comparator." + {:added "1.0"} ([keyfn coll] (sort-by keyfn compare coll)) ([keyfn ^java.util.Comparator comp coll] @@ -2139,6 +2337,7 @@ do not overlap. If a pad collection is supplied, use its elements as necessary to complete last partition upto n items. In case there are not enough padding elements, return a partition with less than n items." + {:added "1.0"} ([n coll] (partition n n coll)) ([n step coll] @@ -2159,12 +2358,14 @@ (defn eval "Evaluates the form data structure (not text!) and returns the result." + {:added "1.0"} [form] (. clojure.lang.Compiler (eval form))) (defmacro doseq "Repeatedly executes body (presumably for side-effects) with bindings and filtering as provided by \"for\". Does not retain the head of the sequence. Returns nil." + {:added "1.0"} [seq-exprs & body] (assert-args doseq (vector? seq-exprs) "a vector for its binding" @@ -2224,6 +2425,7 @@ element in the seq do not occur until the seq is consumed. dorun can be used to force any effects. Walks through the successive nexts of the seq, does not retain the head and returns nil." + {:added "1.0"} ([coll] (when (seq coll) (recur (next coll)))) @@ -2238,6 +2440,7 @@ be used to force any effects. Walks through the successive nexts of the seq, retains the head and returns it, thus causing the entire seq to reside in memory at one time." + {:added "1.0"} ([coll] (dorun coll) coll) @@ -2250,6 +2453,7 @@ dispatched thus far, from this thread or agent, to the agent(s) have occurred. Will block on failed agents. Will never return if a failed agent is restarted with :clear-actions true." + {:added "1.0"} [& agents] (io! "await in transaction" (when *agent* @@ -2270,6 +2474,7 @@ far (from this thread or agent) to the agents have occurred, or the timeout (in milliseconds) has elapsed. Returns nil if returning due to timeout, non-nil otherwise." + {:added "1.0"} [timeout-ms & agents] (io! "await-for in transaction" (when *agent* @@ -2285,6 +2490,7 @@ Repeatedly executes body (presumably for side-effects) with name bound to integers from 0 through n-1." + {:added "1.0"} [bindings & body] (assert-args dotimes (vector? bindings) "a vector for its binding" @@ -2300,6 +2506,7 @@ (defn into "Returns a new coll consisting of to-coll with all of the items of from-coll conjoined." + {:added "1.0"} [to from] (let [ret to items (seq from)] (if items @@ -2312,6 +2519,7 @@ For each name in class-name-symbols, adds a mapping from name to the class named by package.name to the current namespace. Use :import in the ns macro in preference to calling this directly." + {:added "1.0"} [& import-symbols-or-lists] (let [specs (map #(if (and (seq? %) (= 'quote (first %))) (second %) %) import-symbols-or-lists)] @@ -2329,6 +2537,7 @@ aseq if present, or Object. All values in aseq must be compatible with the component type. Class objects for the primitive types can be obtained using, e.g., Integer/TYPE." + {:added "1.0"} ([aseq] (clojure.lang.RT/seqToTypedArray (seq aseq))) ([type aseq] @@ -2340,47 +2549,55 @@ (defn ^Class class "Returns the Class of x" + {:added "1.0"} [^Object x] (if (nil? x) x (. x (getClass)))) (defn type "Returns the :type metadata of x, or its Class if none" + {:added "1.0"} [x] (or (:type (meta x)) (class x))) (defn num "Coerce to Number" {:tag Number - :inline (fn [x] `(. clojure.lang.Numbers (num ~x)))} + :inline (fn [x] `(. clojure.lang.Numbers (num ~x))) + :added "1.0"} [x] (. clojure.lang.Numbers (num x))) (defn long "Coerce to long" {:tag Long - :inline (fn [x] `(. clojure.lang.RT (longCast ~x)))} + :inline (fn [x] `(. clojure.lang.RT (longCast ~x))) + :added "1.0"} [^Number x] (clojure.lang.RT/longCast x)) (defn float "Coerce to float" {:tag Float - :inline (fn [x] `(. clojure.lang.RT (floatCast ~x)))} + :inline (fn [x] `(. clojure.lang.RT (floatCast ~x))) + :added "1.0"} [^Number x] (clojure.lang.RT/floatCast x)) (defn double "Coerce to double" {:tag Double - :inline (fn [x] `(. clojure.lang.RT (doubleCast ~x)))} + :inline (fn [x] `(. clojure.lang.RT (doubleCast ~x))) + :added "1.0"} [^Number x] (clojure.lang.RT/doubleCast x)) (defn short "Coerce to short" {:tag Short - :inline (fn [x] `(. clojure.lang.RT (shortCast ~x)))} + :inline (fn [x] `(. clojure.lang.RT (shortCast ~x))) + :added "1.0"} [^Number x] (clojure.lang.RT/shortCast x)) (defn byte "Coerce to byte" {:tag Byte - :inline (fn [x] `(. clojure.lang.RT (byteCast ~x)))} + :inline (fn [x] `(. clojure.lang.RT (byteCast ~x))) + :added "1.0"} [^Number x] (clojure.lang.RT/byteCast x)) (defn char @@ -2393,16 +2610,19 @@ (defn boolean "Coerce to boolean" {:tag Boolean - :inline (fn [x] `(. clojure.lang.RT (booleanCast ~x)))} + :inline (fn [x] `(. clojure.lang.RT (booleanCast ~x))) + :added "1.0"} [x] (clojure.lang.RT/booleanCast x)) (defn number? "Returns true if x is a Number" + {:added "1.0"} [x] (instance? Number x)) (defn integer? "Returns true if n is an integer" + {:added "1.0"} [n] (or (instance? Integer n) (instance? Long n) @@ -2411,7 +2631,8 @@ (instance? Byte n))) (defn mod - "Modulus of num and div. Truncates toward negative infinity." + "Modulus of num and div. Truncates toward negative infinity." + {:added "1.0"} [num div] (let [m (rem num div)] (if (or (zero? m) (pos? (* num div))) @@ -2420,6 +2641,7 @@ (defn ratio? "Returns true if n is a Ratio" + {:added "1.0"} [n] (instance? clojure.lang.Ratio n)) (defn numerator @@ -2438,21 +2660,25 @@ (defn decimal? "Returns true if n is a BigDecimal" + {:added "1.0"} [n] (instance? BigDecimal n)) (defn float? "Returns true if n is a floating point number" + {:added "1.0"} [n] (or (instance? Double n) (instance? Float n))) (defn rational? [n] "Returns true if n is a rational number" + {:added "1.0"} (or (integer? n) (ratio? n) (decimal? n))) (defn bigint "Coerce to BigInteger" - {:tag BigInteger} + {:tag BigInteger + :added "1.0"} [x] (cond (instance? BigInteger x) x (decimal? x) (.toBigInteger ^BigDecimal x) @@ -2462,7 +2688,8 @@ (defn bigdec "Coerce to BigDecimal" - {:tag BigDecimal} + {:tag BigDecimal + :added "1.0"} [x] (cond (decimal? x) x (float? x) (. BigDecimal valueOf (double x)) @@ -2489,7 +2716,8 @@ of *out*. Prints the object(s), separated by spaces if there is more than one. By default, pr and prn print in a way that objects can be read by the reader" - {:dynamic true} + {:dynamic true + :added "1.0"} ([] nil) ([x] (pr-on x *out*)) @@ -2501,6 +2729,7 @@ (defn newline "Writes a newline to the output stream that is the current value of *out*" + {:added "1.0"} [] (. *out* (append \newline)) nil) @@ -2508,12 +2737,14 @@ (defn flush "Flushes the output stream that is the current value of *out*" + {:added "1.0"} [] (. *out* (flush)) nil) (defn prn "Same as pr followed by (newline). Observes *flush-on-newline*" + {:added "1.0"} [& more] (apply pr more) (newline) @@ -2523,12 +2754,14 @@ (defn print "Prints the object(s) to the output stream that is the current value of *out*. print and println produce output for human consumption." + {:added "1.0"} [& more] (binding [*print-readably* nil] (apply pr more))) (defn println "Same as print followed by (newline)" + {:added "1.0"} [& more] (binding [*print-readably* nil] (apply prn more))) @@ -2537,6 +2770,7 @@ "Reads the next object from stream, which must be an instance of java.io.PushbackReader or some derivee. stream defaults to the current value of *in* ." + {:added "1.0"} ([] (read *in*)) ([stream] @@ -2548,6 +2782,7 @@ (defn read-line "Reads the next line from stream that is the current value of *in* ." + {:added "1.0"} [] (if (instance? clojure.lang.LineNumberingPushbackReader *in*) (.readLine ^clojure.lang.LineNumberingPushbackReader *in*) @@ -2555,6 +2790,7 @@ (defn read-string "Reads one object from the string s" + {:added "1.0"} [s] (clojure.lang.RT/readString s)) (defn subvec @@ -2563,6 +2799,7 @@ defaults to (count vector). This operation is O(1) and very fast, as the resulting vector shares structure with the original and no trimming is done." + {:added "1.0"} ([v start] (subvec v start (count v))) ([v start end] @@ -2574,6 +2811,7 @@ Evaluates body in a try expression with names bound to the values of the inits, and a finally clause that calls (.close name) on each name in reverse order." + {:added "1.0"} [bindings & body] (assert-args with-open (vector? bindings) "a vector for its binding" @@ -2594,6 +2832,7 @@ are evaluated in order. Returns x. (doto (new java.util.HashMap) (.put \"a\" 1) (.put \"b\" 2))" + {:added "1.0"} [x & forms] (let [gx (gensym)] `(let [~gx ~x] @@ -2609,6 +2848,7 @@ object and any args and calls the named instance method on the object passing the args. Use when you want to treat a Java method as a first-class fn." + {:added "1.0"} [name & args] `(fn [target# ~@args] (. target# (~name ~@args)))) @@ -2616,6 +2856,7 @@ (defmacro time "Evaluates expr and prints the time it took. Returns the value of expr." + {:added "1.0"} [expr] `(let [start# (. System (nanoTime)) ret# ~expr] @@ -2629,20 +2870,23 @@ (defn alength "Returns the length of the Java array. Works on arrays of all types." - {:inline (fn [a] `(. clojure.lang.RT (alength ~a)))} + {:inline (fn [a] `(. clojure.lang.RT (alength ~a))) + :added "1.0"} [array] (. clojure.lang.RT (alength array))) (defn aclone "Returns a clone of the Java array. Works on arrays of known types." - {:inline (fn [a] `(. clojure.lang.RT (aclone ~a)))} + {:inline (fn [a] `(. clojure.lang.RT (aclone ~a))) + :added "1.0"} [array] (. clojure.lang.RT (aclone array))) (defn aget "Returns the value at the index/indices. Works on Java arrays of all types." {:inline (fn [a i] `(. clojure.lang.RT (aget ~a (int ~i)))) - :inline-arities #{2}} + :inline-arities #{2} + :added "1.0"} ([array idx] (clojure.lang.Reflector/prepRet (. Array (get array idx)))) ([array idx & idxs] @@ -2652,7 +2896,8 @@ "Sets the value at the index/indices. Works on Java arrays of reference types. Returns val." {:inline (fn [a i v] `(. clojure.lang.RT (aset ~a (int ~i) ~v))) - :inline-arities #{3}} + :inline-arities #{3} + :added "1.0"} ([array idx val] (. Array (set array idx val)) val) @@ -2671,35 +2916,43 @@ (apply ~name (aget array# idx#) idx2# idxv#)))) (def-aset - ^{:doc "Sets the value at the index/indices. Works on arrays of int. Returns val."} + ^{:doc "Sets the value at the index/indices. Works on arrays of int. Returns val." + :added "1.0"} aset-int setInt int) (def-aset - ^{:doc "Sets the value at the index/indices. Works on arrays of long. Returns val."} + ^{:doc "Sets the value at the index/indices. Works on arrays of long. Returns val." + :added "1.0"} aset-long setLong long) (def-aset - ^{:doc "Sets the value at the index/indices. Works on arrays of boolean. Returns val."} + ^{:doc "Sets the value at the index/indices. Works on arrays of boolean. Returns val." + :added "1.0"} aset-boolean setBoolean boolean) (def-aset - ^{:doc "Sets the value at the index/indices. Works on arrays of float. Returns val."} + ^{:doc "Sets the value at the index/indices. Works on arrays of float. Returns val." + :added "1.0"} aset-float setFloat float) (def-aset - ^{:doc "Sets the value at the index/indices. Works on arrays of double. Returns val."} + ^{:doc "Sets the value at the index/indices. Works on arrays of double. Returns val." + :added "1.0"} aset-double setDouble double) (def-aset - ^{:doc "Sets the value at the index/indices. Works on arrays of short. Returns val."} + ^{:doc "Sets the value at the index/indices. Works on arrays of short. Returns val." + :added "1.0"} aset-short setShort short) (def-aset - ^{:doc "Sets the value at the index/indices. Works on arrays of byte. Returns val."} + ^{:doc "Sets the value at the index/indices. Works on arrays of byte. Returns val." + :added "1.0"} aset-byte setByte byte) (def-aset - ^{:doc "Sets the value at the index/indices. Works on arrays of char. Returns val."} + ^{:doc "Sets the value at the index/indices. Works on arrays of char. Returns val." + :added "1.0"} aset-char setChar char) (defn make-array @@ -2708,6 +2961,7 @@ Class objects can be obtained by using their imported or fully-qualified name. Class objects for the primitive types can be obtained using, e.g., Integer/TYPE." + {:added "1.0"} ([^Class type len] (. Array (newInstance type (int len)))) ([^Class type dim & more-dims] @@ -2721,7 +2975,8 @@ "Returns a (potentially-ragged) 2-dimensional array of Objects containing the contents of coll, which can be any Collection of any Collection." - {:tag "[[Ljava.lang.Object;"} + {:tag "[[Ljava.lang.Object;" + :added "1.0"} [^java.util.Collection coll] (let [ret (make-array (. Class (forName "[Ljava.lang.Object;")) (. coll (size)))] (loop [i 0 xs (seq coll)] @@ -2733,6 +2988,7 @@ (defn macroexpand-1 "If form represents a macro form, returns its expansion, else returns form." + {:added "1.0"} [form] (. clojure.lang.Compiler (macroexpand1 form))) @@ -2740,6 +2996,7 @@ "Repeatedly calls macroexpand-1 on form until it no longer represents a macro form, then returns it. Note neither macroexpand-1 nor macroexpand expand macros in subforms." + {:added "1.0"} [form] (let [ex (macroexpand-1 form)] (if (identical? ex form) @@ -2748,11 +3005,13 @@ (defn create-struct "Returns a structure basis object." + {:added "1.0"} [& keys] (. clojure.lang.PersistentStructMap (createSlotMap keys))) (defmacro defstruct "Same as (def name (create-struct keys...))" + {:added "1.0"} [name & keys] `(def ~name (create-struct ~@keys))) @@ -2761,6 +3020,7 @@ structure-basis. keyvals may contain all, some or none of the basis keys - where values are not supplied they will default to nil. keyvals can also contain keys not in the basis." + {:added "1.0"} [s & inits] (. clojure.lang.PersistentStructMap (create s inits))) @@ -2768,6 +3028,7 @@ "Returns a new structmap instance with the keys of the structure-basis. vals must be supplied for basis keys in order - where values are not supplied they will default to nil." + {:added "1.0"} [s & vals] (. clojure.lang.PersistentStructMap (construct s vals))) @@ -2777,17 +3038,20 @@ returned function should be (slightly) more efficient than using get, but such use of accessors should be limited to known performance-critical areas." + {:added "1.0"} [s key] (. clojure.lang.PersistentStructMap (getAccessor s key))) (defn load-reader "Sequentially read and evaluate the set of forms contained in the stream/file" + {:added "1.0"} [rdr] (. clojure.lang.Compiler (load rdr))) (defn load-string "Sequentially read and evaluate the set of forms contained in the string" + {:added "1.0"} [s] (let [rdr (-> (java.io.StringReader. s) (clojure.lang.LineNumberingPushbackReader.))] @@ -2795,6 +3059,7 @@ (defn set "Returns a set of the distinct elements of coll." + {:added "1.0"} [coll] (clojure.lang.PersistentHashSet/create ^clojure.lang.ISeq (seq coll))) (defn ^{:private true} @@ -2808,27 +3073,32 @@ (defn find-ns "Returns the namespace named by the symbol or nil if it doesn't exist." + {:added "1.0"} [sym] (clojure.lang.Namespace/find sym)) (defn create-ns "Create a new namespace named by the symbol if one doesn't already exist, returns it or the already-existing namespace of the same name." + {:added "1.0"} [sym] (clojure.lang.Namespace/findOrCreate sym)) (defn remove-ns "Removes the namespace named by the symbol. Use with caution. Cannot be used to remove the clojure namespace." + {:added "1.0"} [sym] (clojure.lang.Namespace/remove sym)) (defn all-ns "Returns a sequence of all namespaces." + {:added "1.0"} [] (clojure.lang.Namespace/all)) (defn ^clojure.lang.Namespace the-ns "If passed a namespace, returns it. Else, when passed a symbol, returns the namespace named by it, throwing an exception if not found." + {:added "1.0"} [x] (if (instance? clojure.lang.Namespace x) x @@ -2836,16 +3106,19 @@ (defn ns-name "Returns the name of the namespace, a symbol." + {:added "1.0"} [ns] (.getName (the-ns ns))) (defn ns-map "Returns a map of all the mappings for the namespace." + {:added "1.0"} [ns] (.getMappings (the-ns ns))) (defn ns-unmap "Removes the mappings for the symbol from the namespace." + {:added "1.0"} [ns sym] (.unmap (the-ns ns) sym)) @@ -2855,6 +3128,7 @@ (defn ns-publics "Returns a map of the public intern mappings for the namespace." + {:added "1.0"} [ns] (let [ns (the-ns ns)] (filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v) @@ -2864,6 +3138,7 @@ (defn ns-imports "Returns a map of the import mappings for the namespace." + {:added "1.0"} [ns] (filter-key val (partial instance? Class) (ns-map ns))) @@ -2882,6 +3157,7 @@ select a subset, via inclusion or exclusion, or to provide a mapping to a symbol different from the var's name, in order to prevent 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) @@ -2898,6 +3174,7 @@ (defn ns-refers "Returns a map of the refer mappings for the namespace." + {:added "1.0"} [ns] (let [ns (the-ns ns)] (filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v) @@ -2906,6 +3183,7 @@ (defn ns-interns "Returns a map of the intern mappings for the namespace." + {:added "1.0"} [ns] (let [ns (the-ns ns)] (filter-key val (fn [^clojure.lang.Var v] (and (instance? clojure.lang.Var v) @@ -2917,21 +3195,25 @@ namespace. Arguments are two symbols: the alias to be used, and the symbolic name of the target namespace. Use :as in the ns macro in preference to calling this directly." + {:added "1.0"} [alias namespace-sym] (.addAlias *ns* alias (find-ns namespace-sym))) (defn ns-aliases "Returns a map of the aliases for the namespace." + {:added "1.0"} [ns] (.getAliases (the-ns ns))) (defn ns-unalias "Removes the alias for the symbol from the namespace." + {:added "1.0"} [ns sym] (.removeAlias (the-ns ns) sym)) (defn take-nth "Returns a lazy seq of every nth item in coll." + {:added "1.0"} [n coll] (lazy-seq (when-let [s (seq coll)] @@ -2939,6 +3221,7 @@ (defn interleave "Returns a lazy seq of the first item in each coll, then the second etc." + {:added "1.0"} ([c1 c2] (lazy-seq (let [s1 (seq c1) s2 (seq c2)] @@ -2953,11 +3236,13 @@ (defn var-get "Gets the value in the var object" + {:added "1.0"} [^clojure.lang.Var x] (. x (get))) (defn var-set "Sets the value in the var object to val. The var must be thread-locally bound." + {:added "1.0"} [^clojure.lang.Var x val] (. x (set val))) (defmacro with-local-vars @@ -2967,6 +3252,7 @@ vars with per-thread bindings to the init-exprs. The symbols refer to the var objects themselves, and must be accessed with var-get and var-set" + {:added "1.0"} [name-vals-vec & body] (assert-args with-local-vars (vector? name-vals-vec) "a vector for its binding" @@ -2983,20 +3269,24 @@ namespace, else nil. Note that if the symbol is fully qualified, the var/Class to which it resolves need not be present in the namespace." + {:added "1.0"} [ns sym] (clojure.lang.Compiler/maybeResolveIn (the-ns ns) sym)) (defn resolve "same as (ns-resolve *ns* symbol)" + {:added "1.0"} [sym] (ns-resolve *ns* sym)) (defn array-map "Constructs an array-map." + {:added "1.0"} ([] (. clojure.lang.PersistentArrayMap EMPTY)) ([& keyvals] (clojure.lang.PersistentArrayMap/createWithCheck (to-array keyvals)))) (defn nthnext "Returns the nth next of coll, (seq coll) when n is 0." + {:added "1.0"} [coll n] (loop [n n xs (seq coll)] (if (and xs (pos? n)) @@ -3066,6 +3356,7 @@ "Evaluates the exprs in a lexical context in which the symbols in the binding-forms are bound to their respective init-exprs or parts therein." + {:added "1.0"} [bindings & body] (assert-args let (vector? bindings) "a vector for its binding" @@ -3101,6 +3392,7 @@ name => symbol Defines a function" + {:added "1.0"} [& sigs] (let [name (if (symbol? (first sigs)) (first sigs) nil) sigs (if name (next sigs) sigs) @@ -3136,6 +3428,7 @@ "Evaluates the exprs in a lexical context in which the symbols in the binding-forms are bound to their respective init-exprs or parts therein. Acts as a recur target." + {:added "1.0"} [bindings & body] (assert-args loop (vector? bindings) "a vector for its binding" @@ -3160,6 +3453,7 @@ "bindings => x xs Same as (when (seq xs) (let [x (first xs)] body))" + {:added "1.0"} [bindings & body] (assert-args when-first (vector? bindings) "a vector for its binding" @@ -3174,7 +3468,8 @@ of the supplied colls. Each coll expr is not evaluated until it is needed. - (lazy-cat xs ys zs) === (concat (lazy-seq xs) (lazy-seq ys) (lazy-seq zs))" + (lazy-cat xs ys zs) === (concat (lazy-seq xs) (lazy-seq ys) (lazy-seq zs))" + {:added "1.0"} [& colls] `(concat ~@(map #(list `lazy-seq %) colls))) @@ -3188,6 +3483,7 @@ :while test, :when test. (take 100 (for [x (range 100000000) y (range 1000000) :while (< y x)] [x y]))" + {:added "1.0"} [seq-exprs body-expr] (assert-args for (vector? seq-exprs) "a vector for its binding" @@ -3266,12 +3562,14 @@ (defmacro comment "Ignores body, yields nil" + {:added "1.0"} [& body]) (defmacro with-out-str "Evaluates exprs in a context in which *out* is bound to a fresh StringWriter. Returns the string created by any nested printing calls." + {:added "1.0"} [& body] `(let [s# (new java.io.StringWriter)] (binding [*out* s#] @@ -3281,6 +3579,7 @@ (defmacro with-in-str "Evaluates body in a context in which *in* is bound to a fresh StringReader initialized with the string s." + {:added "1.0"} [s & body] `(with-open [s# (-> (java.io.StringReader. ~s) clojure.lang.LineNumberingPushbackReader.)] (binding [*in* s#] @@ -3288,28 +3587,32 @@ (defn pr-str "pr to a string, returning it" - {:tag String} + {:tag String + :added "1.0"} [& xs] (with-out-str (apply pr xs))) (defn prn-str "prn to a string, returning it" - {:tag String} + {:tag String + :added "1.0"} [& xs] (with-out-str (apply prn xs))) (defn print-str "print to a string, returning it" - {:tag String} + {:tag String + :added "1.0"} [& xs] (with-out-str (apply print xs))) (defn println-str "println to a string, returning it" - {:tag String} + {:tag String + :added "1.0"} [& xs] (with-out-str (apply println xs))) @@ -3317,6 +3620,7 @@ (defmacro assert "Evaluates expr and throws an exception if it does not evaluate to logical true." + {:added "1.0"} [x] (when *assert* `(when-not ~x @@ -3325,6 +3629,7 @@ (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 @@ -3334,7 +3639,8 @@ (defn re-pattern "Returns an instance of java.util.regex.Pattern, for use, e.g. in re-matcher." - {:tag java.util.regex.Pattern} + {:tag java.util.regex.Pattern + :added "1.0"} [s] (if (instance? java.util.regex.Pattern s) s (. java.util.regex.Pattern (compile s)))) @@ -3342,7 +3648,8 @@ (defn re-matcher "Returns an instance of java.util.regex.Matcher, for use, e.g. in re-find." - {:tag java.util.regex.Matcher} + {:tag java.util.regex.Matcher + :added "1.0"} [^java.util.regex.Pattern re s] (. re (matcher s))) @@ -3351,6 +3658,7 @@ nested groups, returns a string of the entire match. If there are nested groups, returns a vector of the groups, the first element being the entire match." + {:added "1.0"} [^java.util.regex.Matcher m] (let [gc (. m (groupCount))] (if (zero? gc) @@ -3364,6 +3672,7 @@ "Returns a lazy sequence of successive matches of pattern in string, using java.util.regex.Matcher.find(), each such match processed with re-groups." + {:added "1.0"} [^java.util.regex.Pattern re s] (let [m (re-matcher re s)] ((fn step [] @@ -3374,6 +3683,7 @@ "Returns the match, if any, of string to pattern, using java.util.regex.Matcher.matches(). Uses re-groups to return the groups." + {:added "1.0"} [^java.util.regex.Pattern re s] (let [m (re-matcher re s)] (when (. m (matches)) @@ -3384,6 +3694,7 @@ "Returns the next regex match, if any, of string to pattern, using java.util.regex.Matcher.find(). Uses re-groups to return the groups." + {:added "1.0"} ([^java.util.regex.Matcher m] (when (. m (find)) (re-groups m))) @@ -3394,15 +3705,18 @@ (defn rand "Returns a random floating point number between 0 (inclusive) and n (default 1) (exclusive)." + {:added "1.0"} ([] (. Math (random))) ([n] (* n (rand)))) (defn rand-int "Returns a random integer between 0 (inclusive) and n (exclusive)." + {:added "1.0"} [n] (int (rand n))) (defmacro defn- "same as defn, yielding non-public def" + {:added "1.0"} [name & decls] (list* `defn (with-meta name (assoc (meta name) :private true)) decls)) @@ -3417,6 +3731,7 @@ (defn find-doc "Prints documentation for any var whose documentation or name contains a match for re-string-or-pattern" + {:added "1.0"} [re-string-or-pattern] (let [re (re-pattern re-string-or-pattern)] (doseq [ns (all-ns) @@ -3429,6 +3744,7 @@ (defn special-form-anchor "Returns the anchor tag on http://clojure.org/special_forms for the special form x, or nil" + {:added "1.0"} [x] (#{'. 'def 'do 'fn 'if 'let 'loop 'monitor-enter 'monitor-exit 'new 'quote 'recur 'set! 'throw 'try 'var} x)) @@ -3436,6 +3752,7 @@ (defn syntax-symbol-anchor "Returns the anchor tag on http://clojure.org/special_forms for the special form that uses syntax symbol x, or nil" + {:added "1.0"} [x] ({'& 'fn 'catch 'try 'finally 'try} x)) @@ -3448,6 +3765,7 @@ (defn print-namespace-doc "Print the documentation string of a Namespace." + {:added "1.0"} [nspace] (println "-------------------------") (println (str (ns-name nspace))) @@ -3455,6 +3773,7 @@ (defmacro doc "Prints documentation for a var or special form given its name" + {:added "1.0"} [name] (cond (special-form-anchor `~name) @@ -3473,7 +3792,8 @@ that can have children (but may not). children must be a fn of one arg that returns a sequence of the children. Will only be called on nodes for which branch? returns true. Root is the root node of the - tree." + tree." + {:added "1.0"} [branch? children root] (let [walk (fn walk [node] (lazy-seq @@ -3484,6 +3804,7 @@ (defn file-seq "A tree seq on java.io.Files" + {:added "1.0"} [dir] (tree-seq (fn [^java.io.File f] (. f (isDirectory))) @@ -3492,6 +3813,7 @@ (defn xml-seq "A tree seq on the xml elements as per xml/parse" + {:added "1.0"} [root] (tree-seq (complement string?) @@ -3500,16 +3822,19 @@ (defn special-symbol? "Returns true if s names a special form" + {:added "1.0"} [s] (contains? (. clojure.lang.Compiler specials) s)) (defn var? "Returns true if v is of type clojure.lang.Var" + {:added "1.0"} [v] (instance? clojure.lang.Var v)) (defn slurp "Reads the file named by f using the encoding enc into a string and returns it." + {:added "1.0"} ([f] (slurp f (.name (java.nio.charset.Charset/defaultCharset)))) ([^String f ^String enc] (with-open [r (new java.io.BufferedReader @@ -3526,11 +3851,13 @@ (defn subs "Returns the substring of s beginning at start inclusive, and ending at end (defaults to length of string), exclusive." + {:added "1.0"} ([^String s start] (. s (substring start))) ([^String s start end] (. s (substring start end)))) (defn max-key "Returns the x for which (k x), a number, is greatest." + {:added "1.0"} ([k x] x) ([k x y] (if (> (k x) (k y)) x y)) ([k x y & more] @@ -3538,6 +3865,7 @@ (defn min-key "Returns the x for which (k x), a number, is least." + {:added "1.0"} ([k x] x) ([k x y] (if (< (k x) (k y)) x y)) ([k x y & more] @@ -3545,6 +3873,7 @@ (defn distinct "Returns a lazy sequence of the elements of coll with duplicates removed" + {:added "1.0"} [coll] (let [step (fn step [xs seen] (lazy-seq @@ -3562,6 +3891,7 @@ "Given a map of replacement pairs and a vector/collection, returns a vector/seq with any elements = a key in smap replaced with the corresponding val in smap" + {:added "1.0"} [smap coll] (if (vector? coll) (reduce (fn [v i] @@ -3577,6 +3907,7 @@ running on this thread. Any uncaught exception will abort the transaction and flow out of dosync. The exprs may be run more than once, but any effects on Refs will be atomic." + {:added "1.0"} [& exprs] `(sync nil ~@exprs)) @@ -3588,6 +3919,7 @@ The rounding mode is one of CEILING, FLOOR, HALF_UP, HALF_DOWN, 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)) @@ -3606,6 +3938,7 @@ "sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true" + {:added "1.0"} ([^clojure.lang.Sorted sc test key] (let [include (mk-bound-fn sc test key)] (if (#{> >=} test) @@ -3621,6 +3954,7 @@ "sc must be a sorted collection, test(s) one of <, <=, > or >=. Returns a reverse seq of those entries with keys ek for which (test (.. sc comparator (compare ek key)) 0) is true" + {:added "1.0"} ([^clojure.lang.Sorted sc test key] (let [include (mk-bound-fn sc test key)] (if (#{< <=} test) @@ -3635,7 +3969,8 @@ (defn repeatedly "Takes a function of no args, presumably with side effects, and returns an infinite (or length n if supplied) lazy sequence of calls - to it" + to it" + {:added "1.0"} ([f] (lazy-seq (cons (f) (repeatedly f)))) ([n f] (take n (repeatedly f)))) @@ -3644,6 +3979,7 @@ Adds the url (String or URL object) to the classpath per URLClassLoader.addURL" + {:added "1.0"} [url] (println "WARNING: add-classpath is deprecated") (clojure.lang.RT/addURL url)) @@ -3652,16 +3988,19 @@ (defn hash "Returns the hash code of its argument" + {:added "1.0"} [x] (. clojure.lang.Util (hash x))) (defn interpose "Returns a lazy seq of the elements of coll separated by sep" + {:added "1.0"} [sep coll] (drop 1 (interleave (repeat sep) coll))) (defmacro definline "Experimental - like defmacro, except defines a named function whose body is the expansion, calls to which may be expanded inline as if - it were a macro. Cannot be used with variadic (&) args." + it were a macro. Cannot be used with variadic (&) args." + {:added "1.0"} [name & decl] (let [[pre-args [args expr]] (split-with (comp not vector?) decl)] `(do @@ -3671,6 +4010,7 @@ (defn empty "Returns an empty collection of the same category as coll, or nil" + {:added "1.0"} [coll] (when (instance? clojure.lang.IPersistentCollection coll) (.empty ^clojure.lang.IPersistentCollection coll))) @@ -3680,6 +4020,7 @@ return value named ret, initialized to a clone of a, then setting each element of ret to the evaluation of expr, returning the new array ret." + {:added "1.0"} [a idx ret expr] `(let [a# ~a ~ret (aclone a#)] @@ -3694,6 +4035,7 @@ "Reduces an expression across an array a, using an index named idx, and return value named ret, initialized to init, setting ret to the evaluation of expr at each step, returning ret." + {:added "1.0"} [a idx ret init expr] `(let [a# ~a] (loop [~idx (int 0) ~ret ~init] @@ -3704,7 +4046,8 @@ (defn float-array "Creates an array of floats" {:inline (fn [& args] `(. clojure.lang.Numbers float_array ~@args)) - :inline-arities #{1 2}} + :inline-arities #{1 2} + :added "1.0"} ([size-or-seq] (. clojure.lang.Numbers float_array size-or-seq)) ([size init-val-or-seq] (. clojure.lang.Numbers float_array size init-val-or-seq))) @@ -3743,7 +4086,8 @@ (defn double-array "Creates an array of doubles" {:inline (fn [& args] `(. clojure.lang.Numbers double_array ~@args)) - :inline-arities #{1 2}} + :inline-arities #{1 2} + :added "1.0"} ([size-or-seq] (. clojure.lang.Numbers double_array size-or-seq)) ([size init-val-or-seq] (. clojure.lang.Numbers double_array size init-val-or-seq))) @@ -3757,14 +4101,16 @@ (defn int-array "Creates an array of ints" {:inline (fn [& args] `(. clojure.lang.Numbers int_array ~@args)) - :inline-arities #{1 2}} + :inline-arities #{1 2} + :added "1.0"} ([size-or-seq] (. clojure.lang.Numbers int_array size-or-seq)) ([size init-val-or-seq] (. clojure.lang.Numbers int_array size init-val-or-seq))) (defn long-array "Creates an array of longs" {:inline (fn [& args] `(. clojure.lang.Numbers long_array ~@args)) - :inline-arities #{1 2}} + :inline-arities #{1 2} + :added "1.0"} ([size-or-seq] (. clojure.lang.Numbers long_array size-or-seq)) ([size init-val-or-seq] (. clojure.lang.Numbers long_array size init-val-or-seq))) @@ -3790,18 +4136,22 @@ (definline floats "Casts to float[]" + {:added "1.0"} [xs] `(. clojure.lang.Numbers floats ~xs)) (definline ints "Casts to int[]" + {:added "1.0"} [xs] `(. clojure.lang.Numbers ints ~xs)) (definline doubles "Casts to double[]" + {:added "1.0"} [xs] `(. clojure.lang.Numbers doubles ~xs)) (definline longs "Casts to long[]" + {:added "1.0"} [xs] `(. clojure.lang.Numbers longs ~xs)) (import '(java.util.concurrent BlockingQueue LinkedBlockingQueue)) @@ -3813,6 +4163,7 @@ size, or an instance of java.util.concurrent BlockingQueue. Note that reading from a seque can block if the reader gets ahead of the producer." + {:added "1.0"} ([s] (seque 100 s)) ([n-or-q s] (let [^BlockingQueue q (if (instance? BlockingQueue n-or-q) @@ -3844,6 +4195,7 @@ (defn class? "Returns true if x is an instance of Class" + {:added "1.0"} [x] (instance? Class x)) (defn- is-annotation? [c] @@ -3905,6 +4257,7 @@ (defn alter-var-root "Atomically alters the root binding of var v by applying f to its current value plus any args" + {:added "1.0"} [^clojure.lang.Var v f & args] (.alterRoot v f args)) (defn bound? @@ -3923,6 +4276,7 @@ (defn make-hierarchy "Creates a hierarchy object for use with derive, isa? etc." + {:added "1.0"} [] {:parents {} :descendants {} :ancestors {}}) (def ^{:private true} @@ -3930,10 +4284,12 @@ (defn not-empty "If coll is empty, returns nil, else coll" + {:added "1.0"} [coll] (when (seq coll) coll)) (defn bases "Returns the immediate superclass and direct interfaces of c, if any" + {:added "1.0"} [^Class c] (when c (let [i (.getInterfaces c) @@ -3943,6 +4299,7 @@ (defn supers "Returns the immediate and indirect superclasses and interfaces of c, if any" + {:added "1.0"} [^Class class] (loop [ret (set (bases class)) cs ret] (if (seq cs) @@ -3956,6 +4313,7 @@ relationship established via derive. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to the global hierarchy" + {:added "1.0"} ([child parent] (isa? global-hierarchy child parent)) ([h child parent] (or (= child parent) @@ -3975,6 +4333,7 @@ inheritance relationship or a relationship established via derive. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to the global hierarchy" + {:added "1.0"} ([tag] (parents global-hierarchy tag)) ([h tag] (not-empty (let [tp (get (:parents h) tag)] @@ -3987,6 +4346,7 @@ inheritance relationship or a relationship established via derive. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to the global hierarchy" + {:added "1.0"} ([tag] (ancestors global-hierarchy tag)) ([h tag] (not-empty (let [ta (get (:ancestors h) tag)] @@ -4003,6 +4363,7 @@ from make-hierarchy, if not supplied defaults to the global hierarchy. Note: does not work on Java type inheritance relationships." + {:added "1.0"} ([tag] (descendants global-hierarchy tag)) ([h tag] (if (class? tag) (throw (java.lang.UnsupportedOperationException. "Can't get descendants of classes")) @@ -4014,6 +4375,7 @@ child can be either a namespace-qualified symbol or keyword or a class. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to, and modifies, the global hierarchy." + {:added "1.0"} ([tag parent] (assert (namespace parent)) (assert (or (class? tag) (and (instance? clojure.lang.Named tag) (namespace tag)))) @@ -4047,6 +4409,7 @@ "Removes a parent/child relationship between parent and tag. h must be a hierarchy obtained from make-hierarchy, if not supplied defaults to, and modifies, the global hierarchy." + {:added "1.0"} ([tag parent] (alter-var-root #'global-hierarchy underive tag parent) nil) ([h tag parent] (let [tp (:parents h) @@ -4067,7 +4430,8 @@ (defn distinct? "Returns true if no two of the arguments are =" - {:tag Boolean} + {:tag Boolean + :added "1.0"} ([x] true) ([x y] (not (= x y))) ([x y & more] @@ -4083,6 +4447,7 @@ (defn resultset-seq "Creates and returns a lazy sequence of structmaps corresponding to 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)))) @@ -4101,23 +4466,27 @@ (defn iterator-seq "Returns a seq on a java.util.Iterator. Note that most collections providing iterators implement Iterable and thus support seq directly." + {:added "1.0"} [iter] (clojure.lang.IteratorSeq/create iter)) (defn enumeration-seq "Returns a seq on a java.util.Enumeration" + {:added "1.0"} [e] (clojure.lang.EnumerationSeq/create e)) (defn format "Formats a string using java.lang.String.format, see java.util.Formatter for format string syntax" - {:tag String} + {:tag String + :added "1.0"} [fmt & args] (String/format fmt (to-array args))) (defn printf "Prints formatted output, as per format" + {:added "1.0"} [fmt & args] (print (apply format fmt args))) @@ -4153,7 +4522,8 @@ (:use (my.lib this that)) (:import (java.util Date Timer Random) (java.sql Connection Statement)))" - {:arglists '([name docstring? attr-map? references*])} + {:arglists '([name docstring? attr-map? references*]) + :added "1.0"} [name & references] (let [process-reference (fn [[kname & args]] @@ -4186,12 +4556,14 @@ (defmacro refer-clojure "Same as (refer 'clojure.core <filters>)" + {:added "1.0"} [& filters] `(clojure.core/refer '~'clojure.core ~@filters)) (defmacro defonce "defs name to have the root value of the expr iff the named var has no root value, else expr is unevaluated" + {:added "1.0"} [name expr] `(let [v# (def ~name)] (when-not (.hasRoot v#) @@ -4401,6 +4773,7 @@ abbreviated as 's'. (require '(clojure zip [set :as s]))" + {:added "1.0"} [& args] (apply load-libs :require args)) @@ -4413,16 +4786,19 @@ 'use accepts additional options in libspecs: :exclude, :only, :rename. The arguments and semantics for :exclude, :only, and :rename are the same as those documented for clojure.core/refer." + {:added "1.0"} [& args] (apply load-libs :require :use args)) (defn loaded-libs "Returns a sorted set of symbols naming the currently loaded libs" + {:added "1.0"} [] @*loaded-libs*) (defn load "Loads Clojure code from resources in classpath. A path is interpreted as classpath-relative if it begins with a slash or relative to the root directory for the current namespace otherwise." + {:added "1.0"} [& paths] (doseq [^String path paths] (let [^String path (if (.startsWith path "/") @@ -4444,6 +4820,7 @@ classpath-relative directory. The output files will go into the directory specified by *compile-path*, and that directory too must be in the classpath." + {:added "1.0"} [lib] (binding [*compile-files* true] (load-one lib true true)) @@ -4453,6 +4830,7 @@ (defn get-in "returns the value in a nested associative structure, where ks is a sequence of keys" + {:added "1.0"} [m ks] (reduce get m ks)) @@ -4460,6 +4838,7 @@ "Associates a value in a nested associative structure, where ks is a sequence of keys and v is the new value and returns a new nested structure. If any levels do not exist, hash-maps will be created." + {:added "1.0"} [m [k & ks] v] (if ks (assoc m k (assoc-in (get m k) ks v)) @@ -4471,6 +4850,7 @@ and any supplied args and return the new value, and returns a new nested structure. If any levels do not exist, hash-maps will be created." + {:added "1.0"} ([m [k & ks] f & args] (if ks (assoc m k (apply update-in (get m k) ks f args)) @@ -4480,64 +4860,79 @@ (defn empty? "Returns true if coll has no items - same as (not (seq coll)). Please use the idiom (seq x) rather than (not (empty? x))" + {:added "1.0"} [coll] (not (seq coll))) (defn coll? "Returns true if x implements IPersistentCollection" + {:added "1.0"} [x] (instance? clojure.lang.IPersistentCollection x)) (defn list? "Returns true if x implements IPersistentList" + {:added "1.0"} [x] (instance? clojure.lang.IPersistentList x)) (defn set? "Returns true if x implements IPersistentSet" + {:added "1.0"} [x] (instance? clojure.lang.IPersistentSet x)) (defn ifn? "Returns true if x implements IFn. Note that many data structures (e.g. sets and maps) implement IFn" + {:added "1.0"} [x] (instance? clojure.lang.IFn x)) (defn fn? "Returns true if x implements Fn, i.e. is an object created via fn." + {:added "1.0"} [x] (instance? clojure.lang.Fn x)) (defn associative? "Returns true if coll implements Associative" + {:added "1.0"} [coll] (instance? clojure.lang.Associative coll)) (defn sequential? "Returns true if coll implements Sequential" + {:added "1.0"} [coll] (instance? clojure.lang.Sequential coll)) (defn sorted? "Returns true if coll implements Sorted" + {:added "1.0"} [coll] (instance? clojure.lang.Sorted coll)) (defn counted? "Returns true if coll implements count in constant time" + {:added "1.0"} [coll] (instance? clojure.lang.Counted coll)) (defn reversible? "Returns true if coll implements Reversible" + {:added "1.0"} [coll] (instance? clojure.lang.Reversible coll)) (def - ^{:doc "bound in a repl thread to the most recent value printed"} + ^{:doc "bound in a repl thread to the most recent value printed" + :added "1.0"} *1) (def - ^{:doc "bound in a repl thread to the second most recent value printed"} + ^{:doc "bound in a repl thread to the second most recent value printed" + :added "1.0"} *2) (def - ^{:doc "bound in a repl thread to the third most recent value printed"} + ^{:doc "bound in a repl thread to the third most recent value printed" + :added "1.0"} *3) (def - ^{:doc "bound in a repl thread to the most recent exception caught by the repl"} + ^{:doc "bound in a repl thread to the most recent exception caught by the repl" + :added "1.0"} *e) (defn trampoline @@ -4548,6 +4943,7 @@ returns that non-fn value. Note that if you want to return a fn as a final value, you must wrap it in some data structure and unpack it after trampoline returns." + {:added "1.0"} ([f] (let [ret (f)] (if (fn? ret) @@ -4561,6 +4957,7 @@ ns (which can be a symbol or a namespace), setting its root binding to val if supplied. The namespace must exist. The var will adopt any metadata from the name symbol. Returns the var." + {:added "1.0"} ([ns ^clojure.lang.Symbol name] (let [v (clojure.lang.Var/intern (the-ns ns) name)] (when (meta name) (.setMeta v (meta name))) @@ -4573,6 +4970,7 @@ (defmacro while "Repeatedly executes body while test expression is true. Presumes some side-effect will cause test to become false/nil. Returns nil" + {:added "1.0"} [test & body] `(loop [] (when ~test @@ -4584,6 +4982,7 @@ memoized version of the function keeps a cache of the mapping from arguments to results and, when calls with the same arguments are repeated often, has higher performance at the expense of higher memory use." + {:added "1.0"} [f] (let [mem (atom {})] (fn [& args] @@ -4612,6 +5011,7 @@ and its value will be returned if no clause matches. If no default expression is provided and no clause matches, an IllegalArgumentException is thrown." + {:added "1.0"} [pred expr & clauses] (let [gpred (gensym "pred__") @@ -4636,81 +5036,99 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; var documentation ;;;;;;;;;;;;;;;;;;;;;;;;;; -(defmacro add-doc {:private true} [name docstring] - `(alter-meta! (var ~name) assoc :doc ~docstring)) +(alter-meta! #'*agent* assoc :added "1.0") +(alter-meta! #'in-ns assoc :added "1.0") +(alter-meta! #'load-file assoc :added "1.0") + +(defmacro add-doc-and-meta {:private true} [name docstring meta] + `(alter-meta! (var ~name) merge (assoc ~meta :doc ~docstring))) -(add-doc *file* +(add-doc-and-meta *file* "The path of the file being evaluated, as a String. - Evaluates to nil when there is no file, eg. in the REPL.") + Evaluates to nil when there is no file, eg. in the REPL." + {:added "1.0"}) -(add-doc *command-line-args* +(add-doc-and-meta *command-line-args* "A sequence of the supplied command line arguments, or nil if - none were supplied") + none were supplied" + {:added "1.0"}) -(add-doc *warn-on-reflection* +(add-doc-and-meta *warn-on-reflection* "When set to true, the compiler will emit warnings when reflection is needed to resolve Java method calls or field accesses. - Defaults to false.") + Defaults to false." + {:added "1.0"}) -(add-doc *compile-path* +(add-doc-and-meta *compile-path* "Specifies the directory where 'compile' will write out .class files. This directory must be in the classpath for 'compile' to work. - Defaults to \"classes\"") + Defaults to \"classes\"" + {:added "1.0"}) -(add-doc *compile-files* - "Set to true when compiling files, false otherwise.") +(add-doc-and-meta *compile-files* + "Set to true when compiling files, false otherwise." + {:added "1.0"}) -(add-doc *ns* - "A clojure.lang.Namespace object representing the current namespace.") +(add-doc-and-meta *ns* + "A clojure.lang.Namespace object representing the current namespace." + {:added "1.0"}) -(add-doc *in* +(add-doc-and-meta *in* "A java.io.Reader object representing standard input for read operations. - Defaults to System/in, wrapped in a LineNumberingPushbackReader") + Defaults to System/in, wrapped in a LineNumberingPushbackReader" + {:added "1.0"}) -(add-doc *out* +(add-doc-and-meta *out* "A java.io.Writer object representing standard output for print operations. - Defaults to System/out") + Defaults to System/out" + {:added "1.0"}) -(add-doc *err* +(add-doc-and-meta *err* "A java.io.Writer object representing standard error for print operations. - Defaults to System/err, wrapped in a PrintWriter") + Defaults to System/err, wrapped in a PrintWriter" + {:added "1.0"}) -(add-doc *flush-on-newline* +(add-doc-and-meta *flush-on-newline* "When set to true, output will be flushed whenever a newline is printed. - Defaults to true.") + Defaults to true." + {:added "1.0"}) -(add-doc *print-meta* +(add-doc-and-meta *print-meta* "If set to logical true, when printing an object, its metadata will also be printed in a form that can be read back by the reader. - Defaults to false.") + Defaults to false." + {:added "1.0"}) -(add-doc *print-dup* +(add-doc-and-meta *print-dup* "When set to logical true, objects will be printed in a way that preserves their type when read in later. - Defaults to false.") + Defaults to false." + {:added "1.0"}) -(add-doc *print-readably* +(add-doc-and-meta *print-readably* "When set to logical false, strings and characters will be printed with non-alphanumeric characters converted to the appropriate escape sequences. - Defaults to true") + Defaults to true" + {:added "1.0"}) -(add-doc *read-eval* +(add-doc-and-meta *read-eval* "When set to logical false, the EvalReader (#=(...)) is disabled in the read/load in the thread-local binding. Example: (binding [*read-eval* false] (read-string \"#=(eval (def x 3))\")) - Defaults to true") + Defaults to true" + {:added "1.0"}) (defn future? "Returns true if x is a future" @@ -4728,7 +5146,8 @@ bindings of functions to their names. All of the names are available in all of the definitions of the functions, as well as the body. - fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)" + fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)" + {:added "1.0"} [fnspecs & body] `(letfn* ~(vec (interleave (map first fnspecs) (map #(cons `fn %) fnspecs))) @@ -4822,6 +5241,7 @@ result of applying f to val and the first item in coll, then applying f to that result and the 2nd item, etc. If coll contains no items, returns val and f is not called." + {:added "1.0"} ([f coll] (if-let [s (seq coll)] (reduce f (first s) (next s)) @@ -4874,6 +5294,7 @@ realize the entire result unless required. Only useful for computationally intensive functions where the time of f dominates the coordination overhead." + {:added "1.0"} ([f coll] (let [n (+ 2 (.. Runtime getRuntime availableProcessors)) rets (map #(future (f %)) coll) @@ -4893,12 +5314,14 @@ (defn pcalls "Executes the no-arg fns in parallel, returning a lazy sequence of - their values" + their values" + {:added "1.0"} [& fns] (pmap #(%) fns)) (defmacro pvalues "Returns a lazy sequence of the values of the exprs, which are - evaluated in parallel" + evaluated in parallel" + {:added "1.0"} [& exprs] `(pcalls ~@(map #(list `fn [] %) exprs))) @@ -4918,15 +5341,17 @@ (clojure.lang.RT/assoc clojure-version :interim true) clojure-version))) -(add-doc *clojure-version* +(add-doc-and-meta *clojure-version* "The version info for Clojure core, as a map containing :major :minor :incremental and :qualifier keys. Feature releases may increment :minor and/or :major, bugfix releases will increment :incremental. - Possible values of :qualifier include \"GA\", \"SNAPSHOT\", \"RC-x\" \"BETA-x\"") + Possible values of :qualifier include \"GA\", \"SNAPSHOT\", \"RC-x\" \"BETA-x\"" + {:added "1.0"}) (defn clojure-version "Returns clojure version as a printable string." + {:added "1.0"} [] (str (:major *clojure-version*) "." @@ -5042,6 +5467,7 @@ (defn into "Returns a new coll consisting of to-coll with all of the items of from-coll conjoined." + {:added "1.0"} [to from] (if (instance? clojure.lang.IEditableCollection to) (persistent! (reduce conj! (transient to) from)) @@ -5138,6 +5564,7 @@ and the first item of coll, followed by applying f to 1 and the second item in coll, etc, until coll is exhausted. Thus function f should accept 2 arguments, index and item." + {:added "1.2"} [f coll] (letfn [(mapi [idx coll] (lazy-seq @@ -5156,6 +5583,7 @@ "Returns a lazy sequence of the non-nil results of (f item). Note, this means false return values will be included. f must be free of side-effects." + {:added "1.2"} ([f coll] (lazy-seq (when-let [s (seq coll)] @@ -5177,6 +5605,7 @@ "Returns a lazy sequence of the non-nil results of (f index item). Note, this means false return values will be included. f must be free of side-effects." + {:added "1.2"} ([f coll] (letfn [(keepi [idx coll] (lazy-seq diff --git a/src/clj/clojure/core_print.clj b/src/clj/clojure/core_print.clj index 22aa39eb..b10cd14f 100644 --- a/src/clj/clojure/core_print.clj +++ b/src/clj/clojure/core_print.clj @@ -19,7 +19,8 @@ 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."} + indicating no limit." + :added "1.0"} *print-length* nil) (def @@ -30,7 +31,8 @@ collection, its items are at level 1; and so on. If an object is a 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."} + is nil indicating no limit." + :added "1.0"} *print-level* nil) (defn- print-sequential [^String begin, print-one, ^String sep, ^String end, sequence, ^Writer w] @@ -158,7 +160,8 @@ (prefer-method print-dup clojure.lang.IPersistentCollection java.util.Collection) (def ^{:tag String - :doc "Returns escape string for char or nil if none"} + :doc "Returns escape string for char or nil if none" + :added "1.0"} char-escape-string {\newline "\\n" \tab "\\t" @@ -216,7 +219,8 @@ (print-sequential "#{" pr-on " " "}" (seq s) w)) (def ^{:tag String - :doc "Returns name string for char or nil if none"} + :doc "Returns name string for char or nil if none" + :added "1.0"} char-name-string {\newline "newline" \tab "tab" diff --git a/src/clj/clojure/core_proxy.clj b/src/clj/clojure/core_proxy.clj index ae130068..c88b1fe3 100644 --- a/src/clj/clojure/core_proxy.clj +++ b/src/clj/clojure/core_proxy.clj @@ -252,7 +252,8 @@ interfaces. If not supplied class defaults to Object. Creates an returns an instance of a proxy class derived from the supplied classes. The resulting value is cached and used for any subsequent - requests for the same class set. Returns a Class object." + 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)] @@ -262,7 +263,8 @@ (defn construct-proxy "Takes a proxy class and any arguments for its superclass ctor and - creates and returns an instance of the proxy." + creates and returns an instance of the proxy." + {:added "1.0"} [c & ctor-args] (. Reflector (invokeConstructor c (to-array ctor-args)))) @@ -272,6 +274,7 @@ fns (which must take arguments matching the corresponding method, plus an additional (explicit) first arg corresponding to this, and sets the proxy's fn map." + {:added "1.0"} [^IProxy proxy mappings] (. proxy (__initClojureFnMappings mappings))) @@ -284,11 +287,13 @@ a fn, in which case the corresponding method will revert to the default behavior. Note that this function can be used to update the behavior of an existing instance without changing its identity." + {:added "1.0"} [^IProxy proxy mappings] (. proxy (__updateClojureFnMappings mappings))) (defn proxy-mappings "Takes a proxy instance and returns the proxy's fn map." + {:added "1.0"} [^IProxy proxy] (. proxy (__getClojureFnMappings))) @@ -316,6 +321,7 @@ be provided to override protected methods, they have no other access to protected members, nor to super, as these capabilities cannot be proxied." + {:added "1.0"} [class-and-interfaces args & fs] (let [bases (map #(or (resolve %) (throw (Exception. (str "Can't resolve: " %)))) class-and-interfaces) @@ -354,12 +360,14 @@ (defmacro proxy-super "Use to call a superclass method in the body of a proxy method. Note, expansion captures 'this" + {:added "1.0"} [meth & args] `(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 map abstraction based upon its JavaBean properties." + {:added "1.0"} [^Object x] (let [c (. x (getClass)) pmap (reduce (fn [m ^java.beans.PropertyDescriptor pd] diff --git a/src/clj/clojure/genclass.clj b/src/clj/clojure/genclass.clj index a6f14e82..35cbf21d 100644 --- a/src/clj/clojure/genclass.clj +++ b/src/clj/clojure/genclass.clj @@ -586,6 +586,7 @@ to reference the load code for the implementing namespace. Should be true when implementing-ns is the default, false if you intend to load the code via some other method." + {:added "1.0"} [& options] (when *compile-files* @@ -664,6 +665,7 @@ This parameter is used to specify the signatures of the methods of the generated interface. Do not repeat superinterface signatures here." + {:added "1.0"} [& options] (let [options-map (apply hash-map options) @@ -682,6 +684,7 @@ 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"} [& options] (let [options-map (apply hash-map options) diff --git a/src/clj/clojure/gvec.clj b/src/clj/clojure/gvec.clj index c8a70e47..feff544a 100644 --- a/src/clj/clojure/gvec.clj +++ b/src/clj/clojure/gvec.clj @@ -450,7 +450,8 @@ "Creates a new vector of a single primitive type t, where t is one of :int :long :float :double :byte :short :char or :boolean. The resulting vector complies with the interface of vectors in general, - but stores the values unboxed internally." + but stores the values unboxed internally." + {:added "1.2"} [t] (let [am ^clojure.core.ArrayManager (ams t)] (Vec. am 0 5 EMPTY-NODE (.array am 0) nil))) diff --git a/src/clj/clojure/inspector.clj b/src/clj/clojure/inspector.clj index d28d1ea8..aa708b5e 100644 --- a/src/clj/clojure/inspector.clj +++ b/src/clj/clojure/inspector.clj @@ -86,6 +86,7 @@ (defn inspect-tree "creates a graphical (Swing) inspector on the supplied hierarchical data" + {:added "1.0"} [data] (doto (JFrame. "Clojure Inspector") (.add (JScrollPane. (JTree. (tree-model data)))) @@ -96,6 +97,7 @@ "creates a graphical (Swing) inspector on the supplied regular data, which must be a sequential data structure of data structures of equal length" + {:added "1.0"} [data] (doto (JFrame. "Clojure Inspector") (.add (JScrollPane. (JTable. (old-table-model data)))) @@ -147,6 +149,7 @@ (defn inspect "creates a graphical (Swing) inspector on the supplied object" + {:added "1.0"} [x] (doto (JFrame. "Clojure Inspector") (.add diff --git a/src/clj/clojure/set.clj b/src/clj/clojure/set.clj index dbfcd194..2d861511 100644 --- a/src/clj/clojure/set.clj +++ b/src/clj/clojure/set.clj @@ -18,6 +18,7 @@ (defn union "Return a set that is the union of the input sets" + {:added "1.0"} ([] #{}) ([s1] s1) ([s1 s2] @@ -30,6 +31,7 @@ (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)) @@ -45,6 +47,7 @@ (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)) @@ -60,17 +63,20 @@ (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)) (defn project "Returns a rel of the elements of xrel with only the keys in ks" + {:added "1.0"} [xrel ks] (set (map #(select-keys % ks) xrel))) (defn rename-keys "Returns the map with the keys in kmap renamed to the vals in kmap" + {:added "1.0"} [map kmap] (reduce (fn [m [old new]] @@ -82,12 +88,14 @@ (defn rename "Returns a rel of the maps in xrel with the keys in kmap renamed to the vals in kmap" + {:added "1.0"} [xrel kmap] (set (map #(rename-keys % kmap) xrel))) (defn index "Returns a map of the distinct values of ks in the xrel mapped to a set of the maps in xrel with the corresponding values of ks." + {:added "1.0"} [xrel ks] (reduce (fn [m x] @@ -97,12 +105,14 @@ (defn map-invert "Returns the map with the vals mapped to the keys." + {:added "1.0"} [m] (reduce (fn [m [k v]] (assoc m v k)) {} m)) (defn join "When passed 2 rels, returns the rel corresponding to the natural join. When passed an additional keymap, joins on the corresponding keys." + {:added "1.0"} ([xrel yrel] ;natural join (if (and (seq xrel) (seq yrel)) (let [ks (intersection (set (keys (first xrel))) (set (keys (first yrel)))) diff --git a/src/clj/clojure/test.clj b/src/clj/clojure/test.clj index 997b60d5..25d1eb9a 100644 --- a/src/clj/clojure/test.clj +++ b/src/clj/clojure/test.clj @@ -499,6 +499,7 @@ (defmacro try-expr "Used by the 'is' macro to catch unexpected exceptions. You don't call this." + {:added "1.1"} [msg form] `(try ~(assert-expr msg form) (catch Throwable t# diff --git a/src/clj/clojure/xml.clj b/src/clj/clojure/xml.clj index 7df67bfa..78f053fb 100644 --- a/src/clj/clojure/xml.clj +++ b/src/clj/clojure/xml.clj @@ -82,6 +82,7 @@ attrs, and content. Other parsers can be supplied by passing startparse, a fn taking a source and a ContentHandler and returning a parser" + {:added "1.0"} ([s] (parse s startparse-sax)) ([s startparse] (binding [*stack* nil diff --git a/src/clj/clojure/zip.clj b/src/clj/clojure/zip.clj index 74797ad8..7848ab06 100644 --- a/src/clj/clojure/zip.clj +++ b/src/clj/clojure/zip.clj @@ -26,13 +26,15 @@ make-node is a fn that, given an existing node and a seq of children, returns a new branch node with the supplied children. - root is the root node." + 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]) (defn seq-zip "Returns a zipper for nested sequences, given a root sequence" + {:added "1.0"} [root] (zipper seq? identity @@ -41,6 +43,7 @@ (defn vector-zip "Returns a zipper for nested vectors, given a root vector" + {:added "1.0"} [root] (zipper vector? seq @@ -50,6 +53,7 @@ (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) @@ -59,15 +63,18 @@ (defn node "Returns the node at loc" + {:added "1.0"} [loc] (loc 0)) (defn branch? "Returns true if the node at loc is a branch" + {:added "1.0"} [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)) @@ -76,21 +83,25 @@ (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)) (defn path "Returns a seq of nodes leading to this loc" + {:added "1.0"} [loc] (:pnodes (loc 1))) (defn lefts "Returns a seq of the left siblings of this loc" + {:added "1.0"} [loc] (seq (:l (loc 1)))) (defn rights "Returns a seq of the right siblings of this loc" + {:added "1.0"} [loc] (:r (loc 1))) @@ -98,6 +109,7 @@ (defn down "Returns the loc of the leftmost child of the node at this loc, or nil if no children" + {:added "1.0"} [loc] (when (branch? loc) (let [[node path] loc @@ -111,6 +123,7 @@ (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 @@ -124,6 +137,7 @@ (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) @@ -134,6 +148,7 @@ (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) @@ -141,6 +156,7 @@ (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) @@ -149,6 +165,7 @@ (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)) @@ -156,6 +173,7 @@ (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)) @@ -165,6 +183,7 @@ (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) @@ -174,6 +193,7 @@ (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) @@ -182,24 +202,28 @@ (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)))) (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))) (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))))) (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])))) @@ -207,6 +231,7 @@ "Moves to the next loc in the hierarchy, depth-first. When reaching the end, returns a distinguished loc detectable via end?. If already at the end, stays there." + {:added "1.0"} [loc] (if (= :end (loc 1)) loc @@ -221,6 +246,7 @@ (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] @@ -231,12 +257,14 @@ (defn end? "Returns true if loc represents the end of a depth-first walk" + {:added "1.0"} [loc] (= :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) diff --git a/test/clojure/test_clojure/metadata.clj b/test/clojure/test_clojure/metadata.clj index 3130b489..27f13cd0 100644 --- a/test/clojure/test_clojure/metadata.clj +++ b/test/clojure/test_clojure/metadata.clj @@ -6,14 +6,29 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. -; Author: Frantisek Sodomka +; Authors: Stuart Halloway, Frantisek Sodomka (ns clojure.test-clojure.metadata (:use clojure.test)) +(def public-namespaces + '[clojure.core + clojure.inspector + clojure.set + clojure.stacktrace + clojure.test + clojure.walk + clojure.xml + clojure.zip]) -; http://clojure.org/metadata +(doseq [ns public-namespaces] + (require ns)) -; meta -; with-meta +(def public-vars + (mapcat #(vals (ns-publics %)) public-namespaces)) +(def public-vars-with-docstrings + (filter (comp :doc meta) public-vars)) + +(deftest public-vars-with-docstrings-have-added + (is (= [] (remove (comp :added meta) public-vars-with-docstrings)))) |