diff options
-rw-r--r-- | src/clj/clojure/core.clj | 574 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Compiler.java | 17 | ||||
-rw-r--r-- | test/clojure/test_clojure/logic.clj | 2 | ||||
-rw-r--r-- | test/clojure/test_clojure/numbers.clj | 18 | ||||
-rw-r--r-- | test/clojure/test_clojure/other_functions.clj | 4 | ||||
-rw-r--r-- | test/clojure/test_clojure/sequences.clj | 16 |
6 files changed, 364 insertions, 267 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 2a2563f5..5ad2eb53 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -23,9 +23,10 @@ ^{:arglists '([x seq]) :doc "Returns a new seq where x is the first element and seq is the rest." - :added "1.0"} + :added "1.0" + :static true} - cons (fn* cons [x seq] (. clojure.lang.RT (cons x seq)))) + cons (fn* ^:static cons [x seq] (. clojure.lang.RT (cons x seq)))) ;during bootstrap we don't have destructuring let, loop or fn, will redefine later (def @@ -49,24 +50,27 @@ ^{:arglists '([coll]) :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)))) + :added "1.0" + :static true} + first (fn ^:static first [coll] (. clojure.lang.RT (first coll)))) (def ^{:arglists '([coll]) :tag clojure.lang.ISeq :doc "Returns a seq of the items after the first. Calls seq on its argument. If there are no more items, returns nil." - :added "1.0"} - next (fn next [x] (. clojure.lang.RT (next x)))) + :added "1.0" + :static true} + next (fn ^:static next [x] (. clojure.lang.RT (next x)))) (def ^{:arglists '([coll]) :tag clojure.lang.ISeq :doc "Returns a possibly empty seq of the items after the first. Calls seq on its argument." - :added "1.0"} - rest (fn rest [x] (. clojure.lang.RT (more x)))) + :added "1.0" + :static true} + rest (fn ^:static rest [x] (. clojure.lang.RT (more x)))) (def ^{:arglists '([coll x] [coll x & xs]) @@ -84,32 +88,37 @@ (def ^{:doc "Same as (first (next x))" :arglists '([x]) - :added "1.0"} - second (fn second [x] (first (next x)))) + :added "1.0" + :static true} + second (fn ^:static second [x] (first (next x)))) (def ^{:doc "Same as (first (first x))" :arglists '([x]) - :added "1.0"} - ffirst (fn ffirst [x] (first (first x)))) + :added "1.0" + :static true} + ffirst (fn ^:static ffirst [x] (first (first x)))) (def ^{:doc "Same as (next (first x))" :arglists '([x]) - :added "1.0"} - nfirst (fn nfirst [x] (next (first x)))) + :added "1.0" + :static true} + nfirst (fn ^:static nfirst [x] (next (first x)))) (def ^{:doc "Same as (first (next x))" :arglists '([x]) - :added "1.0"} - fnext (fn fnext [x] (first (next x)))) + :added "1.0" + :static true} + fnext (fn ^:static fnext [x] (first (next x)))) (def ^{:doc "Same as (next (next x))" :arglists '([x]) - :added "1.0"} - nnext (fn nnext [x] (next (next x)))) + :added "1.0" + :static true} + nnext (fn ^:static nnext [x] (next (next x)))) (def ^{:arglists '([coll]) @@ -118,8 +127,9 @@ Strings, native Java arrays (of reference types) and any objects that implement Iterable." :tag clojure.lang.ISeq - :added "1.0"} - seq (fn seq [coll] (. clojure.lang.RT (seq coll)))) + :added "1.0" + :static true} + seq (fn ^:static seq ^clojure.lang.ISeq [coll] (. clojure.lang.RT (seq coll)))) (def ^{:arglists '([^Class c x]) @@ -131,32 +141,37 @@ (def ^{:arglists '([x]) :doc "Return true if x implements ISeq" - :added "1.0"} - seq? (fn seq? [x] (instance? clojure.lang.ISeq x))) + :added "1.0" + :static true} + seq? (fn ^:static seq? [x] (instance? clojure.lang.ISeq x))) (def ^{:arglists '([x]) :doc "Return true if x is a Character" - :added "1.0"} - char? (fn char? [x] (instance? Character x))) + :added "1.0" + :static true} + char? (fn ^:static char? [x] (instance? Character x))) (def ^{:arglists '([x]) :doc "Return true if x is a String" - :added "1.0"} - string? (fn string? [x] (instance? String x))) + :added "1.0" + :static true} + string? (fn ^:static string? [x] (instance? String x))) (def ^{:arglists '([x]) :doc "Return true if x implements IPersistentMap" - :added "1.0"} - map? (fn map? [x] (instance? clojure.lang.IPersistentMap x))) + :added "1.0" + :static true} + map? (fn ^:static map? [x] (instance? clojure.lang.IPersistentMap x))) (def ^{:arglists '([x]) :doc "Return true if x implements IPersistentVector" - :added "1.0"} - vector? (fn vector? [x] (instance? clojure.lang.IPersistentVector x))) + :added "1.0" + :static true} + vector? (fn ^:static vector? [x] (instance? clojure.lang.IPersistentVector x))) (def ^{:arglists '([map key val] [map key val & kvs]) @@ -178,8 +193,9 @@ (def ^{:arglists '([obj]) :doc "Returns the metadata of obj, returns nil if there is no metadata." - :added "1.0"} - meta (fn meta [x] + :added "1.0" + :static true} + meta (fn ^:static meta [x] (if (instance? clojure.lang.IMeta x) (. ^clojure.lang.IMeta x (meta))))) @@ -187,8 +203,9 @@ ^{:arglists '([^clojure.lang.IObj obj m]) :doc "Returns an object of the same type and value as obj, with map m as its metadata." - :added "1.0"} - with-meta (fn with-meta [^clojure.lang.IObj x m] + :added "1.0" + :static true} + with-meta (fn ^:static with-meta [^clojure.lang.IObj x m] (. x (withMeta m)))) (def ^{:private true :dynamic true} @@ -223,8 +240,9 @@ (def ^{:arglists '([coll]) :doc "Return the last item in coll, in linear time" - :added "1.0"} - last (fn last [s] + :added "1.0" + :static true} + last (fn ^:static last [s] (if (next s) (recur (next s)) (first s)))) @@ -232,8 +250,9 @@ (def ^{:arglists '([coll]) :doc "Return a seq of all but the last item in coll, in linear time" - :added "1.0"} - butlast (fn butlast [s] + :added "1.0" + :static true} + butlast (fn ^:static butlast [s] (loop [ret [] s s] (if (next s) (recur (conj ret (first s)) (next s)) @@ -282,17 +301,17 @@ m)) m (conj (if (meta name) (meta name) {}) m)] (list 'def (with-meta name m) - (list '.withMeta (cons `fn (cons name fdecl)) (list '.meta (list 'var name))))))) + (list '.withMeta (cons `fn (cons (with-meta name m) fdecl)) (list '.meta (list 'var name))))))) (. (var defn) (setMacro)) -(defn cast +(defn ^:static 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 +(defn ^:static 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;" @@ -310,7 +329,7 @@ ([a b c d & args] (. clojure.lang.LazilyPersistentVector (create (cons a (cons b (cons c (cons d args)))))))) -(defn vec +(defn ^:static vec "Creates a new vector containing the contents of coll." {:added "1.0"} ([coll] @@ -361,7 +380,7 @@ ;;;;;;;;;;;;;;;;;;;; -(defn nil? +(defn ^:static nil? "Returns true if x is nil, false otherwise." {:tag Boolean :added "1.0"} @@ -428,19 +447,19 @@ [test & body] (list 'if test nil (cons 'do body))) -(defn false? +(defn ^:static false? "Returns true if x is the value false, false otherwise." {:tag Boolean, :added "1.0"} [x] (clojure.lang.Util/identical x false)) -(defn true? +(defn ^:static true? "Returns true if x is the value true, false otherwise." {:tag Boolean, :added "1.0"} [x] (clojure.lang.Util/identical x true)) -(defn not +(defn ^:static not "Returns true if x is logical false, false otherwise." {:tag Boolean :added "1.0"} @@ -463,17 +482,17 @@ (new StringBuilder ^String (str x)) ys))) -(defn symbol? +(defn ^:static symbol? "Return true if x is a Symbol" {:added "1.0"} [x] (instance? clojure.lang.Symbol x)) -(defn keyword? +(defn ^:static keyword? "Return true if x is a Keyword" {:added "1.0"} [x] (instance? clojure.lang.Keyword x)) -(defn symbol +(defn ^:static symbol "Returns a Symbol with the given namespace and name." {:tag clojure.lang.Symbol :added "1.0"} @@ -503,7 +522,7 @@ "cond requires an even number of forms"))) (cons 'clojure.core/cond (next (next clauses)))))) -(defn keyword +(defn ^:static 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 @@ -563,30 +582,34 @@ [& body] (list 'new 'clojure.lang.LazySeq (list* '^{:once true} fn* [] body))) -(defn ^clojure.lang.ChunkBuffer chunk-buffer [capacity] +(defn ;^clojure.lang.ChunkBuffer + ^:static chunk-buffer [capacity] (clojure.lang.ChunkBuffer. capacity)) -(defn chunk-append [^clojure.lang.ChunkBuffer b x] +(defn ^:static chunk-append [^clojure.lang.ChunkBuffer b x] (.add b x)) -(defn chunk [^clojure.lang.ChunkBuffer b] +(defn ^:static chunk [^clojure.lang.ChunkBuffer b] (.chunk b)) -(defn ^clojure.lang.IChunk chunk-first [^clojure.lang.IChunkedSeq s] +(defn ;^clojure.lang.IChunk + ^:static chunk-first [^clojure.lang.IChunkedSeq s] (.chunkedFirst s)) -(defn ^clojure.lang.ISeq chunk-rest [^clojure.lang.IChunkedSeq s] +(defn ;^clojure.lang.ISeq + ^:static chunk-rest [^clojure.lang.IChunkedSeq s] (.chunkedMore s)) -(defn ^clojure.lang.ISeq chunk-next [^clojure.lang.IChunkedSeq s] +(defn ;^clojure.lang.ISeq + ^:static chunk-next [^clojure.lang.IChunkedSeq s] (.chunkedNext s)) -(defn chunk-cons [chunk rest] +(defn ^:static chunk-cons [chunk rest] (if (clojure.lang.Numbers/isZero (clojure.lang.RT/count chunk)) rest (clojure.lang.ChunkedCons. chunk rest))) -(defn chunked-seq? [s] +(defn ^:static chunked-seq? [s] (instance? clojure.lang.IChunkedSeq s)) (defn concat @@ -625,12 +648,12 @@ [& body] (list 'new 'clojure.lang.Delay (list* `^{:once true} fn* [] body))) -(defn delay? +(defn ^:static delay? "returns true if x is a Delay created with delay" {:added "1.0"} [x] (instance? clojure.lang.Delay x)) -(defn force +(defn ^:static 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))) @@ -787,7 +810,7 @@ (recur f (f val (first s)) (next s))) val))))) -(defn reverse +(defn ^:static reverse "Returns a seq of the items in coll in reverse order. Not lazy." {:added "1.0"} [coll] @@ -989,19 +1012,19 @@ :added "1.0"} [x] (. clojure.lang.Numbers (isNeg x))) -(defn quot +(defn ^:static quot "quot[ient] of dividing numerator by denominator." {:added "1.0"} [num div] (. clojure.lang.Numbers (quotient num div))) -(defn rem +(defn ^:static rem "remainder of dividing numerator by denominator." {:added "1.0"} [num div] (. clojure.lang.Numbers (remainder num div))) -(defn rationalize +(defn ^:static rationalize "returns the rational value of num" {:added "1.0"} [num] @@ -1034,28 +1057,28 @@ :added "1.0"} [x y] (. clojure.lang.Numbers xor x y)) -(defn bit-and-not +(defn ^:static bit-and-not "Bitwise and with complement" {:added "1.0"} [x y] (. clojure.lang.Numbers andNot x y)) -(defn bit-clear +(defn ^:static bit-clear "Clear bit at index n" {:added "1.0"} [x n] (. clojure.lang.Numbers clearBit x n)) -(defn bit-set +(defn ^:static bit-set "Set bit at index n" {:added "1.0"} [x n] (. clojure.lang.Numbers setBit x n)) -(defn bit-flip +(defn ^:static bit-flip "Flip bit at index n" {:added "1.0"} [x n] (. clojure.lang.Numbers flipBit x n)) -(defn bit-test +(defn ^:static bit-test "Test bit at index n" {:added "1.0"} [x n] (. clojure.lang.Numbers testBit x n)) @@ -1073,12 +1096,12 @@ :added "1.0"} [x n] (. clojure.lang.Numbers shiftRight x n)) -(defn even? +(defn ^:static 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? +(defn ^:static odd? "Returns true if n is odd, throws an exception if n is not an integer" {:added "1.0"} [n] (not (even? n))) @@ -1086,7 +1109,7 @@ ;; -(defn complement +(defn ^:static 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"} @@ -1097,12 +1120,12 @@ ([x y] (not (f x y))) ([x y & zs] (not (apply f x y zs))))) -(defn constantly +(defn ^:static constantly "Returns a function that takes any number of arguments and returns x." {:added "1.0"} [x] (fn [& args] x)) -(defn identity +(defn ^:static identity "Returns its argument." {:added "1.0"} [x] x) @@ -1114,13 +1137,13 @@ ;;list stuff -(defn peek +(defn ^:static 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 +(defn ^:static pop "For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item. If the collection is empty, throws an exception. Note - not the same @@ -1130,7 +1153,7 @@ ;;map stuff -(defn contains? +(defn ^:static contains? "Returns true if key is present in the given collection, otherwise returns false. Note that for numerically indexed collections like vectors and Java arrays, this tests if the numeric key is within the @@ -1139,7 +1162,7 @@ {:added "1.0"} [coll key] (. clojure.lang.RT (contains coll key))) -(defn get +(defn ^:static 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} @@ -1177,12 +1200,12 @@ (recur ret (first ks) (next ks)) ret))))) -(defn find +(defn ^:static 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 +(defn ^:static select-keys "Returns a map containing only those entries in map whose key is in keys" {:added "1.0"} [map keyseq] @@ -1196,43 +1219,43 @@ (next keys))) ret))) -(defn keys +(defn ^:static keys "Returns a sequence of the map's keys." {:added "1.0"} [map] (. clojure.lang.RT (keys map))) -(defn vals +(defn ^:static vals "Returns a sequence of the map's values." {:added "1.0"} [map] (. clojure.lang.RT (vals map))) -(defn key +(defn ^:static key "Returns the key of the map entry." {:added "1.0"} [^java.util.Map$Entry e] (. e (getKey))) -(defn val +(defn ^:static val "Returns the value in the map entry." {:added "1.0"} [^java.util.Map$Entry e] (. e (getValue))) -(defn rseq +(defn ^:static 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 +(defn ^:static name "Returns the name String of a string, symbol or keyword." {:tag String :added "1.0"} - [^clojure.lang.Named x] - (if (string? x) x (. x (getName)))) + [x] + (if (string? x) x (. ^clojure.lang.Named x (getName)))) -(defn namespace +(defn ^:static namespace "Returns the namespace String of a symbol or keyword, or nil if not present." {:tag String :added "1.0"} @@ -1343,37 +1366,37 @@ [multifn dispatch-val & fn-tail] `(. ~(with-meta multifn {:tag 'clojure.lang.MultiFn}) addMethod ~dispatch-val (fn ~@fn-tail))) -(defn remove-all-methods +(defn ^:static remove-all-methods "Removes all of the methods of multimethod." {:added "1.2"} [^clojure.lang.MultiFn multifn] (.reset multifn)) -(defn remove-method +(defn ^:static 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 +(defn ^:static 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 +(defn ^:static methods "Given a multimethod, returns a map of dispatch values -> dispatch fns" {:added "1.0"} [^clojure.lang.MultiFn multifn] (.getMethodTable multifn)) -(defn get-method +(defn ^:static 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 +(defn ^:static prefers "Given a multimethod, returns a map of preferred value -> set of other values" {:added "1.0"} [^clojure.lang.MultiFn multifn] (.getPreferTable multifn)) @@ -1422,7 +1445,7 @@ (let [~form temp#] ~@body))))) -(defn push-thread-bindings +(defn ^:static push-thread-bindings "WARNING: This is a low-level function. Prefer high-level macros like binding where ever possible. @@ -1439,14 +1462,14 @@ [bindings] (clojure.lang.Var/pushThreadBindings bindings)) -(defn pop-thread-bindings +(defn ^:static pop-thread-bindings "Pop one set of bindings pushed with push-binding before. It is an error to pop bindings without pushing before." {:added "1.1"} [] (clojure.lang.Var/popThreadBindings)) -(defn get-thread-bindings +(defn ^:static get-thread-bindings "Get a map with the Var/value pairs which is currently in effect for the current thread." {:added "1.1"} @@ -1499,7 +1522,7 @@ [binding-map & body] `(with-bindings* ~binding-map (fn [] ~@body))) -(defn bound-fn* +(defn ^:static bound-fn* "Returns a function, which will install the same bindings in effect as in the thread at the time bound-fn* was called and then call f with any given arguments. This may be used to define a helper function which runs on a @@ -1519,7 +1542,7 @@ [& fntail] `(bound-fn* (fn ~@fntail))) -(defn find-var +(defn ^:static find-var "Returns the global var named by the namespace-qualified symbol, or nil if no var with that name." {:added "1.0"} @@ -1588,7 +1611,7 @@ [^clojure.lang.Agent a f & args] (. a (dispatch f args true))) -(defn release-pending-sends +(defn ^:static release-pending-sends "Normally, actions sent directly or indirectly during another action are held until the action completes (changes the agent's state). This function can be used to dispatch any pending sent @@ -1598,7 +1621,7 @@ {:added "1.0"} [] (clojure.lang.Agent/releasePendingSends)) -(defn add-watch +(defn ^:static add-watch "Alpha - subject to change. Adds a watch function to an agent/atom/var/ref reference. The watch fn must be a fn of 4 args: a key, the reference, its old-state, its @@ -1616,14 +1639,14 @@ {:added "1.0"} [^clojure.lang.IRef reference key fn] (.addWatch reference key fn)) -(defn remove-watch +(defn ^:static 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)) -(defn agent-error +(defn ^:static agent-error "Returns the exception thrown during an asynchronous action of the agent if the agent is failed. Returns nil if the agent is not failed." @@ -1645,7 +1668,7 @@ (let [opts (apply hash-map options)] (.restart a new-state (if (:clear-actions opts) true false)))) -(defn set-error-handler! +(defn ^:static set-error-handler! "Sets the error-handler of agent a to handler-fn. If an action being run by the agent throws an exception or doesn't pass the validator fn, handler-fn will be called with two arguments: the @@ -1654,14 +1677,14 @@ [^clojure.lang.Agent a, handler-fn] (.setErrorHandler a handler-fn)) -(defn error-handler +(defn ^:static error-handler "Returns the error-handler of agent a, or nil if there is none. See set-error-handler!" {:added "1.2"} [^clojure.lang.Agent a] (.getErrorHandler a)) -(defn set-error-mode! +(defn ^:static set-error-mode! "Sets the error-mode of agent a to mode-keyword, which must be either :fail or :continue. If an action being run by the agent throws an exception or doesn't pass the validator fn, an @@ -1677,7 +1700,7 @@ [^clojure.lang.Agent a, mode-keyword] (.setErrorMode a mode-keyword)) -(defn error-mode +(defn ^:static error-mode "Returns the error-mode of agent a. See set-error-mode!" {:added "1.2"} [^clojure.lang.Agent a] @@ -1701,7 +1724,7 @@ :deprecated "1.2"} [^clojure.lang.Agent a] (restart-agent a (.deref a))) -(defn shutdown-agents +(defn ^:static 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" @@ -1742,7 +1765,7 @@ (.setMinHistory r (:min-history opts))) r))) -(defn deref +(defn ^:static deref "Also reader macro: @ref/@agent/@var/@atom/@delay/@future. Within a transaction, returns the in-transaction-value of ref, else returns the most-recently-committed value of ref. When applied to a var, agent @@ -1780,20 +1803,20 @@ ([^clojure.lang.Atom atom f x y] (.swap atom f x y)) ([^clojure.lang.Atom atom f x y & args] (.swap atom f x y args))) -(defn compare-and-set! +(defn ^:static compare-and-set! "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! +(defn ^:static 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! +(defn ^:static set-validator! "Sets the validator-fn for a var/ref/agent/atom. validator-fn must be nil or a side-effect-free fn of one argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the @@ -1803,7 +1826,7 @@ {:added "1.0"} [^clojure.lang.IRef iref validator-fn] (. iref (setValidator validator-fn))) -(defn get-validator +(defn ^:static get-validator "Gets the validator-fn for a var/ref/agent/atom." {:added "1.0"} [^clojure.lang.IRef iref] (. iref (getValidator))) @@ -1817,7 +1840,7 @@ {:added "1.0"} [^clojure.lang.IReference iref f & args] (.alterMeta iref f args)) -(defn reset-meta! +(defn ^:static 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)) @@ -1853,20 +1876,20 @@ [^clojure.lang.Ref ref fun & args] (. ref (alter fun args))) -(defn ref-set +(defn ^:static 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))) -(defn ref-history-count +(defn ^:static ref-history-count "Returns the history count of a ref" {:added "1.1"} [^clojure.lang.Ref ref] (.getHistoryCount ref)) -(defn ref-min-history +(defn ^:static ref-min-history "Gets the min-history of a ref, or sets it and returns the ref" {:added "1.1"} ([^clojure.lang.Ref ref] @@ -1874,7 +1897,7 @@ ([^clojure.lang.Ref ref n] (.setMinHistory ref n))) -(defn ref-max-history +(defn ^:static ref-max-history "Gets the max-history of a ref, or sets it and returns the ref" {:added "1.1"} ([^clojure.lang.Ref ref] @@ -1882,7 +1905,7 @@ ([^clojure.lang.Ref ref n] (.setMaxHistory ref n))) -(defn ensure +(defn ^:static ensure "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)" @@ -2003,7 +2026,7 @@ (fn [& args] (apply f arg1 arg2 arg3 (concat more args))))) ;;;;;;;;;;;;;;;;;;; sequence fns ;;;;;;;;;;;;;;;;;;;;;;; -(defn sequence +(defn ^:static sequence "Coerces coll to a (possibly empty) sequence, if it is not already one. Will not force a lazy seq. (sequence nil) yields ()" {:added "1.0"} @@ -2011,7 +2034,7 @@ (if (seq? coll) coll (or (seq coll) ()))) -(defn every? +(defn ^:static every? "Returns true if (pred x) is logical true for every x in coll, else false." {:tag Boolean @@ -2030,7 +2053,7 @@ :added "1.0"} not-every? (comp not every?)) -(defn some +(defn ^:static some "Returns the first logical true value of (pred x) for any x in coll, 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: @@ -2130,7 +2153,7 @@ (filter pred r)))))))) -(defn remove +(defn ^:static 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"} @@ -2157,7 +2180,7 @@ (when (pred (first s)) (cons (first s) (take-while pred (rest s))))))) -(defn drop +(defn ^:static drop "Returns a lazy sequence of all but the first n items in coll." {:added "1.0"} [n coll] @@ -2184,7 +2207,7 @@ (recur (next s) (next lead)) s))) -(defn drop-while +(defn ^:static 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"} @@ -2203,13 +2226,13 @@ (when-let [s (seq coll)] (concat s (cycle s))))) -(defn split-at +(defn ^:static 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 +(defn ^:static split-with "Returns a vector of [(take-while pred coll) (drop-while pred coll)]" {:added "1.0"} [pred coll] @@ -2221,7 +2244,7 @@ ([x] (lazy-seq (cons x (repeat x)))) ([n x] (take n (repeat x)))) -(defn replicate +(defn ^:static replicate "Returns a lazy seq of n xs." {:added "1.0"} [n x] (take n (repeat x))) @@ -2281,7 +2304,7 @@ -(defn zipmap +(defn ^:static zipmap "Returns a map with the keys mapped to the corresponding vals." {:added "1.0"} [keys vals] @@ -2307,7 +2330,7 @@ (when-let [line (.readLine rdr)] (cons line (lazy-seq (line-seq rdr))))) -(defn comparator +(defn ^:static comparator "Returns an implementation of java.util.Comparator based upon pred." {:added "1.0"} [pred] @@ -2364,7 +2387,7 @@ ;; evaluation -(defn eval +(defn ^:static eval "Evaluates the form data structure (not text!) and returns the result." {:added "1.0"} [form] (. clojure.lang.Compiler (eval form))) @@ -2427,7 +2450,7 @@ ~@(when needrec [recform]))))))])))))] (nth (step nil (seq seq-exprs)) 1))) -(defn dorun +(defn ^:static dorun "When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. dorun can @@ -2441,7 +2464,7 @@ (when (and (seq coll) (pos? n)) (recur (dec n) (next coll))))) -(defn doall +(defn ^:static doall "When lazy sequences are produced via functions that have side effects, any effects other than those needed to produce the first element in the seq do not occur until the seq is consumed. doall can @@ -2472,7 +2495,7 @@ (send agent count-down)) (. latch (await))))) -(defn await1 [^clojure.lang.Agent a] +(defn ^:static await1 [^clojure.lang.Agent a] (when (pos? (.getQueueCount a)) (await a)) a) @@ -2522,14 +2545,14 @@ ret))) ;;;;;;;;;;;;;;;;;;;;; editable collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defn transient +(defn ^:static transient "Alpha - subject to change. Returns a new, transient version of the collection, in constant time." {:added "1.1"} [^clojure.lang.IEditableCollection coll] (.asTransient coll)) -(defn persistent! +(defn ^:static persistent! "Alpha - subject to change. Returns a new, persistent version of the transient collection, in constant time. The transient collection cannot be used after this @@ -2538,7 +2561,7 @@ [^clojure.lang.ITransientCollection coll] (.persistent coll)) -(defn conj! +(defn ^:static conj! "Alpha - subject to change. Adds x to the transient collection, and return coll. The 'addition' may happen at different 'places' depending on the concrete type." @@ -2570,7 +2593,7 @@ (recur ret (first ks) (next ks)) ret)))) -(defn pop! +(defn ^:static pop! "Alpha - subject to change. Removes the last item from a transient vector. If the collection is empty, throws an exception. Returns coll" @@ -2593,7 +2616,7 @@ ret)))) ;redef into with batch support -(defn into +(defn ^:static into "Returns a new coll consisting of to-coll with all of the items of from-coll conjoined." {:added "1.0"} @@ -2620,7 +2643,7 @@ (into v (map #(str p "." %) cs))))) [] specs))))) -(defn into-array +(defn ^:static into-array "Returns an array with components set to the values in aseq. The array's component type is type if provided, or the type of the first value in aseq if present, or Object. All values in aseq must be compatible with @@ -2636,7 +2659,7 @@ array [& items] (into-array items)) -(defn ^Class class +(defn ^Class ^:static class "Returns the Class of x" {:added "1.0"} [^Object x] (if (nil? x) x (. x (getClass)))) @@ -2703,13 +2726,13 @@ :added "1.0"} [x] (clojure.lang.RT/booleanCast x)) -(defn number? +(defn ^:static number? "Returns true if x is a Number" {:added "1.0"} [x] (instance? Number x)) -(defn integer? +(defn ^:static integer? "Returns true if n is an integer" {:added "1.0"} [n] @@ -2719,7 +2742,7 @@ (instance? Short n) (instance? Byte n))) -(defn mod +(defn ^:static mod "Modulus of num and div. Truncates toward negative infinity." {:added "1.0"} [num div] @@ -2728,43 +2751,43 @@ m (+ m div)))) -(defn ratio? +(defn ^:static ratio? "Returns true if n is a Ratio" {:added "1.0"} [n] (instance? clojure.lang.Ratio n)) -(defn numerator +(defn ^:static numerator "Returns the numerator part of a Ratio." {:tag BigInteger :added "1.2"} [r] (.numerator ^clojure.lang.Ratio r)) -(defn denominator +(defn ^:static denominator "Returns the denominator part of a Ratio." {:tag BigInteger :added "1.2"} [r] (.denominator ^clojure.lang.Ratio r)) -(defn decimal? +(defn ^:static decimal? "Returns true if n is a BigDecimal" {:added "1.0"} [n] (instance? BigDecimal n)) -(defn float? +(defn ^:static float? "Returns true if n is a floating point number" {:added "1.0"} [n] (or (instance? Double n) (instance? Float n))) -(defn rational? [n] +(defn ^:static rational? [n] "Returns true if n is a rational number" {:added "1.0"} (or (integer? n) (ratio? n) (decimal? n))) -(defn bigint +(defn ^:static bigint "Coerce to BigInteger" {:tag BigInteger :added "1.0"} @@ -2775,7 +2798,7 @@ (number? x) (BigInteger/valueOf (long x)) :else (BigInteger. x))) -(defn bigdec +(defn ^:static bigdec "Coerce to BigDecimal" {:tag BigDecimal :added "1.0"} @@ -2817,7 +2840,7 @@ (recur (first more) nmore) (apply pr more)))) -(defn newline +(defn ^:static newline "Writes a newline to the output stream that is the current value of *out*" {:added "1.0"} @@ -2825,7 +2848,7 @@ (. *out* (append \newline)) nil) -(defn flush +(defn ^:static flush "Flushes the output stream that is the current value of *out*" {:added "1.0"} @@ -2879,7 +2902,7 @@ (.readLine ^clojure.lang.LineNumberingPushbackReader *in*) (.readLine ^java.io.BufferedReader *in*))) -(defn read-string +(defn ^:static read-string "Reads one object from the string s" {:added "1.0"} [s] (clojure.lang.RT/readString s)) @@ -3062,7 +3085,7 @@ (aset-int dimarray i (nth dims i))) (. Array (newInstance type dimarray))))) -(defn to-array-2d +(defn ^:static to-array-2d |