diff options
author | Rich Hickey <richhickey@gmail.com> | 2010-06-09 20:50:52 -0400 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2010-06-09 20:50:52 -0400 |
commit | 662b38415e15edcbd720628c0c07a8f8817c96b4 (patch) | |
tree | 59a05d1829042c5435b673df6b507d812c54efd3 | |
parent | 48bfe3bba0035f555a045ae4d2a5933ff57eea0a (diff) |
detect constant maps, emit as constants
break down constant inits into separate methods, call from init
move core.clj to statics
-rw-r--r-- | src/clj/clojure/core.clj | 958 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Compiler.java | 99 | ||||
-rw-r--r-- | test/clojure/test_clojure/metadata.clj | 2 | ||||
-rw-r--r-- | test/clojure/test_clojure/sequences.clj | 2 |
4 files changed, 669 insertions, 392 deletions
diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index fa0e75d5..445387a0 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -77,8 +77,9 @@ :doc "conj[oin]. Returns a new collection with the xs 'added'. (conj nil item) returns (item). The 'addition' may happen at different 'places' depending on the concrete type." - :added "1.0"} - conj (fn conj + :added "1.0" + :static true} + conj (fn ^:static conj ([coll x] (. clojure.lang.RT (conj coll x))) ([coll x & xs] (if xs @@ -297,7 +298,7 @@ (if (if (clojure.lang.Util/equiv 'fn ifn) (if (instance? clojure.lang.Symbol iname) false true)) ;; inserts the same fn name to the inline fn if it does not have one - (assoc m :inline (cons ifn (cons (clojure.lang.Symbol/intern (.concat (.getName name) "__inliner")) + (assoc m :inline (cons ifn (cons (clojure.lang.Symbol/intern (.concat (.getName ^clojure.lang.Symbol name) "__inliner")) (next inline)))) m)) m (conj (if (meta name) (meta name) {}) m)] @@ -306,22 +307,25 @@ (. (var defn) (setMacro)) -(defn ^:static cast +(defn cast "Throws a ClassCastException if x is not a c, else returns x." - {:added "1.0"} + {:added "1.0" + :static true} [^Class c x] (. c (cast x))) -(defn ^:static to-array +(defn to-array "Returns an array of Objects containing the contents of coll, which can be any Collection. Maps to java.util.Collection.toArray()." {:tag "[Ljava.lang.Object;" - :added "1.0"} + :added "1.0" + :static true} [coll] (. clojure.lang.RT (toArray coll))) (defn vector "Creates a new vector containing the args." - {:added "1.0"} + {:added "1.0" + :static true} ([] []) ([a] [a]) ([a b] [a b]) @@ -330,9 +334,10 @@ ([a b c d & args] (. clojure.lang.LazilyPersistentVector (create (cons a (cons b (cons c (cons d args)))))))) -(defn ^:static vec +(defn vec "Creates a new vector containing the contents of coll." - {:added "1.0"} + {:added "1.0" + :static true} ([coll] (if (instance? java.util.Collection coll) (clojure.lang.LazilyPersistentVector/create coll) @@ -341,14 +346,16 @@ (defn hash-map "keyval => key val Returns a new hash map with supplied mappings." - {:added "1.0"} + {:added "1.0" + :static true} ([] {}) ([& keyvals] (. clojure.lang.PersistentHashMap (createWithCheck keyvals)))) (defn hash-set "Returns a new hash set with supplied keys." - {:added "1.0"} + {:added "1.0" + :static true} ([] #{}) ([& keys] (clojure.lang.PersistentHashSet/createWithCheck keys))) @@ -356,35 +363,40 @@ (defn sorted-map "keyval => key val Returns a new sorted map with supplied mappings." - {:added "1.0"} + {:added "1.0" + :static true} ([& keyvals] (clojure.lang.PersistentTreeMap/create keyvals))) (defn sorted-map-by "keyval => key val Returns a new sorted map with supplied mappings, using the supplied comparator." - {:added "1.0"} + {:added "1.0" + :static true} ([comparator & keyvals] (clojure.lang.PersistentTreeMap/create comparator keyvals))) (defn sorted-set "Returns a new sorted set with supplied keys." - {:added "1.0"} + {:added "1.0" + :static true} ([& keys] (clojure.lang.PersistentTreeSet/create keys))) (defn sorted-set-by "Returns a new sorted set with supplied keys, using the supplied comparator." - {:added "1.1"} + {:added "1.1" + :static true} ([comparator & keys] (clojure.lang.PersistentTreeSet/create comparator keys))) ;;;;;;;;;;;;;;;;;;;; -(defn ^:static nil? +(defn nil? "Returns true if x is nil, false otherwise." {:tag Boolean - :added "1.0"} + :added "1.0" + :static true} [x] (clojure.lang.Util/identical x nil)) (def @@ -448,22 +460,25 @@ [test & body] (list 'if test nil (cons 'do body))) -(defn ^:static false? +(defn false? "Returns true if x is the value false, false otherwise." {:tag Boolean, - :added "1.0"} + :added "1.0" + :static true} [x] (clojure.lang.Util/identical x false)) -(defn ^:static true? +(defn true? "Returns true if x is the value true, false otherwise." {:tag Boolean, - :added "1.0"} + :added "1.0" + :static true} [x] (clojure.lang.Util/identical x true)) -(defn ^:static not +(defn not "Returns true if x is logical false, false otherwise." {:tag Boolean - :added "1.0"} + :added "1.0" + :static true} [x] (if x false true)) (defn str @@ -471,7 +486,8 @@ x.toString(). (str nil) returns the empty string. With more than one arg, returns the concatenation of the str values of the args." {:tag String - :added "1.0"} + :added "1.0" + :static true} ([] "") ([^Object x] (if (nil? x) "" (. x (toString)))) @@ -483,20 +499,23 @@ (new StringBuilder ^String (str x)) ys))) -(defn ^:static symbol? +(defn symbol? "Return true if x is a Symbol" - {:added "1.0"} + {:added "1.0" + :static true} [x] (instance? clojure.lang.Symbol x)) -(defn ^:static keyword? +(defn keyword? "Return true if x is a Keyword" - {:added "1.0"} + {:added "1.0" + :static true} [x] (instance? clojure.lang.Keyword x)) -(defn ^:static symbol +(defn symbol "Returns a Symbol with the given namespace and name." {:tag clojure.lang.Symbol - :added "1.0"} + :added "1.0" + :static true} ([name] (if (symbol? name) name (clojure.lang.Symbol/intern name))) ([ns name] (clojure.lang.Symbol/intern ns name))) @@ -504,7 +523,8 @@ "Returns a new symbol with a unique name. If a prefix string is supplied, the name is prefix# where # is some unique number. If prefix is not supplied, the prefix is 'G__'." - {:added "1.0"} + {:added "1.0" + :static true} ([] (gensym "G__")) ([prefix-string] (. clojure.lang.Symbol (intern (str prefix-string (str (. clojure.lang.RT (nextID)))))))) @@ -523,18 +543,20 @@ "cond requires an even number of forms"))) (cons 'clojure.core/cond (next (next clauses)))))) -(defn ^:static keyword +(defn keyword "Returns a Keyword with the given namespace and name. Do not use : in the keyword strings, it will be added automatically." {:tag clojure.lang.Keyword - :added "1.0"} + :added "1.0" + :static true} ([name] (cond (keyword? name) name (symbol? name) (clojure.lang.Keyword/intern ^clojure.lang.Symbol name) (string? name) (clojure.lang.Keyword/intern ^String name))) ([ns name] (clojure.lang.Keyword/intern ns name))) (defn spread - {:private true} + {:private true + :static true} [arglist] (cond (nil? arglist) nil @@ -544,7 +566,8 @@ (defn list* "Creates a new list containing the items prepended to the rest, the last of which will be treated as a sequence." - {:added "1.0"} + {:added "1.0" + :static true} ([args] (seq args)) ([a args] (cons a args)) ([a b args] (cons a (cons b args))) @@ -553,9 +576,9 @@ (cons a (cons b (cons c (cons d (spread more))))))) (defn apply - "Applies fn f to the argument list formed by prepending args to argseq." - {:arglists '([f args* argseq]) - :added "1.0"} + "Applies fn f to the argument list formed by prepending intervening arguments to args." + {:added "1.0" + :static true} ([^clojure.lang.IFn f args] (. f (applyTo (seq args)))) ([^clojure.lang.IFn f x args] @@ -570,7 +593,8 @@ (defn vary-meta "Returns an object of the same type and value as obj, with (apply f (meta obj) args) as its metadata." - {:added "1.0"} + {:added "1.0" + :static true} [obj f & args] (with-meta obj (apply f (meta obj) args))) @@ -583,8 +607,7 @@ [& body] (list 'new 'clojure.lang.LazySeq (list* '^{:once true} fn* [] body))) -(defn ;^clojure.lang.ChunkBuffer - ^:static chunk-buffer [capacity] +(defn ^:static chunk-buffer [capacity] (clojure.lang.ChunkBuffer. capacity)) (defn ^:static chunk-append [^clojure.lang.ChunkBuffer b x] @@ -593,16 +616,13 @@ (defn ^:static chunk [^clojure.lang.ChunkBuffer b] (.chunk b)) -(defn ;^clojure.lang.IChunk - ^:static chunk-first [^clojure.lang.IChunkedSeq s] +(defn ^:static chunk-first [^clojure.lang.IChunkedSeq s] (.chunkedFirst s)) -(defn ;^clojure.lang.ISeq - ^:static chunk-rest [^clojure.lang.IChunkedSeq s] +(defn ^:static chunk-rest [^clojure.lang.IChunkedSeq s] (.chunkedMore s)) -(defn ;^clojure.lang.ISeq - ^:static chunk-next [^clojure.lang.IChunkedSeq s] +(defn ^:static chunk-next [^clojure.lang.IChunkedSeq s] (.chunkedNext s)) (defn ^:static chunk-cons [chunk rest] @@ -615,7 +635,8 @@ (defn concat "Returns a lazy seq representing the concatenation of the elements in the supplied colls." - {:added "1.0"} + {:added "1.0" + :static true} ([] (lazy-seq nil)) ([x] (lazy-seq x)) ([x y] @@ -649,14 +670,16 @@ [& body] (list 'new 'clojure.lang.Delay (list* `^{:once true} fn* [] body))) -(defn ^:static delay? +(defn delay? "returns true if x is a Delay created with delay" - {:added "1.0"} + {:added "1.0" + :static true} [x] (instance? clojure.lang.Delay x)) -(defn ^:static force +(defn force "If x is a Delay, returns the (possibly cached) value of its expression, else returns x" - {:added "1.0"} + {:added "1.0" + :static true} [x] (. clojure.lang.Delay (force x))) (defmacro if-not @@ -695,7 +718,8 @@ (defn not= "Same as (not (= obj1 obj2))" {:tag Boolean - :added "1.0"} + :added "1.0" + :static true} ([x] false) ([x y] (not (= x y))) ([x y & more] @@ -811,9 +835,10 @@ (recur f (f val (first s)) (next s))) val))))) -(defn ^:static reverse +(defn reverse "Returns a seq of the items in coll in reverse order. Not lazy." - {:added "1.0"} + {:added "1.0" + :static true} [coll] (reduce conj () coll)) @@ -923,7 +948,8 @@ (defn max "Returns the greatest of the nums." - {:added "1.0"} + {:added "1.0" + :static true} ([x] x) ([x y] (if (> x y) x y)) ([x y & more] @@ -931,7 +957,8 @@ (defn min "Returns the least of the nums." - {:added "1.0"} + {:added "1.0" + :static true} ([x] x) ([x y] (if (< x y) x y)) ([x y & more] @@ -1013,21 +1040,24 @@ :added "1.0"} [x] (. clojure.lang.Numbers (isNeg x))) -(defn ^:static quot +(defn quot "quot[ient] of dividing numerator by denominator." - {:added "1.0"} + {:added "1.0" + :static true} [num div] (. clojure.lang.Numbers (quotient num div))) -(defn ^:static rem +(defn rem "remainder of dividing numerator by denominator." - {:added "1.0"} + {:added "1.0" + :static true} [num div] (. clojure.lang.Numbers (remainder num div))) -(defn ^:static rationalize +(defn rationalize "returns the rational value of num" - {:added "1.0"} + {:added "1.0" + :static true} [num] (. clojure.lang.Numbers (rationalize num))) @@ -1058,30 +1088,35 @@ :added "1.0"} [x y] (. clojure.lang.Numbers xor x y)) -(defn ^:static bit-and-not +(defn bit-and-not "Bitwise and with complement" - {:added "1.0"} + {:added "1.0" + :static true} [x y] (. clojure.lang.Numbers andNot x y)) -(defn ^:static bit-clear +(defn bit-clear "Clear bit at index n" - {:added "1.0"} + {:added "1.0" + :static true} [x n] (. clojure.lang.Numbers clearBit x n)) -(defn ^:static bit-set +(defn bit-set "Set bit at index n" - {:added "1.0"} + {:added "1.0" + :static true} [x n] (. clojure.lang.Numbers setBit x n)) -(defn ^:static bit-flip +(defn bit-flip "Flip bit at index n" - {:added "1.0"} + {:added "1.0" + :static true} [x n] (. clojure.lang.Numbers flipBit x n)) -(defn ^:static bit-test +(defn bit-test "Test bit at index n" - {:added "1.0"} + {:added "1.0" + :static true} [x n] (. clojure.lang.Numbers testBit x n)) @@ -1097,23 +1132,26 @@ :added "1.0"} [x n] (. clojure.lang.Numbers shiftRight x n)) -(defn ^:static even? +(defn even? "Returns true if n is even, throws an exception if n is not an integer" - {:added "1.0"} + {:added "1.0" + :static true} [n] (zero? (bit-and n 1))) -(defn ^:static odd? +(defn odd? "Returns true if n is odd, throws an exception if n is not an integer" - {:added "1.0"} + {:added "1.0" + :static true} [n] (not (even? n))) ;; -(defn ^:static complement +(defn complement "Takes a fn f and returns a fn that takes the same arguments as f, has the same effects, if any, and returns the opposite truth value." - {:added "1.0"} + {:added "1.0" + :static true} [f] (fn ([] (not (f))) @@ -1121,49 +1159,50 @@ ([x y] (not (f x y))) ([x y & zs] (not (apply f x y zs))))) -(defn ^:static constantly +(defn constantly "Returns a function that takes any number of arguments and returns x." - {:added "1.0"} + {:added "1.0" + :static true} [x] (fn [& args] x)) -(defn ^:static identity +(defn identity "Returns its argument." - {:added "1.0"} + {:added "1.0" + :static true} [x] x) ;;Collection stuff - - - - ;;list stuff -(defn ^:static peek +(defn peek "For a list or queue, same as first, for a vector, same as, but much more efficient than, last. If the collection is empty, returns nil." - {:added "1.0"} + {:added "1.0" + :static true} [coll] (. clojure.lang.RT (peek coll))) -(defn ^:static pop +(defn 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 as next/butlast." - {:added "1.0"} + {:added "1.0" + :static true} [coll] (. clojure.lang.RT (pop coll))) ;;map stuff -(defn ^:static contains? +(defn 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 range of indexes. 'contains?' operates constant or logarithmic time; it will not perform a linear search for a value. See also 'some'." - {:added "1.0"} + {:added "1.0" + :static true} [coll key] (. clojure.lang.RT (contains coll key))) -(defn ^:static get +(defn get "Returns the value mapped to key, not-found or nil if key not present." {:inline (fn [m k & nf] `(. clojure.lang.RT (get ~m ~k ~@nf))) :inline-arities #{2 3} @@ -1176,7 +1215,8 @@ (defn dissoc "dissoc[iate]. Returns a new map of the same (hashed/sorted) type, that does not contain a mapping for key(s)." - {:added "1.0"} + {:added "1.0" + :static true} ([map] map) ([map key] (. clojure.lang.RT (dissoc map key))) @@ -1189,7 +1229,8 @@ (defn disj "disj[oin]. Returns a new set of the same (hashed/sorted) type, that does not contain key(s)." - {:added "1.0"} + {:added "1.0" + :static true} ([set] set) ([^clojure.lang.IPersistentSet set key] (when set @@ -1201,14 +1242,16 @@ (recur ret (first ks) (next ks)) ret))))) -(defn ^:static find +(defn find "Returns the map entry for key, or nil if key not present." - {:added "1.0"} + {:added "1.0" + :static true} [map key] (. clojure.lang.RT (find map key))) -(defn ^:static select-keys +(defn select-keys "Returns a map containing only those entries in map whose key is in keys" - {:added "1.0"} + {:added "1.0" + :static true} [map keyseq] (loop [ret {} keys (seq keyseq)] (if keys @@ -1220,46 +1263,53 @@ (next keys))) ret))) -(defn ^:static keys +(defn keys "Returns a sequence of the map's keys." - {:added "1.0"} + {:added "1.0" + :static true} [map] (. clojure.lang.RT (keys map))) -(defn ^:static vals +(defn vals "Returns a sequence of the map's values." - {:added "1.0"} + {:added "1.0" + :static true} [map] (. clojure.lang.RT (vals map))) -(defn ^:static key +(defn key "Returns the key of the map entry." - {:added "1.0"} + {:added "1.0" + :static true} [^java.util.Map$Entry e] (. e (getKey))) -(defn ^:static val +(defn val "Returns the value in the map entry." - {:added "1.0"} + {:added "1.0" + :static true} [^java.util.Map$Entry e] (. e (getValue))) -(defn ^:static rseq +(defn rseq "Returns, in constant time, a seq of the items in rev (which can be a vector or sorted-map), in reverse order. If rev is empty returns nil" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.Reversible rev] (. rev (rseq))) -(defn ^:static name +(defn name "Returns the name String of a string, symbol or keyword." {:tag String - :added "1.0"} + :added "1.0" + :static true} [x] (if (string? x) x (. ^clojure.lang.Named x (getName)))) -(defn ^:static namespace +(defn namespace "Returns the namespace String of a symbol or keyword, or nil if not present." {:tag String - :added "1.0"} + :added "1.0" + :static true} [^clojure.lang.Named x] (. x (getNamespace))) @@ -1367,39 +1417,45 @@ [multifn dispatch-val & fn-tail] `(. ~(with-meta multifn {:tag 'clojure.lang.MultiFn}) addMethod ~dispatch-val (fn ~@fn-tail))) -(defn ^:static remove-all-methods +(defn remove-all-methods "Removes all of the methods of multimethod." - {:added "1.2"} + {:added "1.2" + :static true} [^clojure.lang.MultiFn multifn] (.reset multifn)) -(defn ^:static remove-method +(defn remove-method "Removes the method of multimethod associated with dispatch-value." - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.MultiFn multifn dispatch-val] (. multifn removeMethod dispatch-val)) -(defn ^:static prefer-method +(defn prefer-method "Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y when there is a conflict" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.MultiFn multifn dispatch-val-x dispatch-val-y] (. multifn preferMethod dispatch-val-x dispatch-val-y)) -(defn ^:static methods +(defn methods "Given a multimethod, returns a map of dispatch values -> dispatch fns" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.MultiFn multifn] (.getMethodTable multifn)) -(defn ^:static get-method +(defn get-method "Given a multimethod and a dispatch value, returns the dispatch fn that would apply to that value, or nil if none apply and no default" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.MultiFn multifn dispatch-val] (.getMethod multifn dispatch-val)) -(defn ^:static prefers +(defn prefers "Given a multimethod, returns a map of preferred value -> set of other values" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.MultiFn multifn] (.getPreferTable multifn)) ;;;;;;;;; var stuff @@ -1446,7 +1502,7 @@ (let [~form temp#] ~@body))))) -(defn ^:static push-thread-bindings +(defn push-thread-bindings "WARNING: This is a low-level function. Prefer high-level macros like binding where ever possible. @@ -1459,21 +1515,24 @@ ... (finally (pop-thread-bindings)))" - {:added "1.1"} + {:added "1.1" + :static true} [bindings] (clojure.lang.Var/pushThreadBindings bindings)) -(defn ^:static pop-thread-bindings +(defn 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"} + {:added "1.1" + :static true} [] (clojure.lang.Var/popThreadBindings)) -(defn ^:static get-thread-bindings +(defn get-thread-bindings "Get a map with the Var/value pairs which is currently in effect for the current thread." - {:added "1.1"} + {:added "1.1" + :static true} [] (clojure.lang.Var/getThreadBindings)) @@ -1507,7 +1566,8 @@ "Takes a map of Var/value pairs. Installs for the given Vars the associated values as thread-local bindings. Then calls f with the supplied arguments. Pops the installed bindings after f returned. Returns whatever f returns." - {:added "1.1"} + {:added "1.1" + :static true} [binding-map f & args] (push-thread-bindings binding-map) (try @@ -1523,12 +1583,13 @@ [binding-map & body] `(with-bindings* ~binding-map (fn [] ~@body))) -(defn ^:static bound-fn* +(defn 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 different thread, but needs the same bindings in place." - {:added "1.1"} + {:added "1.1" + :static true} [f] (let [bindings (get-thread-bindings)] (fn [& args] @@ -1543,10 +1604,11 @@ [& fntail] `(bound-fn* (fn ~@fntail))) -(defn ^:static find-var +(defn find-var "Returns the global var named by the namespace-qualified symbol, or nil if no var with that name." - {:added "1.0"} + {:added "1.0" + :static true} [sym] (. clojure.lang.Var (find sym))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Refs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1581,7 +1643,9 @@ :continue (the default if an error-handler is given) or :fail (the default if no error-handler is given) -- see set-error-mode! for details." - {:added "1.0"} + {:added "1.0" + ;:static true ;can't due to keyword callsite + } ([state & options] (let [a (new clojure.lang.Agent state) opts (apply hash-map options)] @@ -1598,7 +1662,8 @@ will be set to the value of: (apply action-fn state-of-agent args)" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.Agent a f & args] (. a (dispatch f args false))) @@ -1608,21 +1673,23 @@ the agent will be set to the value of: (apply action-fn state-of-agent args)" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.Agent a f & args] (. a (dispatch f args true))) -(defn ^:static release-pending-sends +(defn 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 actions immediately. This has no impact on actions sent during a transaction, which are still held until commit. If no action is occurring, does nothing. Returns the number of actions dispatched." - {:added "1.0"} + {:added "1.0" + :static true} [] (clojure.lang.Agent/releasePendingSends)) -(defn ^:static add-watch +(defn 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 @@ -1637,21 +1704,24 @@ set!s. Keys must be unique per reference, and can be used to remove the watch with remove-watch, but are otherwise considered opaque by the watch mechanism." - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.IRef reference key fn] (.addWatch reference key fn)) -(defn ^:static remove-watch +(defn remove-watch "Alpha - subject to change. Removes a watch (set by add-watch) from a reference" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.IRef reference key] (.removeWatch reference key)) -(defn ^:static agent-error +(defn 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." - {:added "1.2"} + {:added "1.2" + :static true} [^clojure.lang.Agent a] (.getError a)) (defn restart-agent @@ -1664,28 +1734,32 @@ agent will remain failed with its old state and error. Watchers, if any, will NOT be notified of the new state. Throws an exception if the agent is not failed." - {:added "1.2"} + {:added "1.2" + ;:static true ;can't due to keyword callsite + } [^clojure.lang.Agent a, new-state & options] (let [opts (apply hash-map options)] (.restart a new-state (if (:clear-actions opts) true false)))) -(defn ^:static set-error-handler! +(defn 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 agent and the exception." - {:added "1.2"} + {:added "1.2" + :static true} [^clojure.lang.Agent a, handler-fn] (.setErrorHandler a handler-fn)) -(defn ^:static error-handler +(defn error-handler "Returns the error-handler of agent a, or nil if there is none. See set-error-handler!" - {:added "1.2"} + {:added "1.2" + :static true} [^clojure.lang.Agent a] (.getErrorHandler a)) -(defn ^:static set-error-mode! +(defn 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 @@ -1697,13 +1771,15 @@ accepting new 'send' and 'send-off' actions, and any previously queued actions will be held until a 'restart-agent'. Deref will still work, returning the state of the agent before the error." - {:added "1.2"} + {:added "1.2" + :static true} [^clojure.lang.Agent a, mode-keyword] (.setErrorMode a mode-keyword)) -(defn ^:static error-mode +(defn error-mode "Returns the error-mode of agent a. See set-error-mode!" - {:added "1.2"} + {:added "1.2" + :static true} [^clojure.lang.Agent a] (.getErrorMode a)) @@ -1725,11 +1801,12 @@ :deprecated "1.2"} [^clojure.lang.Agent a] (restart-agent a (.deref a))) -(defn ^:static shutdown-agents +(defn shutdown-agents "Initiates a shutdown of the thread pools that back the agent system. Running actions will complete, but no new actions will be accepted" - {:added "1.0"} + {:added "1.0" + :static true} [] (. clojure.lang.Agent shutdown)) (defn ref @@ -1755,7 +1832,9 @@ set :min-history to ensure it will be available when first needed (instead of after a read fault). History is limited, and the limit can be set with :max-history." - {:added "1.0"} + {:added "1.0" + ;:static true ;can't due to keyword callsite + } ([x] (new clojure.lang.Ref x)) ([x & options] (let [r ^clojure.lang.Ref (setup-reference (ref x) options) @@ -1766,14 +1845,15 @@ (.setMinHistory r (:min-history opts))) r))) -(defn ^:static deref +(defn 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 or atom, returns its current state. When applied to a delay, forces it if not already forced. When applied to a future, will block if computation not complete" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.IDeref ref] (.deref ref)) (defn atom @@ -1789,7 +1869,8 @@ argument, which will be passed the intended new state on any state change. If the new state is unacceptable, the validate-fn should return false or throw an exception." - {:added "1.0"} + {:added "1.0" + :static true} ([x] (new clojure.lang.Atom x)) ([x & options] (setup-reference (atom x) options))) @@ -1798,38 +1879,43 @@ (apply f current-value-of-atom args). Note that f may be called multiple times, and thus should be free of side effects. Returns the value that was swapped in." - {:added "1.0"} + {:added "1.0" + :static true} ([^clojure.lang.Atom atom f] (.swap atom f)) ([^clojure.lang.Atom atom f x] (.swap atom f x)) ([^clojure.lang.Atom atom f x y] (.swap atom f x y)) ([^clojure.lang.Atom atom f x y & args] (.swap atom f x y args))) -(defn ^:static compare-and-set! +(defn 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"} + {:added "1.0" + :static true} [^clojure.lang.Atom atom oldval newval] (.compareAndSet atom oldval newval)) -(defn ^:static reset! +(defn reset! "Sets the value of atom to newval without regard for the current value. Returns newval." - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.Atom atom newval] (.reset atom newval)) -(defn ^:static set-validator! +(defn 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 validator-fn should return false or throw an exception. If the current state (root value if var) is not acceptable to the new validator, an exception will be thrown and the validator will not be changed." - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.IRef iref validator-fn] (. iref (setValidator validator-fn))) -(defn ^:static get-validator +(defn get-validator "Gets the validator-fn for a var/ref/agent/atom." - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.IRef iref] (. iref (getValidator))) (defn alter-meta! @@ -1838,12 +1924,14 @@ (apply f its-current-meta args) f must be free of side-effects" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.IReference iref f & args] (.alterMeta iref f args)) -(defn ^:static reset-meta! +(defn reset-meta! "Atomically resets the metadata for a namespace/var/ref/agent/atom" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.IReference iref metadata-map] (.resetMeta iref metadata-map)) (defn commute @@ -1861,7 +1949,8 @@ Thus fun should be commutative, or, failing that, you must accept last-one-in-wins behavior. commute allows for more concurrency than ref-set." - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.Ref ref fun & args] (. ref (commute fun args))) @@ -1873,44 +1962,50 @@ (apply fun in-transaction-value-of-ref args) and returns the in-transaction-value of ref." - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.Ref ref fun & args] (. ref (alter fun args))) -(defn ^:static ref-set +(defn ref-set "Must be called in a transaction. Sets the value of ref. Returns val." - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.Ref ref val] (. ref (set val))) -(defn ^:static ref-history-count +(defn ref-history-count "Returns the history count of a ref" - {:added "1.1"} + {:added "1.1" + :static true} [^clojure.lang.Ref ref] (.getHistoryCount ref)) -(defn ^:static ref-min-history +(defn ref-min-history "Gets the min-history of a ref, or sets it and returns the ref" - {:added "1.1"} + {:added "1.1" + :static true} ([^clojure.lang.Ref ref] (.getMinHistory ref)) ([^clojure.lang.Ref ref n] (.setMinHistory ref n))) -(defn ^:static ref-max-history +(defn ref-max-history "Gets the max-history of a ref, or sets it and returns the ref" - {:added "1.1"} + {:added "1.1" + :static true} ([^clojure.lang.Ref ref] (.getMaxHistory ref)) ([^clojure.lang.Ref ref n] (.setMaxHistory ref n))) -(defn ^:static ensure +(defn 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)" - {:added "1.0"} + {:added "1.0" + :static true} [^clojure.lang.Ref ref] (. ref (touch)) (. ref (deref))) @@ -1950,7 +2045,8 @@ of those fns. The returned fn takes a variable number of args, applies the rightmost of fns to the args, the next fn (right-to-left) to the result, etc." - {:added "1.0"} + {:added "1.0" + :static true} ([f] f) ([f g] (fn |