diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-03-01 21:37:13 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-03-01 21:37:13 +0000 |
commit | 80163d0baf5ad3ce8ab5b52342bab22c869e9d91 (patch) | |
tree | e645dece1e006fc576c9f876c5c4f0393170407d | |
parent | 3afd0faecd03d5a01528a74d3f50c253e4dd5c9d (diff) |
doc reformatting
-rw-r--r-- | src/boot.clj | 764 |
1 files changed, 487 insertions, 277 deletions
diff --git a/src/boot.clj b/src/boot.clj index 1ccd5cdc..582191be 100644 --- a/src/boot.clj +++ b/src/boot.clj @@ -15,7 +15,8 @@ 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."} + :doc "Returns a new seq where x is the first element and + seq is the rest."} cons (fn* [x seq] (. clojure.lang.RT (cons x seq)))) ;during bootstrap we don't have destructuring let or fn, will redefine later @@ -29,19 +30,22 @@ fn (fn* [& decl] (cons 'fn* decl))) (def #^{:arglists '([coll x]) - :doc "conj[oin]. Returns a new collection with the item 'added'. (conj nil item) returns (item). - The 'addition' may happen at different 'places' depending on the concrete type."} + :doc "conj[oin]. Returns a new collection with the item + 'added'. (conj nil item) returns (item). The 'addition' + may happen at different 'places' depending on the concrete + type."} conj (fn [coll x] (. clojure.lang.RT (conj coll x)))) (def #^{:arglists '([x]) - :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."} first (fn [coll] (. clojure.lang.RT (first coll)))) (def #^{:arglists '([x]) - :doc "Returns a seq of the items after the first. Calls seq on its argument. - If there are no more items, returns nil."} + :doc "Returns a seq of the items after the first. Calls seq on + its argument. If there are no more items, returns nil."} rest (fn [x] (. clojure.lang.RT (rest x)))) (def @@ -66,14 +70,16 @@ rrest (fn [x] (rest (rest x)))) (def #^{:arglists '([coll]) - :doc "Sequence. Returns a new ISeq 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."} + :doc "Sequence. Returns a new ISeq 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."} seq (fn [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"} instance? (fn [#^Class c x] (. c (isInstance x)))) (def @@ -94,9 +100,11 @@ sigs (def #^{:arglists '([map key val] [map key val & kvs]) - :doc "assoc[iate]. When applied to a map, returns a new map of the same (hashed/sorted) type, - that contains the mapping of key(s) to val(s). When applied to a vector, returns a new vector that contains val - at index. Note - index must be <= (count vector)."} + :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)."} assoc (fn ([map key val] (. clojure.lang.RT (assoc map key val))) ([map key val & kvs] @@ -108,20 +116,23 @@ assoc (fn ;;;;;;;;;;;;;;;;; metadata ;;;;;;;;;;;;;;;;;;;;;;;;;;; (def #^{:arglists '([x]) - :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."} meta (fn [x] (if (instance? clojure.lang.IObj x) (. #^clojure.lang.IObj x (meta))))) (def #^{:arglists '([#^clojure.lang.IObj x 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."} with-meta (fn [#^clojure.lang.IObj x m] (. x (withMeta m)))) (def - #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def name (fn ([params* ] exprs*)+))"} + #^{:doc "Same as (def name (fn [params* ] exprs*)) or + (def name (fn ([params* ] exprs*)+))"} defn (fn [name & fdecl] (list 'def (with-meta name (assoc (meta name) :arglists (list 'quote (sigs fdecl)))) (cons `fn (cons name fdecl))))) @@ -142,7 +153,7 @@ vector (defn #^{:doc "keyval => key val - Returns a new hash map with supplied mappings."} + Returns a new hash map with supplied mappings."} hash-map ([] {}) ([& keyvals] @@ -150,14 +161,15 @@ hash-map (defn #^{:doc "keyval => key val - Returns a new sorted map with supplied mappings."} + Returns a new sorted map with supplied mappings."} sorted-map ([& keyvals] (. clojure.lang.PersistentTreeMap (create keyvals)))) (defn #^{:doc "keyval => key val - Returns a new sorted map with supplied mappings, using the supplied comparator."} + Returns a new sorted map with supplied mappings, using the + supplied comparator."} sorted-map-by ([comparator & keyvals] (. clojure.lang.PersistentTreeMap (create comparator keyvals)))) @@ -166,8 +178,9 @@ sorted-map-by ;;;;;;;;;;;;;;;;;;;; (def - #^{: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."} + #^{: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."} defmacro (fn [name & args] (list 'do (cons `defn (cons name args)) @@ -176,12 +189,14 @@ defmacro (fn [name & args] (. (var defmacro) (setMacro)) (defmacro - #^{:doc "Evaluates test. If logical true, evaluates body in an implicit do."} + #^{:doc "Evaluates test. If logical true, evaluates body + in an implicit do."} when [test & body] (list 'if test (cons 'do body))) (defmacro - #^{:doc "Evaluates test. If logical false, evaluates body in an implicit do."} + #^{:doc "Evaluates test. If logical false, evaluates body + in an implicit do."} when-not [test & body] (list 'if test nil (cons 'do body))) @@ -208,9 +223,12 @@ not [x] (if x false true)) (defn #^{:tag Boolean - :doc "Equality. Returns true if obj1 equals obj2, false if not. Same as Java obj1.equals(obj2) - except it also works for nil, and compares numbers in a type-independent manner. - Clojure's immutable data structures define equals() (and thus =) as a value, not an identity, comparison."} + :doc "Equality. Returns true if obj1 equals obj2, false if + not. Same as Java obj1.equals(obj2) except it also works + for nil, and compares numbers in a type-independent + manner. Clojure's immutable data structures define + equals() (and thus =) as a value, not an identity, + comparison."} = [x y] (. clojure.lang.RT (equal x y))) (defn @@ -220,9 +238,10 @@ not= [x y] (not (= x y))) (defn #^{:tag String - :doc "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."} + :doc "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."} str ([] "") ([#^Object x] @@ -240,23 +259,28 @@ symbol ([ns name] (. clojure.lang.Symbol (intern ns name)))) (defn - #^{:doc "Returns a Keyword with the given namespace and name. - Do not use : in the keyword strings, it will be added automatically."} + #^{:doc "Returns a Keyword with the given namespace and name. Do + not use : in the keyword strings, it will be added + automatically."} keyword ([name] (. clojure.lang.Keyword (intern nil name))) ([ns name] (. clojure.lang.Keyword (intern ns name)))) (defn - #^{:doc "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'."} + #^{:doc "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'."} gensym ([] (gensym "G__")) ([prefix-string] (. clojure.lang.Symbol (intern (str prefix-string (str (. clojure.lang.RT (nextID)))))))) (defmacro - #^{:doc "Takes a set of test/expr pairs. It evaluates each test one at a 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."} + #^{:doc "Takes a set of test/expr pairs. It evaluates each test + one at a 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."} cond [& clauses] (when clauses (list 'if (first clauses) @@ -272,7 +296,8 @@ spread [arglist] :else (cons (first arglist) (spread (rest arglist))))) (defn - #^{:doc "Applies fn f to the argument list formed by prepending args to argseq."} + #^{:doc "Applies fn f to the argument list formed by prepending + args to argseq."} apply [#^clojure.lang.IFn f & args] (. f (applyTo (spread args)))) @@ -286,23 +311,30 @@ delay [& body] (list 'new 'clojure.lang.Delay (list* `fn [] body))) (defn - #^{:doc "Returns a seq object whose first is first and whose rest is the value produced by calling restfn - with no arguments. restfn will be called at most once per step in the sequence, e.g. calling rest repeatedly - on the head of the seq calls restfn once - the value it yields is cached."} + #^{:doc "Returns a seq object whose first is first and whose rest + is the value produced by calling restfn with no + arguments. restfn will be called at most once per step in + the sequence, e.g. calling rest repeatedly on the head of + the seq calls restfn once - the value it yields is + cached."} fnseq [x restfn] (new clojure.lang.FnSeq x restfn)) (defmacro - #^{:doc "Expands to code which produces a seq object whose first is first-expr (evaluated) and whose rest is body, - which is not evaluated until rest is called. rest-expr will be evaluated at most once per step in the sequence, - e.g. calling rest repeatedly on the head of the seq evaluates rest-expr once - the value it yields is cached."} + #^{:doc "Expands to code which produces a seq object whose first + is first-expr (evaluated) and whose rest is body, which is + not evaluated until rest is called. rest-expr will be + evaluated at most once per step in the sequence, + e.g. calling rest repeatedly on the head of the seq + evaluates rest-expr once - the value it yields is cached."} lazy-cons [x & body] (list 'fnseq x (list* `fn [] body))) (defn - #^{:doc "Returns a lazy seq representing the concatenation of the elements in colls."} + #^{:doc "Returns a lazy seq representing the concatenation of + the elements in colls."} concat ([] nil) ([x & xs] @@ -314,9 +346,11 @@ concat ;;at this point all the support for syntax-quote exists (defmacro - #^{:doc "Evaluates exprs one at a time, from left to right. If a form 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."} + #^{:doc "Evaluates exprs one at a time, from left to right. If a + form 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."} and ([] true) ([x] x) @@ -325,9 +359,11 @@ and (if and# (and ~@rest) and#)))) (defmacro - #^{:doc "Evaluates exprs one at a time, from left to right. If a form 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."} + #^{:doc "Evaluates exprs one at a time, from left to right. If a + form 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."} or ([] nil) ([x] x) @@ -338,12 +374,17 @@ or ;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;; (defn - #^{:doc "f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the - first 2 items in coll, then applying f to that result and the 3rd item, etc. If coll contains no items, - f must accept no arguments as well, and reduce returns the result of calling f with no arguments. - If coll has only 1 item, it is returned and f is not called. - If val is supplied, returns the 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."} + #^{:doc "f should be a function of 2 arguments. If val is not + supplied, returns the result of applying f to the first 2 + items in coll, then applying f to that result and the 3rd + item, etc. If coll contains no items, f must accept no + arguments as well, and reduce returns the result of + calling f with no arguments. If coll has only 1 item, it + is returned and f is not called. If val is supplied, + returns the 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."} reduce ([f coll] (if (seq coll) @@ -355,7 +396,8 @@ reduce val))) (defn - #^{:doc "Returns a seq of the items in coll in reverse order. Not lazy."} + #^{:doc "Returns a seq of the items in coll in reverse order. + Not lazy."} reverse [coll] (reduce conj nil coll)) @@ -380,7 +422,8 @@ reverse [coll] (defn #^{:doc "If no denominators are supplied, returns 1/numerator, - else returns numerator divided by all of the denominators."} + else returns numerator divided by all of the + denominators."} / ([x] (/ 1 x)) ([x y] (. clojure.lang.Num (divide x y))) @@ -388,7 +431,8 @@ reverse [coll] (reduce / (/ x y) more))) (defn - #^{:doc "If no ys are supplied, returns the negation of x, else subtracts the ys from x and returns the result."} + #^{:doc "If no ys are supplied, returns the negation of x, else + subtracts the ys from x and returns the result."} - ([x] (. clojure.lang.Num (negate x))) ([x y] (. clojure.lang.Num (subtract x y))) @@ -396,7 +440,8 @@ reverse [coll] (reduce - (- x y) more))) (defn - #^{:doc "Returns non-nil if nums are in monotonically increasing order, otherwise false."} + #^{:doc "Returns non-nil if nums are in monotonically increasing + order, otherwise false."} < ([x] true) ([x y] (. clojure.lang.Num (lt x y))) @@ -408,7 +453,8 @@ reverse [coll] false))) (defn - #^{:doc "Returns non-nil if nums are in monotonically non-decreasing order, otherwise false."} + #^{:doc "Returns non-nil if nums are in monotonically + non-decreasing order, otherwise false."} <= ([x] true) ([x y] (. clojure.lang.Num (lte x y))) @@ -420,7 +466,8 @@ reverse [coll] false))) (defn - #^{:doc "Returns non-nil if nums are in monotonically decreasing order, otherwise false."} + #^{:doc "Returns non-nil if nums are in monotonically decreasing + order, otherwise false."} > ([x] true) ([x y] (. clojure.lang.Num (gt x y))) @@ -432,7 +479,8 @@ reverse [coll] false))) (defn - #^{:doc "Returns non-nil if nums are in monotonically non-increasing order, otherwise false."} + #^{:doc "Returns non-nil if nums are in monotonically + non-increasing order, otherwise false."} >= ([x] true) ([x y] (. clojure.lang.Num (gte x y))) @@ -444,7 +492,8 @@ reverse [coll] false))) (defn - #^{:doc "Returns non-nil if nums all have the same value, otherwise false"} + #^{:doc "Returns non-nil if nums all have the same value, + otherwise false"} == ([x] true) ([x y] (. clojure.lang.Num (equiv x y))) @@ -542,14 +591,16 @@ bit-not [x] (. clojure.lang.IntegerNum (bitNot x))) (defn - #^{:doc "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."} + #^{:doc "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."} complement [f] (fn [& args] (not (apply f args)))) (defn - #^{:doc "Returns a function that takes any number of arguments and returns x."} + #^{:doc "Returns a function that takes any number of arguments and + returns x."} constantly [x] (fn [& args] x)) @@ -562,26 +613,30 @@ identity [x] x) (defn - #^{:doc "Returns the number of items in the collection. (count nil) returns 0. - Also works on strings, arrays, and Java Collections and Maps"} + #^{:doc "Returns the number of items in the collection. (count + nil) returns 0. Also works on strings, arrays, and Java + Collections and Maps"} count [coll] (. clojure.lang.RT (count coll))) ;;list stuff (defn - #^{:doc "Same as first. Returns the first item in the list. If the list is empty, returns nil."} + #^{:doc "Same as first. Returns the first item in the list. If the + list is empty, returns nil."} peek [list] (. clojure.lang.RT (peek list))) (defn - #^{:doc "Returns a new list without the first item. If the list is empty, throws an exception. - Note - not the same as rest."} + #^{:doc "Returns a new list without the first item. If the list is + empty, throws an exception. Note - not the same as rest."} pop [list] (. clojure.lang.RT (pop list))) (defn - #^{:doc "Returns the value at the index. get returns nil if index out of bounds, nth throws an exception. - nth also works for strings, Java arrays and Lists, and, in O(n) time, for sequences."} + #^{:doc "Returns the value at the index. get returns nil if index + out of bounds, nth throws an exception. nth also works + for strings, Java arrays and Lists, and, in O(n) time, + for sequences."} nth [coll index] (. clojure.lang.RT (nth coll index))) @@ -593,7 +648,8 @@ contains? [map key] (. clojure.lang.RT (contains map key))) (defn - #^{:doc "Returns the value mapped to key, not-found or nil if key not present."} + #^{:doc "Returns the value mapped to key, not-found or + nil if key not present."} get ([map key] (. clojure.lang.RT (get map key))) @@ -601,7 +657,9 @@ get (. clojure.lang.RT (get map key not-found)))) (defn - #^{:doc "dissoc[iate]. Returns a new map of the same (hashed/sorted) type, that does not contain a mapping for key(s)."} + #^{:doc "dissoc[iate]. Returns a new map of the same + (hashed/sorted) type, that does not contain a mapping for + key(s)."} dissoc ([map] map) ([map key] @@ -618,7 +676,8 @@ find [map key] (. clojure.lang.RT (find map key))) (defn - #^{:doc "Returns a map containing only those entries in map whose key is in keys"} + #^{:doc "Returns a map containing only those entries in map whose + key is in keys"} select [map keyseq] (loop [ret {} keys (seq keyseq)] (if keys @@ -651,8 +710,8 @@ val [#^java.util.Map$Entry e] (. e (getValue))) (defn - #^{:doc "Returns, in constant time, a sequence of the items in rev (which can be a vector or sorted-map), - in reverse order."} + #^{:doc "Returns, in constant time, a sequence of the items in rev + (which can be a vector or sorted-map), in reverse order."} rseq [#^clojure.lang.Reversible rev] (. rev (rseq))) @@ -662,7 +721,8 @@ name [#^clojure.lang.Named x] (. x (getName))) (defn - #^{:doc "Returns the namespace String of a symbol or keyword, or nil if not present."} + #^{:doc "Returns the namespace String of a symbol or keyword, or + nil if not present."} namespace [#^clojure.lang.Named x] (. x (getNamespace))) @@ -680,8 +740,9 @@ orfn [& args] (defmacro - #^{:doc "Executes exprs in an implicit do, while holding the monitor of x. -Will release the monitor of x in all circumstances."} + #^{:doc "Executes exprs in an implicit do, while holding the + monitor of x. Will release the monitor of x in all + circumstances."} locking [x & body] `(let [lockee# ~x] (try @@ -692,20 +753,28 @@ locking [x & body] (defmacro #^{:doc "form => fieldName-symbol or (instanceMethodName-symbol args*) - Expands into a member access (.) of the first member on the first argument, followed by the next member on the result, - etc. For instance: - (.. System (getProperties) (get \"os.name\")) - expands to: - (. (. System (getProperties)) (get \"os.name\")) - but is easier to write, read, and understand."} + + Expands into a member access (.) of the first member on + the first argument, followed by the next member on the + result, etc. For instance: + + (.. System (getProperties) (get \"os.name\")) + + expands to: + + (. (. System (getProperties)) (get \"os.name\")) + + but is easier to write, read, and understand."} .. ([x form] `(. ~x ~form)) ([x form & more] `(.. (. ~x ~form) ~@more))) (defmacro - #^{:doc "Macro. Threads the expr through the forms. Inserts expr as the 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."} + #^{:doc "Macro. Threads the expr through the forms. Inserts expr + as the 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."} -> ([x form] (if (seq? form) `(~(first form) ~x ~@(rest form)) @@ -714,21 +783,25 @@ locking [x & body] ;;multimethods (defmacro - #^{:doc "Creates a new multimethod with the associated dispatch function. If default-dispatch-val is supplied - it becomes the default dispatch value of the multimethod, otherwise the default dispatch value is :default."} + #^{:doc "Creates a new multimethod with the associated dispatch + function. If default-dispatch-val is supplied it becomes + the default dispatch value of the multimethod, otherwise + the default dispatch value is :default."} defmulti ([name dispatch-fn] `(defmulti ~name ~dispatch-fn :default)) ([name dispatch-fn default-val] `(def ~name (new clojure.lang.MultiFn ~dispatch-fn ~default-val)))) (defmacro - #^{:doc "Creates and installs a new method of multimethod associated with dispatch-value. "} + #^{:doc "Creates and installs a new method of multimethod + associated with dispatch-value. "} defmethod [multifn dispatch-val & fn-tail] `(let [pvar# (var ~multifn)] (. pvar# (commuteRoot (fn [mf#] (. mf# (assoc ~dispatch-val (fn ~@fn-tail)))))))) (defmacro - #^{:doc "Removes the method of multimethod associated with dispatch-value."} + #^{:doc "Removes the method of multimethod associated + with dispatch-value."} remove-method [multifn dispatch-val] `(let [pvar# (var ~multifn)] (. pvar# (commuteRoot (fn [mf#] (. mf# (dissoc ~dispatch-val))))))) @@ -737,8 +810,10 @@ remove-method [multifn dispatch-val] (defmacro #^{:doc "binding => var-symbol init-expr - Creates new bindings for the (already-existing) vars, with the supplied initial values, - executes the exprs in an implicit do, then re-establishes the bindings that existed before."} + Creates new bindings for the (already-existing) vars, with + the supplied initial values, executes the exprs in an + implicit do, then re-establishes the bindings that existed + before."} binding [bindings & body] (let [var-ize (fn [var-vals] (loop [ret [] vvs (seq var-vals)] @@ -753,13 +828,15 @@ binding [bindings & body] (. clojure.lang.Var (popThreadBindings)))))) (defn - #^{:doc "Returns the global var named by the namespace-qualified symbol, or nil if no var with that name."} + #^{:doc "Returns the global var named by the namespace-qualified + symbol, or nil if no var with that name."} find-var [sym] (. clojure.lang.Var (find sym))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Refs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defn - #^{:doc "Creates and returns an agent with an initial value of state."} + #^{:doc "Creates and returns an agent with an initial + value of state."} agent [state] (new clojure.lang.Agent state)) @@ -768,19 +845,23 @@ agent-of [state] (:agent ^state)) (defn - #^{:doc "Dispatch an action to an agent. Returns the agent immediately. Subsequently, in a thread in a thread pool, - the state of the agent will be set to the value of: - (apply action-fn state-of-agent args)"} + #^{:doc "Dispatch an action to an agent. Returns the agent + immediately. Subsequently, in a thread in a thread pool, + the state of the agent will be set to the value of: + + (apply action-fn state-of-agent args)"} ! [#^clojure.lang.Agent a f & args] (. a (dispatch f args))) (defn - #^{:doc "Returns a sequence of the exceptions thrown during asynchronous actions of the agent."} + #^{:doc "Returns a sequence of the exceptions thrown during + asynchronous actions of the agent."} agent-errors [#^clojure.lang.Agent a] (. a (getErrors))) (defn - #^{:doc "Clears any exceptions thrown during asynchronous actions of the agent, allowing subsequent actions to occur."} + #^{:doc "Clears any exceptions thrown during asynchronous actions + of the agent, allowing subsequent actions to occur."} clear-agent-errors [#^clojure.lang.Agent a] (. a (clearErrors))) @@ -791,44 +872,61 @@ ref [x] (defn #^{:doc "Also reader macro: @ref/@agent - Within a transaction, returns the in-transaction-value of ref, else returns the - most-recently-committed value of ref. When applied to an agent, returns its current state."} + Within a transaction, returns the in-transaction-value of + ref, else returns the most-recently-committed value of + ref. When applied to an agent, returns its current state."} deref [#^clojure.lang.IRef ref] (. ref (get))) (defn - #^{:doc "Must be called in a transaction. Sets the in-transaction-value of ref to: - (apply fun in-transaction-value-of-ref args) - At the commit point of the transaction, sets the value of ref to be: - (apply fun most-recently-committed-value-of-ref args) - Thus fun should be commutative, or, failing that, you must accept last-one-in-wins behavior. - commute allows for more concurrency than set."} + #^{:doc "Must be called in a transaction. Sets the + in-transaction-value of ref to: + + (apply fun in-transaction-value-of-ref args) + + At the commit point of the transaction, sets the value of + ref to be: + + (apply fun most-recently-committed-value-of-ref args) + + Thus fun should be commutative, or, failing that, you must + accept last-one-in-wins behavior. commute allows for more + concurrency than set."} commute [#^clojure.lang.Ref ref fun & args] (. ref (commute fun args))) (defn - #^{:doc "Must be called in a transaction. Sets the in-transaction-value of ref to: - (apply fun in-transaction-value-of-ref args)"} + #^{:doc "Must be called in a transaction. Sets the + in-transaction-value of ref to: + + (apply fun in-transaction-value-of-ref args)"} alter [#^clojure.lang.Ref ref fun & args] (. ref (alter fun args))) (defn - #^{:doc "Must be called in a transaction. Sets the value of ref. Returns val."} + #^{:doc "Must be called in a transaction. Sets the value of ref. + Returns val."} set [#^clojure.lang.Ref ref val] (. ref (set val))) (defn - #^{:doc "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 (set ref @ref)"} + #^{:doc "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 (set ref @ref)"} ensure [#^clojure.lang.Ref ref] (. ref (touch)) (. ref (get))) (defmacro #^{:doc "transaction-flags => TBD, pass nil for now - Runs the exprs (in an implicit do) in a transaction that encompasses exprs and any nested calls. - Starts a transaction if none is already 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."} + + Runs the exprs (in an implicit do) in a transaction that + encompasses exprs and any nested calls. Starts a + transaction if none is already 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."} sync [flags-ignored-for-now & body] `(. clojure.lang.LockingTransaction (runInTransaction (fn [] ~@body)))) @@ -839,9 +937,10 @@ sync [flags-ignored-for-now & body] (defn - #^{:doc "Takes a set of functions and returns a fn that is the composition 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."} + #^{:doc "Takes a set of functions and returns a fn that is the + composition 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."} comp [& fs] (let [fs (reverse fs)] (fn [& args] @@ -851,8 +950,10 @@ comp [& fs] ret))))) (defn - #^{:doc "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."} + #^{:doc "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."} partial ([f arg1] (fn [& args] (apply f arg1 args))) @@ -869,7 +970,8 @@ partial (defn #^{:tag Boolean - :doc "Returns true if (pred x) is logical true for every x in coll, else false."} + :doc "Returns true if (pred x) is logical true for + every x in coll, else false."} every? [pred coll] (if (seq coll) (and (pred (first coll)) @@ -878,24 +980,30 @@ every? [pred coll] (def #^{:tag Boolean - :doc "Returns false if (pred x) is logical true for every x in coll, else true."} + :doc "Returns false if (pred x) is logical true for + every x in coll, else true."} not-every? (comp not every?)) (defn - #^{:doc "Returns the first logical true value of (pred x) for any x in coll, else nil."} + #^{:doc "Returns the first logical true value of (pred x) for + any x in coll, else nil."} some [pred coll] (when (seq coll) (or (pred (first coll)) (recur pred (rest coll))))) (def #^{:tag Boolean - :doc "Returns false if (pred x) is logical true for any x in coll, else true."} + :doc "Returns false if (pred x) is logical true for + any x in coll, else true."} not-any? (comp not some)) (defn - #^{:doc "Returns a lazy seq consisting of the result of applying f to the set of first items of each coll, - followed by applying f to the set 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."} + #^{:doc "Returns a lazy seq consisting of the result of applying f + to the set of first items of each coll, followed by + applying f to the set 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."} map ([f coll] (when (seq coll) @@ -906,13 +1014,15 @@ map (apply map f (rest coll) (map rest colls)))))) (defn - #^{:doc "Returns the result of applying concat to the result of applying map to f and colls. - Thus function f should return a collection."} + #^{:doc "Returns the result of applying concat to the result of + applying map to f and colls. Thus function f should + return a collection."} mapcat [f & colls] (apply concat (apply map f colls))) (defn - #^{:doc "Returns a lazy seq of the items in coll for which (pred item) returns true."} + #^{:doc "Returns a lazy seq of the items in coll for which + (pred item) returns true."} filter [pred coll] (when (seq coll) (if (pred (first coll)) @@ -920,13 +1030,15 @@ filter [pred coll] (recur pred (rest coll))))) (defn - #^{:doc "Returns a lazy seq of the first n items in coll, or all items if there are fewer than n."} + #^{:doc "Returns a lazy seq of the first n items in coll, or all + items if there are fewer than n."} take [n coll] (when (and (pos? n) (seq coll)) (lazy-cons (first coll) (take (dec n) (rest coll))))) (defn - #^{:doc "Returns a lazy seq of successive items from coll while (pred item) returns true."} + #^{:doc "Returns a lazy seq of successive items from coll while + (pred item) returns true."} take-while [pred coll] (when (and (seq coll) (pred (first coll))) (lazy-cons (first coll) (take-while pred (rest coll))))) @@ -939,14 +1051,16 @@ drop [n coll] coll)) (defn - #^{:doc "Returns a lazy seq of the items in coll starting from the first item for which (pred item) returns nil."} + #^{:doc "Returns a lazy seq of the items in coll starting from + the first item for which (pred item) returns nil."} drop-while [pred coll] (if (and (seq coll) (pred (first coll))) (recur pred (rest coll)) coll)) (defn - #^{:doc "Returns a lazy (infinite!) seq of repetitions of the items in coll."} + #^{:doc "Returns a lazy (infinite!) seq of repetitions of + the items in coll."} cycle [coll] (when (seq coll) (let [rep (fn thisfn [xs] @@ -981,8 +1095,9 @@ iterate [f x] (lazy-cons x (iterate f (f x)))) (defn - #^{:doc "Returns a lazy seq of nums from start (inclusive) to end (exclusive), by step, - where start defaults to 0 and step to 1."} + #^{:doc "Returns a lazy seq of nums from start (inclusive) to end + (exclusive), by step, where start defaults to 0 and step + to 1."} range ([end] (take end (iterate inc 0))) ([start end] (take (- end start) (iterate inc start))) @@ -990,16 +1105,19 @@ range (take-while (partial (if (pos? step) > <) end) (iterate (partial + step) start)))) (defn - #^{:doc "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."} + #^{:doc "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."} merge [& maps] (reduce conj maps)) (defn - #^{:doc "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(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)."} + #^{:doc "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(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)."} merge-with [f & maps] (let [merge-entry (fn [m e] (let [k (key e) v (val e)] @@ -1025,21 +1143,23 @@ zipmap [keys vals] map))) (defn - #^{:doc "Returns the lines of text from rdr as a lazy sequence of strings. - rdr must implement java.io.BufferedReader."} + #^{:doc "Returns the lines of text from rdr as a lazy sequence of + strings. rdr must implement java.io.BufferedReader."} line-seq [#^java.io.BufferedReader rdr] (let [line (. rdr (readLine))] (when line (lazy-cons line (line-seq rdr))))) (defn - #^{:doc "Returns an implementation of java.util.Comparator based upon pred."} + #^{:doc "Returns an implementation of java.util.Comparator based + upon pred."} comparator [pred] (fn [x y] (cond (pred x y) -1 (pred y x) 1 :else 0))) (defn - #^{:doc "Returns a sorted sequence of the items in coll. If no comparator is supplied, - the items must implement Comparable. comparator must implement java.util.Comparator."} + #^{:doc "Returns a sorted sequence of the items in coll. If no + comparator is supplied, the items must implement + Comparable. comparator must implement java.util.Comparator."} sort ([#^java.util.Collection coll] (when (and coll (not (. coll (isEmpty)))) @@ -1053,8 +1173,10 @@ sort (seq a))))) (defn - #^{:doc "Returns a sorted sequence of the items in coll, where the sort order is determined by comparing (keyfn item). - If no comparator is supplied, the keys must implement Comparable. comparator must implement java.util.Comparator."} + #^{:doc "Returns a sorted sequence of the items in coll, where the + sort order is determined by comparing (keyfn item). If no + comparator is supplied, the keys must implement + Comparable. comparator must implement java.util.Comparator."} sort-by ([keyfn coll] (sort (fn [x y] (. #^Comparable (keyfn x) (compareTo (keyfn y)))) coll)) @@ -1064,7 +1186,8 @@ sort-by ;; evaluation (defn - #^{:doc "Evaluates the form data structure (not text!) and retu |