diff options
author | Rich Hickey <richhickey@gmail.com> | 2009-03-05 16:20:37 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2009-03-05 16:20:37 +0000 |
commit | 703c847b1a470100d2113ae76352647400d32476 (patch) | |
tree | d33945ad9010824f7669e064ab89548cd9a4fa36 | |
parent | 55a78dd56def991beab489b7cfcb2559f61dca44 (diff) |
sped up for, w/fixed formatting
-rw-r--r-- | src/clj/clojure/core.clj | 2338 |
1 files changed, 1169 insertions, 1169 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 8c21f833..bef817c3 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -12,222 +12,222 @@ (def unquote-splicing) (def - #^{:arglists '([& items]) + #^{:arglists '([& items]) :doc "Creates a new list containing the items."} list (. clojure.lang.PersistentList creator)) (def - #^{:arglists '([x seq]) + #^{:arglists '([x seq]) :doc "Returns a new seq where x is the first element and seq is the rest."} - cons (fn* cons [x seq] (. clojure.lang.RT (cons x seq)))) + 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} let (fn* let [& decl] (cons 'let* decl))) (def - #^{:macro true} - loop (fn* loop [& decl] (cons 'loop* decl))) + #^{:macro true} + loop (fn* loop [& decl] (cons 'loop* decl))) (def - #^{:macro true} - fn (fn* fn [& decl] (cons 'fn* decl))) + #^{:macro true} + fn (fn* fn [& decl] (cons 'fn* decl))) (def - #^{:macro true} - if (fn* if [& decl] (cons 'if* decl))) + #^{:macro true} + if (fn* if [& decl] (cons 'if* decl))) (def - #^{:arglists '([coll]) + #^{:arglists '([coll]) :doc "Returns the first item in the collection. Calls seq on its argument. If coll is nil, returns nil."} - first (fn first [coll] (. clojure.lang.RT (first coll)))) + first (fn first [coll] (. clojure.lang.RT (first coll)))) (def - #^{:arglists '([coll]) + #^{: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."} - next (fn next [x] (. clojure.lang.RT (next x)))) + argument. If there are no more items, returns nil."} + next (fn next [x] (. clojure.lang.RT (next x)))) (def - #^{:arglists '([coll]) + #^{:arglists '([coll]) :tag clojure.lang.ISeq :doc "Returns a possibly empty seq of the items after the first. Calls seq on its - argument."} - rest (fn rest [x] (. clojure.lang.RT (more x)))) + argument."} + rest (fn rest [x] (. clojure.lang.RT (more x)))) (def - #^{:arglists '([coll x] [coll x & xs]) + #^{:arglists '([coll x] [coll x & xs]) :doc "conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' may happen at different 'places' depending on the concrete type."} - conj (fn conj - ([coll x] (. clojure.lang.RT (conj coll x))) - ([coll x & xs] - (if xs - (recur (conj coll x) (first xs) (next xs)) - (conj coll x))))) + conj (fn conj + ([coll x] (. clojure.lang.RT (conj coll x))) + ([coll x & xs] + (if xs + (recur (conj coll x) (first xs) (next xs)) + (conj coll x))))) (def - #^{:doc "Same as (first (next x))" + #^{:doc "Same as (first (next x))" :arglists '([x])} - second (fn second [x] (first (next x)))) + second (fn second [x] (first (next x)))) (def - #^{:doc "Same as (first (first x))" + #^{:doc "Same as (first (first x))" :arglists '([x])} - ffirst (fn ffirst [x] (first (first x)))) + ffirst (fn ffirst [x] (first (first x)))) (def - #^{:doc "Same as (next (first x))" + #^{:doc "Same as (next (first x))" :arglists '([x])} - nfirst (fn nfirst [x] (next (first x)))) + nfirst (fn nfirst [x] (next (first x)))) (def - #^{:doc "Same as (first (next x))" + #^{:doc "Same as (first (next x))" :arglists '([x])} - fnext (fn fnext [x] (first (next x)))) + fnext (fn fnext [x] (first (next x)))) (def - #^{:doc "Same as (next (next x))" + #^{:doc "Same as (next (next x))" :arglists '([x])} - nnext (fn nnext [x] (next (next x)))) + nnext (fn nnext [x] (next (next x)))) (def - #^{:arglists '([coll]) + #^{:arglists '([coll]) :doc "Returns a seq on the collection. If the collection is empty, returns nil. (seq nil) returns nil. seq also works on Strings, native Java arrays (of reference types) and any objects that implement Iterable." :tag clojure.lang.ISeq} - seq (fn seq [coll] (. clojure.lang.RT (seq coll)))) + seq (fn seq [coll] (. clojure.lang.RT (seq coll)))) (def - #^{:arglists '([#^Class c x]) + #^{:arglists '([#^Class c x]) :doc "Evaluates x and tests if it is an instance of the class c. Returns true or false"} - instance? (fn instance? [#^Class c x] (. c (isInstance x)))) + instance? (fn instance? [#^Class c x] (. c (isInstance x)))) (def - #^{:arglists '([x]) + #^{:arglists '([x]) :doc "Return true if x implements ISeq"} - seq? (fn seq? [x] (instance? clojure.lang.ISeq x))) + seq? (fn seq? [x] (instance? clojure.lang.ISeq x))) (def - #^{:arglists '([x]) + #^{:arglists '([x]) :doc "Return true if x is a String"} - string? (fn string? [x] (instance? String x))) + string? (fn string? [x] (instance? String x))) (def - #^{:arglists '([x]) + #^{:arglists '([x]) :doc "Return true if x implements IPersistentMap"} - map? (fn map? [x] (instance? clojure.lang.IPersistentMap x))) + map? (fn map? [x] (instance? clojure.lang.IPersistentMap x))) (def - #^{:arglists '([x]) + #^{:arglists '([x]) :doc "Return true if x implements IPersistentVector "} - vector? (fn vector? [x] (instance? clojure.lang.IPersistentVector x))) + vector? (fn vector? [x] (instance? clojure.lang.IPersistentVector x))) (def - #^{:private true} - sigs - (fn [fdecl] - (if (seq? (first fdecl)) - (loop [ret [] fdecl fdecl] - (if fdecl - (recur (conj ret (first (first fdecl))) (next fdecl)) - (seq ret))) - (list (first fdecl))))) + #^{:private true} + sigs + (fn [fdecl] + (if (seq? (first fdecl)) + (loop [ret [] fdecl fdecl] + (if fdecl + (recur (conj ret (first (first fdecl))) (next fdecl)) + (seq ret))) + (list (first fdecl))))) (def - #^{:arglists '([map key val] [map key val & kvs]) + #^{: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)."} - assoc - (fn assoc - ([map key val] (. clojure.lang.RT (assoc map key val))) - ([map key val & kvs] - (let [ret (assoc map key val)] - (if kvs - (recur ret (first kvs) (second kvs) (nnext kvs)) - ret))))) + assoc + (fn assoc + ([map key val] (. clojure.lang.RT (assoc map key val))) + ([map key val & kvs] + (let [ret (assoc map key val)] + (if kvs + (recur ret (first kvs) (second kvs) (nnext kvs)) + ret))))) ;;;;;;;;;;;;;;;;; metadata ;;;;;;;;;;;;;;;;;;;;;;;;;;; (def - #^{:arglists '([obj]) + #^{:arglists '([obj]) :doc "Returns the metadata of obj, returns nil if there is no metadata."} - meta (fn meta [x] - (if (instance? clojure.lang.IMeta x) - (. #^clojure.lang.IMeta x (meta))))) + meta (fn meta [x] + (if (instance? clojure.lang.IMeta x) + (. #^clojure.lang.IMeta x (meta))))) (def - #^{:arglists '([#^clojure.lang.IObj obj m]) + #^{:arglists '([#^clojure.lang.IObj obj m]) :doc "Returns an object of the same type and value as obj, with map m as its metadata."} - with-meta (fn with-meta [#^clojure.lang.IObj x m] - (. x (withMeta m)))) + with-meta (fn with-meta [#^clojure.lang.IObj x m] + (. x (withMeta m)))) -(def - #^{:arglists '([coll]) +(def + #^{:arglists '([coll]) :doc "Return the last item in coll, in linear time"} - last (fn last [s] - (if (next s) - (recur (next s)) - (first s)))) + last (fn last [s] + (if (next s) + (recur (next s)) + (first s)))) -(def - #^{:arglists '([coll]) +(def + #^{:arglists '([coll]) :doc "Return a seq of all but the last item in coll, in linear time"} - butlast (fn butlast [s] - (loop [ret [] s s] - (if (next s) - (recur (conj ret (first s)) (next s)) - (seq ret))))) + butlast (fn butlast [s] + (loop [ret [] s s] + (if (next s) + (recur (conj ret (first s)) (next s)) + (seq ret))))) -(def +(def - #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def + #^{:doc "Same as (def name (fn [params* ] exprs*)) or (def name (fn ([params* ] exprs*)+)) with any doc-string or attrs added to the var metadata" :arglists '([name doc-string? attr-map? [params*] body] - [name doc-string? attr-map? ([params*] body) + attr-map?])} - defn (fn defn [name & fdecl] - (let [m (if (string? (first fdecl)) - {:doc (first fdecl)} - {}) - fdecl (if (string? (first fdecl)) - (next fdecl) - fdecl) - m (if (map? (first fdecl)) - (conj m (first fdecl)) - m) - fdecl (if (map? (first fdecl)) - (next fdecl) - fdecl) - fdecl (if (vector? (first fdecl)) - (list fdecl) - fdecl) - m (if (map? (last fdecl)) - (conj m (last fdecl)) - m) - fdecl (if (map? (last fdecl)) - (butlast fdecl) - fdecl) - m (conj {:arglists (list 'quote (sigs fdecl))} m)] - (list 'def (with-meta name (conj (if (meta name) (meta name) {}) m)) - (cons `fn fdecl))))) + [name doc-string? attr-map? ([params*] body)+ attr-map?])} + defn (fn defn [name & fdecl] + (let [m (if (string? (first fdecl)) + {:doc (first fdecl)} + {}) + fdecl (if (string? (first fdecl)) + (next fdecl) + fdecl) + m (if (map? (first fdecl)) + (conj m (first fdecl)) + m) + fdecl (if (map? (first fdecl)) + (next fdecl) + fdecl) + fdecl (if (vector? (first fdecl)) + (list fdecl) + fdecl) + m (if (map? (last fdecl)) + (conj m (last fdecl)) + m) + fdecl (if (map? (last fdecl)) + (butlast fdecl) + fdecl) + m (conj {:arglists (list 'quote (sigs fdecl))} m)] + (list 'def (with-meta name (conj (if (meta name) (meta name) {}) m)) + (cons `fn fdecl))))) (. (var defn) (setMacro)) (defn cast "Throws a ClassCastException if x is not a c, else returns x." - [#^Class c x] + [#^Class c x] (. c (cast x))) (defn to-array @@ -235,61 +235,61 @@ can be any Collection. Maps to java.util.Collection.toArray()." {:tag "[Ljava.lang.Object;"} [coll] (. clojure.lang.RT (toArray coll))) - + (defn vector "Creates a new vector containing the args." ([] []) ([& args] - (. clojure.lang.LazilyPersistentVector (create args)))) + (. clojure.lang.LazilyPersistentVector (create args)))) (defn vec "Creates a new vector containing the contents of coll." ([coll] - (. clojure.lang.LazilyPersistentVector (createOwning (to-array coll))))) + (. clojure.lang.LazilyPersistentVector (createOwning (to-array coll))))) (defn hash-map "keyval => key val Returns a new hash map with supplied mappings." ([] {}) ([& keyvals] - (. clojure.lang.PersistentHashMap (create keyvals)))) + (. clojure.lang.PersistentHashMap (create keyvals)))) (defn hash-set "Returns a new hash set with supplied keys." ([] #{}) ([& keys] - (. clojure.lang.PersistentHashSet (create keys)))) + (. clojure.lang.PersistentHashSet (create keys)))) (defn sorted-map "keyval => key val Returns a new sorted map with supplied mappings." ([& keyvals] - (. clojure.lang.PersistentTreeMap (create keyvals)))) + (. clojure.lang.PersistentTreeMap (create keyvals)))) (defn sorted-set "Returns a new sorted set with supplied keys." ([& keys] - (. clojure.lang.PersistentTreeSet (create keys)))) + (. clojure.lang.PersistentTreeSet (create keys)))) (defn sorted-map-by "keyval => key val Returns a new sorted map with supplied mappings, using the supplied comparator." ([comparator & keyvals] - (. clojure.lang.PersistentTreeMap (create comparator keyvals)))) - + (. clojure.lang.PersistentTreeMap (create comparator keyvals)))) + ;;;;;;;;;;;;;;;;;;;; (def - #^{:doc "Like defn, but the resulting function name is declared as a + #^{:doc "Like defn, but the resulting function name is declared as a macro and will be used as a macro by the compiler when it is called." :arglists '([name doc-string? attr-map? [params*] body] - [name doc-string? attr-map? ([params*] body) + attr-map?])} - defmacro (fn [name & args] - (list 'do - (cons `defn (cons name args)) - (list '. (list 'var name) '(setMacro)) - (list 'var name)))) + [name doc-string? attr-map? ([params*] body)+ attr-map?])} + defmacro (fn [name & args] + (list 'do + (cons `defn (cons name args)) + (list '. (list 'var name) '(setMacro)) + (list 'var name)))) (. (var defmacro) (setMacro)) @@ -302,9 +302,9 @@ (if* (assert-if-lazy-seq?) (let [tstsym 'G__0_0] (list 'clojure.core/let [tstsym tst] - (list 'if* (list 'clojure.core/instance? clojure.lang.LazySeq tstsym) - (list 'throw (list 'new Exception "LazySeq used in 'if'")) - (cons 'if* (cons tstsym etc))))) + (list 'if* (list 'clojure.core/instance? clojure.lang.LazySeq tstsym) + (list 'throw (list 'new Exception "LazySeq used in 'if'")) + (cons 'if* (cons tstsym etc))))) (cons 'if* (cons tst etc)))) (defmacro when @@ -315,7 +315,7 @@ (defmacro when-not "Evaluates test. If logical false, evaluates body in an implicit do." [test & body] - (list 'if test nil (cons 'do body))) + (list 'if test nil (cons 'do body))) (defn nil? "Returns true if x is nil, false otherwise." @@ -344,12 +344,12 @@ {:tag String} ([] "") ([#^Object x] - (if (nil? x) "" (. x (toString)))) + (if (nil? x) "" (. x (toString)))) ([x & ys] - ((fn [#^StringBuilder sb more] - (if more - (recur (. sb (append (str (first more)))) (next more)) - (str sb))) + ((fn [#^StringBuilder sb more] + (if more + (recur (. sb (append (str (first more)))) (next more)) + (str sb))) (new StringBuilder #^String (str x)) ys))) @@ -385,67 +385,67 @@ the value of the corresponding expr and doesn't evaluate any of the other tests or exprs. (cond) returns nil." [& clauses] - (when clauses - (list 'if (first clauses) - (if (next clauses) - (second clauses) - (throw (IllegalArgumentException. - "cond requires an even number of forms"))) - (cons 'clojure.core/cond (next (next clauses)))))) + (when clauses + (list 'if (first clauses) + (if (next clauses) + (second clauses) + (throw (IllegalArgumentException. + "cond requires an even number of forms"))) + (cons 'clojure.core/cond (next (next clauses)))))) (defn spread {:private true} [arglist] (cond - (nil? arglist) nil - (nil? (next arglist)) (seq (first arglist)) - :else (cons (first arglist) (spread (next arglist))))) + (nil? arglist) nil + (nil? (next arglist)) (seq (first arglist)) + :else (cons (first arglist) (spread (next arglist))))) (defn apply "Applies fn f to the argument list formed by prepending args to argseq." {:arglists '([f args* argseq])} [#^clojure.lang.IFn f & args] - (. f (applyTo (spread args)))) + (. f (applyTo (spread args)))) (defn vary-meta - "Returns an object of the same type and value as obj, with - (apply f (meta obj) args) as its metadata." - [obj f & args] + "Returns an object of the same type and value as obj, with + (apply f (meta obj) args) as its metadata." + [obj f & args] (with-meta obj (apply f (meta obj) args))) (defn list* "Creates a new list containing the item prepended to more." [item & more] - (spread (cons item more))) + (spread (cons item more))) (defmacro lazy-seq "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. Any closed over locals will be cleared prior to the tail - call of body." + call of body." [& body] - (list 'new 'clojure.lang.LazySeq (list* '#^{:once true} fn* [] body))) + (list 'new 'clojure.lang.LazySeq (list* '#^{:once true} fn* [] body))) (defn concat "Returns a lazy seq representing the concatenation of the elements in the supplied colls." ([] (lazy-seq nil)) ([x] (lazy-seq x)) ([x y] - (lazy-seq + (lazy-seq (let [s (seq x)] (if s (cons (first s) (concat (rest s) y)) y)))) ([x y & zs] - (let [cat (fn cat [xys zs] - (lazy-seq - (let [xys (seq xys)] - (if xys - (cons (first xys) (cat (rest xys) zs)) - (when zs - (cat (first zs) (next zs)))))))] - (cat (concat x y) zs)))) + (let [cat (fn cat [xys zs] + (lazy-seq + (let [xys (seq xys)] + (if xys + (cons (first xys) (cat (rest xys) zs)) + (when zs + (cat (first zs) (next zs)))))))] + (cat (concat x y) zs)))) ;;;;;;;;;;;;;;;;at this point all the support for syntax-quote exists;;;;;;;;;;;;;;;;;;;;;; @@ -455,9 +455,9 @@ invoke the body only the first time it is forced (with force), and will cache the result and return it on all subsequent force calls. Any closed over locals will be cleared prior to the tail call - of body, (i.e. they will not be retained)." + of body, (i.e. they will not be retained)." [& body] - (list 'new 'clojure.lang.Delay (list* `#^{:once true} fn* [] body))) + (list 'new 'clojure.lang.Delay (list* `#^{:once true} fn* [] body))) (defn delay? "returns true if x is a Delay created with delay" @@ -471,7 +471,7 @@ "Evaluates test. If logical false, evaluates and returns then expr, otherwise else expr, if supplied, else nil." ([test then] `(if-not ~test ~then nil)) ([test then else] - `(if (not ~test) ~then ~else))) + `(if (not ~test) ~then ~else))) (defn = "Equality. Returns true if x equals y, false if not. Same as @@ -480,16 +480,16 @@ structures define equals() (and thus =) as a value, not an identity, comparison." {:tag Boolean - :inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y)) - :inline-arities #{2}} + :inline (fn [x y] `(. clojure.lang.Util equiv ~x ~y)) + :inline-arities #{2}} ([x] true) ([x y] (clojure.lang.Util/equiv x y)) ([x y & more] - (if (= x y) - (if (next more) - (recur y (first more) (next more)) - (= y (first more))) - false))) + (if (= x y) + (if (next more) + (recur y (first more) (next more)) + (= y (first more))) + false))) (defn not= "Same as (not (= obj1 obj2))" @@ -497,7 +497,7 @@ ([x] false) ([x y] (not (= x y))) ([x y & more] - (not (apply = x y more)))) + (not (apply = x y more)))) @@ -507,7 +507,7 @@ for nil, and 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))} [x y] (. clojure.lang.Util (compare x y))) (defmacro and @@ -518,7 +518,7 @@ ([] true) ([x] x) ([x & next] - `(let [and# ~x] + `(let [and# ~x] (if and# (and ~@next) and#)))) (defmacro or @@ -529,8 +529,8 @@ ([] nil) ([x] x) ([x & next] - `(let [or# ~x] - (if or# or# (or ~@next))))) + `(let [or# ~x] + (if or# or# (or ~@next))))) ;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;; (defn reduce @@ -544,150 +544,150 @@ applying f to that result and the 2nd item, etc. If coll contains no items, returns val and f is not called." ([f coll] - (let [s (seq coll)] - (if s - (if (instance? clojure.lang.IReduce s) - (. #^clojure.lang.IReduce s (reduce f)) - (reduce f (first s) (next s))) - (f)))) + (let [s (seq coll)] + (if s + (if (instance? clojure.lang.IReduce s) + (. #^clojure.lang.IReduce s (reduce f)) + (reduce f (first s) (next s))) + (f)))) ([f val coll] - (let [s (seq coll)] - (if (instance? clojure.lang.IReduce s) - (. #^clojure.lang.IReduce s (reduce f val)) - ((fn [f val s] - (if s - (recur f (f val (first s)) (next s)) - val)) + (let [s (seq coll)] + (if (instance? clojure.lang.IReduce s) + (. #^clojure.lang.IReduce s (reduce f val)) + ((fn [f val s] + (if s + (recur f (f val (first s)) (next s)) + val)) f val s))))) (defn reverse "Returns a seq of the items in coll in reverse order. Not lazy." [coll] - (reduce conj () coll)) + (reduce conj () coll)) ;;math stuff (defn + "Returns the sum of nums. (+) returns 0." {:inline (fn [x y] `(. clojure.lang.Numbers (add ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2}} ([] 0) ([x] (cast Number x)) ([x y] (. clojure.lang.Numbers (add x y))) ([x y & more] - (reduce + (+ x y) more))) + (reduce + (+ x y) more))) (defn * "Returns the product of nums. (*) returns 1." {:inline (fn [x y] `(. clojure.lang.Numbers (multiply ~x ~y))) - :inline-arities #{2}} + :inline-arities #{2}} ([] 1) ([x] (cast Number x)) ([x y] (. clojure.lang.Numbers (multiply x y))) ([x y & more] - (reduce * (* x y) more))) + (reduce * (* x y) more))) (defn / "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}} ([x] (/ 1 x)) ([x y] (. clojure.lang.Numbers (divide x y))) ([x y & more] - (reduce / (/ x y) more))) + (reduce / (/ x y) more))) (defn - "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}} ([x] (. clojure.lang.Numbers (minus x))) ([x y] (. clojure.lang.Numbers (minus x y))) ([x y & more] - (reduce - (- x y) more))) + (reduce - (- x y) more))) (defn < "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}} ([x] true) ([x y] (. clojure.lang.Numbers (lt x y))) ([x y & more] - (if (< x y) - (if (next more) - (recur y (first more) (next more)) - (< y (first more))) - false))) + (if (< x y) + (if (next more) + (recur y (first more) (next more)) + (< y (first more))) + false))) (defn <= "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}} ([x] true) ([x y] (. clojure.lang.Numbers (lte x y))) ([x y & more] - (if (<= x y) - (if (next more) - (recur y (first more) (next more)) - (<= y (first more))) - false))) + (if (<= x y) + (if (next more) + (recur y (first more) (next more)) + (<= y (first more))) + false))) (defn > "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}} ([x] true) ([x y] (. clojure.lang.Numbers (gt x y))) ([x y & more] - (if (> x y) - (if (next more) - (recur y (first more) (next more)) - (> y (first more))) - false))) + (if (> x y) + (if (next more) + (recur y (first more) (next more)) + (> y (first more))) + false))) (defn >= "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}} ([x] true) ([x y] (. clojure.lang.Numbers (gte x y))) ([x y & more] - (if (>= x y) - (if (next more) - (recur y (first more) (next more)) - (>= y (first more))) - false))) + (if (>= x y) + (if (next more) + (recur y (first more) (next more)) + (>= y (first more))) + false))) (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}} ([x] true) ([x y] (. clojure.lang.Numbers (equiv x y))) ([x y & more] - (if (== x y) - (if (next more) - (recur y (first more) (next more)) - (== y (first more))) - false))) + (if (== x y) + (if (next more) + (recur y (first more) (next more)) + (== y (first more))) + false))) (defn max "Returns the greatest of the nums." ([x] x) ([x y] (if (> x y) x y)) ([x y & more] - (reduce max (max x y) more))) + (reduce max (max x y) more))) (defn min "Returns the least of the nums." ([x] x) ([x y] (if (< x y) x y)) ([x y & more] - (reduce min (min x y) more))) + (reduce min (min x y) more))) (defn inc "Returns a number one greater than num." @@ -750,30 +750,30 @@ (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)))} [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)))} [x] (. clojure.lang.Numbers (isNeg x))) (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)))} [x] (. clojure.lang.Numbers (isZero x))) (defn quot "quot[ient] of dividing numerator by denominator." [num div] - (. clojure.lang.Numbers (quotient num div))) + (. clojure.lang.Numbers (quotient num div))) (defn rem "remainder of dividing numerator by denominator." [num div] - (. clojure.lang.Numbers (remainder num div))) + (. clojure.lang.Numbers (remainder num div))) (defn rationalize "returns the rational value of num" @@ -790,7 +790,7 @@ (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)))} [x y] (. clojure.lang.Numbers and x y)) (defn bit-or @@ -847,8 +847,8 @@ (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." - [f] - (fn + [f] + (fn ([] (not (f))) ([x] (not (f x))) ([x y] (not (f x y))) @@ -905,33 +905,33 @@ (defn get "Returns the value mapped to key, not-found or nil if key not present." ([map key] - (. clojure.lang.RT (get map key))) + (. clojure.lang.RT (get map key))) ([map key not-found] - (. clojure.lang.RT (get map key not-found)))) + (. clojure.lang.RT (get map key not-found)))) (defn dissoc "dissoc[iate]. Returns a new map of the same (hashed/sorted) type, that does not contain a mapping for key(s)." ([map] map) ([map key] - (. clojure.lang.RT (dissoc map key))) + (. clojure.lang.RT (dissoc map key))) ([map key & ks] - (let [ret (dissoc map key)] - (if ks - (recur ret (first ks) (next ks)) - ret)))) + (let [ret (dissoc map key)] + (if ks + (recur ret (first ks) (next ks)) + ret)))) (defn disj "disj[oin]. Returns a new set of the same (hashed/sorted) type, that does not contain key(s)." ([set] set) ([#^clojure.lang.IPersistentSet set key] - (. set (disjoin key))) + (. set (disjoin key))) ([set key & ks] - (let [ret (disj set key)] - (if ks - (recur ret (first ks) (next ks)) - ret)))) + (let [ret (disj set key)] + (if ks + (recur ret (first ks) (next ks)) + ret)))) (defn find "Returns the map entry for key, or nil if key not present." @@ -940,15 +940,15 @@ (defn select-keys "Returns a map containing only those entries in map whose key is in keys" [map keyseq] - (loop [ret {} keys (seq keyseq)] - (if keys - (let [entry (. clojure.lang.RT (find map (first keys)))] - (recur - (if entry - (conj ret entry) - ret) - (next keys))) - ret))) + (loop [ret {} keys (seq keyseq)] + (if keys + (let [entry (. clojure.lang.RT (find map (first keys)))] + (recur + (if entry + (conj ret entry) + ret) + (next keys))) + ret))) (defn keys "Returns a sequence of the map's keys." @@ -961,41 +961,41 @@ (defn key "Returns the key of the map entry." [#^java.util.Map$Entry e] - (. e (getKey))) + (. e (getKey))) (defn val "Returns the value in the map entry." [#^java.util.Map$Entry e] - (. e (getValue))) + (. 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" [#^clojure.lang.Reversible rev] - (. rev (rseq))) + (. rev (rseq))) (defn name "Returns the name String of a symbol or keyword." {:tag String} [#^clojure.lang.Named x] - (. x (getName))) + (. x (getName))) (defn namespace "Returns the namespace String of a symbol or keyword, or nil if not present." {:tag String} [#^clojure.lang.Named x] - (. x (getNamespace))) + (. 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." [x & body] `(let [lockee# ~x] - (try + (try (monitor-enter lockee#) ~@body (finally - (monitor-exit lockee#))))) + (monitor-exit lockee#))))) (defmacro .. "form => fieldName-symbol or (instanceMethodName-symbol args*) @@ -1020,8 +1020,8 @@ 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 ~@(next form)) - (list form x))) + `(~(first form) ~x ~@(next form)) + (list form x))) ([x form & more] `(-> (-> ~x ~form) ~@more))) ;;multimethods @@ -1037,34 +1037,34 @@ defaults to the global hierarchy" {:arglists '([name docstring? attr-map? dispatch-fn & options])} [mm-name & options] - (let [docstring (if (string? (first options)) - (first options) - nil) - options (if (string? (first options)) - (next options) - options) - m (if (map? (first options)) - (first options) - {}) - options (if (map? (first options)) - (next options) - options) - dispatch-fn (first options) - options (next options) - m (assoc m :tag 'clojure.lang.MultiFn) - m (if docstring - (assoc m :doc docstring) - m) - m (if (meta mm-name) - (conj (meta mm-name) m) - m)] + (let [docstring (if (string? (first options)) + (first options) + nil) + options (if (string? (first options)) + (next options) + options) + m (if (map? (first options)) + (first options) + {}) + options (if (map? (first options)) + (next options) + options) + dispatch-fn (first options) + options (next options) + m (assoc m :tag 'clojure.lang.MultiFn) + m (if docstring + (assoc m :doc docstring) + m) + m (if (meta mm-name) + (conj (meta mm-name) m) + m)] (when (= (count options) 1) (throw (Exception. "The syntax for defmulti has changed. Example: (defmulti name dispatch-fn :default dispatch-value)"))) - (let [options (apply hash-map options) - default (get options :default :default) - hierarchy (get options :hierarchy #'global-hierarchy)] + (let [options (apply hash-map options) + default (get options :default :default) + hierarchy (get options :hierarchy #'global-hierarchy)] `(def ~(with-meta mm-name m) - (new clojure.lang.MultiFn ~dispatch-fn ~default ~hierarchy))))) + (new clojure.lang.MultiFn ~dispatch-fn ~default ~hierarchy))))) (defmacro defmethod "Creates and installs a new method of multimethod associated with dispatch-value. " @@ -1073,8 +1073,8 @@ (defn remove-method "Removes the method of multimethod associated with dispatch-value." - [#^clojure.lang.MultiFn multifn dispatch-val] - (. multifn removeMethod dispatch-val)) + [#^clojure.lang.MultiFn multifn dispatch-val] + (. multifn removeMethod dispatch-val)) (defn prefer-method "Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y when there is a conflict" @@ -1093,24 +1093,24 @@ (defmacro #^{:private true} assert-args [fnname & pairs] `(do (when-not ~(first pairs) - (throw (IllegalArgumentException. - ~(str fnname " requires " (second pairs))))) - ~(let [more (nnext pairs)] - (when more - (list* `assert-args fnname more))))) + (throw (IllegalArgumentException. + ~(str fnname " requires " (second pairs))) |