From 2e08cf39dc574e31898ba914dc29be09f07cbbbb Mon Sep 17 00:00:00 2001
From: EXPORTS-bot
Date: Wed, 30 Aug 2023 01:47:39 +0000
Subject: [PATCH] Updated exports
---
exports/export.compact.edn | 3 ++-
exports/export.compact.min.edn | 2 +-
exports/export.edn | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/exports/export.compact.edn b/exports/export.compact.edn
index 05b6c47..8cb4cdd 100644
--- a/exports/export.compact.edn
+++ b/exports/export.compact.edn
@@ -10157,7 +10157,8 @@
:clojure.core/get-method
:clojure.core/defprotocol
:clojure.core/make-hierarchy
- :clojure.spec/multi-spec],
+ :clojure.spec/multi-spec
+ :clojure.core/derive],
:line 1725,
:examples
[";; Define the multimethod\n(defmulti service-charge (juxt account-level :tag))\n\n;; Handlers for resulting dispatch values\n(defmethod service-charge [::acc/Basic ::acc/Checking] [_] 25)\n(defmethod service-charge [::acc/Basic ::acc/Savings] [_] 10)\n(defmethod service-charge [::acc/Premium ::acc/Account] [_] 0)"
diff --git a/exports/export.compact.min.edn b/exports/export.compact.min.edn
index 6016954..66c97f7 100644
--- a/exports/export.compact.min.edn
+++ b/exports/export.compact.min.edn
@@ -1 +1 @@
-{:clojure.test/do-report {:added "1.2", :ns "clojure.test", :name "do-report", :file "clojure/test.clj", :type "function", :column 1, :see-alsos nil, :line 351, :examples nil, :notes nil, :arglists ["m"], :doc "Add file and line information to a test result and call report.\n If you are writing a custom assert-expr method, call this function\n to pass test results to report.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/do-report"}, :clojure.core/ns-unalias {:added "1.0", :ns "clojure.core", :name "ns-unalias", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/alias :clojure.core/ns-aliases :clojure.core/ns-unmap], :line 4281, :examples [";; You are having a problem loading a redefined namespace:\nuser=> (load \"src/clj/com/tizra/layout_expander.clj\")\n#\n\n;; ns-unalias to the rescue!\nuser=> (ns-unalias (find-ns 'com.tizra.layout-expander) 'xml)\nnil\n\nuser=> (load \"src/clj/com/tizra/layout_expander.clj\")\n#'com.tizra.layout-expander/junk\n" "user=> (ns-aliases *ns*)\n{}\nuser=> (alias 'string 'clojure.string)\nnil\nuser=> (ns-aliases *ns*)\n{string #}\nuser=> (ns-unalias *ns* 'string)\nnil\nuser=> (ns-aliases *ns*)\n{}" ";; To wipe aliases of current namespace:\n*my-ns*=> (map (partial ns-unalias *ns*) (keys (ns-aliases *ns*)))"], :notes nil, :arglists ["ns sym"], :doc "Removes the alias for the symbol from the namespace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ns-unalias"}, :clojure.core/number? {:added "1.0", :ns "clojure.core", :name "number?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/num :clojure.core/integer?], :line 3559, :examples ["user=> (number? 1)\ntrue\nuser=> (number? 1.0)\ntrue\nuser=> (number? :a)\nfalse\nuser=> (number? nil)\nfalse\nuser=> (number? \"23\")\nfalse\n\n" ";; map number? over the vector\n(map number? [1 0.44 3e6 0xFF])\n;;=> (true true true true)\n\n;; map number? over the vector created by converting a list into a vector \n;; with the function \"into\"\n(map number? (into [] '(1 0.44 3e6 0xFF)))\n;;=> (true true true true)\n\n" ";; Works for rationals\nuser=> (number? (/ 2 3))\ntrue"], :notes nil, :arglists ["x"], :doc "Returns true if x is a Number", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/number_q"}, :clojure.core/set? {:added "1.0", :ns "clojure.core", :name "set?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/set :clojure.core/map? :clojure.core/vector?], :line 4099, :examples ["user> (set? #{1 2 3})\ntrue\n\nuser> (set? (hash-set 1 2 3))\ntrue\n\nuser> (set? (sorted-set 1 2 3))\ntrue\n\nuser> (set? [1 2 3])\nfalse\n\nuser> (set? {:a 1 :b 2})\nfalse"], :notes nil, :arglists ["x"], :doc "Returns true if x implements IPersistentSet", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/set_q"}, :clojure.reflect/flag-descriptors {:ns "clojure.reflect", :name "flag-descriptors", :file "clojure/reflect/java.clj", :type "var", :column 1, :see-alsos nil, :line 77, :examples ["(use 'clojure.reflect)\n\n(pprint clojure.reflect/flag-descriptors)\n;;=> [{:name :public, :flag 1, :contexts #{:method :field :class}}\n;; {:name :private, :flag 2, :contexts #{:method :field :class}}\n;; {:name :protected, :flag 4, :contexts #{:method :field :class}}\n;; {:name :static, :flag 8, :contexts #{:method :field}}\n;; {:name :final, :flag 16, :contexts #{:method :field :class}}\n;; {:name :synchronized, :flag 32, :contexts #{:method}}\n;; {:name :volatile, :flag 64, :contexts #{:field}}\n;; {:name :bridge, :flag 64, :contexts #{:method}}\n;; {:name :varargs, :flag 128, :contexts #{:method}}\n;; {:name :transient, :flag 128, :contexts #{:field}}\n;; {:name :native, :flag 256, :contexts #{:method}}\n;; {:name :interface, :flag 512, :contexts #{:class}}\n;; {:name :abstract, :flag 1024, :contexts #{:method :class}}\n;; {:name :strict, :flag 2048, :contexts #{:method}}\n;; {:name :synthetic, :flag 4096, :contexts #{:method :field :class}}\n;; {:name :annotation, :flag 8192, :contexts #{:class}}\n;; {:name :enum, :flag 16384, :contexts #{:field :inner :class}}]"], :notes ["The value of the `:flag` field for each modifier is identical to the value of the constant representing the modifier in [`java.lang.reflect.Modifier`](https://docs.oracle.com/javase/8/docs/api/java/lang/reflect/Modifier.html#field.summary), which in turn is taken from [Table 4.1-A](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.1-200-E.1), [Table 4.5-A](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.5-200-A.1), [Table 4.6-A](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.6-200-A.1) and [Table 4.7.6-A](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.6-300-D.1-D.1) of *The Java™ Virtual Machine Specification.*\n"], :arglists [], :doc "The Java access bitflags, along with their friendly names and\nthe kinds of objects to which they can apply.", :library-url "https://github.com/clojure/clojure", :href "/clojure.reflect/flag-descriptors"}, :clojure.core/reduced? {:added "1.5", :ns "clojure.core", :name "reduced?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/reduced :clojure.core/reduce :clojure.core/unreduced :clojure.core/ensure-reduced], :line 2842, :examples ["(reduced? :foo)\n;;=> false\n\n(reduced? (reduced :foo))\n;;=> true\n\n(reduced? (clojure.lang.Reduced. :foo))\n;;=> true"], :notes nil, :arglists ["x"], :doc "Returns true if x is the result of a call to reduced", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reduced_q"}, :clojure.core/int-array {:added "1.0", :ns "clojure.core", :name "int-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/ints :clojure.core/aget :clojure.core/aset :clojure.core/aset-int], :line 5332, :examples [";; if you have a sequence, perhaps lazy, int-array will figure out the size\n(aget (int-array [1 2 3]) 0)\n;;=> 1\n(int-array [1 2 3])\n;;=> \n\n;; if you need a certain size, with a constant initial value\n(aget (int-array 5 1) 4)\n;;=> 1\n(alength (int-array 5))\n;;=> 5\n\n;; finally, you can specify a size + a sequence, which will initialize the array \n;; by taking size from the sequence\n(alength (int-array 5 (range 10)))\n;;=> 5\n;; which is equivalent to\n(alength (int-array (take 5 (range 10)))\n;;=> 5\n"], :notes nil, :arglists ["size-or-seq" "size init-val-or-seq"], :doc "Creates an array of ints", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/int-array"}, :clojure.core.async/do-alt {:ns "clojure.core.async", :name "do-alt", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 302, :examples nil, :notes nil, :arglists ["alts clauses"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/do-alt"}, :clojure.core/nthnext {:added "1.0", :ns "clojure.core", :name "nthnext", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/nth :clojure.core/drop :clojure.core/nthrest], :line 3164, :examples ["(nthnext (range 10) 3)\n;;=> (3 4 5 6 7 8 9)\n\n(nthnext [] 3)\n;;=> nil\n\n(nthnext [1 2 3 4 5 6 7] 4)\n;;=> (5 6 7)\n\n" ";; drop is also similar, but different \n(nthnext (range 10) 5) ;;=> (5 6 7 8 9)\n(drop 5 (range 10)) ;;=> (5 6 7 8 9)\n\n;; here is a case where the results differ\n(nthnext [] 3) ;;=> nil\n(drop 3 []) ;;=> () ; a lazy sequence"], :notes ["`nthnext` is similar to `drop`.\r\nBut `nthnext` is eager, while `drop` is lazy.
\r\nAlso parameters are in opposite order."], :arglists ["coll n"], :doc "Returns the nth next of coll, (seq coll) when n is 0.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/nthnext"}, :clojure.core.logic/copy-term {:ns "clojure.core.logic", :name "copy-term", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1439, :examples nil, :notes nil, :arglists ["u v"], :doc "Copies a term u into v. Non-relational.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/copy-term"}, :clojure.spec.alpha/map-of {:ns "clojure.spec.alpha", :name "map-of", :file "clojure/spec/alpha.clj", :type "macro", :column 1, :see-alsos [:clojure.spec.alpha/every-kv :clojure.spec.alpha/every :clojure.spec.alpha/coll-of], :line 587, :examples ["(require '[clojure.spec.alpha :as spec])\n\n(spec/def ::animals (spec/map-of #{:duck :cat :chicken} (spec/and int? #(> % 1))))\n\n(spec/valid? ::animals {:duck 2})\n\n;;=> true\n\n(spec/valid? ::animals {:duck 1})\n\n;;=> false" ";; Validating that the value of a map is related to the key \n;; can not normally be done with map-of as the predicates \n;; are applied independently.\n\n(require '[clojure.spec.alpha :as s])\n(require '[clojure.spec.gen.alpha :as gen])\n\n(s/def ::id pos-int?)\n(s/def ::name string?)\n\n(s/def ::tag (s/keys :req-un [::id ::name]))\n(s/def ::tags (s/map-of ::id ::tag))\n\n(gen/sample (s/gen ::tags))\n;; => ({1 {:id 2, :name \"\"}, 2 {:id 3, :name \"\"}}...)\n\n;; The key has no relation to the value.\n\n;; Lets try again and add in another spec that validates the key and value\n(s/def ::tags (s/and \n (s/map-of ::id ::tag) \n (s/every (fn [[k v]] (= (:id v) k)))))\n\n(s/valid? ::tags {101 {:id 101 :name \"foo\"}})\n;; => true\n(s/valid? ::tags {33 {:id 101 :name \"foo\"}})\n;; => false\n\n(s/explain ::tags {33 {:id 101 :name \"foo\"}})\n;; => [33 {:id 101, :name \"foo\"}] - failed: (fn [[k v]] (= (:id v) k)) in: [0] ;; ;; => spec: :user/tags\n\n;; Spec seems good - lets try generators\n\n(gen/sample (s/gen ::tags))\n;; => #error {:message \"Couldn't satisfy such-that predicate after 100 tries.\", :data {}}...\n\n;; Dang, must create a generator ourselves.\n\n(s/def ::tags (s/with-gen\n (s/and\n (s/map-of ::id ::tag)\n (s/every (fn [[k v]](= (:id v) k))))\n #(gen/fmap (fn [c]\n ;; Create a map from the collection\n (apply hash-map (->> c\n (map (juxt :id identity))\n (flatten))))\n ;; Generates a collection of the generated vals\n (s/gen (s/coll-of ::tag))))) \n\n(gen/sample (s/gen ::tags))\n;; =>({2 {:id 2, :name \"wx3p3BPir\"},\n;; => 3 {:id 3, :name \"jq8\"},\n;; => 4 {:id 4, :name \"q3I\"},\n;; => 38 {:id 38, :name \"dhPlIf4\"},\n;; => 7 {:id 7, :name \"t\"},\n;; => 67 {:id 167, :name \"KS9uDEYS\"},\n;; => 11 {:id 11, :name \"\"}, \n;; => 147 {:id 147, :name \"hmSAKGpZ\"}}...)"], :macro true, :notes nil, :arglists ["kpred vpred & opts"], :doc "Returns a spec for a map whose keys satisfy kpred and vals satisfy\n vpred. Unlike 'every-kv', map-of will exhaustively conform every\n value.\n\n Same options as 'every', :kind defaults to map?, with the addition of:\n\n :conform-keys - conform keys as well as values (default false)\n\n See also - every-kv", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/map-of"}, :clojure.core/ex-cause {:added "1.10", :ns "clojure.core", :name "ex-cause", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/ex-info :clojure.core/ex-data :clojure.core/ex-message], :line 4808, :examples [";; (ex-cause e) gives you the next linked exception in an Exception-chain\n;; Use \n(def a 1) ;;=> #'user/a\n(def b 0) ;;=> #'user/b\n\n(def chain \n (try \n (/ a b)\n (catch ArithmeticException ae\n (ex-info ;; contextualize ae with ExceptionInfo\n \"Send help, please\"\n {:divisor a\n :divident b}\n ae)))) \n;;=> #'user/chain\n\nchain\n;;=>\n;#error{:cause \"Divide by zero\",\n; :via [{:type clojure.lang.ExceptionInfo,\n; :message \"Send help, please\",\n; :data {:divisor 1, :divident 0},\n; :at [...]}\n; {:type java.lang.ArithmeticException,\n; :message \"Divide by zero\",\n; :at [clojure.lang.Numbers divide \"Numbers.java\" 188]}],\n; :trace [[clojure.lang.Numbers divide \"Numbers.java\" 188]\n; [...]\n; [java.lang.Thread run \"Thread.java\" 829]]}\n\n(ex-cause chain)\n;;=>\n;#error{:cause \"Divide by zero\",\n; :via [{:type java.lang.ArithmeticException, ;; <-- ae is first.\n; :message \"Divide by zero\",\n; :at [clojure.lang.Numbers divide \"Numbers.java\" 188]}],\n; :trace [[clojure.lang.Numbers divide \"Numbers.java\" 188]\n; [...]" ";; You can use ex-cause to extract the messages of a chain:\n(defn ex-msg-chain [ex delimiter]\n (->> ex\n (iterate ex-cause)\n (take-while some?)\n (mapv ex-message)\n (interpose delimiter)\n (apply str))\n;;=> #'user/ex-msg-chain\n\n;; Let's try this on a simple chained Exception\n(def chained-ex\n (ex-info \"top-level\"\n {:level 1}\n (ex-info \"sec-level\"\n {:level 2}\n (ex-info \"low-level\"\n {:level 3}))))\n;;=> #'user/chained-ex\n\n(ex-msg-chain chained-ex \" -> \")\n;;=> \"top-level -> sec-level -> low-level\""], :notes nil, :arglists ["ex"], :doc "Returns the cause of ex if ex is a Throwable.\n Otherwise returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ex-cause"}, :clojure.core/create-struct {:added "1.0", :ns "clojure.core", :name "create-struct", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/struct :clojure.core/defstruct :clojure.core/defrecord], :line 4038, :examples [";;Creates a person structure\n(def person (create-struct :name :age))\n\n;;Creates a structure with the given values associated with the structure keys\n(struct person \"Brad Cypert\" 23)\n{:name \"Brad Cypert\", :age 23}"], :notes ["Structs are becoming obsolete. Use records instead. See defrecord." "In _general_, records should be preferred over structs. However, structs aren't _entirely_ obsolete.\n\nThey can still be useful when you need/want to create record-like objects dynamically; That is, when you don't know the field names at compile time. A typical example of this might be loading rows from a CSV (as [semantic-csv](https://github.com/metasoarous/semantic-csv) does). The advantage in this case over using regular maps is significantly improved performance creating and using these objects."], :arglists ["& keys"], :doc "Returns a structure basis object.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/create-struct"}, :clojure.core.logic/nilo {:ns "clojure.core.logic", :name "nilo", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1649, :examples nil, :notes nil, :arglists ["a"], :doc "A relation where a is nil", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/nilo"}, :clojure.core.logic/rem-dom {:ns "clojure.core.logic", :name "rem-dom", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 494, :examples nil, :notes nil, :arglists ["s x dom" "s x dom seenset"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/rem-dom"}, :clojure.core/assoc {:added "1.0", :ns "clojure.core", :name "assoc", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/assoc-in :clojure.core/dissoc :clojure.core/merge :clojure.core/update :clojure.core/associative?], :line 181, :examples ["(assoc {} :key1 \"value\" :key2 \"another value\")\n;;=> {:key2 \"another value\", :key1 \"value\"}\n\n;; Here we see an overwrite by a second entry with the same key\n(assoc {:key1 \"old value1\" :key2 \"value2\"} \n :key1 \"value1\" :key3 \"value3\")\n;;=> {:key3 \"value3\", :key2 \"value2\", :key1 \"value1\"}\n\n;; We see a nil being treated as an empty map\n(assoc nil :key1 4)\n;;=> {:key1 4}\n\n;; 'assoc' can be used on a vector (but not a list), in this way: \n;; (assoc vec index replacement)\n(assoc [1 2 3] 0 10) ;;=> [10 2 3]\n(assoc [1 2 3] 2 '(4 6)) ;;=> [1 2 (4 6)]\n;; Next, 0 < index <= n, so the following will work\n(assoc [1 2 3] 3 10) ;;=> [1 2 3 10]\n;; However, when index > n, an error is thrown\n(assoc [1 2 3] 4 10)\n;; java.lang.IndexOutOfBoundsException (NO_SOURCE_FILE:0)\n\n;; From http://clojure-examples.appspot.com/clojure.core/assoc" ";; here is an example of updating a field in a map.\n(def test-map {:account-no 12345678 :lname \"Jones\" :fnam \"Fred\"})\n(assoc test-map :fnam \"Sue\")\n;;=> {:account-no 12345678, :lname \"Jones\", :fnam \"Sue\"}\n\n;; notice that test-map is unchanged\ntest-map\n;;=> {:account-no 12345678 :lname \"Jones\" :fnam \"Fred\"})" ";; beware of this\n(assoc {} nil nil)\n;;=> {nil nil}" ";;transform a map´s values using reduce and assoc\n\n(defn transform\n [coll]\n (reduce (fn [ncoll [k v]]\n (assoc ncoll k (* 10 v)))\n {}\n coll))\n\n(transform {:a 1 :b 2 :c 3})\n;;{:a 10 :b 20 :c 30}\n" ";;assoc applied to a vector\n\n(def my-vec [1 2 5 6 8 9])\n\n(assoc my-vec 0 77)\n;;[77 2 5 6 8 9]\n" ";; convert a vector into a set with assoc\n\n(def book-city {:awards [\"Hugo\" \"World Fantasy Award\" \"Arthur C. Clarke Award\"\n \"British Science Fiction Award\"]\n :title \"The City and the City\"\n :authors [{:birth-year 1972, :name \"China Miéville\"}]})\n\n(assoc book-city :authors (set (:authors book-city)))\n\n;; {:awards [\"Hugo\" \"World Fantasy Award\" \"Arthur C. Clarke Award\" \"British Science Fiction Award\"], :title \"The City and the City\", :authors #{{:birth-year 1972, :name \"China Miéville\"}}}" ";; You can also change multiple keys at once\n\n(def my-map {:name \"Victor\" :age 27 :city \"Barcelona\"})\n\n(assoc my-map :name \"Tom\" :age 47)\n\n;; {:name \"Tom\", :age 47, :city \"Barcelona\"}\n" ";; You can add some more fields (kvs) to your map\n(assoc {:type \"chicken\"} :home \"Kentucky\" :cooking-method \"fried\" :tasty \"definitely\")" ";; add new key-value from original key value\n(let [contact {:name \"kimim\" :home \"Hangzhou\"}\n new-name \"ivy\"]\n (assoc contact :modified? (not (= (contact :name) new-name)) :name new-name))\n;; {:name \"ivy\" :home \"Hangzhou\" :modified? true}\n"], :notes ["Here is a version that will create a vector when the key is numerical.\r\nThis may be useful instead of throwing an IndexOutOfBoundsException.\r\n\r\n
\r\n(defn assoc-in-idx [m [k & ks] v]\r\n (let [value (get m k (when (number? (first ks)) []))\r\n\tm (if (and (vector? m) (number? k) (-> m count (< k)))\r\n\t (reduce (fn [m _] (conj m nil)) m (range (count m) k))\r\n\t m)\r\n\tv (if ks\r\n\t (assoc-in-idx value ks v)\r\n\t v)]\r\n (assoc m k v)))\r\n
\r\n" "the API is blurry When applied to a vector\r\n\r\n
\r\n;; should indicate following\r\n(assoc vector index val)
"], :arglists ["map key val" "map key val & kvs"], :doc "assoc[iate]. When applied to a map, returns a new map of the\n same (hashed/sorted) type, that contains the mapping of key(s) to\n val(s). When applied to a vector, returns a new vector that\n contains val at index. Note - index must be <= (count vector).", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/assoc"}, :clojure.core/comment {:added "1.0", :ns "clojure.core", :name "comment", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos nil, :line 4711, :examples [";; The commented forms do not get executed\nuser=> (comment\n (functioncall-1)\n (functioncall-2))\nnil" ";; What is inside the (comment ...) form is not completely ignored. Clojure\n;; still tries to use the normal reader to read it, so it must consist of\n;; a sequence of readable forms with balanced parens, braces, square brackets,\n;; with no unreadable elements.\n\n;; If you want lines to be completely ignored, you must use a ; to comment from\n;; the ; until the end of the line. If you want to quickly comment or uncomment\n;; a range of consecutive lines, most text editors have special commands\n;; specifically for that. e.g. Emacs has comment-region\n;; http://www.gnu.org/software/emacs/manual/html_node/emacs/Comment-Commands.html\n;; Vim has visual commands to do this, and probably many other text editors.\n;; (Feel free to edit this text to add links to docs for other editors).\n\n;; What is inside the (comment ...) is readable, so no error for this,\n;; and no code will be generated by the compiler.\n(comment\n(defn foo [x]\n (inc x))\n)\n\n;; What is inside the (comment ...) is NOT readable, so this will give an error\n(comment\na : b\n)" ";; Another thing to watch out for: the comment form IS a form, and is usually\n;; the wrong way to comment out code. For example, let's say that you want to\n;; try out a new \"then\" form in an \"if\":\n(if true (comment :old-then) :new-then) ;;=> nil (Oops, :new-then was desired.)\n\n;; Instead, use the \"ignore next form\" reader macro #_:\n(if true #_(:old-then) :new-then) ;;=> :new-then\n\n;; Note that #_ also allows non-readable code:\n#_(a : b) 1 ;;=> 1 (contrast to (comment a : b) which doesn't compile.)\n" ";; You can use comment to work with a journal\n;; (but beware if you want to denote it as a journal)\n\n(comment) ;; works\n(comment ^:journal []) ;; works\n\n;; Doesn't work\n(comment\n ^:journal \n ;; I did some really cool stuff\n)\nERROR Could not Read: Unmatched delimiter )."], :macro true, :notes ["it doesn't 100% ignore the body. If your comment has a map in it, for example, and that map isn't 100% correct it will fail to compile in some environments. I found that using Light Table. I am certain it would fail on other platforms that won't know to exclude it before parsing.\r\n\r\nExample:\r\n(comment\r\n here is some TeX: \\frac{\\sum_{m=1}^{m}x_{m}}{x_{s}}\r\n)\r\n\r\nThat will produce an error."], :arglists ["& body"], :doc "Ignores body, yields nil", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/comment"}, :clojure.core/*compile-files* {:added "1.0", :ns "clojure.core", :name "*compile-files*", :type "var", :see-alsos nil, :examples [";; Ensure that the `require` doesn't result in AOT'd class files\n(binding [*compile-files* false]\n (require 'foo.bar))" ";; The \"defruntime\" macro below prevents initialization of a definition \n;; during AOT compilation but allows it (once only) at runtime. Can be used to\n;; load configuration files or other runtime only data.\n\n(defmacro defruntime [sym & body]\n `(defonce ~sym\n (when-not *compile-files* ~@body)))\n\n(defruntime config\n (println \"This won't happen during AOT compile\"))\n"], :notes nil, :arglists [], :doc "Set to true when compiling files, false otherwise.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*compile-files*"}, :clojure.repl/root-cause {:added "1.3", :ns "clojure.repl", :name "root-cause", :file "clojure/repl.clj", :type "function", :column 1, :see-alsos nil, :line 215, :examples ["(require '[clojure.repl :refer [root-cause]])\n\n(def chained-exceptions \n (ex-info \"Problem.\" {:status :surprise} \n (try (/ 1 0) \n (catch Exception e \n (ex-info \"What happened?\" {:status :unknown} e)))))\n\n;; Only shows the first 3 items from the stack trace \n;; of the root-cause exception in chained-exceptions.\n\n(pst (root-cause chained-exceptions) 3)\n\n;; ArithmeticException Divide by zero\n;; clojure.lang.Numbers.divide (Numbers.java:158)\n;; clojure.lang.Numbers.divide (Numbers.java:3808)\n;; user/fn--2169 (form-init4179141376169992155.clj:3)\n\n"], :notes nil, :arglists ["t"], :doc "Returns the initial cause of an exception or error by peeling off all of\n its wrappers", :library-url "https://github.com/clojure/clojure", :href "/clojure.repl/root-cause"}, :clojure.core.logic.pldb/rel-key {:ns "clojure.core.logic.pldb", :name "rel-key", :file "clojure/core/logic/pldb.clj", :type "function", :column 1, :see-alsos nil, :line 23, :examples nil, :notes nil, :arglists ["rel"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/rel-key"}, :clojure.spec.alpha/with-gen* {:ns "clojure.spec.alpha", :name "with-gen*", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["spec gfn"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/with-gen*"}, :clojure.core/unchecked-multiply {:added "1.0", :ns "clojure.core", :name "unchecked-multiply", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/* :clojure.core/*'], :line 1226, :examples [";; the unchecked-multiply function silently overflows\n\nuser=> (* 1000000000000 10)\n10000000000000\nuser=> (unchecked-multiply 1000000000000 10)\n10000000000000\n\nuser=> (* 3037000500 3037000500)\nArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1424)\nuser=> (unchecked-multiply 3037000500 3037000500)\n-9223372036709301616\n\n"], :notes nil, :arglists ["x y"], :doc "Returns the product of x and y, both long.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-multiply"}, :clojure.core/chunk-next {:ns "clojure.core", :name "chunk-next", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/chunk-first :clojure.core/chunk-rest :clojure.core/chunk-cons :clojure.core/chunk-buffer :clojure.core/chunk :clojure.core/chunk-append :clojure.core/chunked-seq?], :line 707, :examples ["(let [chunked-cons (seq (range 1 42))]\n\n (class chunked-cons)\n ;; => clojure.lang.ChunkedCons\n\n ;; Returns the next chunk when there are more than 32 elements\n ;; in the ChunkedCons.\n (chunk-next chunked-cons)\n ;; => (33 34 35 36 37 38 39 40 41)\n\n)"], :notes nil, :tag "clojure.lang.ISeq", :arglists ["s"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/chunk-next"}, :clojure.core.async/put! {:ns "clojure.core.async", :name "put!", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos [:clojure.core.async/take! :clojure.core.async/>! :clojure.core.async/>!!], :line 157, :examples ["user=> (def c (chan 1))\n#'user/c\n\nuser=> (take! c\n (fn [x]\n (println \"Clojure callback value \" x)))\nnil\n\nuser=> (put! c \"XYZ\") ; return true unless the channel is closed.\nClojure callback value XYZ\ntrue\n\nuser=> (put! c \"XYZ\")\ntrue\n"], :notes ["The documentation here is somewhat out of date, the real documentation for more recent versions of core.async (0.1.346.0-17112a-alpha, at the time of this note) removes the bit about throwing when the channel is closed. \n\nInstead, put! returns true unless the port is already closed, in which case false is returned.\n\nAn exception *is* thrown is you attempt to put! nil."], :arglists ["port val" "port val fn1" "port val fn1 on-caller?"], :doc "Asynchronously puts a val into port, calling fn1 (if supplied) when\n complete, passing false iff port is already closed. nil values are\n not allowed. If on-caller? (default true) is true, and the put is\n immediately accepted, will call fn1 on calling thread. Returns\n true unless port is already closed.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/put!"}, :clojure.core/deftype {:added "1.2", :ns "clojure.core", :name "deftype", :file "clojure/core_deftype.clj", :type "macro", :column 1, :see-alsos [:clojure.core/definterface :clojure.core/defprotocol :clojure.core/defrecord], :line 422, :examples ["user=> (import (java.awt.datatransfer Transferable DataFlavor)\n javax.swing.ImageIcon)\n\n;; create a Transferable Image from an array of bytes\nuser=> (deftype ImageSelection [data]\n Transferable\n (getTransferDataFlavors\n [this]\n (into-array DataFlavor [DataFlavor/imageFlavor]))\n \n (isDataFlavorSupported\n [this flavor]\n (= DataFlavor/imageFlavor flavor))\n\n (getTransferData\n [this flavor]\n (when (= DataFlavor/imageFlavor flavor)\n (.getImage (ImageIcon. data)))))\n\n;; create a new image selection:\nuser=> (def *selection* (ImageSelection. somedata))" ";; define a couple of shape types\n(deftype Circle [radius])\n(deftype Square [length width])\n\n;; multimethod to calculate the area of a shape\n(defmulti area class)\n(defmethod area Circle [c]\n (* Math/PI (.radius c) (.radius c)))\n(defmethod area Square [s]\n (* (.length s) (.width s)))\n\n;; create a couple shapes and get their area\n(def myCircle (Circle. 10))\n(def mySquare (Square. 5 11))\n\n(area myCircle)\n(area mySquare)" "(deftype Person [first-name last-name])\n\n;; use the factory function instead of the constructor, \"Person.\",\n;; to create a Person\n(->Person \"John\" \"Smith\")" ";; How :load-ns works.\n;; deftype can be used for AOT generation of classes (with gen-class that would be\n;; the only option). For example:\n\n(spit \"foo.clj\"\n \"(ns foo)\n (defn bar [] :bar)\n (defprotocol P (foo [p]))\n (deftype Foo [] :load-ns true P\n (foo [this] (bar)))\")\n\n(binding [*compile-path* \".\"] (compile 'foo))\n\n;; Now close and re-open the REPL to import the newly created class. Note that the\n;; call to (.foo p) doesn't throw exception here because we used \":load-ns true\"\n;; option in deftype. This makes sure that the namespace 'foo is also loaded \n;; forcing the evaluation of the \"bar\" function. This makes especially sense\n;; if Foo is used from a Java application:\n\n(import 'foo.Foo)\n(def p (Foo.))\n(.foo p)\n;; \"bar\"" ";; To refer to a deftype in another namespace, the deftype needs to be imported \n;; because deftype generate a class.\n;; Using the Foo type defined above:\n(ns bar \n (:import [foo Foo]))\n\n(defn foo? [x]\n (instance? Foo x))" ";; deftype allow mutable fields, and their values can be changed with set!.\n;; This works:\n(deftype Test [^:unsynchronized-mutable x]\n ITestProtocol\n (act [this o] (set! x o)))\n\n;; Note that these mutable fields are private, so they are not accessible outside,\n;; and they are not even accessible inside nested functions within the type.\n;; This does not compile, throws error about assigning to non-mutable field x:\n(deftype Test [^:unsynchronized-mutable x]\n ITestProtocol\n (act [this] (fn [o] (set! x o))))\n\n;; Need to define a set function in a protocol and implement it in the type \n(defprotocol ISetX (set-x [this o]))\n\n(deftype Test [^:unsynchronized-mutable x]\n ISetX\n (set-x [this o] (set! x o))\n \n ITestProtocol\n (act [this] (fn [o] (set-x o))))\n" ";; unlike defrecord, deftype does not include extra method definitions\n;; the following will not compile:\n(defrecord Nr [n]\n Object\n (toString [_] (str \"#\" n)) ;; This does work\n (hashCode [_] (+ 10 n))) ;; defrecord already generates this function\n\n;; Syntax error (ClassFormatError) compiling deftype* at (REPL:1:1).\n;; Duplicate method name \"hashCode\" with signature \"()I\" in class file user/Nr\n\n\n;; deftype does not implement methods like hashCode, so it can be overridden\n(deftype Nr [n]\n Object\n (toString [_] (str \"#\" n))\n (hashCode [_] (+ 10 n)))\n\n(def v (->Nr 5))\n\n(str \"The number is: \" v)\n;; \"The number is #5\"\n\n(hash v)\n;; 15"], :macro true, :notes ["There's also some undocumented support for annotations:\r\n\r\n" "Annotation docs now available in the reference: https://clojure.org/reference/datatypes#_java_annotation_support"], :arglists ["name [& fields] & opts+specs"], :doc "(deftype name [fields*] options* specs*)\n\n Options are expressed as sequential keywords and arguments (in any order).\n\n Supported options:\n :load-ns - if true, importing the type class will cause the\n namespace in which the type was defined to be loaded.\n Defaults to false.\n\n Each spec consists of a protocol or interface name followed by zero\n or more method bodies:\n\n protocol-or-interface-or-Object\n (methodName [args*] body)*\n\n Dynamically generates compiled bytecode for class with the given\n name, in a package with the same name as the current namespace, the\n given fields, and, optionally, methods for protocols and/or\n interfaces. \n\n The class will have the (by default, immutable) fields named by\n fields, which can have type hints. Protocols/interfaces and methods\n are optional. The only methods that can be supplied are those\n declared in the protocols/interfaces. Note that method bodies are\n not closures, the local environment includes only the named fields,\n and those fields can be accessed directly. Fields can be qualified\n with the metadata :volatile-mutable true or :unsynchronized-mutable\n true, at which point (set! afield aval) will be supported in method\n bodies. Note well that mutable fields are extremely difficult to use\n correctly, and are present only to facilitate the building of higher\n level constructs, such as Clojure's reference types, in Clojure\n itself. They are for experts only - if the semantics and\n implications of :volatile-mutable or :unsynchronized-mutable are not\n immediately apparent to you, you should not be using them.\n\n Method definitions take the form:\n\n (methodname [args*] body)\n\n The argument and return types can be hinted on the arg and\n methodname symbols. If not supplied, they will be inferred, so type\n hints should be reserved for disambiguation.\n\n Methods should be supplied for all methods of the desired\n protocol(s) and interface(s). You can also define overrides for\n methods of Object. Note that a parameter must be supplied to\n correspond to the target object ('this' in Java parlance). Thus\n methods for interfaces will take one more argument than do the\n interface declarations. Note also that recur calls to the method\n head should *not* pass the target object, it will be supplied\n automatically and can not be substituted.\n\n In the method bodies, the (unqualified) name can be used to name the\n class (for calls to new, instance? etc).\n\n When AOT compiling, generates compiled bytecode for a class with the\n given name (a symbol), prepends the current ns as the package, and\n writes the .class file to the *compile-path* directory.\n\n One constructor will be defined, taking the designated fields. Note\n that the field names __meta, __extmap, __hash and __hasheq are currently\n reserved and should not be used when defining your own types.\n\n Given (deftype TypeName ...), a factory function called ->TypeName\n will be defined, taking positional parameters for the fields", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/deftype"}, :clojure.core/some->> {:added "1.5", :ns "clojure.core", :name "some->>", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/->> :clojure.core/some->], :line 7598, :examples [";; an example of looking up a value from a\n;; map and performing an operation(addition)\n;; on it if it exists\nuser=> (some->> {:y 3 :x 5}\n (:y)\n (- 2))\n\n-1\n\n\n;; if we were to look up a value which\n;; doesn't exist, it will safely short-circuit\nuser=> (some->> {:y 3 :x 5}\n (:z)\n (- 2))\n\nnil\n"], :macro true, :notes nil, :arglists ["expr & forms"], :doc "When expr is not nil, threads it into the first form (via ->>),\n and when that result is not nil, through the next etc", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/some->>"}, :clojure.core.logic/defnm {:ns "clojure.core.logic", :name "defnm", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1639, :examples nil, :macro true, :notes nil, :arglists ["t n & rest"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/defnm"}, :clojure.core/error-mode {:added "1.2", :ns "clojure.core", :name "error-mode", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/set-error-mode!], :line 2229, :examples ["(def a (agent 42))\n(error-mode a);; => :fail\n\n(set-error-mode! a :continue)\n(error-mode a);; => :continue"], :notes nil, :arglists ["a"], :doc "Returns the error-mode of agent a. See set-error-mode!", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/error-mode"}, :clojure.core.logic/add-dom {:ns "clojure.core.logic", :name "add-dom", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 467, :examples nil, :notes nil, :arglists ["s x dom domv" "s x dom domv seenset"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/add-dom"}, :clojure.core.logic/update-eset {:ns "clojure.core.logic", :name "update-eset", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 572, :examples nil, :notes nil, :arglists ["s doms eset"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/update-eset"}, :clojure.core/completing {:added "1.7", :ns "clojure.core", :name "completing", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/transduce], :line 6858, :examples [";; Fix apparently inconsistent behaviour of \"-\" (minus) with transduce:\n(transduce (map inc) - 0 (range 10))\n;; 55\n(transduce (map inc) (completing -) 0 (range 10))\n;; -55" ";; the reducing fn arity-1 executes the last transformation in transduce.\n;; completing defaults to \"identity\" but you can change it.\n;; Use this fact for example with transients and go back to persistent once done.\n(require '[clojure.string :refer [lower-case]])\n(transduce\n (comp\n (remove nil?)\n (map lower-case))\n (completing #(assoc! %1 %2 (inc (get %1 %2 0))) persistent!)\n (transient {})\n [\"hi\" \"ho\" \"Hello\" \"hoi\" \"Hi\" \"Ha\" \"ha\" \"hello\"])\n;; {\"hi\" 2, \"ho\" 1, \"hello\" 2, \"hoi\" 1, \"ha\" 2}" ";; Example calculating the average from \n;; https://aphyr.com/posts/360-loopr-a-loop-reduction-macro-for-clojure#comment-3800\n\n(transduce (map inc)\n (completing (fn [[sum cnt] x] [(+ sum x) (inc cnt)])\n (fn [[sum cnt]] (/ sum cnt)))\n [0 0]\n (range 7))\n\n;; 4"], :notes nil, :arglists ["f" "f cf"], :doc "Takes a reducing function f of 2 args and returns a fn suitable for\n transduce by adding an arity-1 signature that calls cf (default -\n identity) on the result argument.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/completing"}, :clojure.core/rseq {:added "1.0", :ns "clojure.core", :name "rseq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/reverse], :line 1581, :examples ["user=> (vec (range 10))\n[0 1 2 3 4 5 6 7 8 9]\n\nuser=> (rseq (vec (range 10)))\n(9 8 7 6 5 4 3 2 1 0)\n" "(rseq (into (sorted-map) {:a 1 :b 2}))\n;; => ([:b 2] [:a 1])" ";; Huge performance boost for vectors and sorted maps over `reverse`.\n\n(def nums (vec (range 1000000)))\n(time (reverse nums))\n;; \"Elapsed time: 30.1222 msecs\"\n(time (rseq nums))\n;; \"Elapsed time: 0.0664 msecs\"" ";; The docstring doesn't mention sorted-sets directly\n;; Arguably they are implied by mention of sorted-maps\n\n(def ss (into (sorted-set) (range 1e6)))\n\n;; So this is a constant time way of getting the last element:\n\n(time (first (rseq ss)))\n\"Elapsed time: 0.04606 msecs\"\n;; => 999999\n\n;; vs the linear approach:\n\n(time (last ss))\n\"Elapsed time: 164.557625 msecs\"\n;; => 999999\n\n"], :notes nil, :arglists ["rev"], :doc "Returns, in constant time, a seq of the items in rev (which\n can be a vector or sorted-map), in reverse order. If rev is empty returns nil", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/rseq"}, :clojure.core/supers {:added "1.0", :ns "clojure.core", :name "supers", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/type :clojure.core/instance? :clojure.core/bases :clojure.core/ancestors], :line 5553, :examples [";;find superclasses and interfaces of Java objects...\nuser> (supers Object)\nnil\n\nuser> (supers String)\n#{java.lang.Comparable java.lang.CharSequence java.io.Serializable java.lang.Object}\n\n;;...or Java interfaces\nuser> (supers javax.naming.Name)\n#{java.lang.Cloneable java.lang.Comparable java.io.Serializable}\n\n;;Also with clojure types...\nuser> (defrecord MyThing [a b c])\nuser.MyThing\n\nuser> (supers MyThing)\n#{clojure.lang.Counted java.lang.Iterable clojure.lang.IKeywordLookup clojure.lang.IObj clojure.lang.IPersistentMap clojure.lang.Associative clojure.lang.Seqable java.util.Map clojure.lang.IMeta java.io.Serializable java.lang.Object clojure.lang.IPersistentCollection clojure.lang.ILookup}\n" ";; get all superclasses and interfaces for functions\nuser> (defn foo [x] (+ x 1))\nuser> (supers (class foo))\n#{java.lang.Runnable java.util.Comparator java.io.Serializable java.util.concurrent.Callable clojure.lang.AFn clojure.lang.IFn clojure.lang.Fn java.lang.Object clojure.lang.IMeta clojure.lang.AFunction clojure.lang.IObj}"], :notes nil, :arglists ["class"], :doc "Returns the immediate and indirect superclasses and interfaces of c, if any", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/supers"}, :clojure.core.logic/disunify {:ns "clojure.core.logic", :name "disunify", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2290, :examples nil, :notes nil, :arglists ["s u v" "s u v cs"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/disunify"}, :clojure.spec.alpha/spec? {:ns "clojure.spec.alpha", :name "spec?", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 72, :examples nil, :notes nil, :arglists ["x"], :doc "returns x if x is a spec object, else logical false", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/spec_q"}, :clojure.core.logic/conso {:ns "clojure.core.logic", :name "conso", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos [:clojure.core/cons], :line 1659, :examples [";; conso for 1 lvar\n\n(run* [x] (conso 1 x [1 2 3 4]))\n\n;; ((2 3 4))\n\n\n;; conso for 2 lvar\n\n(run* [x y] (conso x y [1 2 3 4]))\n\n;; ([1 (2 3 4)])"], :notes nil, :arglists ["a d l"], :doc "A relation where l is a collection, such that a is the first of l\n and d is the rest of l. If ground d must be bound to a proper tail.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/conso"}, :clojure.core/*agent* {:added "1.0", :ns "clojure.core", :name "*agent*", :type "var", :see-alsos [:clojure.core/agent], :examples [";; *agent* is often used with send or send-off to set up a repeated\n;; transformation of an agent's value. For example, to repeatedly \n;; increment the integer value of an agent 'myagent' until some \n;; flag value 'running' evaluates to false:\n\n;; Create an agent set to an initial value of 0:\n(def myagent (agent 0))\n\n;; Define a variable to act as a boolean flag:\n(def running true)\n\n;; Define a function to increment agent value repeatedly:\n(defn inc-while-running [agent-value]\n (when running\n (send-off *agent* inc-while-running)) ;sets up another call\n (inc agent-value))\n\n;; Dereference myagent to confirm it is set to value 0:\nuser=> @myagent\n0\n\n;; Start the fun:\nuser=> (send-off myagent inc-while-running)\n#<Agent@5fb9f88b: 20>\n\n;; The agent has already been incremented many times (20 when I ran this)\n;; by the time the REPL prints.\n\n;; Redefine running as false to stop repeated send-off:\n(def running false)\n\n;; Dereference myagent to find its new value:\nuser=> @myagent\n848167\n\n;; Dereference again to make sure incrementation has stopped:\nuser=> @myagent\n848167"], :notes nil, :tag "clojure.lang.Agent", :arglists [], :doc "The agent currently running an action on this thread, else nil", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*agent*"}, :clojure.core/tagged-literal? {:added "1.7", :ns "clojure.core", :name "tagged-literal?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 7719, :examples nil, :notes nil, :arglists ["value"], :doc "Return true if the value is the data representation of a tagged literal", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/tagged-literal_q"}, :clojure.java.javadoc/javadoc {:added "1.2", :ns "clojure.java.javadoc", :name "javadoc", :file "clojure/java/javadoc.clj", :type "function", :column 1, :see-alsos [:clojure.repl/doc :clojure.java.javadoc/*local-javadocs* :clojure.java.javadoc/*remote-javadocs*], :line 77, :examples ["user=> (use 'clojure.java.javadoc)\nnil\n\nuser=> (javadoc String)\n\"http://java.sun.com/javase/6/docs/api/java/lang/String.html\"\n\nuser=> (javadoc (java.util.Date.))\n\"http://java.sun.com/javase/6/docs/api/java/util/Date.html\"\n" "user> (javadoc 1)\n\"http://java.sun.com/javase/7/docs/api/java/lang/Long.html\"\n\n(javadoc \"abc\")\n\"http://java.sun.com/javase/7/docs/api/java/lang/String.html\"" "user> (javadoc org.joda.time.DateTime)\n\"http://www.google.com/search?btnI=I%27m%20Feeling%20Lucky&q=allinurl:org/joda/time/DateTime.html\""], :notes nil, :arglists ["class-or-object"], :doc "Opens a browser window displaying the javadoc for the argument.\n Tries *local-javadocs* first, then *remote-javadocs*.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.javadoc/javadoc"}, :clojure.main/main {:ns "clojure.main", :name "main", :file "clojure/main.clj", :type "function", :column 1, :see-alsos nil, :line 616, :examples ["java -cp clojure-1.6.0.jar clojure.main hey.clj"], :notes nil, :arglists ["& args"], :doc "Usage: java -cp clojure.jar clojure.main [init-opt*] [main-opt] [arg*]\n\n With no options or args, runs an interactive Read-Eval-Print Loop\n\n init options:\n -i, --init path Load a file or resource\n -e, --eval string Evaluate expressions in string; print non-nil values\n --report target Report uncaught exception to \"file\" (default), \"stderr\",\n or \"none\", overrides System property clojure.main.report\n\n main options:\n -m, --main ns-name Call the -main function from a namespace with args\n -r, --repl Run a repl\n path Run a script from a file or resource\n - Run a script from standard input\n -h, -?, --help Print this help message and exit\n\n operation:\n\n - Establishes thread-local bindings for commonly set!-able vars\n - Enters the user namespace\n - Binds *command-line-args* to a seq of strings containing command line\n args that appear after any main option\n - Runs all init options in order\n - Calls a -main function or runs a repl or script if requested\n\n The init options may be repeated and mixed freely, but must appear before\n any main option. The appearance of any eval option before running a repl\n suppresses the usual repl greeting message: \"Clojure ~(clojure-version)\".\n\n Paths may be absolute or relative in the filesystem or relative to\n classpath. Classpath-relative paths have prefix of @ or @/", :library-url "https://github.com/clojure/clojure", :href "/clojure.main/main"}, :clojure.core/unchecked-inc {:added "1.0", :ns "clojure.core", :name "unchecked-inc", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/unchecked-add :clojure.core/unchecked-dec :clojure.core/unchecked-inc :clojure.core/unchecked-negate :clojure.core/unchecked-divide :clojure.core/unchecked-subtract :clojure.core/unchecked-multiply :clojure.core/unchecked-remainder :clojure.core/inc :clojure.core/inc'], :line 1156, :examples ["users=> (unchecked-inc Integer/MAX_VALUE)\n-2147483648\n\nusers=> (unchecked-inc 0)\n1" ";; Illustrates the difference between (inc), (inc') and (unchecked-inc)\n\n;; The \"N\" suffix denotes a BigInt instance\n;; https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/BigInt.java\n\nLong/MAX_VALUE\n;;=> 9223372036854775807\n\n(inc Long/MAX_VALUE)\n;;=> ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1501)\n\n(inc' Long/MAX_VALUE)\n;;=> 9223372036854775808N\n\n;; Notice how the resulting number becomes NEGATIVE:\n(unchecked-inc Long/MAX_VALUE)\n;;=> -9223372036854775808"], :notes nil, :arglists ["x"], :doc "Returns a number one greater than x, a long.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-inc"}, :clojure.core.logic.fd/list-sorted? {:ns "clojure.core.logic.fd", :name "list-sorted?", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 1031, :examples nil, :notes nil, :arglists ["pred ls"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/list-sorted_q"}, :clojure.test.tap/print-diagnostics {:ns "clojure.test.tap", :name "print-diagnostics", :file "clojure/test/tap.clj", :type "function", :column 1, :see-alsos nil, :line 78, :examples nil, :notes nil, :arglists ["data"], :library-url "https://github.com/clojure/clojure", :href "/clojure.test.tap/print-diagnostics"}, :clojure.pprint/print-length-loop {:added "1.3", :ns "clojure.pprint", :name "print-length-loop", :file "clojure/pprint/pprint_base.clj", :type "macro", :column 1, :see-alsos nil, :line 391, :examples ["(set! *print-length* 5)\n\n(print-length-loop [a 0]\n (pprint a)\n (recur (inc a)))\n;; 0\n;; 1\n;; 2\n;; 3\n;; 4\n;; ...\n;; => nil"], :macro true, :notes nil, :arglists ["bindings & body"], :doc "A version of loop that iterates at most *print-length* times. This is designed \nfor use in pretty-printer dispatch functions.", :library-url "https://github.com/clojure/clojure", :href "/clojure.pprint/print-length-loop"}, :clojure.test/run-tests {:added "1.1", :ns "clojure.test", :name "run-tests", :file "clojure/test.clj", :type "function", :column 1, :see-alsos [:clojure.test/run-all-tests], :line 768, :examples [";; assuming current namespace is user\n(use 'clojure.test)\n(deftest eg-tests (is (= 1 1)))\n(run-tests)\n;;=> Testing user\n;;=> Ran 1 tests containing 1 assertions.\n;;=> 0 failures, 0 errors.\n;;=> {:type :summary, :fail 0, :error 0, :pass 1, :test 1}\n\n(run-tests 'user) ; if supplying a namespace to test, must quote\n;;=> Testing user\n;;=> Ran 1 tests containing 1 assertions.\n;;=> 0 failures, 0 errors.\n;;=> {:type :summary, :fail 0, :error 0, :pass 1, :test 1}"], :notes nil, :arglists ["" "& namespaces"], :doc "Runs all tests in the given namespaces; prints results.\n Defaults to current namespace if none given. Returns a map\n summarizing test results.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/run-tests"}, :clojure.core/finally {:ns "clojure.core", :name "finally", :type "var", :see-alsos [:clojure.core/try :clojure.core/catch :clojure.core/ex-data :clojure.core/throw], :examples ["(try\n (/ 1 0)\n (catch ArithmeticException e (str \"caught exception: \" (.getMessage e)))\n (finally (prn \"final exception.\")))\n\"final exception.\"\n\"caught exception: Divide by zero\"" ";; finally will always run before returning, even if there is no exception.\n(try\n (+ 1 1)\n (catch ArithmeticException e (str \"caught exception: \" (.getMessage e)))\n (finally (prn \"final print.\")))\n\"final print.\"\n2\n"], :notes nil, :arglists [], :doc "The exprs are evaluated and, if no exceptions occur, the value of the last\nis returned. If an exception occurs and catch clauses are provided, each is\nexamined in turn and the first for which the thrown exception is an instance\nof the named class is considered a matching catch clause. If there is a\nmatching catch clause, its exprs are evaluated in a context in which name is\nbound to the thrown exception, and the value of the last is the return value\nof the function. If there is no matching catch clause, the exception\npropagates out of the function. Before returning, normally or abnormally,\nany finally exprs will be evaluated for their side effects. See\nhttp://clojure.org/special_forms for more information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/finally"}, :clojure.core/double-array {:added "1.0", :ns "clojure.core", :name "double-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/doubles :clojure.core/aget :clojure.core/aset :clojure.core/aset-double], :line 5317, :examples [";; create a double array using double-array\n;; and show it can be used with the standard Java functions\n;; binarySearch and fill\n\nuser=> (def ds (double-array (range 3 20)))\n#'user/ds\nuser=> (type ds)\n[D\nuser=> (vec ds)\n[3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19.0]\nuser=> (java.util.Arrays/binarySearch ds 10.0)\n7\nuser=> (java.util.Arrays/fill ds 3 8 99.0)\nnil\nuser=> (vec ds)\n[3.0 4.0 5.0 99.0 99.0 99.0 99.0 99.0 11.0 12.0 13.0 14.0 15.0 16.0 17.0 18.0 19\n.0]\nuser=>" "(double-array [1 2.2 3.5])\n;;=> #object[\"[D\" 0x249e3e74 \"[D@249e3e74\"]\n\n(vec (double-array [1 2.2 3.5]))\n;;=> [1.0 2.2 3.5]"], :notes nil, :arglists ["size-or-seq" "size init-val-or-seq"], :doc "Creates an array of doubles", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/double-array"}, :clojure.core/sorted-map-by {:added "1.0", :ns "clojure.core", :name "sorted-map-by", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/sorted-map :clojure.core/subseq :clojure.core/rsubseq :clojure.core/sorted-set-by :clojure.core/compare :clojure.core/comparator], :line 407, :examples ["; The basic function requires discrete elements, and cannot accept a \n; pre-existing map:\nuser=> (sorted-map-by > 1 \"a\", 2 \"b\", 3 \"c\")\n{3 \"c\", 2 \"b\", 1 \"a\"}\n\n; We can use the syntax \"(sorted-map >)\" to create an empty sorted map that sorts \n; in reverse order (i.e. the opposite of \"(sorted-map)\"). It we can then fill\n; it using (into ...) with a pre-existing map:\nuser=> (into (sorted-map-by >) {1 :a 2 :b 3 :c} )\n{3 :c, 2 :b, 1 :a}\n\n; This two are the same\nuser=> (into (sorted-map-by <) {1 :a 2 :b 3 :c} )\n{1 :a, 2 :b, 3 :c}\nuser=> (into (sorted-map) {1 :a 2 :b 3 :c} )\n{1 :a, 2 :b, 3 :c}\n\n" ";; If you wish to sort the map according to the values, instead of by keys \n;; the following code WILL NOT WORK! This is because the map values are not unique.\n\nuser=> (let [results {:A 1 :B 2 :C 2 :D 5 :E 1 :F 1}]\n (into (sorted-map-by (fn [key1 key2]\n (compare (get results key2)\n (get results key1))))\n results))\n\n=> {:D 5, :C 2, :A 1}\n\n;; To make sure that the sorting works, we can make sure that the comparator \n;; works on unique values\n\nuser=> (let [results {:A 1 :B 2 :C 2 :D 5 :E 1 :F 1}]\n (into (sorted-map-by (fn [key1 key2]\n (compare [(get results key2) key2]\n [(get results key1) key1])))\n results))\n\n=> {:D 5, :C 2, :B 2, :F 1, :E 1, :A 1}\n\n;; See this article for more details: https://clojure.org/guides/comparators" ";; Ordering using nested values\n\n(def rows {:45 {:ordnen 5} :55 {:ordnen 8} :66 {:ordnen 3} :68 {:ordnen 90} :13 {:ordnen 1}})\n\n(into (sorted-map-by (fn [key1 key2]\n (compare\n (get-in rows [key1 :ordnen])\n (get-in rows [key2 :ordnen]))))\n rows)\n\n{:13 {:ordnen 1},\n :66 {:ordnen 3},\n :45 {:ordnen 5},\n :55 {:ordnen 8},\n :68 {:ordnen 90}}\n " ";; Note that when querying values from the map, the comparator will be called, \n;; and must work on values that are not keys in the map:\n\nuser=> (get (into (sorted-map-by (fn [a b] (println a b) (compare a b))) \n {\"a\" 1 \"b\" 2})) \n \"c\")\nb a\nc a\nc b\n=> nil\n\n;; If the comparator looks into an auxiliary data structure for a comparison\n;; value, ensure that the comparator can handle a missing value in that data\n;; structure:\n\nuser=> (let [other {\"a\" 10 \"b\" 1}\n m (into (sorted-map-by (fn [a b] (< (get other a) (get other b)))) \n {\"a\" 1 \"b\" 2})]\n (println (get m \"a\"))\n (println (get m \"b\"))\n (println (get m \"c\")))\n1\n2\nNullPointerException clojure.lang.Numbers.ops (Numbers.java:1013)\nuser=>"], :notes ["an unstable sorting function will give nonsense results:\n\n
\nuser=> (into (sorted-map-by (fn [_ _] (rand-int Integer/MAX_VALUE))) [[:a 0] [:a 1] [:a 2]])\n\n{:a 0, :a 1, :a 2}\n" "As previously noted, using an unstable sorting function could lead to unexpected results and hard to find bug. The `PersistentTreeMap` object returned by `sorted-map-by`, stores the `comparator` function and will reuse it in consecutive operations as `assoc`.\n\n```\n(def ord [:a :b :c])\n(def m (into (sorted-map-by (fn [a b] \n (compare (.indexOf ord a) \n (.indexOf ord b)))) \n {:a 1 :b 2 :c 3}))\n(assoc m :d 4) ; => {:d 4, :a 1, :b 2, :c 3}\n(-> (assoc m :d 4)\n (assoc :e 5)) ; => {:d 5, :a 1, :b 2, :c 3} WRONG\n```\n\n[Source reference](https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/PersistentTreeMap.java#L28)\n"], :arglists ["comparator & keyvals"], :doc "keyval => key val\n Returns a new sorted map with supplied mappings, using the supplied\n comparator. If any keys are equal, they are handled as if by\n repeated uses of assoc.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/sorted-map-by"}, :clojure.core/make-array {:added "1.0", :ns "clojure.core", :name "make-array", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/int-array :clojure.core/double-array :clojure.core/float-array :clojure.core/short-array :clojure.core/long-array :clojure.core/char-array :clojure.core/byte-array :clojure.core/boolean-array :clojure.core/object-array :clojure.core/to-array :clojure.core/to-array-2d :clojure.core/into-array :clojure.core/aget :clojure.core/aset :clojure.core/alength :clojure.core/amap :clojure.core/areduce], :line 3986, :examples ["(make-array Integer/TYPE 3)\n\n; Types are defined in clojure/genclass.clj:\n; Boolean/TYPE\n; Character/TYPE\n; Byte/TYPE\n; Short/TYPE\n; Integer/TYPE\n; Long/TYPE\n; Float/TYPE\n; Double/TYPE\n; Void/TYPE" "user=> (pprint (make-array Double/TYPE 3))\n[0.0, 0.0, 0.0]\n\nuser=> (pprint (make-array Integer/TYPE 2 3))\n[[0, 0, 0], [0, 0, 0]]\n\n\n;; Create an array of Threads, then show content and type\nuser=> (def ar (make-array Thread 3))\n#'user/ar\n\nuser=> (pprint ar)\n[nil, nil, nil]\n\nuser=> (type ar)\n[Ljava.lang.Thread;\n"], :notes nil, :arglists ["type len" "type dim & more-dims"], :doc "Creates and returns an array of instances of the specified class of\n the specified dimension(s). Note that a class object is required.\n Class objects can be obtained by using their imported or\n fully-qualified name. Class objects for the primitive types can be\n obtained using, e.g., Integer/TYPE.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/make-array"}, :clojure.core.logic/sort-by-strategy {:ns "clojure.core.logic", :name "sort-by-strategy", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2223, :examples nil, :notes nil, :arglists ["v x a"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/sort-by-strategy"}, :clojure.core.logic/ifu* {:ns "clojure.core.logic", :name "ifu*", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1369, :examples nil, :macro true, :notes nil, :arglists ["" "[e & gs] & grest"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/ifu*"}, :clojure.core.async/admix* {:ns "clojure.core.async", :name "admix*", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["m ch"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/admix*"}, :clojure.core/boolean {:added "1.0", :ns "clojure.core", :name "boolean", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/boolean?], :line 1605, :examples [";; Everything except `false' and `nil' is true in boolean context.\nuser=> (into {} (map #(vector % (boolean %)) [true false nil [] {} '() #{} \"\"]))\n{true true, false false, nil false, [] true, {} true, #{} true, \"\" true}\n\nuser=> (clojure.pprint/pp)\n{true true,\n false false,\n nil false,\n [] true,\n {} true,\n #{} true,\n \"\" true}\nnil\n\n;; Unrelated to `boolean`, but notice that the `'()` entry is missing. This\n;; due to Clojure treating `[]` and `'()` as equal. When combined into the map \n;; the `'() => true` key-value pair is overwritten by the `[] => true` key-value\n;; pair. See https://github.com/zk/clojuredocs/issues/114#issuecomment-132153637\n" ";; Beware that boolean returns true for numbers 0 and 1\nuser=> (boolean 0)\ntrue\nuser=> (boolean 1)\ntrue" ";; Simply defined: Everything except false and nil is logically true in Clojure." ";; Corrected definition:\n;; returns `false' for `false', `nil' and `(Boolean. false)`.\n;; returns `true' for everything else.\n"], :notes nil, :arglists ["x"], :doc "Coerce to boolean", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/boolean"}, :clojure.core/*print-namespace-maps* {:added "1.9", :ns "clojure.core", :name "*print-namespace-maps*", :file "clojure/core_print.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 41, :examples [";; In a REPL:\n\n(prn {:num/val 1 :num/name \"one\"})\n;; #:num{:val 1, :name \"one\"}\n;;=> nil\n\n(binding [*print-namespace-maps* false] \n (prn {:num/val 1 :num/name \"one\"}))\n;; {:num/val 1, :num/name \"one\"}\n;;=> nil\n"], :notes ["In the Cursive or CIDER REPL the dynamic var is already set (defaults to `true`). Changing the binding would only work within bound expressions but it won't change the behaviour of the REPL itself.\n\nChanging the printing multi-method allows you to \"turn it off\" completely:\n```\n; don't use namespaced maps by default in the REPL\n(defmethod print-method clojure.lang.IPersistentMap [m, ^java.io.Writer w]\n (#'clojure.core/print-meta m w)\n (#'clojure.core/print-map m #'clojure.core/pr-on w))\n```"], :arglists [], :doc "*print-namespace-maps* controls whether the printer will print\n namespace map literal syntax. It defaults to false, but the REPL binds\n to true.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*print-namespace-maps*"}, :clojure.spec.alpha/*explain-out* {:ns "clojure.spec.alpha", :name "*explain-out*", :file "clojure/spec/alpha.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 252, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/*explain-out*"}, :clojure.core.logic.fd/->IntervalFD {:ns "clojure.core.logic.fd", :name "->IntervalFD", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 231, :examples nil, :notes nil, :arglists ["lb ub"], :doc "Positional factory function for class clojure.core.logic.fd.IntervalFD.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/->IntervalFD"}, :clojure.core/re-groups {:added "1.0", :ns "clojure.core", :name "re-groups", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/re-find :clojure.core/re-matcher], :line 4858, :examples ["user=> (def phone-number \"672-345-456-3212\")\n#'user/phone-number\n\nuser=> (def matcher (re-matcher #\"((\\d+)-(\\d+))\" phone-number))\n#'user/matcher\n\nuser=> (re-find matcher)\n[\"672-345\" \"672-345\" \"672\" \"345\"]\n\n;; re-groups gets the most recent find or matches\nuser=> (re-groups matcher)\n[\"672-345\" \"672-345\" \"672\" \"345\"]\nuser=> (re-groups matcher)\n[\"672-345\" \"672-345\" \"672\" \"345\"]\n\n\nuser=> (re-find matcher)\n[\"456-3212\" \"456-3212\" \"456\" \"3212\"]\n\nuser=> (re-groups matcher)\n[\"456-3212\" \"456-3212\" \"456\" \"3212\"]\nuser=> (re-groups matcher)\n[\"456-3212\" \"456-3212\" \"456\" \"3212\"]\n\n\nuser=> (re-find matcher)\nnil\n\nuser=> (re-groups matcher)\nIllegalStateException No match found java.util.regex.Matcher.group (Matcher.java:468)" ";;given a string to match\nuser=> (def flight \"AF-22-CDG-JFK-2017-09-08\")\n#'User/flight\n;; groups and give a name to matches\nuser=> (def flight-regex #\"(?[A-Z0-9]+)-(?[0-9]+[A-Z]?)-(?[A-Z]+)-(?[A-Z]+)-(?[0-9]+)-(?[0-9]+)-(?[0-9]+)\")\n#'user/flight-regex\nuser=> (def matcher (re-matcher flight-regex flight))\n#'user/matcher\n;; it allows good grasp of meaning and understanding of the data extraction from the regex\nuser=> (if (.matches matcher)\n {:airline-code (.group matcher \"airlineCode\") \n :flight-number (.group matcher \"flightNumber\") \n :from (.group matcher \"from\") \n :to (.group matcher \"to\") \n :year (.group matcher \"year\") \n :month (.group matcher \"month\") \n :day (.group matcher \"day\")}\n (throw (ex-info (str \"Can't extract detailed value from flight\"))))\n{:airline-code \"AF\", :flight-number \"22\", :from \"CDG\", :to \"JFK\", :year \"2017\", :month \"09\", :day \"08\"}\nuser=>\n;;Beware that groups are available in Java Regex not in Javascript ones..." ";\n; Java supports named capture groups\n;\n; Define a phone number pattern with some named groups\n(let [patt (re-pattern \"(?\\\\d{3})-(?\\\\d{3})-(?\\\\d{4})\")]\n ; `re-matches` will find the capturing groups and stick them in a vector\n ; after the full match The capture groups are numbered starting with 1.\n ; The full match is like group zero.\n (is= [\"619-239-5464\" \"619\" \"239\" \"5464\"] (re-matches patt \"619-239-5464\"))\n\n ; Construct a java.util.regex.Matcher. Keep in mind that it is a mutable object!\n (let [matcher (re-matcher patt \"619-239-5464\")]\n ; Execute the Matcher via `re-find`. It returns all 4 groups and caches them\n (is= [\"619-239-5464\" \"619\" \"239\" \"5464\"] (re-find matcher))\n\n ; `re-groups` simply returns the cached result from the Matcher\n (is= [\"619-239-5464\" \"619\" \"239\" \"5464\"] (re-groups matcher))\n\n ; We need the instance function Matcher.group( ) to\n ; extract the named group\n (is= \"619\" (.group matcher \"area\"))\n (is= \"239\" (.group matcher \"prefix\"))\n (is= \"5464\" (.group matcher \"tail\"))))\n"], :notes nil, :arglists ["m"], :doc "Returns the groups from the most recent match/find. If there are no\n nested groups, returns a string of the entire match. If there are\n nested groups, returns a vector of the groups, the first element\n being the entire match.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/re-groups"}, :clojure.core.logic/tree-term? {:ns "clojure.core.logic", :name "tree-term?", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 884, :examples nil, :notes nil, :arglists ["x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/tree-term_q"}, :clojure.core/bit-shift-left {:added "1.0", :ns "clojure.core", :name "bit-shift-left", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/bit-shift-left :clojure.core/unsigned-bit-shift-right :clojure.core/bit-shift-right], :line 1356, :examples ["
user=> (bit-shift-left 1 10)\n1024\n
\n\n
user=> (bit-shift-left 2r1101 2) ; fill rightmost bits with 0s\n52 \n;; 52 = 2r110100\n
\n" ";;a bogus bit-array implementation\n\n(def ba (atom (long 0)))\n\n(defn set-ba \n\"sets bit n in long atom ba\"\n [n]\n (let [number-set (bit-shift-left 1 n)\n\t_ (println \"number to set: \" number-set)\n\tnew-array (bit-or @ba number-set)]\n (reset! ba new-array)))\n\n(defn get-ba \n\"gets bit n in long atom ba\"\n[n]\n (not (zero? (bit-and (bit-shift-left 1 n) @ba))))\n\n(comment\n (set-ba 0) ;; 0 [....0001]\n (set-ba 3) ;; 2^3 = 8 [....1001]\n (get-ba 0) ;; (bit-and ba 2^0) = 1\n (get-ba 1) ;; (bit-and ba 2^1) = 0\n (get-ba 3) ;; (bit-and ba 2^3) = 1\n ;;but:\n (set-ba 65) ;; [....1011]\n ;;number to set: 2\n ;;modulo because long has only 64 bit\n ;;also note that long always is two-complemented (signed) in java implementation\n )"], :notes nil, :arglists ["x n"], :doc "Bitwise shift left", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-shift-left"}, :clojure.core/requiring-resolve {:added "1.10", :ns "clojure.core", :name "requiring-resolve", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/resolve], :line 6082, :examples [";; Resolve a qualified symbol\n(requiring-resolve 'clojure.java.shell/sh)\n\n;; Resolve and evaluate\n((requiring-resolve 'some-ns/some-fn))\n\n;; In deps.edn, replace all spaces with the \"Corfield\" comma, ;)\n((requiring-resolve,'clojure.java.shell/sh))" "(defn debug? [] (= (env :debug?) \"true\"))\n\n;; If you need to do conditional requires such as the one below:\n(if (debug?)\n (do\n (require '[nrepl.cmdline :refer [-main] :rename {-main -nrepl-main}])\n (resolve 'nrepl.cmdline))\n (declare -nrepl-main))\n\n(defn -main [& args]\n (when (debug?)\n (future (apply -nrepl-main args))))\n\n;; This is strictly better!\n(defn -main [& args]\n (when (debug?)\n ;; Swap to require and resolve in one step!\n (future (apply (requiring-resolve 'nrepl.cmdline/-main) args))))"], :notes nil, :arglists ["sym"], :doc "Resolves namespace-qualified sym per 'resolve'. If initial resolve\nfails, attempts to require sym's namespace and retries.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/requiring-resolve"}, :clojure.walk/postwalk-demo {:added "1.1", :ns "clojure.walk", :name "postwalk-demo", :file "clojure/walk.clj", :type "function", :column 1, :see-alsos [:clojure.walk/postwalk :clojure.walk/postwalk-replace], :line 80, :examples ["(use 'clojure.walk)\n\nuser> (postwalk-demo [[1 2] [3 4 [5 6]] [7 8]])\nWalked: 1\nWalked: 2\nWalked: [1 2]\nWalked: 3\nWalked: 4\nWalked: 5\nWalked: 6\nWalked: [5 6]\nWalked: [3 4 [5 6]]\nWalked: 7\nWalked: 8\nWalked: [7 8]\nWalked: [[1 2] [3 4 [5 6]] [7 8]]\n[[1 2] [3 4 [5 6]] [7 8]]\n\nuser> (postwalk-demo {:a 1 :b 2})\nWalked: :a\nWalked: 1\nWalked: [:a 1]\nWalked: :b\nWalked: 2\nWalked: [:b 2]\nWalked: {:a 1, :b 2}\n{:a 1, :b 2}"], :notes nil, :arglists ["form"], :doc "Demonstrates the behavior of postwalk by printing each form as it is\n walked. Returns form.", :library-url "https://github.com/clojure/clojure", :href "/clojure.walk/postwalk-demo"}, :clojure.core.logic/master {:ns "clojure.core.logic", :name "master", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1976, :examples nil, :notes nil, :arglists ["argv cache"], :doc "Take the argument to the goal and check that we don't\n have an alpha equivalent cached answer term in the cache.\n If it doesn't already exist in the cache add the new\n answer term.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/master"}, :clojure.test/with-test {:added "1.1", :ns "clojure.test", :name "with-test", :file "clojure/test.clj", :type "macro", :column 1, :see-alsos [:clojure.core/test :clojure.core/meta :clojure.test/deftest], :line 609, :examples [";with test is the same as using {:test #((is...)(is...))} in the meta data of the function.\n\n(:use 'clojure.test)\n\n(with-test\n (defn my-function [x y]\n (+ x y))\n (is (= 4 (my-function 2 2)))\n (is (= 7 (my-function 3 4))))\n\n(test #'my-function) ;(test (var my-function))\n=> :ok"], :macro true, :notes nil, :arglists ["definition & body"], :doc "Takes any definition form (that returns a Var) as the first argument.\n Remaining body goes in the :test metadata function for that Var.\n\n When *load-tests* is false, only evaluates the definition, ignoring\n the tests.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/with-test"}, :clojure.spec.alpha/describe {:ns "clojure.spec.alpha", :name "describe", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 198, :examples nil, :notes nil, :arglists ["spec"], :doc "returns an abbreviated description of the spec as data", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/describe"}, :clojure.core/bytes {:added "1.1", :ns "clojure.core", :name "bytes", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/byte-array :clojure.core/bytes?], :line 5353, :examples [";; for fast interop\n(bytes (byte-array (map (comp byte int) \"ascii\")))\n;=> #\n(def the-bytes *1)\n;=> #'user/the-bytes\n(set! *warn-on-reflection* true)\n(defn get-byte [the-bytes i] (aget the-bytes i))\n;=> #'user/get-byte Reflection warning, NO_SOURCE_PATH:1 - call to aget can't be resolved.\n\n(defn get-byte [the-bytes i] \n (let [the-bytes (bytes the-bytes)] \n (aget the-bytes i)))\n;=> #'user/get-byte\n(get-byte the-bytes 0)\n;=> 97\n" ";; byte-array will convert where possible\n(byte-array [127 128 129]);; => [127, -128, -127]\n\n;; bytes will not\n(try (bytes [127 128 129])\n (catch ClassCastException e (ex-message e)))\n;; => \"clojure.lang.PersistentVector cannot be cast to [B\"\n"], :notes ["Why is the `(comp byte int)` required in the example? This seems to work just as well:\r\n\r\n
\r\nuser=> (def b (bytes (byte-array (map byte \"ascii\"))))\r\nuser=> (String. b)\r\n\"ascii\"\r\n
" "For that matter, why is the `bytes` needed? Consider:\r\n\r\n
\r\n" "AFAIK, `bytes` is used for referring to `bytes[].class` from JAVA\r\n\r\nExample (midje):\r\n\r\n (fact (class (.getBytes \"test\")) => bytes) ; true\r\n"], :arglists ["xs"], :doc "Casts to bytes[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bytes"}, :clojure.core/future-call {:added "1.1", :ns "clojure.core", :name "future-call", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/future], :line 6963, :examples [";; future-call is used to implement 'future'. See examples for 'future'\n;; for discussion of an undesirable 1-minute wait that can occur before\n;; your standalone Clojure program exits if you do not use shutdown-agents."], :notes ["`future-call` will also preserve the calling thread's dynamic bindings in the thread that executes f."], :arglists ["f"], :doc "Takes a function of no args and yields a future object that will\n invoke the function in another thread, and will cache the result and\n return it on all subsequent calls to deref/@. If the computation has\n not yet finished, calls to deref/@ will block, unless the variant\n of deref with timeout is used. See also - realized?.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/future-call"}, :clojure.core/resultset-seq {:added "1.0", :ns "clojure.core", :name "resultset-seq", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 5702, :examples [";; To run this you need [mysql/mysql-connector-java \"5.1.x\"] dependency \n;; in the classpath and a running MySql instance. The statement is set\n;; to enable streaming and go fully lazy with restultset-seq.\n;; \"f\" is expected to produce the required results *before* exiting \n;; the try-finally block that closes the connection.\n\n(import '[java.sql DriverManager ResultSet])\n\n(defn with-mysql-query [url query f]\n (Class/forName \"com.mysql.jdbc.Driver\")\n (let [db url\n conn (DriverManager/getConnection db)\n stmt (doto\n (.createStatement conn\n ResultSet/TYPE_FORWARD_ONLY\n ResultSet/CONCUR_READ_ONLY)\n (.setFetchSize Integer/MIN_VALUE))\n rs (.executeQuery stmt query)]\n (try\n (f (resultset-seq rs))\n (finally\n (.close stmt)\n (.close conn)))))\n\n(with-mysql-query\n \"jdbc:mysql://localhost/mysql?user=root&password=\"\n \"SELECT * FROM user\"\n (comp count keys first))\n\n;; 45\n"], :notes nil, :arglists ["rs"], :doc "Creates and returns a lazy sequence of structmaps corresponding to\n the rows in the java.sql.ResultSet rs", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/resultset-seq"}, :clojure.core/refer-clojure {:added "1.0", :ns "clojure.core", :name "refer-clojure", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/refer], :line 5822, :examples [";; Prevent namespace conflicts like:\n\n;; `WARNING: time already refers to: #'clojure.core/time in namespace: \n;; time, being replaced by: #'time/time`\n\nuser=> (ns time\n (:refer-clojure :exclude [time]))\n\n(defn time []\n (System/nanoTime))\n" ";; Copied from https://gist.github.com/jkk/284230 (ns-cheatsheet.clj):\n\n;; Excludes built-in print\n(:refer-clojure :exclude [print])\n\n;; Excludes all built-ins except print\n(:refer-clojure :only [print])\n\n;; Renames built-in print to core-print\n(:refer-clojure :rename {print core-print})"], :macro true, :notes nil, :arglists ["& filters"], :doc "Same as (refer 'clojure.core )", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/refer-clojure"}, :clojure.java.io/Coercions {:added "1.2", :ns "clojure.java.io", :name "Coercions", :file "clojure/java/io.clj", :type "var", :column 1, :see-alsos nil, :line 35, :examples nil, :notes nil, :arglists [], :doc "Coerce between various 'resource-namish' things.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/Coercions"}, :clojure.core/satisfies? {:added "1.2", :ns "clojure.core", :name "satisfies?", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos [:clojure.core/extend :clojure.core/defprotocol :clojure.core/instance? :clojure.core/extends? :clojure.core/extenders], :line 569, :examples ["(ns foo)\n\n(defprotocol Foo\n (foo [this]))\n\n(defprotocol Bar\n (bar [this]))\n\n(extend java.lang.Number\n Bar\n {:bar (fn [this] 42)})\n\n(extend java.lang.String\n Foo\n {:foo (fn [this] \"foo\")}\n Bar\n {:bar (fn [this] \"forty two\")})\n\n(satisfies? Foo \"zam\") ; => true\n(satisfies? Bar \"zam\") ; => true\n(satisfies? Foo 123) ; => false\n(satisfies? Bar 123) ; => true" ";; Note that protocol argument should be the var generated by the \n;; defprotocol call, not the Java interface.\n\n(ns a)\n\n(defprotocol Foo\n (foo [this]))\n\n(ns b\n (:require [a])\n (:import a.Foo))\n\n;; bad\n(satisfies? Foo :test) ; => NPE\n;; good\n(satisfies? a/Foo :test) ; => false"], :notes ["Unless this issue is resolved, do not use this function in a hot path, for it is extremely slow. See also this post "], :arglists ["protocol x"], :doc "Returns true if x satisfies the protocol", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/satisfies_q"}, :clojure.java.io/default-streams-impl {:ns "clojure.java.io", :name "default-streams-impl", :file "clojure/java/io.clj", :type "var", :column 1, :see-alsos nil, :line 164, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/default-streams-impl"}, :clojure.core.logic.fd/finite-domain? {:ns "clojure.core.logic.fd", :name "finite-domain?", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 145, :examples ["(fd/finite-domain? (fd/domain 0 1));; => true\n(fd/finite-domain? (fd/interval 0 1));; => false"], :notes nil, :arglists ["x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/finite-domain_q"}, :clojure.core/assoc-in {:added "1.0", :ns "clojure.core", :name "assoc-in", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/assoc :clojure.core/update-in :clojure.core/get-in :clojure.core/associative?], :line 6161, :examples ["(def users [{:name \"James\" :age 26} {:name \"John\" :age 43}])\n\n;; update the age of the second (index 1) user \n(assoc-in users [1 :age] 44)\n;;=> [{:name \"James\", :age 26} {:name \"John\", :age 44}]\n\n;; insert the password of the second (index 1) user\n(assoc-in users [1 :password] \"nhoJ\")\n;;=> [{:name \"James\", :age 26} {:password \"nhoJ\", :name \"John\", :age 43}]\n\n;; create a third (index 2) user\n;; Also (assoc m 2 {...}) or (conj m {...})\n(assoc-in users [2] {:name \"Jack\" :age 19}) \n;;=> [{:name \"James\", :age 26} {:name \"John\", :age 43} {:name \"Jack\", :age 19}]\n\n;; From http://clojure-examples.appspot.com/clojure.core/assoc-in" ";; can be used to update a mutable item.\n(def ppl (atom {\"persons\" {\"joe\" {:age 1}}}))\n(swap! ppl assoc-in [\"persons\" \"bob\"] {:age 2})\n\n@ppl\n;;=> {\"persons\" {\"joe\" {:age 1}, \"bob\" {:age 2}}}" ";; be careful with that empty path sequence, it's seldom what you want\n(assoc-in {} [] {:k :v})\n;;=> {nil {:k :v}}\n\n;; In general, you find that for a non-empty path\n;; (get-in (assoc-in m path v) path) \n;; is equal to v.\n;; Surprisingly this does not hold true in case of an empty path." ";; another example of updating a mutable item.\n;; this time the first key is to a map and the second to a vector.\n(def foo (atom {:users [{:a \"a\"} {:b \"b\"}]}))\n(swap! foo assoc-in [:users 2] {:c \"c\"})\n;;=> {:users [{:a \"a\"} {:b \"b\"} {:c \"c\"}]}\n\n" ";; assoc-in into a nested map structure\n(def foo {:user {:bar \"baz\"}})\n(assoc-in foo [:user :id] \"some-id\")\n;;=> {:user {:bar \"baz\", :id \"some-id\"}}\n" "(assoc-in {} [:cookie :monster :vocals] \"Finntroll\")\n; => {:cookie {:monster {:vocals \"Finntroll\"}}}\n\n(get-in {:cookie {:monster {:vocals \"Finntroll\"}}} [:cookie :monster])\n; => {:vocals \"Finntroll\"}\n\n(assoc-in {} [1 :connections 4] 2)\n; => {1 {:connections {4 2}}}\n\n;; from http://www.braveclojure.com/functional-programming/" ";; assoc-in can be used on vectors too\n\n(def row 0)\n(def col 0)\n\n(assoc-in [[1 1 1]\n [1 1 1]\n [1 1 1]] [row col] 0)\n; => [[0 1 1][1 1 1][1 1 1]]\n\n(get-in [[0 1 1]\n [1 1 1]\n [1 1 1]] [row col])\n; => 0" "; Playing around with assoc-in\n\n(assoc-in {:person {:name \"Mike\"}} [:person :name] \"Violet\")\n; => {:person {:name \"Violet\"}}\n\n(assoc-in {:person {:name \"Mike\"}} [:person] \"Violet\")\n; => {:person \"Violet\"}\n\n(assoc-in [{:person {:name \"Mike\"}}] [0 :person :name] \"Violet\")\n; => [{:person {:name \"Violet\"}}]\n\n(assoc-in [{:person {:name [\"Mike\"]}}] [0 :person :name 1] \"Smith\")\n; => [{:person {:name [\"Mike\" \"Smith\"]}}]\n\n(assoc-in [{:person {:name [\"Mike\"]}}] [0 :person :name 2] \"Smith\")\n; => IndexOutOfBoundsException" ";; Note that, unlike `assoc`, `assoc-in` cannot be used with multiple values.\n\n(def my-map {})\n\n;; This works\n(assoc my-map :a 1\n :b 2\n :c 3)\n; => {:a 1, :b 2, :c 3}\n\n;; This doesn’t\n(assoc-in my-map [:a :aa] 1\n [:b :bb] 2\n [:c :cc] 3)\n; ArityException Wrong number of args (7) passed to: core/assoc-in\n\n;; This works\n(-> my-map\n (assoc-in [:a :aa] 1)\n (assoc-in [:b :bb] 2)\n (assoc-in [:c :cc] 3))"], :notes ["Unlike `assoc`, you can only do one kv at a time:\n\n```\n;; Allowed\n(assoc {} :a \"a\" :b \"b\" :c \"c\")\n;; Not allowed:\n(assoc-in {} [:a :b] \"cya\" [:a :d :e] \"f\" [:b :g] \"wow\")\n```"], :arglists ["m [k & ks] v"], :doc "Associates a value in a nested associative structure, where ks is a\n sequence of keys and v is the new value and returns a new nested structure.\n If any levels do not exist, hash-maps will be created.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/assoc-in"}, :clojure.core/tagged-literal {:added "1.7", :ns "clojure.core", :name "tagged-literal", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.edn/read-string], :line 7725, :examples ["(def x (tagged-literal 'user {:name \"Foo\"}))\n\n(:form x) ;; Get the actual codeform\n;; => {:name \"Foo\"}\n\n(:tag x) ;; Get the tagged symbol\n;; => user" "(require '[clojure.edn :as edn])\n(edn/read-string {:default tagged-literal} \"#js [1 2 3]\")\n;; => #js [1 2 3]\n"], :notes ["`tagged-literal` is useful as a value fo `clojure.core/*default-data-reader-fn*`"], :arglists ["tag form"], :doc "Construct a data representation of a tagged literal from a\n tag symbol and a form.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/tagged-literal"}, :clojure.core/gen-class {:added "1.0", :ns "clojure.core", :name "gen-class", :file "clojure/genclass.clj", :type "macro", :column 1, :see-alsos [:clojure.core/proxy :clojure.core/gen-interface], :line 507, :examples ["(gen-class\n\t:name \"some.package.RefMap\"\n\t:implements [java.util.Map]\n\t:state \"state\"\n\t:init \"init\"\n\t:constructors {[] []}\n\t:prefix \"ref-map-\")\n\n(defn ref-map-init []\n\t[[] (ref {})])\n\n(defn ref-map-size [this]\n\t(let [state (.state this)] (.size @state)))\n\t\n(defn ref-map-isEmpty [this]\n\t(let [state (.state this)] (.isEmpty @state)))\n\n(defn ref-map-containsKey [this o]\n\t(let [state (.state this)] (.containsKey @state o)))\n\t\n(defn ref-map-containsValue [this o]\n\t(let [state (.state this)] (.containsValue @state o)))\n\t\n(defn ref-map-get [this o]\n\t(let [state (.state this)] (.get @state o)))\n\t\n(defn ref-map-keySet [this]\n\t(let [state (.state this)] (.keySet @state)))\n\t\n(defn ref-map-values [this]\n\t(let [state (.state this)] (.values @state)))\n\t\n(defn ref-map-entrySet [this]\n\t(let [state (.state this)] (.entrySet @state)))\n\t\n(defn ref-map-equals [this o]\n\t(let [state (.state this)] (.equals @state o)))\n\t\n(defn ref-map-hashCode [this]\n\t(let [state (.state this)] (.hashCode @state)))\n\t\n(defn ref-map-put [this k v]\n\t(let [state (.state this)] \n\t\t(dosync (alter state assoc k v)) v))\n\t\n(defn ref-map-putAll [this m]\n\t(let [state (.state this)]\n\t\t(doseq [[k v] (map identity m)] (.put this k v))))\n\t\t\n(defn ref-map-remove [this o]\n\t(let [state (.state this) v (get @state o)] \n\t\t(dosync (alter state dissoc o)) v))\n\t\n(defn ref-map-clear [this]\n\t(let [state (.state this)] \n\t\t(dosync (ref-set state {}))))\n\t\n(defn ref-map-toString [this]\n\t(let [state (.state this)] (.toString @state)))" ";; I found managing state a bit confusing at first.\n;; here's a dumb little class with a getter and setter for a \"location\" field.\n\n(ns com.example )\n\n(gen-class\n :name com.example.Demo\n :state state\n :init init\n :prefix \"-\"\n :main false\n ;; declare only new methods, not superclass methods\n :methods [[setLocation [String] void]\n [getLocation [] String]])\n\n;; when we are created we can set defaults if we want.\n(defn -init []\n \"store our fields as a hash\"\n [[] (atom {:location \"default\"})])\n\n;; little functions to safely set the fields.\n(defn setfield\n [this key value]\n (swap! (.state this) into {key value}))\n\n(defn getfield\n [this key]\n (@(.state this) key))\n\n;; \"this\" is just a parameter, not a keyword\n(defn -setLocation [this loc]\n (setfield this :location loc))\n\n(defn -getLocation\n [this]\n (getfield this :location))\n\n;; running it -- you must compile and put output on the classpath\n;; create a Demo, check the default value, then set it and check again.\nuser=> (def ex (com.example.Demo.))\n#'user/ex\nuser=> (.getLocation ex)\n\"default\"\nuser=> (.setLocation ex \"time\")\nnil\nuser=> (.getLocation ex)\n\"time\"\n" ";; This example illustrates the syntax intended by the docstring's remark that \n;; \"Static methods can be specified with ^{:static true} in the signature's \n;; metadata\", and notes a case in which you might not think that you need to use\n;; :methods.\n\n;; The docs say, about :methods, \"Do not repeat superclass/interface\n;; signatures here.\" That applies to non-static methods. If you want to\n;; define a static method to hide a static method in the superclass, you\n;; are not overriding the superclass method (the behavior is different).\n;; You are simply defining a new method with the same name. In this case,\n;; you should add a signature to :methods if you want your function to be\n;; visible to Java, with metadata indicating that it is static placed\n;; before the signature vector:\n\n(ns \n ...\n (:gen-class \n ...\n :methods [[...] ...\n ^{:static true} [name [] java.lang.String]\n [...] ...]\n ...))\n\n(defn -name [] \"My name is Foo\")\n\n;; Also note that you can replace \"^{:static true}\" with \"^:static\"." ";; It is possible to attach Java annotations to the class,\n;; constructors, and methods \n;; Source: https://github.com/clojure/clojure/blob/8af7e9a92570eb28c58b15481ae9c271d891c028/test/clojure/test_clojure/genclass/examples.clj#L34\n(gen-class :name ^{Deprecated {}\n SuppressWarnings [\"Warning1\"] ; discarded\n java.lang.annotation.Target []}\n clojure.test_clojure.genclass.examples.ExampleAnnotationClass\n :prefix \"annot-\"\n :methods [[^{Deprecated {}\n Override {}} ;discarded\n foo [^{java.lang.annotation.Retention java.lang.annotation.RetentionPolicy/SOURCE\n java.lang.annotation.Target [java.lang.annotation.ElementType/TYPE\n java.lang.annotation.ElementType/PARAMETER]}\n String] void]])\n" ";; Defining a custom constructor which calls a superclass constructor:\n(ns my.CustomException\n (:gen-class\n :implements [clojure.lang.IExceptionInfo]\n :extends java.lang.RuntimeException\n :constructors {[String Throwable clojure.lang.IPersistentMap] [String Throwable]} ; mapping of my-constructor -> superclass constuctor\n :init init\n :state state ; name for the var that holds your internal state\n :main false\n :prefix \"my-ex-\"))\n\n(defn my-ex-init [msg t context]\n ;; first element of vector contains parameters for the superclass constructor\n ;; Second element will be your internal state \n [[msg t] context]) \n\n(defn my-ex-getData [this]\n (.state this)) ; accessing the internal state\n"], :macro true, :notes ["When implementing interface methods with `gen-class` (when using `:implements`) watch out for primitive return types in interface methods.\r\n\r\nWhen you get weird `NullPointerException`s or `ClassPathException`s then make sure whether the value returned by your functions can be converted by Clojure to the primitive return type defined in the interface for that method.\r\n\r\nExample:\r\n\r\nGiven:\r\n\r\n
\r\ninterface Test {\r\n boolean isTest();\r\n}\r\n
\r\n\r\nClojure implementation:\r\n\r\n
\r\n(gen-class :name \"MyTest\" :implements [Test])\r\n\r\n; Will throw NPE when executed, \r\n; can't be converted to boolean\r\n(defn -isTest [this] nil) \r\n
\r\n\r\n
\r\n(gen-class :name \"MyTest\" :implements [Test])\r\n\r\n; Will throw ClassCastExcpetion when executed, \r\n; can't be converted to boolean\r\n(defn -isTest [this] (Object.)) \r\n
" "When implementing an interface or extending an abstract class that implements an interface, be careful to implement all methods in the implemented interfaces. Note: The abstract class is not required to implement all methods in the interface. The clojure compiler does not throw compiler errors if you do not implement a method. A runtime error will be thrown when someone tries to use the function. The documentation suggests that you will receive UnsupportedOperationException, however in the case of the abstract class a java.lang.AbstractMethodError is thrown. \r\n\r\n**example:**\r\n\r\nLog4j appender - Extending AppenderSkeleton will fail with runtime error\r\n
\r\n\r\n\r\n" "If your namespace has dashes in it, then the class name will be mangled so the dashes become underscores, unless you have a :name directive. Your naive instantiation will fail with ClassNotFoundException.\n\n (ns my-project.MyClass\n (:gen-class))\n\n (my-project.MyClass.) ;;=> java.lang.ClassNotFoundException\n (my_project.MyClass.) ;;=> #" "Note: If you are using :extends you must use the fully qualified class name even if the class is in the :import list for the namespace. " "Not strictly speaking a `gen-class` issue, but if you need to override a Java method that's overloaded by specifying different classes for its arguments, this can be done by incorporating the class names into Clojure function names. See:\n\nhttps://groups.google.com/forum/#!topic/clojure/TVRsy4Gnf70\n\nhttps://puredanger.github.io/tech.puredanger.com/2011/08/12/subclassing-in-clojure\n\nhttp://stackoverflow.com/questions/32773861/clojure-gen-class-for-overloaded-and-overridden-methods\n\nhttp://dishevelled.net/Tricky-uses-of-Clojure-gen-class-and-AOT-compilation.html\n"], :arglists ["& options"], :doc "When compiling, generates compiled bytecode for a class with the\n given package-qualified :name (which, as all names in these\n parameters, can be a string or symbol), and writes the .class file\n to the *compile-path* directory. When not compiling, does\n nothing. The gen-class construct contains no implementation, as the\n implementation will be dynamically sought by the generated class in\n functions in an implementing Clojure namespace. Given a generated\n class org.mydomain.MyClass with a method named mymethod, gen-class\n will generate an implementation that looks for a function named by \n (str prefix mymethod) (default prefix: \"-\") in a\n Clojure namespace specified by :impl-ns\n (defaults to the current namespace). All inherited methods,\n generated methods, and init and main functions (see :methods, :init,\n and :main below) will be found similarly prefixed. By default, the\n static initializer for the generated class will attempt to load the\n Clojure support code for the class as a resource from the classpath,\n e.g. in the example case, ``org/mydomain/MyClass__init.class``. This\n behavior can be controlled by :load-impl-ns\n\n Note that methods with a maximum of 18 parameters are supported.\n\n In all subsequent sections taking types, the primitive types can be\n referred to by their Java names (int, float etc), and classes in the\n java.lang package can be used without a package qualifier. All other\n classes must be fully qualified.\n\n Options should be a set of key/value pairs, all except for :name are optional:\n\n :name aname\n\n The package-qualified name of the class to be generated\n\n :extends aclass\n\n Specifies the superclass, the non-private methods of which will be\n overridden by the class. If not provided, defaults to Object.\n\n :implements [interface ...]\n\n One or more interfaces, the methods of which will be implemented by the class.\n\n :init name\n\n If supplied, names a function that will be called with the arguments\n to the constructor. Must return [ [superclass-constructor-args] state] \n If not supplied, the constructor args are passed directly to\n the superclass constructor and the state will be nil\n\n :constructors {[param-types] [super-param-types], ...}\n\n By default, constructors are created for the generated class which\n match the signature(s) of the constructors for the superclass. This\n parameter may be used to explicitly specify constructors, each entry\n providing a mapping from a constructor signature to a superclass\n constructor signature. When you supply this, you must supply an :init\n specifier. \n\n :post-init name\n\n If supplied, names a function that will be called with the object as\n the first argument, followed by the arguments to the constructor.\n It will be called every time an object of this class is created,\n immediately after all the inherited constructors have completed.\n Its return value is ignored.\n\n :methods [ [name [param-types] return-type], ...]\n\n The generated class automatically defines all of the non-private\n methods of its superclasses/interfaces. This parameter can be used\n to specify the signatures of additional methods of the generated\n class. Static methods can be specified with ^{:static true} in the\n signature's metadata. Do not repeat superclass/interface signatures\n here.\n\n :main boolean\n\n If supplied and true, a static public main function will be generated. It will\n pass each string of the String[] argument as a separate argument to\n a function called (str prefix main).\n\n :factory name\n\n If supplied, a (set of) public static factory function(s) will be\n created with the given name, and the same signature(s) as the\n constructor(s).\n \n :state name\n\n If supplied, a public final instance field with the given name will be\n created. You must supply an :init function in order to provide a\n value for the state. Note that, though final, the state can be a ref\n or agent, supporting the creation of Java objects with transactional\n or asynchronous mutation semantics.\n\n :exposes {protected-field-name {:get name :set name}, ...}\n\n Since the implementations of the methods of the generated class\n occur in Clojure functions, they have no access to the inherited\n protected fields of the superclass. This parameter can be used to\n generate public getter/setter methods exposing the protected field(s)\n for use in the implementation.\n\n :exposes-methods {super-method-name exposed-name, ...}\n\n It is sometimes necessary to call the superclass' implementation of an\n overridden method. Those methods may be exposed and referred in \n the new method implementation by a local name.\n\n :prefix string\n\n Default: \"-\" Methods called e.g. Foo will be looked up in vars called\n prefixFoo in the implementing ns.\n\n :impl-ns name\n\n Default: the name of the current ns. Implementations of methods will be \n looked up in this namespace.\n\n :load-impl-ns boolean\n\n Default: true. Causes the static initializer for the generated class\n to reference the load code for the implementing namespace. Should be\n true when implementing-ns is the default, false if you intend to\n load the code via some other method.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/gen-class"}, :clojure.core/simple-keyword? {:added "1.9", :ns "clojure.core", :name "simple-keyword?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/keyword? :clojure.core/qualified-keyword?], :line 1637, :examples ["(simple-keyword? :keyword)\n;;=> true\n\n(simple-keyword? :user/:keyword)\n;;=> false\n(simple-keyword? ::keyword)\n;;=> false\n\n(simple-keyword? \"string\")\n;;=> false\n(simple-keyword? 42)\n;;=> false\n(simple-keyword? nil)\n;;=> false"], :notes nil, :arglists ["x"], :doc "Return true if x is a keyword without a namespace", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/simple-keyword_q"}, :clojure.core.logic.fd/difference* {:ns "clojure.core.logic.fd", :name "difference*", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 408, :examples nil, :notes nil, :arglists ["is js"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/difference*"}, :clojure.core.logic.fd/== {:ns "clojure.core.logic.fd", :name "==", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 749, :examples nil, :notes nil, :arglists ["u v"], :doc "A finite domain constraint. u and v must be equal. u and v must\n eventually be given domains if vars.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/=="}, :clojure.core.async/remove< {:ns "clojure.core.async", :name "remove<", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 1086, :examples nil, :deprecated "0.1.319.0-6b1aca-alpha", :notes nil, :arglists ["p ch" "p ch buf-or-n"], :doc "Deprecated - this function will be removed. Use transducer instead", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/remove<"}, :clojure.core/symbol? {:added "1.0", :ns "clojure.core", :name "symbol?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/simple-symbol? :clojure.core/qualified-symbol?], :line 562, :examples ["user=> (symbol? 'a)\ntrue\nuser=> (symbol? 1)\nfalse\nuser=> (symbol? :a)\nfalse"], :notes nil, :arglists ["x"], :doc "Return true if x is a Symbol", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/symbol_q"}, :clojure.instant/read-instant-timestamp {:ns "clojure.instant", :name "read-instant-timestamp", :file "clojure/instant.clj", :type "function", :column 1, :see-alsos [:clojure.instant/read-instant-date], :line 288, :examples ["(clojure.instant/read-instant-date \"2020-03-23T01:17Z\")\n;=> #inst \"2020-03-23T01:17:00.000-00:00\""], :notes nil, :arglists ["cs"], :doc "To read an instant as a java.sql.Timestamp, bind *data-readers* to a\nmap with this var as the value for the 'inst key. Timestamp preserves\nfractional seconds with nanosecond precision. The timezone offset will\nbe used to convert into UTC.", :library-url "https://github.com/clojure/clojure", :href "/clojure.instant/read-instant-timestamp"}, :clojure.spec.alpha/explain-out {:ns "clojure.spec.alpha", :name "explain-out", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 254, :examples nil, :notes nil, :arglists ["ed"], :doc "Prints explanation data (per 'explain-data') to *out* using the printer in *explain-out*,\n by default explain-printer.", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/explain-out"}, :clojure.core.logic/resto {:ns "clojure.core.logic", :name "resto", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos [:clojure.core.logic/firsto], :line 1671, :examples nil, :notes nil, :arglists ["l d"], :doc "A relation where l is a collection, such that d is the rest of l", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/resto"}, :clojure.instant/validated {:ns "clojure.instant", :name "validated", :file "clojure/instant.clj", :type "function", :column 1, :see-alsos nil, :line 139, :examples nil, :notes nil, :arglists ["new-instance"], :doc "Return a function which constructs an instant by calling constructor\nafter first validating that those arguments are in range and otherwise\nplausible. The resulting function will throw an exception if called\nwith invalid arguments.", :library-url "https://github.com/clojure/clojure", :href "/clojure.instant/validated"}, :clojure.core/read+string {:added "1.10", :ns "clojure.core", :name "read+string", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 3770, :examples [";; read from *in*\n;; notice that whitespace is trimmed\nuser=> (read+string)\n :a\n[:a \":a\"]\nuser=> (read+string)\n 1234 56 7\n[1234 \"1234\"]\nuser=> (read+string)\n[56 \"56\"]\nuser=> (read+string)\n[7 \"7\"]\n\n;; if there is a comment it is included in the string read\nuser=> (read+string)\n;comment\n:value\n[:value \";comment\\n:value\"] "], :notes nil, :arglists ["" "stream" "stream eof-error? eof-value" "stream eof-error? eof-value recursive?" "opts stream"], :doc "Like read, and taking the same args. stream must be a LineNumberingPushbackReader.\n Returns a vector containing the object read and the (whitespace-trimmed) string read.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/read+string"}, :clojure.core/var-get {:added "1.0", :ns "clojure.core", :name "var-get", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/with-local-vars :clojure.core/var-set :clojure.core/var], :line 4327, :examples ["user=> map\n#\n\nuser=> #'map ;; The reader macro #'x expands to (var x).\n#'clojure.core/map\n\nuser=> (var-get #'map)\n#" "user=> ((var-get (var inc)) 1)\n2" ";; var-get is the same as @\nuser> (def a-var 1)\n#'user/a-var\nuser> (var-get #'a-var)\n1\nuser> @#'a-var\n1\nuser> (var-get (resolve 'a-var))\n1\nuser> @(resolve 'a-var)\n1"], :notes nil, :arglists ["x"], :doc "Gets the value in the var object", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/var-get"}, :clojure.core/while {:added "1.0", :ns "clojure.core", :name "while", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/loop :clojure.core/dotimes :clojure.core/repeatedly :clojure.core/swap! :clojure.core/atom], :line 6333, :examples [";; a var to be used for its side effects\n(def a (atom 10)) \n;; #'user/a\n\n(while (pos? @a)\n (println @a)\n (swap! a dec))\n;; 10\n;; 9\n;; 8\n;; 7\n;; 6\n;; 5\n;; 4\n;; 3\n;; 2\n;; 1\n;;=> nil" ";; calculate the MD5 of a file incrementally:\n\n(import\n 'java.io.File\n 'javax.xml.bind.DatatypeConverter\n 'java.security.MessageDigest\n 'java.security.DigestInputStream)\n\n(require '[clojure.java.io :as io])\n\n(defn md5-file [file]\n (let [sha (MessageDigest/getInstance \"MD5\")] \n (with-open [dis (DigestInputStream. (io/input-stream file) sha)] \n (while (> (.read dis) -1))) \n (DatatypeConverter/printHexBinary (.digest sha)))) \n\n(md5-file (File. \"/etc/hosts\"))\n;; \"04F186E74288A10E09DFBF8A88D64A1F33C0E698AAA6B75CDB0AC3ABA87D5644\""], :macro true, :notes nil, :arglists ["test & body"], :doc "Repeatedly executes body while test expression is true. Presumes\n some side-effect will cause test to become false/nil. Returns nil", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/while"}, :clojure.core/line-seq {:added "1.0", :ns "clojure.core", :name "line-seq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/read-line], :line 3085, :examples [";; Count lines of a file (loses head):\nuser=> (with-open [rdr (clojure.java.io/reader \"/etc/passwd\")]\n (count (line-seq rdr)))\n\n" "(import '(java.io BufferedReader StringReader))\n\n;; line terminators are stripped\nuser=> (line-seq (BufferedReader. (StringReader. \"1\\n2\\n\\n3\")))\n(\"1\" \"2\" \"\" \"3\")\n\n;; empty string gives nil\nuser=> (line-seq (BufferedReader. (StringReader. \"\")))\nnil\n" ";; read from standard input\nuser=> (nth (line-seq (java.io.BufferedReader. *in*)) 2)\n #_=> 0\n #_=> 1\n #_=> 2\n\"2\"\n"], :notes ["Documentation says that `line-seq` returns a lazy sequence, however \nthe actual return value is a `Cons` cell of the first line to a `LazySeq` of \nthe second line. Calling `realized?` on the `Cons` cell will fail with an exception.\n\n`(cons (.readLine rdr) (lazy-seq (line-seq rdr)))` \n\nExample: \n`(def rdr (BufferedReader. (StringReader. \" 1\\n 2\\n 3\")))` \n`(def x (line-seq rdr))` \n`(class x)` \n`=> clojure.lang.Cons`\n\n`(realized? x)` \n`=> Execution error (ClassCastException) class clojure.lang.Cons cannot be cast to class clojure.lang.IPending`\n\nThe first line was eagerly realized by the initial call to the `line-seq`. \n`(.readLine rdr)` \n`=> \" 2\"`"], :arglists ["rdr"], :doc "Returns the lines of text from rdr as a lazy sequence of strings.\n rdr must implement java.io.BufferedReader.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/line-seq"}, :clojure.core/any? {:added "1.9", :ns "clojure.core", :name "any?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/constantly :clojure.core/some?], :line 538, :examples [";; All known practical uses are in the context of core.spec\n;; Specifically indicates that any type is allowed.\n\n;; https://clojure.org/guides/spec#_macros\n(s/fdef clojure.core/declare\n :args (s/cat :names (s/* simple-symbol?))\n :ret any?)\n" ";; any? never returns false\n\nuser=> (any? {})\n;; true\nuser=> (any? [])\n;; true\nuser=> (any? nil)\n;; true\nuser=> (any? true)\n;; true\nuser=> (any? false)\n;; true" ";; Combined with `halt-when` to make a \"first\" transducer\n(transduce (comp (filter even?) (halt-when any?)) identity nil [1 3 5 6 7 8 9])\n;; => 6\n"], :notes ["The current implementation of [any?](https://github.com/clojure/clojure/blob/clojure-1.9.0/src/clj/clojure/core.clj#L538-L542) is incorrect and must be fixed IMO.\nThere was a [PR](https://github.com/clojure/clojure/pull/49) (copied below) submitted in 2014 to add a correct implementation which is consistent with behaviour in other languages. \n\n```\n(def\n ^{:tag Boolean\n :doc \"Returns true if (pred x) is logical true for any x in coll,\n else false.\"\n :arglists '([pred coll])\n :added \"1.7\"}\n any? (comp boolean some))\n```" "any? never returns false. Is this a bug?" "You can think of this function as a non-variadic `(constantly true)`." "[Explanation by Alex Miller:](https://ask.clojure.org/index.php/11260/does-the-any-function-have-the-correct-behavior?show=11261#a11261)\n\n> \n`any?` is a predicate that is intended to always return true, so yes it is the correct behavior. `any?` was added as a predicate to use with spec in the case where any value is valid. It is not a complement to `not-any?`, despite that obvious assumption. There are, in the end, only so many words and despite a lot of care in this regard, there are times when these confusions exist.\n\n> ...this is similar to `and` (for N args) but that does have limits as a macro, or `every?` (for a coll), or the higher-order function `every-pred` for creating a composite pred. Depending on your case, one of those probably makes sense."], :tag "java.lang.Boolean", :arglists ["x"], :doc "Returns true given any argument.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/any_q"}, :clojure.core/future? {:added "1.1", :ns "clojure.core", :name "future?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/future], :line 6530, :examples ["user=> (def f (future (inc 0)))\n#'user/f\n\nuser=> (future? f)\ntrue\n\nuser=> (future? 1)\nfalse\n"], :notes nil, :arglists ["x"], :doc "Returns true if x is a future", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/future_q"}, :clojure.core/*reader-resolver* {:ns "clojure.core", :name "*reader-resolver*", :type "var", :see-alsos nil, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*reader-resolver*"}, :clojure.spec.alpha/*coll-check-limit* {:ns "clojure.spec.alpha", :name "*coll-check-limit*", :file "clojure/spec/alpha.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 29, :examples nil, :notes nil, :arglists [], :doc "The number of elements validated in a collection spec'ed with 'every'", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/*coll-check-limit*"}, :clojure.core/keep-indexed {:added "1.2", :ns "clojure.core", :name "keep-indexed", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/map-indexed :clojure.core/keep], :line 7346, :examples ["user=> (keep-indexed #(if (odd? %1) %2) [:a :b :c :d :e])\n(:b :d)" "user=> (keep-indexed #(if (pos? %2) %1) [-9 0 29 -7 45 3 -8])\n(2 4 5)\n;; f takes 2 args: 'index' and 'value' where index is 0-based\n;; when f returns nil the index is not included in final result\nuser=> (keep-indexed (fn [idx v]\n (if (pos? v) idx)) [-9 0 29 -7 45 3 -8])\n(2 4 5)" "(defn position [x coll & {:keys [from-end all] :or {from-end false all false}}]\n (let [all-idxs (keep-indexed (fn [idx val] (when (= val x) idx)) coll)]\n (cond\n (true? from-end) (last all-idxs)\n (true? all) all-idxs\n :else (first all-idxs))))\n\nuser> (position [1 1] [[1 0][1 1][2 3][1 1]])\n1\nuser> (position [1 1] [[1 0][1 1][2 3][1 1]] :from-end true)\n3\nuser> (position [1 1] [[1 0][1 1][2 3][1 1]] :all true)\n(1 3)\n\nuser> (def foo (shuffle (range 10)))\n#'user/foo\nuser> foo\n(5 8 9 1 2 7 0 6 3 4)\nuser> (position 5 foo)\n0\nuser> (position 0 foo)\n6" ";; Simpler version of \"position\" above\n;; Get position of first element that satisfies the predicate\n(let [predicate #(= 1 %)\n sequence [3 2 4 1 5 6 7]]\n (first (keep-indexed (fn [i x] (when (predicate x) i)) \n sequence)))\n\n;; The same logic but implemented with map-indexed\n(let [predicate #(= 1 %)\n sequence [3 2 4 1 5 6 7]]\n (some identity \n (map-indexed (fn [i x] (when (predicate x) i)) \n sequence)))" "(require '[clojure.pprint :as p]\n '[clojure.java.jdbc :as j])\n \n(def db\n {:classname \"org.sqlite.JDBC\"\n :subprotocol \"sqlite\"\n :subname \"/home/liuwensui/Downloads/chinook.db\"})\n \n(def orders (j/query db \"select billingcountry as country, count(*) as orders from invoices group by billingcountry;\"))\n \n(def clist '(\"USA\" \"India\" \"Canada\" \"France\")\n\n(def country (map #(get % :country) orders))\n\n(p/print-table \n (map #(nth orders %) \n (flatten (pmap (fn [c] (keep-indexed (fn [i v] (if (= v c) i)) country)) clist))))\n\n;| :country | :orders |\n;|----------+---------|\n;| USA | 91 |\n;| India | 13 |\n;| Canada | 56 |\n;| France | 35 |" ";; a simple example\n(map-indexed #(when (< % 2) (str % %2)) [:a :b :c])\n;;=> (\"0:a\" \"1:b\" nil)\n\n(keep-indexed #(when (< % 2) (str % %2)) [:a :b :c])\n;;=> (\"0:a\" \"1:b\")" ";; returns a new list by removing the elements at odd positions\n(defn filter-list-by-position\n [lst]\n (into []\n (keep-indexed #(when (odd? %1) %2)) ;; transducer\n lst))\n\n;; 0 1 2 3 4 5 6 8\n(def nums [2 5 3 4 6 7 9 8])\n\n(filter-list-by-position nums)\n;;=> [5 4 7 8]"], :notes nil, :arglists ["f" "f coll"], :doc "Returns a lazy sequence of the non-nil results of (f index item). Note,\n this means false return values will be included. f must be free of\n side-effects. Returns a stateful transducer when no collection is\n provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/keep-indexed"}, :clojure.core.logic/run-constraint {:ns "clojure.core.logic", :name "run-constraint", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2070, :examples nil, :notes nil, :arglists ["c"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/run-constraint"}, :clojure.core.logic/-reify {:ns "clojure.core.logic", :name "-reify", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 263, :examples nil, :notes nil, :arglists ["s v" "s v r"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/-reify"}, :clojure.core.logic.fd/get-dom {:ns "clojure.core.logic.fd", :name "get-dom", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 591, :examples nil, :notes nil, :arglists ["a x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/get-dom"}, :clojure.core.logic/-conjo {:ns "clojure.core.logic", :name "-conjo", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2768, :examples nil, :notes nil, :arglists ["coll args out"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/-conjo"}, :clojure.core.logic/add-attr {:ns "clojure.core.logic", :name "add-attr", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 432, :examples nil, :notes nil, :arglists ["s x attr attrv"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/add-attr"}, :clojure.core.logic.fd/expand {:ns "clojure.core.logic.fd", :name "expand", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 1113, :examples nil, :notes nil, :arglists ["form"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/expand"}, :clojure.test/is {:added "1.1", :ns "clojure.test", :name "is", :file "clojure/test.clj", :type "macro", :column 1, :see-alsos [:clojure.test/are :clojure.test/deftest :clojure.test/testing], :line 554, :examples ["(use '[clojure.test :only [is]])\n\nuser=> (is (true? true))\ntrue\n\n;; false assertions print a message and evaluate to false\n\nuser=> (is (true? false))\nFAIL in clojure.lang.PersistentList$EmptyList@1 (NO_SOURCE_FILE:1)\nexpected: (true? false)\n actual: (not (true? false))\nfalse\n\n" "; Testing for thrown exceptions\n\n; Verifies that the specified exception is thrown\nuser=> (is (thrown? ArithmeticException (/ 1 0)))\n#\n\n; Verified that the exception is thrown, and that the error message matches the specified regular expression.\nuser=> (is (thrown-with-msg? ArithmeticException #\"Divide by zero\"\n #_=> (/ 1 0)))\n#\nuser=> \n\n"], :macro true, :notes nil, :arglists ["form" "form msg"], :doc "Generic assertion macro. 'form' is any predicate test.\n 'msg' is an optional message to attach to the assertion.\n \n Example: (is (= 4 (+ 2 2)) \"Two plus two should be 4\")\n\n Special forms:\n\n (is (thrown? c body)) checks that an instance of c is thrown from\n body, fails if not; then returns the thing thrown.\n\n (is (thrown-with-msg? c re body)) checks that an instance of c is\n thrown AND that the message on the exception matches (with\n re-find) the regular expression re.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/is"}, :clojure.core/aget {:added "1.0", :ns "clojure.core", :name "aget", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/aclone :clojure.core/get :clojure.core/nth :clojure.core/contains? :clojure.core/aset], :line 3912, :examples ["\n;; create two arrays\n(def a1 (double-array '(1.0 2.0 3.0 4.0)))\n;;=> #'user/a1\n(def a2 (int-array '(9 8 7 6)))\n;;=> #'user/a2\n\n;; get an item by index\n(aget a1 2)\n;;=> 3.0\n(aget a2 3)\n;;=> 6\n\n;; 2d array and 2 indicies\n(def a3 (make-array Integer/TYPE 100 100))\n;;=> #'user/a3\n(aget a3 23 42)\n;;=> 0" ";; aget can be used to check the existence of an element\n;; this approach works with documents in ClojureScript where core/contains? does not\n(aget js/document \"getElementById\")\n;;=> #object[getElementById \"function getElementById() { [native code] }\"]\n(contains? js/document \"getElementById\")\n;;=> false"], :notes nil, :arglists ["array idx" "array idx & idxs"], :doc "Returns the value at the index/indices. Works on Java arrays of all\n types.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aget"}, :clojure.pprint/pprint {:added "1.2", :ns "clojure.pprint", :name "pprint", :file "clojure/pprint/pprint_base.clj", :type "function", :column 1, :see-alsos [:clojure.pprint/pp :clojure.pprint/print-table :clojure.core/prn :clojure.core/prn-str :clojure.core/pr :clojure.core/pr-str :clojure.pprint/pprint-tab], :line 241, :examples ["(def big-map (zipmap \n [:a :b :c :d :e] \n (repeat \n (zipmap [:a :b :c :d :e] \n (take 5 (range))))))\n;;=> #'user/big-map\n\nbig-map\n;;=> {:a {:a 0, :b 1, :c 2, :d 3, :e 4}, :b {:a 0, :b 1, :c 2, :d 3, :e 4}, :c {:a 0, :b 1, :c 2, :d 3, :e 4}, :d {:a 0, :b 1, :c 2, :d 3, :e 4}, :e {:a 0, :b 1, :c 2, :d 3, :e 4}}\n\n(clojure.pprint/pprint big-map)\n;; {:e {:e 4, :d 3, :c 2, :b 1, :a 0},\n;; :d {:e 4, :d 3, :c 2, :b 1, :a 0},\n;; :c {:e 4, :d 3, :c 2, :b 1, :a 0},\n;; :b {:e 4, :d 3, :c 2, :b 1, :a 0},\n;; :a {:e 4, :d 3, :c 2, :b 1, :a 0}}\n;; nil" ";; suppose you want to pretty print to a file.\n(clojure.pprint/pprint *map* (clojure.java.io/writer \"foo.txt\"))\n;; writes the contents of *map* to a file named 'foo.txt'" ";; pprint into a string using with-out-str\n(with-out-str (clojure.pprint/pprint {:x 1 :y -1}))\n;; => \"{:x 1, :y -1}\\n\"\n\n;; pprint into a string using StringWriter\n(let [out (java.io.StringWriter.)]\n (clojure.pprint/pprint {:a 1 :b 2} out)\n (clojure.pprint/pprint {:c 3 :d 4} out)\n (.toString out))\n;; => \"{:a 1, :b 2}\\n{:c 3, :d 4}\\n\"\n" ";;how to use it with :require and :use\n\n;; :require \n(ns example.pprinter\n (:require [clojure.pprint :as pp]))\n\n(def myname \"John Smith\")\n(pp/pprint myname)\n\n--------------\n\n;;:use\n(ns example.pprinter\n (:use clojure.pprint))\n\n(def myname \"John Smith\")\n(pprint myname)" ";; get Clojure snippets to print nicely\n(require '[clojure.pprint :as p])\n\n(def lost-formatting \n \"(defn op [sel] (condp = sel :plus + :minus - :mult * \n :div / :rem rem :quot quot :mod mod))\")\n\n(p/with-pprint-dispatch\n p/code-dispatch\n (p/pprint \n (clojure.edn/read-string lost-formatting)))\n\n;; (defn op [sel]\n;; (condp = sel\n;; :plus +\n;; :minus -\n;; :mult *\n;; :div /\n;; :rem rem\n;; :quot quot\n;; :mod mod))" ";; pprint with metadata, requires Clojure >= 1.10.2\n(require '[clojure.pprint :as p])\n(binding [*print-meta* true]\n (p/pprint ^{:hello :world} {}))"], :notes ["When using Clojure from the REPL, you don't need to specify `clojure.pprint` to use `pprint` or `pp`. At the REPL `(clojure.pprint x)` is equivalent to `(pprint x)`."], :arglists ["object" "object writer"], :doc "Pretty print object to the optional output writer. If the writer is not provided, \nprint the object to the currently bound value of *out*.", :library-url "https://github.com/clojure/clojure", :href "/clojure.pprint/pprint"}, :clojure.core.logic.fd/< {:ns "clojure.core.logic.fd", :name "<", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 825, :examples nil, :notes nil, :arglists ["u v"], :doc "A finite domain constraint. u must be less than v. u and v\n must eventually be given domains if vars.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/<"}, :clojure.core/throw {:ns "clojure.core", :name "throw", :type "var", :see-alsos [:clojure.core/try :clojure.core/catch :clojure.core/finally :clojure.core/ex-info :clojure.core/ex-data], :examples ["=> (throw (Exception. \"my exception message\"))\njava.lang.Exception: my exception message (NO_SOURCE_FILE:0)\n" ";; Different types of exception can be thrown\n=> (throw (AssertionError. \"Wrong input.\"))\njava.lang.AssertionError: Wrong input." ";; ClojureScript usage\n=> (throw (js/Error. \"something went wrong...\"))"], :notes nil, :arglists [], :doc "The expr is evaluated and thrown, therefore it should yield an instance of\nsome derivee of Throwable. Please see http://clojure.org/special_forms#throw", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/throw"}, :clojure.core.logic/map->PMap {:ns "clojure.core.logic", :name "map->PMap", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2518, :examples nil, :notes nil, :arglists ["m__8876__auto__"], :doc "Factory function for class clojure.core.logic.PMap, taking a map of keywords to field values.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/map->PMap"}, :clojure.spec.alpha/conformer {:ns "clojure.spec.alpha", :name "conformer", :file "clojure/spec/alpha.clj", :type "macro", :column 1, :see-alsos [:clojure.spec.alpha/unform], :line 661, :examples [";; One use of clojure.spec.alpha/conformer is to convert inputs to a data\n;; structure more suitable for further conforming. In this sketch we use a regex\n;; spec to describe a string representing a binary number.\n\n(require '[clojure.spec.alpha :as s]\n '[clojure.spec.gen.alpha :as gen])\n\n(s/def ::str->chars (s/conformer seq #(apply str %)))\n\n(s/def ::binary-digits (s/cat :initial #{\\1}, :more (s/* #{\\0 \\1})))\n\n;; Look, no \"re-matches\"!\n(s/def ::binary-string\n (s/with-gen (s/and string? ::str->chars ::binary-digits)\n (fn []\n (gen/fmap #(s/unform ::str->chars %) (s/gen ::binary-digits)))))\n\n(s/conform ::binary-string \"1011\")\n;;=> {:initial \\1, :more [\\0 \\1 \\1]}\n\n(gen/sample (s/gen ::binary-string))\n;;=> (\"1\" \"1\" \"11\" \"1\" \"1001\" \"11\" \"1100\" \"110011\" \"111111\" \"10\")\n" "(s/conform map? {:a 1})\n;;=> {:a 1}\n\n(s/conform (s/conformer map?) {:a 1})\n;;=> true\n\n-------------------------------\n\n(s/conform second [:a :b :c])\n;;=> [:a :b :c]\n\n(s/conform (s/conformer second) [:a :b :c])\n;;=> :b"], :macro true, :notes nil, :arglists ["f" "f unf"], :doc "takes a predicate function with the semantics of conform i.e. it should return either a\n (possibly converted) value or :clojure.spec.alpha/invalid, and returns a\n spec that uses it as a predicate/conformer. Optionally takes a\n second fn that does unform of result of first", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/conformer"}, :clojure.core.logic/->LVar {:ns "clojure.core.logic", :name "->LVar", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 621, :examples nil, :notes nil, :arglists ["id unique name oname hash meta"], :doc "Positional factory function for class clojure.core.logic.LVar.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/->LVar"}, :clojure.java.io/file {:added "1.2", :ns "clojure.java.io", :name "file", :file "clojure/java/io.clj", :type "function", :column 1, :see-alsos [:clojure.core/file-seq :clojure.java.io/reader :clojure.java.io/writer :clojure.java.io/delete-file :clojure.java.io/make-parents :clojure.java.io/as-file :clojure.core/load-file], :line 418, :examples ["user> (clojure.java.io/file \"/tmp/foo\")\n#\n\nuser> (clojure.java.io/file \"http://asdf.com\")\n#\n\nuser> (clojure.java.io/file \"/tmp/foo\" \"bar\")\n#" "; Use clojure.java.io to read in resources from the classpath\n\n(ns rescue.core\n (:require [clojure.java.io :as io] ))\n\n; Populate the file on the command line: \n; echo \"Hello Resources!\" > resources/hello.txt\n(def data-file (io/resource \n \"hello.txt\" ))\n(defn -main []\n (println (slurp data-file)) )\n; When do \"lein run\"\n; => Hello Resources!" "; slurp can be used directly on value of io/resource\n\n(ns rescue.core\n (require [clojure.java.io :as io]))\n\n; echo \"hello world\" > resources/hello.txt\n(def data (io/resource \"hello.txt\"))\n\n(defn -main []\n (println (slurp data-file))\n; when do \"lein run\"\n; => hello world"], :notes nil, :tag "java.io.File", :arglists ["arg" "parent child" "parent child & more"], :doc "Returns a java.io.File, passing each arg to as-file. Multiple-arg\n versions treat the first argument as parent and subsequent args as\n children relative to the parent.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/file"}, :clojure.core/print-method {:ns "clojure.core", :name "print-method", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [:clojure.core/print-dup], :line 3663, :examples ["(deftype XYZ [])\n\n; without custom print-method defined:\nuser=> (prn (XYZ.))\n# \n\n(defmethod print-method XYZ [v ^java.io.Writer w]\n (.write w \"<<-XYZ->>\"))\n\n; with print-method\nuser=> (prn (XYZ.))\n<<-XYZ->>\n" "(import '[java.net URL] [java.io File])\n\n;; Extends pr-str to URL objects with a form suitable for \n;; read-string to read back into an URL with the related\n;; https://clojuredocs.org/clojure.core/*data-readers* binding:\n\n(defmethod print-method URL [url writer]\n (doto writer\n (.write \"#url \")\n (.write \"\\\"\")\n (.write (.toString url))\n (.write \"\\\"\")))\n\n(-> \"/etc/hosts\" File. .toURL pr-str)\n;; \"#url \\\"file:/etc/hosts\\\"\"\n"], :notes ["Take care when writing things that look like a reader macro, like `#mything<42 42 42>`.\nIt may break your AOT compilations with a `java.lang.RuntimeException: No reader function for tag mything`.\n\nA quick workaround is not to emit a `#` character.\nThe thorough solution starts by reading https://clojuredocs.org/clojure.core/*data-readers* and is beyond the scope of this note."], :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/print-method"}, :clojure.core.logic/->AnswerCache {:ns "clojure.core.logic", :name "->AnswerCache", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1818, :examples nil, :notes nil, :arglists ["ansl anss _meta"], :doc "Positional factory function for class clojure.core.logic.AnswerCache.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/->AnswerCache"}, :clojure.inspector/atom? {:ns "clojure.inspector", :name "atom?", :file "clojure/inspector.clj", :type "function", :column 1, :see-alsos [:clojure.core/isa?], :line 19, :examples [";; atom? returns true if the form passed does not \n;; implement IPersistentCollection. The atom referred \n;; here is not the atom used in managing mutable state \n\nuser=> (use `[clojure.inspector :include (atom?)])\n\nuser=> (atom? 1)\ntrue\n\nuser=> (atom? \\a)\ntrue\n\nuser=> (atom? \"hello world\")\ntrue\n\nuser=> (atom? :keyword)\ntrue\n\nuser=> (atom? nil)\ntrue\n\nuser=> (atom? '())\nfalse\n\nuser=> (atom? [1, 3, 5])\nfalse\n\nuser=> (atom? #{\\a \\e \\i \\o \\u})\nfalse\n\nuser=> (atom? {:x 16 :y 25})\nfalse"], :notes nil, :arglists ["x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.inspector/atom_q"}, :clojure.spec.alpha/? {:ns "clojure.spec.alpha", :name "?", :file "clojure/spec/alpha.clj", :type "macro", :column 1, :see-alsos [:clojure.spec.alpha/+], :line 614, :examples [";; Think of this as a regex like \"ab?\"\n(s/def ::ab (s/cat :a #{:a}\n :b (s/? #{:b})))\n\n(s/valid? ::ab [:a :b])\n; => true\n\n(s/valid? ::ab [:a])\n; => true\n\n(s/valid? ::ab [:a :c])\n; => false"], :macro true, :notes nil, :arglists ["pred-form"], :doc "Returns a regex op that matches zero or one value matching\n pred. Produces a single value (not a collection) if matched.", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/_q"}, :clojure.test.tap/tap-report {:ns "clojure.test.tap", :name "tap-report", :file "clojure/test/tap.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 72, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.test.tap/tap-report"}, :clojure.core/chunk-first {:ns "clojure.core", :name "chunk-first", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/chunk-next :clojure.core/chunk-rest], :line 701, :examples ["(let [chunked-cons (seq (range 1 42))\n first-chunk (chunk-first chunked-cons)]\n\n (class chunked-cons)\n ;; => clojure.lang.ChunkedCons\n\n (class first-chunk)\n ;; clojure.lang.ArrayChunk\n\n ;; Demonstrating chunk size of 32.\n (.nth first-chunk 0)\n ;; => 1\n (.nth first-chunk 31)\n ;; => 32\n)"], :notes nil, :tag "clojure.lang.IChunk", :arglists ["s"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/chunk-first"}, :clojure.core/await-for {:added "1.0", :ns "clojure.core", :name "await-for", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/await], :line 3296, :examples [";; construct simple agent\n(def agnt (agent 5))\n\n;; increment agent\n(send agnt inc) \n\n;; system does not wait for the value change\n(println @agnt) \n;; => 5 \n\n;; increment agent\n(send agnt inc)\n\n;; wait for maximum 1000 ms\n(await-for 1000 agnt) \n\n;; print out the value of the agent \n(println @agnt) \n;; => 7"], :notes nil, :arglists ["timeout-ms & agents"], :doc "Blocks the current thread until all actions dispatched thus\n far (from this thread or agent) to the agents have occurred, or the\n timeout (in milliseconds) has elapsed. Returns logical false if\n returning due to timeout, logical true otherwise.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/await-for"}, :clojure.core/reduce-kv {:added "1.4", :ns "clojure.core", :name "reduce-kv", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/reduce :clojure.core/reduced], :line 6847, :examples ["Let's assume you want to apply a function to a vector of maps,\n\nInput: [{:a 1 :b 2} {:a 3 :b 4}]\n\nsuch that all vals are incremented by 1.\n\nResult: [{:a 2 :b 3} {:a 4 :b 5}]\n\nAn easy way to do so is using reduce-kv,\n\n(def vector-of-maps [{:a 1 :b 2} {:a 3 :b 4}])\n\n(defn update-map [m f] \n (reduce-kv (fn [m k v] \n (assoc m k (f v))) {} m))\n\n(map #(update-map % inc) vector-of-maps)\n\n=> ({:b 3, :a 2} {:b 5, :a 4})" ";; Swap keys and values in a map\nuser=> (reduce-kv #(assoc %1 %3 %2) {} {:a 1 :b 2 :c 3})\n{1 :a, 2 :b, 3 :c}" ";; Swap keys with values, only if values are not empty,\n;; while turning values into proper keys\n\n(def someMap { :foo \"food\", :bar \"barista\", :baz \"bazaar\"})\n\n(defn swap [someMap]\n (reduce-kv (fn [m k v]\n (if (empty? v) m (assoc m (keyword v) (name k)))) {} someMap))\n\n(swap someMap)\n\n=> {:food \"foo\", :barista \"bar\", :bazaar \"baz\"}\n" ";; Calculate total wins and winning streaks\n(def all-games \n [{:game 1 :won true} \n {:game 2 :won false} \n {:game 3 :won true} \n {:game 4 :won true}])\n\n(reduce-kv\n (fn [result index game]\n (let [last-game (last result)\n wins (if (:won game) \n (inc (:total last-game 0)) \n (:total last-game))\n streak (if (:won game) \n (inc (:streak last-game 0)) \n 0)]\n (println (assoc game :total wins :streak streak))\n (conj result (assoc game :total wins :streak streak))))\n []\n all-games)\n\n;; Output\n;; {:game 1, :won true, :total 1, :streak 1}\n;; {:game 2, :won false, :total 1, :streak 0}\n;; {:game 3, :won true, :total 2, :streak 1}\n;; {:game 4, :won true, :total 3, :streak 2}\n\n;; [{:game 1, :won true, :total 1, :streak 1} {:game 2, :won false, :total 1, :streak 0} {:game 3, :won true, :total 2, :streak 1} {:game 4, :won true, :total 3, :streak 2}]" ";; You can define map-kv using reduce-kv, \n;; to do something to every value in a map.\n\n(defn map-kv [f coll]\n (reduce-kv (fn [m k v] (assoc m k (f v))) (empty coll) coll))\n\n(map-kv inc {:a 12, :b 19, :c 2})\n;;=> {:c 3, :b 20, :a 13}\n\n;; It works on vectors, too.\n(map-kv inc [1 1 2 3 5])\n;;=> [2 2 3 4 6]" ";; It works with indexes on vectors as well\n\n(reduce-kv (fn [res idx itm] (assoc res idx itm)) {} [\"one\" \"two\" \"three\"])\n\n;;=> {2 \"three\", 1 \"two\", 0 \"one\"}" "\n(defn update-map-entries[m e]\n (reduce-kv (fn [r k v] (assoc r k v)) m e))\n\n;;user=> (update-map-entries {:a 1 :b 2 :c 3} {:a 5 :b 9})\n;;{:a 5, :b 9, :c 3}\n;;user=> (update-map-entries {:a 1 :b 2 :c 3} {:a 5 :b 9 :d 8})\n;;{:a 5, :b 9, :c 3, :d 8}\n\n\n" ";; increment map values \n(def abc-map {:a 1\n :b 2\n :c 3})\n(seq abc-map)\n;; => ([:a 1] [:b 2] [:c 3])\n\n;; via reduce \n(reduce (fn [new-map [k v]]\n (assoc new-map k (inc v)))\n {}\n abc-map)\n;; => {:a 2, :b 3, :c 4}\n\n\n;; via reduce-kv\n(reduce-kv (fn [new-map k v]\n (assoc new-map k (inc v)))\n {}\n abc-map)\n;; => {:a 2, :b 3, :c 4}\n" ";; filter a coll of maps with arbitrary # of preds\n\n;; setup coll\n(def people '(\t{:gender \"male\", :age-group \"child\", :origin \"Germany\", :prename \"Hans\"}\n\t\t{:gender \"male\", :age-group \"adult\", :origin \"France\", :prename \"Jacques\"}\n\t\t{:gender \"male\", :age-group \"senior\", :origin \"Estonia\", :prename \"Rasmus\"}\n\t\t{:gender \"male\", :age-group \"adult\", :origin \"Poland\", :prename \"Jakub\"}\n\t\t{:gender \"male\", :age-group \"senior\", :origin \"Germany\", :prename \"Uwe\"}\n\t\t{:gender \"female\", :age-group \"adult\", :origin \"France\", :prename \"Amélie\"}\n\t\t{:gender \"female\", :age-group \"child\", :origin \"Estonia\", :prename \"Sofia\"}\n\t\t{:gender \"female\", :age-group \"child\", :origin \"Germany\", :prename \"Emma\"}\n\t\t{:gender \"female\", :age-group \"child\", :origin \"Estonia\", :prename \"Alisa\"}\n\t\t{:gender \"female\", :age-group \"senior\", :origin \"Poland\", :prename \"Anna\"}))\n\n;; select elements using reduce-kv & filter\n(defn multi-pred [coll m] \n (reduce-kv \n (fn [erg k v] (filter #(= v (k %)) erg)) coll m) )\n\n;; two \"preds\"\n(multi-pred people {:gender \"male\", :age-group \"senior\"})\n;; => ({:gender \"male\", :age-group \"senior\", :origin \"Estonia\", :prename \"Rasmus\"} {:gender \"male\", :age-group \"senior\", :origin \"Germany\", :prename \"Uwe\"})\n\n;; three \"preds\"\n(multi-pred people {:gender \"female\", :age-group \"child\", :origin \"Estonia\"})\n;; => ({:gender \"female\", :age-group \"child\", :origin \"Estonia\", :prename \"Sofia\"} {:gender \"female\", :age-group \"child\", :origin \"Estonia\", :prename \"Alisa\"})" ";; an example to show how to add a new key to nested maps.\n\n;; consider a map with submaps\n{:a {:b 1} :c {:d 2} :e {:f 3}}\n\n\n;; reduce-kv keeps an accumulator that \n;; starts with the value provided in init, \n;; in this case an empty map.\n\n\n;; you can return the original collection via reduce-kv this way\n(reduce-kv\n (fn [acc k v]\n (assoc acc k v))\n {}\n {:a {:b 1} :c {:d 2} :e {:f 3}}))\n\n;; the output is identical to the input.\n=> {:a {:b 1} :c {:d 2} :e {:f 3}}\n\n;; you can insert a new key-value pair into each submap \n;; by using this instead, generalized as a function\n;; that takes a map and a new-key and its new-key-value as inputs:\n\n(defn add-submap [m new-key new-keys-value]\n (reduce-kv\n (fn [acc k v]\n (assoc acc k (assoc v new-key new-keys-value)))\n {}\n m))\n\n;; notice how the value \"v\" of the key \"k\" is actually the submap on each key,\n;; when we visit :a we are looking at the first k-v pair,\n;; the key is :a, \n;; and the value is {:b 1}\n;; \n;; so we assoc a new key into that submap (the value) \n;; for each key-and-submap pairing.\n\n;; so when you run this function \n=> (add-submap {:a {:b 1} \n :c {:d 2} \n :e {:f 3}} :email-verified nil)\n\n;; the result is the original data with the new key and its val in each submap.\n=> {:a {:b 1, :email-verified nil}, \n :c {:d 2, :email-verified nil}, \n :e {:f 3, :email-verified nil}}"], :notes ["Currently broken for subvectors: [CLJ-2065](https://clojure.atlassian.net/browse/CLJ-2065)" "Seems to be fixed for subvectors as of release 1.11. https://clojure.atlassian.net/browse/CLJ-2065"], :arglists ["f init coll"], :doc "Reduces an associative collection. f should be a function of 3\n arguments. Returns the result of applying f to init, the first key\n and the first value in coll, then applying f to that result and the\n 2nd key and value, etc. If coll contains no entries, returns init\n and f is not called. Note that reduce-kv is supported on vectors,\n where the keys will be the ordinals.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reduce-kv"}, :clojure.core.logic/to-subst-val {:ns "clojure.core.logic", :name "to-subst-val", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 604, :examples nil, :notes nil, :arglists ["v"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/to-subst-val"}, :clojure.core.async/unblocking-buffer? {:ns "clojure.core.async", :name "unblocking-buffer?", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 67, :examples nil, :notes nil, :arglists ["buff"], :doc "Returns true if a channel created with buff will never block. That is to say,\n puts into this buffer will never cause the buffer to be full. ", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/unblocking-buffer_q"}, :clojure.core/ensure {:added "1.0", :ns "clojure.core", :name "ensure", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/commute :clojure.core/ref-set :clojure.core/ref :clojure.core/alter], :line 2488, :examples [";; Count votes to elect the favorite color.\n;; Batches of votes are processed concurrently using a map of shared refs.\n;; The competition stops immediately if there are more than 3 \"honeypots\" votes.\n;; \"ensure\" ensures other transactions cannot change the honeypot count,\n;; guaranteeing no votes are counted after a possible fraud.\n\n(def colors\n {:blue (ref 0)\n :green (ref 0)\n :red (ref 0)\n :honeypots (ref 0)})\n\n(defn batch [prefs]\n (future\n (dosync\n (ensure (:honeypots colors))\n (doseq [color prefs\n :while (< @(:honeypots colors) 3)]\n (update colors color commute inc)))))\n\n(let [b1 (batch [:red :honeypots :green :blue :blue :red :honeypots])\n b2 (batch [:green :blue :blue :green :red :blue :red :red])\n b3 (batch [:honeypots :blue :red :red :blue :green :green :red])]\n [@b1 @b2 @b3]\n {:total-votes (reduce + (map deref (vals colors)))\n :winner (ffirst (sort-by (comp deref second) > colors))\n :fraud? (= @(:honeypots colors) 3)})\n\n;; {:total-votes 16, :winner :blue, :fraud? true}"], :notes ["This is for preventing [write skew](http://clojure.higher-order.net/?p=50), which Clojure's concurrency model is susceptible to. If you have a transaction where several refs' values must remain in some consistent relationship to each other, but you are only writing to some of them, you should use ensure on the other refs to prevent other transactions from writing to them in the meantime." "The doc string says:\n\n> Allows for more concurrency than (ref-set ref @ref)\n\nWhat it doesn’t say is that `ensure` may degrade performance very seriously, as\nit is prone to livelock: see\n[CLJ-2301](https://clojure.atlassian.net/projects/CLJ/issues/CLJ-2301).\n`(ref-set ref @ref)` is certainly more reliable than `(ensure ref)`.\n"], :arglists ["ref"], :doc "Must be called in a transaction. Protects the ref from modification\n by other transactions. Returns the in-transaction-value of\n ref. Allows for more concurrency than (ref-set ref @ref)", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ensure"}, :clojure.core.logic/let-dom {:ns "clojure.core.logic", :name "let-dom", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 2211, :examples nil, :macro true, :notes nil, :arglists ["a vars & body"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/let-dom"}, :clojure.core/hash-unordered-coll {:added "1.6", :ns "clojure.core", :name "hash-unordered-coll", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/hash :clojure.core/hash-ordered-coll], :line 5195, :examples [";;;; Clojure's (hash-unordered-coll) ALWAYS produces the same hash code EVEN:\n;;;; (1) for different collection types\n;;;; (2) for differently ordered collections of the same type\n;;;; AS LONG AS the collections contain the same elements \n\n(hash-unordered-coll #{1 2})\n;;=> 460223544\n(hash-unordered-coll (sorted-set 1 2))\n;;=> 460223544\n(hash-unordered-coll (doto (new java.util.HashSet) (.add 1) (.add 2)))\n;;=> 460223544\n(hash-unordered-coll (doto (new java.util.TreeSet) (.add 1) (.add 2)))\n;;=> 460223544\n(hash-unordered-coll [1 2])\n;;=> 460223544\n(hash-unordered-coll [2 1])\n;;=> 460223544\n(hash-unordered-coll (doto (new java.util.ArrayList) (.add 1) (.add 2)))\n;;=> 460223544\n(hash-unordered-coll (doto (new java.util.ArrayList) (.add 2) (.add 1)))\n;;=> 460223544\n\n;;;; On the other hand: both Clojure's (hash) and Java's .hashCode()\n;;;; CAN (and often WILL) produce different hash codes:\n;;;; (1) for different collection types\n;;;; (2) for differently ordered collections of the same type\n;;;; EVEN if the collections contain the same elements\n\n(hash #{1 2})\n;;=> 460223544\n(hash (sorted-set 1 2))\n;;=> 460223544\n(hash (doto (new java.util.HashSet) (.add 1) (.add 2)))\n;;=> 3\n(hash (doto (new java.util.TreeSet) (.add 1) (.add 2)))\n;;=> 3\n(hash [1 2])\n;;=> 156247261\n(hash [2 1])\n;;=> -1994590503\n(hash (doto (new java.util.ArrayList) (.add 1) (.add 2)))\n;;=> 994\n(hash (doto (new java.util.ArrayList) (.add 2) (.add 1)))\n;;=> 1024\n\n(.hashCode #{1 2})\n;;=> 3\n(.hashCode (sorted-set 1 2))\n;;=> 3\n(.hashCode (doto (new java.util.HashSet) (.add 1) (.add 2)))\n;;=> 3\n(.hashCode (doto (new java.util.TreeSet) (.add 1) (.add 2)))\n;;=> 3\n(.hashCode [1 2])\n;;=> 994\n(.hashCode [2 1])\n;;=> 1024\n(.hashCode (doto (new java.util.ArrayList) (.add 1) (.add 2)))\n;;=> 994\n(.hashCode (doto (new java.util.ArrayList) (.add 2) (.add 1)))\n;;=> 1024\n" ";;;;\n;;;; Only accepts implementations of java.lang.Iterable\n;;;;\n\n(hash-unordered-coll true)\n;;=> ClassCastException java.lang.Boolean cannot be cast to java.lang.Iterable\n(hash-unordered-coll 1)\n;;=> ClassCastException java.lang.Long cannot be cast to java.lang.Iterable\n(hash-unordered-coll \\c)\n;;=> ClassCastException java.lang.Character cannot be cast to java.lang.Iterable\n\n;;;;\n;;;; Being seqable is not sufficient!\n;;;;\n\n(hash-unordered-coll \"12\")\n;;=> ClassCastException java.lang.String cannot be cast to java.lang.Iterable\n(hash-unordered-coll (int-array [1 2]))\n;;=> ClassCastException [I cannot be cast to java.lang.Iterable\n(hash-unordered-coll nil)\n;;=> NullPointerException"], :notes nil, :arglists ["coll"], :doc "Returns the hash code, consistent with =, for an external unordered\n collection implementing Iterable. For maps, the iterator should\n return map entries whose hash is computed as\n (hash-ordered-coll [k v]).\n See http://clojure.org/data_structures#hash for full algorithms.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/hash-unordered-coll"}, :clojure.spec.alpha/keys* {:ns "clojure.spec.alpha", :name "keys*", :file "clojure/spec/alpha.clj", :type "macro", :column 1, :see-alsos [:clojure.spec.alpha/keys], :line 1789, :examples nil, :macro true, :notes nil, :arglists ["& kspecs"], :doc "takes the same arguments as spec/keys and returns a regex op that matches sequences of key/values,\n converts them into a map, and conforms that map with a corresponding\n spec/keys call:\n\n user=> (s/conform (s/keys :req-un [::a ::c]) {:a 1 :c 2})\n {:a 1, :c 2}\n user=> (s/conform (s/keys* :req-un [::a ::c]) [:a 1 :c 2])\n {:a 1, :c 2}\n\n the resulting regex op can be composed into a larger regex:\n\n user=> (s/conform (s/cat :i1 integer? :m (s/keys* :req-un [::a ::c]) :i2 integer?) [42 :a 1 :c 2 :d 4 99])\n {:i1 42, :m {:a 1, :c 2, :d 4}, :i2 99}", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/keys*"}, :clojure.core/repeat {:added "1.0", :ns "clojure.core", :name "repeat", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/repeatedly :clojure.core/cycle :clojure.core/constantly :clojure.core/dotimes], :line 2999, :examples ["user=> (take 5 (repeat \"x\"))\n(\"x\" \"x\" \"x\" \"x\" \"x\")\n\n;; which is the same as:\nuser=> (repeat 5 \"x\")\n(\"x\" \"x\" \"x\" \"x\" \"x\")\n\n;; It should be noted that repeat simply repeats the value n number of times.\n;; If you wish to execute a function to calculate the value each time you \n;; probably want the repeatedly function.\n\n" "(defn tally [n]\n (apply str\n (concat\n (repeat (quot n 5) \"卌\")\n (repeat (mod n 5) \"|\"))))\n\n(map tally (range 1 11))\n;; (\"|\" \"||\" \"|||\" \"||||\" \"卌\" \"卌|\" \"卌||\" \"卌|||\" \"卌||||\" \"卌卌\")"], :notes nil, :arglists ["x" "n x"], :doc "Returns a lazy (infinite!, or length n if supplied) sequence of xs.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/repeat"}, :clojure.core/seq {:added "1.0", :ns "clojure.core", :name "seq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/seq? :clojure.core/empty? :clojure.core/iterator-seq :clojure.core/seqable? :clojure.core/sequential? :clojure.core/sequence], :line 126, :examples ["(seq '(1)) ;;=> (1)\n(seq [1 2]) ;;=> (1 2)\n(seq \"abc\") ;;=> (\\a \\b \\c)\n\n;; Corner cases\n(seq nil) ;;=> nil\n(seq '()) ;;=> nil\n(seq []) ;;=> nil\n(seq \"\") ;;=> nil" ";; (seq x) is the recommended idiom for testing if a collection is not empty\n(every? seq [\"1\" [1] '(1) {:1 1} #{1}])\n;;=> true" ";; 'seq' can be used to turn a map into a list of vectors.\n;; Notice how the list is built adding elements to the beginning \n;; of the seq (list) not to the end, as with vectors.\n;; (Of course, the order that items are \n;; taken from a map should not be relied upon\n;; unless a deterministic 'sorted-map' is used.)\n(seq {:key1 \"value1\" :key2 \"value2\"})\n;;=> ([:key2 \"value2\"] [:key1 \"value1\"])" ";; Here is the difference between seq and sequence\n\n(seq nil)\n;;=> nil\n\n(seq ())\n;;=> nil\n\n(sequence ())\n;;=> ()\n\n(sequence nil)\n;;=> ()" ";; seq is very similar to not-empty:\n\n(every? seq [\"1\" [1] '(1) {:1 1} #{1}])\n;;=> true\n(every? not-empty [\"1\" [1] '(1) {:1 1} #{1}])\n;;=> true\n\n(seq '(1)) ;;=> (1)\n(not-empty '(1)) ;;=> (1)\n\n(seq [1 2]) ;;=> (1 2)\n(not-empty [1 2]) ;;=> [1 2]\n\n\n(seq \"abc\") ;;=> (\\a \\b \\c)\n(not-empty \"abc\") ;;=> \"abc\"\n\n(map seq [nil '() [] \"\" {}])\n;;=> (nil nil nil nil nil)\n\n(map not-empty [nil '() [] \"\" {}])\n;;=> (nil nil nil nil nil)"], :notes nil, :tag "clojure.lang.ISeq", :arglists ["coll"], :doc "Returns a seq on the collection. If the collection is\n empty, returns nil. (seq nil) returns nil. seq also works on\n Strings, native Java arrays (of reference types) and any objects\n that implement Iterable. Note that seqs cache values, thus seq\n should not be used on any Iterable whose iterator repeatedly\n returns the same mutable object.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/seq"}, :clojure.core/reduce {:added "1.0", :ns "clojure.core", :name "reduce", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/reductions :clojure.core/apply :clojure.core/frequencies :clojure.core/reduced :clojure.core/reduced? :clojure.core/reduce-kv :clojure.core.reducers/fold :clojure.core/partition-by], :line 6810, :examples ["(reduce + [1 2 3 4 5]) ;;=> 15\n(reduce + []) ;;=> 0\n(reduce + [1]) ;;=> 1\n(reduce + [1 2]) ;;=> 3\n(reduce + 1 []) ;;=> 1\n(reduce + 1 [2 3]) ;;=> 6" ";; Converting a vector to a set:\n\n(reduce conj #{} [:a :b :c])\n;; => #{:a :c :b}\n" ";; Create a word frequency map out of a large string s.\n\n;; `s` is a long string containing a lot of words :)\n(reduce #(assoc %1 %2 (inc (%1 %2 0)))\n {}\n (re-seq #\"\\w+\" s))\n\n; (This can also be done using the `frequencies` function.)\n" ";; Calculate primes until 1000\n\n(reduce\n (fn [primes number]\n (if (some zero? (map (partial mod number) primes))\n primes\n (conj primes number)))\n [2]\n (take 1000 (iterate inc 3)))\n\n;;=> [2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 \n;; 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 \n;; 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 \n;; 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 \n;; 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 \n;; 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 \n;; 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 \n;; 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 \n;; 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 \n;; 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 \n;; 991 997]" ";; Add one collection to another (combining sequences is done with cons):\n(reduce conj [1 2 3] [4 5 6])\n;;=> [1 2 3 4 5 6]\n\n(reduce #(cons %2 %1) [1 2 3] [4 5 6])\n;;=> '(6 5 4 1 2 3)" ";; Combine a vector of collections into a single collection \n;; of the type of the first collection in the vector.\n(reduce into [[1 2 3] [:a :b :c] '([4 5] 6)])\n;;=> [1 2 3 :a :b :c [4 5] 6]\n\n;; The flatten function can be used to completely fuse \n;; all of the items of a nested tree into a single sequence.\n;; Sometimes all that is needed is to fuse the first level\n;; of a tree. This can be done with 'reduce' and 'into'.\n(reduce into [] '([] [[10 18]] [[8 18]] [[10 12]] [[0 -6]] [[2 6]]))\n;;=> [[10 18] [8 18] [10 12] [0 -6] [2 6]]\n" "(defn key-pres?\n \"This function accepts a value (cmp-val) and a vector of vectors\n (parsed output from clojure-csv) and returns the match value\n back if found and nil if not found. \n\n Using reduce, the function searches every vector row to see \n if cmp-val is at the col-idx location in the vector.\"\n\n [cmp-val cmp-idx csv-data]\n (reduce\n (fn [ret-rc csv-row]\n (if (= cmp-val (nth csv-row col-idx nil))\n (conj ret-rc cmp-val)))\n [] \n csv-data))" "(defn reduce-csv-row\n \"Accepts a csv-row (a vector) a list of columns to extract, \n and reduces (and returns) a csv-row to a subset based on \n selection using the values in col-nums (a vector of integer \n vector positions.)\"\n\n [csv-row col-nums]\n\n (reduce\n (fn [out-csv-row col-num]\n ; Don't consider short vectors containing junk.\n (if-not (<= (count csv-row) 1)\n (conj out-csv-row (nth csv-row col-num nil))))\n []\n col-nums))\n\n" ";; Some functions update a collection with a single item.\n;; A number of functions have a 'more' argument which lets\n;; them work over collections.\n;; These functions can benefit 'reduce' which lets them work \n;; a collection of items...\n(into {} {:dog :food})\n\n(reduce into {} [{:dog :food} {:cat :chow}])\n;;=> {:dog :food, :cat :chow}" ";; The reduction will terminate early if an intermediate result uses the \n;; `reduced` function.\n\n(defn limit [x y] \n (let [sum (+ x y)] \n (if (> sum 10) (reduced sum) sum)))\n\n(reduce + 0 (range 10))\n;; => 45\n\n(reduce limit 0 (range 10))\n;; => 15" ";; This will generate the first 100 Fibonacci numbers\n;; (size of (range) + 2):\n\n(reduce \n (fn [a b] (conj a (+' (last a) (last (butlast a))))) \n [0 1] \n (range 98))\n\n;; [0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 433494437 701408733 1134903170 1836311903 2971215073 4807526976 7778742049 12586269025 20365011074 32951280099 53316291173 86267571272 139583862445 225851433717 365435296162 591286729879 956722026041 1548008755920 2504730781961 4052739537881 6557470319842 10610209857723 17167680177565 27777890035288 44945570212853 72723460248141 117669030460994 190392490709135 308061521170129 498454011879264 806515533049393 1304969544928657 2111485077978050 3416454622906707 5527939700884757 8944394323791464 14472334024676221 23416728348467685 37889062373143906 61305790721611591 99194853094755497 160500643816367088 259695496911122585 420196140727489673 679891637638612258 1100087778366101931 1779979416004714189 2880067194370816120 4660046610375530309 7540113804746346429 12200160415121876738N 19740274219868223167N 31940434634990099905N 51680708854858323072N 83621143489848422977N 135301852344706746049N 218922995834555169026N]" ";; Reduce can be used to reimplement a map function:\n\n(defn map* [f & c]\n (let [c* (partition (count c)\n (apply interleave c))]\n (reduce (fn [s k] (conj s (apply f k))) [] c*)))\n\n;; user=> (map* * [0.5 0.5 0.5] (range))\n;; [0.0 0.5 1.0]\n;; user=> (map* str \"clojure\" (range))\n;; [\"c0\" \"l1\" \"o2\" \"j3\" \"u4\" \"r5\" \"e6\"]\n" ";; Update map entries:\n(defn update-map-entries [m e]\n (reduce #(update-in %1 [(first %2)] (fn [_] (last %2))) m e))\n\n;; => (update-map-entries {:a 1 :b 2 :c 3} {:a 5 :b 9})\n;; {:a 5, :b 9, :c 3}\n;; => (update-map-entries {:a 1 :b 2 :c 3} {:a 5 :b 9 :d 8})\n;; {:a 5, :b 9, :c 3, :d 8}" ";; Flatten values in a map.\n(reduce\n (fn [flattened [k v]]\n (clojure.set/union flattened v))\n #{}\n {:e #{:m :f}, :c #{:f}, :b #{:c :f}, :d #{:m :f}, :a #{:c :f}})\n\n;; => #{:m :c :f}" ";; A simple factorial function using reduce:\n\n(defn fact\n [x] \n (reduce * (range 1 (inc x))))" ";; Reduce over maps by destructuring keys:\n(def x {:a 1 :b 2})\n\n(reduce (fn [p [k v]]\n (into p {k (+ 1 v)}))\n {} ; First value for p\n x)\n\n;; => {:a 2, :b 3}" ";; conj! over transient array for speed.\n;; This example flattens over one level.\n;; To do so uses reduce twice.\n(persistent!\n (reduce\n (fn [acc0 item-vector]\n (reduce \n (fn [acc1 item]\n (conj! acc1 item))\n acc0 item-vector))\n (transient [])\n [[:foo :bar :baz] [] [:fred :barney]]))\n ;;=> [:foo :bar :baz :fred :barney] " ";;reduce with side effects\n;;given a collection return a new collection\n\n(def initial-coll [1 2 3 4 5])\n\n(defn byten\n [coll]\n (reduce (fn [new-coll unit]\n (into new-coll [(* 10 unit)]))\n []\n coll))\n\n(byten initial-coll)\n;;[10 20 30 40 50]\n\n\n" ";; Reduce with side effects using an anonymous function\n;; given a collection return a new collection:\n\n(def initial-coll [1 2 3 4 5])\n\n(defn byten\n [coll]\n (reduce #(into %1 [(* 10 %2)])\n []\n coll))\n\n(byten initial-coll)\n;; => [10 20 30 40 50]" ";; A practical example of mapping over values\n;; in a hash-map with the `upper-case` function:\n\n(reduce\n (fn [acc [k v]]\n (assoc acc k (clojure.string/upper-case v)))\n {}\n {:a \"aaaaaaa\" :b \"bbbbbbb\"})\n\n;; => {:a \"AAAAAAA\", :b \"BBBBBBB\"}" "(reduce\n (fn [accumulator current-item] ; <-- accumulator is FIRST argument to function\n ...) ; <-- your fn definition goes here\n [] ; <-- initial value for your accumulator \n [:a :b]) ; <-- collection to operate on\n" "(reduce #(str %1 %2) \"\" [\"Woody\" \"Potato\" \"Buzz\"])\n;;=> \"WoodyPotatoBuzz\"\n\n;; or\n\n(reduce (fn [accumulator current-item] (str accumulator current-item)) \"\" [\"Woody\" \"Potato\" \"Buzz\"])\n;;=> \"WoodyPotatoBuzz\"\n\n"], :notes ["clojure.core/reduce seems to be a special case of a function that's defined twice in core.clj, and the first definition (at the line cited above: 773) is just a temporary definition; the real definition is later at line 5323, which contains the docstring." "The reducing function f is of shape:\n\n(f [accumulator next-element] ...)" "The 4th example (generating prime numbers) is kind of nice conceptually, but running it for the first 1m integers is taking 2 min on i7 2.7GHz machine, so it seems to be a very inefficient way of generating prime numbers. "], :arglists ["f coll" "f val coll"], :doc "f should be a function of 2 arguments. If val is not supplied,\n returns the result of applying f to the first 2 items in coll, then\n applying f to that result and the 3rd item, etc. If coll contains no\n items, f must accept no arguments as well, and reduce returns the\n result of calling f with no arguments. If coll has only 1 item, it\n is returned and f is not called. If val is supplied, returns the\n result of applying f to val and the first item in coll, then\n applying f to that result and the 2nd item, etc. If coll contains no\n items, returns val and f is not called.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reduce"}, :clojure.inspector/table-model {:ns "clojure.inspector", :name "table-model", :file "clojure/inspector.clj", :type "var", :column 1, :see-alsos nil, :line 139, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.inspector/table-model"}, :clojure.core/find-ns {:added "1.0", :ns "clojure.core", :name "find-ns", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/create-ns :clojure.core/remove-ns :clojure.core/ns-map], :line 4126, :examples ["(find-ns 'clojure.string)\n;;=> nil\n\n(require 'clojure.string)\n;;=> nil\n\n(find-ns 'clojure.string)\n;;=> #"], :notes nil, :arglists ["sym"], :doc "Returns the namespace named by the symbol or nil if it doesn't exist.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/find-ns"}, :clojure.core/first {:added "1.0", :ns "clojure.core", :name "first", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/rest :clojure.core/next :clojure.core/nth :clojure.core/second :clojure.core/take :clojure.core/ffirst :clojure.core/butlast], :line 49, :examples ["(first '(:alpha :bravo :charlie))\n;;=> :alpha" ";; nil is a valid (but empty) collection.\n(first nil)\n;;=> nil\n\n;; if collection is empty, returns nil.\n(first [])\n;;=> nil\n\n;; if first item in collection is nil, returns nil\n(first [nil])\n;;=> nil" "=> (first [1 2])\n1\n\n=> (first [ [1 2] [3 4] ])\n[1 2]" "=> (first \"j\")\n\\j\n\n=> (int (first \"j\"))\n106"], :notes nil, :arglists ["coll"], :doc "Returns the first item in the collection. Calls seq on its\n argument. If coll is nil, returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/first"}, :clojure.spec.alpha/def {:ns "clojure.spec.alpha", :name "def", :file "clojure/spec/alpha.clj", :type "macro", :column 1, :see-alsos nil, :line 342, :examples ["```clojure\n(ns my-app.entry \n (:require [clojure.spec.alpha :as s]\n [clojure.repl :refer [doc]]))\n\n;; the :: macro will automatically prepend current namespace into \n;; the qualified :entry-state spec keyword\n(s/def ::entry-state #{:entered :exited})\n\n;; check it out:\n(doc :my-app.entry/entry-state)\n;; -------------------------\n;; :my-app.entry/entry-state\n;; Spec\n;; #{:entered :exited}\n```"], :macro true, :notes nil, :arglists ["k spec-form"], :doc "Given a namespace-qualified keyword or resolvable symbol k, and a\n spec, spec-name, predicate or regex-op makes an entry in the\n registry mapping k to the spec. Use nil to remove an entry in\n the registry for k.", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/def"}, :clojure.core.logic.pldb/ground? {:ns "clojure.core.logic.pldb", :name "ground?", :file "clojure/core/logic/pldb.clj", :type "function", :column 1, :see-alsos nil, :line 38, :examples nil, :notes nil, :arglists ["s term"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/ground_q"}, :clojure.core/seq? {:added "1.0", :ns "clojure.core", :name "seq?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/seq :clojure.core/sequential? :clojure.core/vector? :clojure.core/coll? :clojure.core/list? :clojure.core/map? :clojure.core/set? :clojure.core/seqable?], :line 146, :examples ["user> (seq? 1)\nfalse\nuser> (seq? [1])\nfalse\nuser> (seq? (seq [1]))\ntrue" ";; contrast to example code for sequential?\n;;\nuser> (seq? '(1 2 3))\ntrue\nuser=> (seq? #{1 2 3})\nfalse\nuser> (seq? [1 2 3]) ; for sequential?, returns true\nfalse\nuser> (seq? (range 1 5))\ntrue\nuser> (seq? 1)\nfalse\nuser> (seq? {:a 2 :b 1})\nfalse\nuser> " ";; Don't use seq? when you want to check for a vector.\n;; you may have intended to use seq instead\n\ncljs.user=> (def x [:a :b :c])\n#'cljs.user/x\ncljs.user=> (if (seq x) \"Seq ok\" \"No Seqing here\")\n\"Seq ok\"\ncljs.user=> (if (seq? x) \"Seq ok\" \"No Seqing here\")\n\"No Seqing here\""], :notes nil, :arglists ["x"], :doc "Return true if x implements ISeq", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/seq_q"}, :clojure.core/PrintWriter-on {:added "1.10", :ns "clojure.core", :name "PrintWriter-on", :file "clojure/core_print.clj", :type "function", :column 1, :see-alsos nil, :line 559, :examples ["(with-open [writer (PrintWriter-on\n (fn [s] (printf \"Flushing: '%s'%n\" s))\n (fn [] (printf \"Closing.%n\")))]\n (.write writer \"Hello\")\n (.flush writer)\n (.write writer \"World!\")\n (println \"About to finish...\"))\n;; Flushing: 'Hello'\n;; About to finish...\n;; Flushing: 'World!'\n;; Closing.\n;; nil\n"], :notes nil, :tag "java.io.PrintWriter", :arglists ["flush-fn close-fn"], :doc "implements java.io.PrintWriter given flush-fn, which will be called\n when .flush() is called, with a string built up since the last call to .flush().\n if not nil, close-fn will be called with no arguments when .close is called", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/PrintWriter-on"}, :clojure.core/= {:added "1.0", :ns "clojure.core", :name "=", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/== :clojure.core/not= :clojure.core/identical?], :line 783, :examples ["user=> (= 1)\ntrue\nuser=> (= 1 1)\ntrue\nuser=> (= 1 2)\nfalse\nuser=> (= 1 1 1)\ntrue\nuser=> (= 1 1 2)\nfalse\nuser=> (= '(1 2) [1 2])\ntrue\nuser=> (= nil nil)\ntrue\nuser=> (= (sorted-set 2 1) (sorted-set 1 2))\ntrue\n\n;; It should be noted that equality is not defined for Java arrays.\n;; Instead you can convert them into sequences and compare them that way.\n;; (= (seq array1) (seq array2))\n" ";; There are functional differences between = and == \n;; = may introduce java autoboxing \n\n;; true:\n(= 1)\n(= 1 1) \n(= 1/1, 2/2, 3/3, 4/4) \n(= :foo)\n(= nil anything) ; anything = nil\n\n\n;; false:\n(= 1, 1.0, 1/1) ; differs from ==\n(= 1 2)\n(= 1 \\1) ; differs from ==\n(= 1 \"1\") ; differs from ==\n\n" ";; If passed a single value (= x) the result is always true.\n(= 1)\n(= nil)\n(= false)\n(= true)\n(= {:a 1 :b2})\n(= 'false)\n;;=> true \n" ";; = can be used to compare the equality of nested Clojure data structures\n(= {:a [1 {1 2}] :b 'ok :c \"string\"} \n {:b 'ok :c \"string\" :a '(1 {1 2})})\n;;=> true" ";; See the Clojure Equality guide for more details:\n;; https://clojure.org/guides/equality\n\n;; One perhaps surprising case is comparing regular expressions.\n;; In Clojure, regular expressions only equal one another if they are\n;; the same object in memory, i.e. if (identical? x y) is also true.\n;; Therefore, any data structure containing regular expression will \n;; only be equal to one another if the corresponding regular expressions are\n;; identical.\n;; See https://dev.clojure.org/jira/browse/CLJ-1182\n(= #\"fav*\" #\"fav*\")\n;;=> false\n\n;; Another exception is the special floating point value ##NaN for \"Not a Number\".\n;; In Clojure on Java, this value is never equal to itself, and any collections\n;; containing such \"values\" are never equal to any other collections, either:\n(= ##NaN ##NaN)\n;;=> false\n\n(= [1 2 3 ##NaN] [1 2 3 ##NaN])\n;;=> false\n\n;; There are a few other minor exceptions where clojure.core/= might behave in\n;; ways that surprise you. You can find an article describing the known cases\n;; for Clojure on Java here: https://clojure.org/guides/equality" ";; You can test for a Java infinity, but there are quirks to know about. \n\n;; Note particularly that Double/POSITIVE_INFINITY and Float/POSITIVE_INFINITY\n;; are = and ==, but they are neither identical? nor .equals. However, the\n;; value these Java objects return has the same representation, ##Inf, in\n;; Clojure. Further, the literal ##Inf is parsed as something that is\n;; .equals to Double/POSITIVE_INFINITY but not identical? to it. Similar\n;; points hold for the Java NEGATIVE_INFINITY's and their Clojure\n;; representation, ##-Inf.\n\nuser=> Double/POSITIVE_INFINITY\n;;=> ##Inf\nuser=> Float/POSITIVE_INFINITY\n;;=> ##Inf\nuser=> (= Double/POSITIVE_INFINITY Float/POSITIVE_INFINITY)\n;;=> true\nuser=> (= ##Inf ##Inf)\n;;=> true\nuser=> (== Double/POSITIVE_INFINITY Float/POSITIVE_INFINITY)\n;;=> true\nuser=> (== ##Inf ##Inf)\n;;=> true\nuser=> (identical? Double/POSITIVE_INFINITY Float/POSITIVE_INFINITY)\n;;=> false\nuser=> (identical? ##Inf ##Inf)\n;;=> true\nuser=> (.equals Double/POSITIVE_INFINITY Float/POSITIVE_INFINITY)\n;;=> false\nuser=> (.equals ##Inf ##Inf)\n;;=> true\nuser=> (identical? ##Inf Double/POSITIVE_INFINITY)\n;;=> false\nuser=> (identical? ##Inf Float/POSITIVE_INFINITY)\n;;=> false\nuser=> (.equals ##Inf Double/POSITIVE_INFINITY)\n;;=> true\nuser=> (.equals ##Inf Float/POSITIVE_INFINITY)\n;;=> false\n\n;; (Tested with Clojure 1.10.3.)" "user=> (= + +)\ntrue\nuser=> (= = =)\ntrue\nuser=> (= inc inc)\ntrue\nuser=> (= #() #())\nfalse"], :notes ["There is a difference between \"=\" and \"==\". For primitives you definitely want to use \"==\" as \"=\" will result in a cast to the wrapped types for it's arguments. \r\n\r\nThis may not be the case come Clojure 1.3 (see [1])\r\n\r\n[1] http://github.com/clojure/clojure/commit/df8c65a286e90e93972bb69392bc106128427dde" "`=` compares collections in a type-independent manner but not numbers, despite what the docs say. See examples above."], :arglists ["x" "x y" "x y & more"], :doc "Equality. Returns true if x equals y, false if not. Same as\n Java x.equals(y) except it also works for nil, and compares\n numbers and collections in a type-independent manner. Clojure's immutable data\n structures define equals() (and thus =) as a value, not an identity,\n comparison.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/="}, :clojure.core.logic/defne {:ns "clojure.core.logic", :name "defne", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos [:clojure.core.logic/defna :clojure.core.logic/defnu :clojure.core.logic/defnc :clojure.core.logic/fne :clojure.core.logic/conde], :line 1699, :examples ["(defne match1 [x y]\n ([:foo :bar])\n ([:baz :qux]))\n\n(run* [x y] (match1 x y)) ;; => ([:foo :bar] [:baz :qux])\n\n(defne match2 [x y]\n ([[a b . tail] [b a . tail]]))\n\n(run* [r] (match2 '(a b c d) r)) ;; => ((b a c d))\n\n(defne match3 [x y]\n ([[a . _] [a . _]]))\n\n(run* [r] (match3 [3 2 1] [3 4 5])) ;; => (_0)" ";; adapted from:\n;; http://stackoverflow.com/questions/11964055/constraining-two-vectors-to-be-in-the-same-domain-but-not-be-members-of-each-ot\n\n(defne not-membero [x l]\n ([_ []])\n ([_ [?y . ?r]]\n (!= x ?y)\n (not-membero x ?r)))\n\n(run* [q]\n (not-membero q [:a :b :c])) ;; ((_0 :- (!= (_0 :a)) (!= (_0 :b)) (!= (_0 :c))) \n\n(run* [q]\n (membero q [1 2 3 4 5])\n (not-membero q [2 4])) ;; (1 3 5)"], :macro true, :notes nil, :arglists ["& rest"], :doc "Define a goal fn. Supports pattern matching. All\n patterns will be tried. See conde.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/defne"}, :clojure.core/dec {:added "1.2", :ns "clojure.core", :name "dec", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/dec' :clojure.core/inc :clojure.core/unchecked-dec], :line 1142, :examples ["user=> (dec 2)\n1\n\nuser=> (dec 2.0)\n1.0\n\nuser=> (dec 1)\n0\n\nuser=> (dec -1)\n-2"], :notes nil, :arglists ["x"], :doc "Returns a number one less than num. Does not auto-promote\n longs, will throw on overflow. See also: dec'", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/dec"}, :clojure.core/not {:added "1.0", :ns "clojure.core", :name "not", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/complement :clojure.core/false?], :line 524, :examples ["user=> (not true)\nfalse\nuser=> (not false)\ntrue\nuser=> (not nil)\ntrue\n\n;; acts as complement of `boolean`\nuser=> (boolean \"a string\")\ntrue\nuser=> (not \"a string\")\nfalse\nuser=> (boolean 1)\ntrue\nuser=> (not 1)\nfalse" "user=> (not (= \"a\" \"b\"))\ntrue"], :notes nil, :tag "java.lang.Boolean", :arglists ["x"], :doc "Returns true if x is logical false, false otherwise.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/not"}, :clojure.inspector/list-model {:ns "clojure.inspector", :name "list-model", :file "clojure/inspector.clj", :type "function", :column 1, :see-alsos nil, :line 129, :examples nil, :notes nil, :arglists ["provider"], :library-url "https://github.com/clojure/clojure", :href "/clojure.inspector/list-model"}, :clojure.core.logic/defnu {:ns "clojure.core.logic", :name "defnu", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos [:clojure.core.logic/defna :clojure.core.logic/defne :clojure.core.logic/defnc :clojure.core.logic/condu], :line 1733, :examples nil, :macro true, :notes nil, :arglists ["& rest"], :doc "Define a committed choice goal. See condu.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/defnu"}, :clojure.core/the-ns {:added "1.0", :ns "clojure.core", :name "the-ns", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/ns-name :clojure.core/create-ns], :line 4153, :examples [";; Let's play with a namespace by its name and by its symbol \n(def for-later-use (create-ns 'my-namespace))\n;;=> #'user/for-later-use\n\n(the-ns for-later-use)\n;;=> #\n\n(the-ns 'my-namespace)\n;;=> #\n\n;; not going to find anything this way because we just asked the repl\n;; not to perform an evaluate on it and there is not such \n;; namespace with the name \"for-later-use\"\n(the-ns 'for-later-use)\n;; java.lang.Exception: No namespace: for-later-use found (NO_SOURCE_FILE:0)\n\n;; not going to work either because \"my-namespace\" is the name of a namespace\n;; and not a symbol that points to something\n(the-ns my-namespace)\n;; java.lang.Exception: Unable to resolve symbol: my-namespace in this context (NO_SOURCE_FILE:12)\n"], :notes nil, :arglists ["x"], :doc "If passed a namespace, returns it. Else, when passed a symbol,\n returns the namespace named by it, throwing an exception if not\n found.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/the-ns"}, :clojure.core.logic/tabled {:ns "clojure.core.logic", :name "tabled", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1997, :examples nil, :macro true, :notes nil, :arglists ["args & grest"], :doc "Macro for defining a tabled goal. Prefer ^:tabled with the\n defne/a/u forms over using this directly.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/tabled"}, :clojure.core/unreduced {:added "1.7", :ns "clojure.core", :name "unreduced", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/reduced? :clojure.core/reduced :clojure.core/reduce :clojure.core/ensure-reduced], :line 2855, :examples ["(unreduced :foo)\n;;=> :foo\n\n(unreduced (reduced :foo))\n;;=> :foo\n\n(unreduced (clojure.lang.Reduced. :foo))\n;;=> :foo" ";; Transducers have a \"completing arity\" which is called at the end of the\n;; reduction to finalize the output. This is done outside of the normal\n;; reduction loop, so there is nothing to unwrap a reduced return value, should\n;; the reducing function be called from the completing arity and happen to wrap\n;; the return in a Reduced:\n\n(defn conj-till-odd\n ([coll] coll)\n ([coll x] (cond-> (conj coll x) (odd? x) reduced)))\n\n(defn inc-nums+7 [rf]\n (fn new-rf\n ([result] (rf result 7)) ; A bit contrived, but makes the point\n ([result x] (rf result (inc x)))))\n\n(transduce inc-nums+7 conj-till-odd [] [1 3 5 7 9])\n;; => #\n\n;; So we can wrap the return of the completing arity in `unreduced` to make sure\n;; we don't return a Reduced. After all, it's the end of the reduction anyway:\n\n(defn inc-nums+7 [rf]\n (fn new-rf\n ([result] (unreduced (rf result 7)))\n ([result x] (rf result (inc x)))))\n\n(transduce inc-nums+7 conj-till-odd [] [1 3 5 7 9])\n;; => [2 4 6 8 10 7]"], :notes nil, :arglists ["x"], :doc "If x is reduced?, returns (deref x), else returns x", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unreduced"}, :clojure.core/with-bindings* {:added "1.1", :ns "clojure.core", :name "with-bindings*", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/with-bindings], :line 1973, :examples ["user=> (let [f (fn [] *warn-on-reflection*)]\n (with-bindings* {#'*warn-on-reflection* true} f))\ntrue"], :notes nil, :arglists ["binding-map f & args"], :doc "Takes a map of Var/value pairs. Installs for the given Vars the associated\n values as thread-local bindings. Then calls f with the supplied arguments.\n Pops the installed bindings after f returned. Returns whatever f returns.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/with-bindings*"}, :clojure.core/*' {:added "1.0", :ns "clojure.core", :name "*'", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/*], :line 996, :examples [";; there is an implicit 1\n(*')\n;;=> 1 \n\n;; the implicit 1 comes into play\n(*' 6)\n;;=> 6\n\n(*' 2 3)\n;;=> 6\n\n(*' 2 3 4)\n;;=> 24\n\n(*' 0.5 200)\n;;=> 100.0\n\n;; great so it gives the same results as *.\n;; not quite check this out\n(* 1234567890 9876543210)\n;; ArithmeticException integer overflow\n(*' 1234567890 9876543210)\n;;=> 12193263111263526900N"], :notes nil, :arglists ["" "x" "x y" "x y & more"], :doc "Returns the product of nums. (*') returns 1. Supports arbitrary precision.\n See also: *", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*'"}, :clojure.test/*report-counters* {:ns "clojure.test", :name "*report-counters*", :file "clojure/test.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 262, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.test/*report-counters*"}, :clojure.core.logic.pldb/db-rel {:ns "clojure.core.logic.pldb", :name "db-rel", :file "clojure/core/logic/pldb.clj", :type "macro", :column 1, :see-alsos nil, :line 48, :examples [";; To defined an indexed argument for a relation.\n\n(db-rel direction ^:index d p)\n"], :macro true, :notes nil, :arglists ["name & args"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/db-rel"}, :clojure.core/vswap! {:added "1.7", :ns "clojure.core", :name "vswap!", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/volatile! :clojure.core/vreset! :clojure.core/volatile? :clojure.core/swap!], :line 2539, :examples ["(let [interrupt (volatile! false)\n f1 (future (Thread/sleep 1000)\n (vswap! interrupt not))\n f2 (future (while (not @interrupt)\n (println \"Another cycle!\")\n (Thread/sleep 100)))]\n @f1\n @f2)"], :macro true, :notes nil, :arglists ["vol f & args"], :doc "Non-atomically swaps the value of the volatile as if:\n (apply f current-value-of-vol args). Returns the value that\n was swapped in.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/vswap!"}, :clojure.core/with-redefs-fn {:added "1.3", :ns "clojure.core", :name "with-redefs-fn", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/with-redefs], :line 7498, :examples ["(ns http)\n\n(defn post [url]\n {:body \"Hello world\"})\n\n(ns app\n (:require [clojure.test :refer [run-tests]]))\n\n(deftest is-a-fn\n (with-redefs-fn {#'http/post (fn [url] {:body \"Hello world again\"})}\n #(is (= {:body \"Hello world again\"} (http/post \"http://service.com/greet\")))))\n\n(run-tests) ;; test is passing" "=> (defn f [] false)\n\n=> (println (f))\n;; false\n\n=> (with-redefs-fn {#'f (fn [] true)} \n #(println (f)))\n;; true" "(defn add-5 [n] (+ n 5))\n(with-redefs-fn {#'add-5 (fn [n] (+ n 50))}\n #(is (= 60 (add-5 10))))\n\n;; Cannot redefine the reference in the partial function\n(def partial-add-5 (partial add-5))\n(with-redefs-fn {#'add-5 (fn [n] (+ n 50))}\n #(is (= 15 (partial-add-5 10)))) \n"], :notes nil, :arglists ["binding-map func"], :doc "Temporarily redefines Vars during a call to func. Each val of\n binding-map will replace the root value of its key which must be\n a Var. After func is called with no args, the root values of all\n the Vars will be set back to their old values. These temporary\n changes will be visible in all threads. Useful for mocking out\n functions during testing.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/with-redefs-fn"}, :clojure.core/iterator-seq {:added "1.0", :ns "clojure.core", :name "iterator-seq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/seq], :line 5721, :examples [";; Note this is not strictly necessary since keySet is a collection\n;; implementing Iterable but it does show the usage.\n\nuser=> (iterator-seq (.iterator (.keySet (java.lang.System/getProperties))))\n\n(\"java.runtime.name\" \"sun.boot.library.path\" \"java.vm.version\" \"java.vm.vendor\" \"java.vendor.url\" \"path.separator\" \"java.vm.name\" \"file.encoding.pkg\" \"sun.java.launcher\" \"user.country\" \"sun.os.patch.level\" \"java.vm.specification.name\" \"user.dir\" \"java.runtime.version\" \"java.awt.graphicsenv\" \"java.endorsed.dirs\" \"os.arch\" \"javax.accessibility.assistive_technologies\" \"java.io.tmpdir\" \"line.separator\" \"java.vm.specification.vendor\" \"os.name\" \"cljr.home\" \"sun.jnu.encoding\" \"java.library.path\" \"java.specification.name\" \"java.class.version\" \"sun.management.compiler\" \"os.version\" \"user.home\" \"user.timezone\" \"java.awt.printerjob\" \"file.encoding\" \"java.specification.version\" \"include.cljr.repo.jars\" \"java.class.path\" \"user.name\" \"java.vm.specification.version\" \"java.home\" \"sun.arch.data.model\" \"user.language\" \"java.specification.vendor\" \"java.vm.info\" \"java.version\" \"java.ext.dirs\" \"sun.boot.class.path\" \"java.vendor\" \"file.separator\" \"java.vendor.url.bug\" \"clojure.home\" \"sun.io.unicode.encoding\" \"sun.cpu.endian\" \"sun.desktop\" \"sun.cpu.isalist\")\n" ";; Java 8 streams as sequences\n(->> \"Clojure is the best language\"\n (.splitAsStream #\"\\s+\")\n .iterator\n iterator-seq)\n\n;; (\"Clojure\" \"is\" \"the\" \"best\" \"language\")"], :notes ["I've noticed that I needed to use iterator-seq when trying to map over a Java function that returns an AbstractList Iterator. It was not directly seq-able."], :arglists ["iter"], :doc "Returns a seq on a java.util.Iterator. Note that most collections\n providing iterators implement Iterable and thus support seq directly.\n Seqs cache values, thus iterator-seq should not be used on any\n iterator that repeatedly returns the same mutable object.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/iterator-seq"}, :clojure.core.async/!], :line 116, :examples ["user=> (def c (chan 1))\n#'user/c\n\nuser=> (go-loop [data ( \" data)\n (println \"No recur. Won't print again\"))\n\n#\n\nuser=> (put! c \"Example Async Data\")\n\nnil\n\nWaited for => Example Async Data\nNo recur. Won't print again\n\nuser=> (put! c \"Example Async Data\")\nnil\n" ";; Clojure 1.7\nuser=> (let [c (chan 1 (filter pos?))]\n \n (go-loop []\n (let [nums ( (sequence [1 2 3])\n(1 2 3)\nuser> (class (sequence '(1 2 3)))\nclojure.lang.PersistentList" ";; let us make a transducer\nuser=> (def xf (comp (filter odd?) (take 5)))\n#'user/xf\nuser=> (sequence xf (range 1 10))\n(1 3 5 7 9)" ";; turns a string into a sequence of characters:\n(sequence \"abc\")\n=> (\\a \\b \\c)" ";; combine a bunch of collections together\n(sequence cat [[1 2 3] [5 6 7] [8 9 0]])\n;=> (1 2 3 5 6 7 8 9 0) \n(sequence cat [ '(1 2 3) '(5 6 7) '(8 9 0) ])\n;=> (1 2 3 5 6 7 8 9 0)" ";; When called with multiples collections.\n\n(sequence (map vector) [1 2 3] [:a :b :c])\n;=> ([1 :a] [2 :b] [3 :c])" ";; Comparison to seq\n(def v [1 2 3])\n(def l '(1 2 3))\n(def ss (sorted-set 1 2 3))\n(= (seq [1 2 3]) (sequence [1 2 3])) ;;=> true\n(= (sequence v) (seq v)) ;;=> true\n(= (sequence l) (seq l)) ;;=> true\n(= (sequence ss) (seq ss)) ;;=> true\n\n;; Comparison for non-ordered stuff\n(def m {:a 1 :b 2 :c 3})\n(def s #{1 2 3})\n(sequence m) ;;=> ([:a 1] [:b 2] [:c 3])\n(seq m) ;;=> ([:a 1] [:b 2] [:c 3])\n(sequence s) ;;=> (1 3 2)\n(seq s) ;;=> (1 3 2)"], :notes ["Interesting background about `sequence` versus `eduction`: https://groups.google.com/d/msg/clojure/9I6MtgOTD0w/NiG5PimBCP8J"], :arglists ["coll" "xform coll" "xform coll & colls"], :doc "Coerces coll to a (possibly empty) sequence, if it is not already\n one. Will not force a lazy seq. (sequence nil) yields (), When a\n transducer is supplied, returns a lazy sequence of applications of\n the transform to the items in coll(s), i.e. to the set of first\n items of each coll, followed by the set of second\n items in each coll, until any one of the colls is exhausted. Any\n remaining items in other colls are ignored. The transform should accept\n number-of-colls arguments", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/sequence"}, :clojure.core/complement {:added "1.0", :ns "clojure.core", :name "complement", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/not], :line 1433, :examples [";; a simple not-empty? predicate\n(def not-empty? (complement empty?))\n;; #'user/not-empty?\n\n(not-empty? []) ;;=> false\n(not-empty? [1 2]) ;;=> true\n\n\n;; a slightly more complex example\n;; this function takes two arguments, and sometimes returns nil\n(defn contains-char? [the-string, the-char]\n (some #(= the-char %) the-string))\n;; #'user/contains-char?\n\n(contains-char? \"abc\" \\b) ;;=> true\n(contains-char? \"abc\" \\j) ;;=> nil\n\n;; define the complement, to check if a char is absent\n(def does-not-contain-char? (complement contains-char?))\n;; #'user/does-not-contain-char?\n\n;; our complement does exactly what we expect\n(does-not-contain-char? \"abc\" \\b) ;;=> false\n(does-not-contain-char? \"abc\" \\j) ;;=> true\n" "(map (complement even?) '(1 2 3 4))\n\n;; return...\n;; (true false true false)\n\n;; see also ...\n(map even? '(1 2 3 4))\n;; (false true false true)\n\n;; WARNING\n;; This function returns ERROR!!!\n(map (not even?) '(1 2 3 4))\n\n(map #(not (even? %)) '(1 2 3 4)) ; This works\n" "(def not-empty? (complement empty?))\n\n(not-empty? \"abcde\")\n;;true\n\n(not-empty? \"\")\n;;false" ";; flatten function from Clojure core:\n(defn flatten\n \"Takes any nested combination of sequential things (lists, vectors,\n etc.) and returns their contents as a single, flat lazy sequence.\n (flatten nil) returns an empty sequence.\"\n {:added \"1.2\"\n :static true}\n [x]\n (filter (complement sequential?)\n (rest (tree-seq sequential? seq x))))"], :notes nil, :arglists ["f"], :doc "Takes a fn f and returns a fn that takes the same arguments as f,\n has the same effects, if any, and returns the opposite truth value.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/complement"}, :clojure.core.logic/bindable? {:ns "clojure.core.logic", :name "bindable?", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 732, :examples nil, :notes nil, :arglists ["x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/bindable_q"}, :clojure.spec.alpha/fdef {:ns "clojure.spec.alpha", :name "fdef", :file "clojure/spec/alpha.clj", :type "macro", :column 1, :see-alsos nil, :line 709, :examples [";; Example from Clojure.org spec guide:\n;; https://clojure.org/guides/spec\n\n(require '[clojure.spec.alpha :as s])\n\n(s/fdef ranged-rand\n :args (s/and (s/cat :start int? :end int?)\n #(< (:start %) (:end %)))\n :ret int?\n :fn (s/and #(>= (:ret %) (-> % :args :start))\n #(< (:ret %) (-> % :args :end))))" "(...ns declaration...\n(:require [clojure.spec.alpha :as s]\n [clojure.spec.gen.alpha :as gen]))\n\n;; lets say I created a set of specs to build up the fn.\n;;\n(s/def ::significant-string (s/with-gen \n (s/and string? #(not (nil? %)))\n (fn [] (gen/such-that #(not= % \"\")\n (gen/string-alphanumeric)))))\n\n(s/def ::byte-stream \n (s/with-gen #(instance? java.io.ByteArrayInputStream %)\n (gen/fmap #(string->stream %) (gen/string-alphanumeric))))\n\n;; :args spec is invoked with an argument list\n;; using cat to reach into the argument list and test conformity to the\n;; ::significant-string spec.\n;; :ret is invoked with the return value (testing conformity to a ::byte-stream)\n;; :fn spec is invoked with a map of the input and return values. (not using args here)\n(s/fdef string->stream\n :args (s/cat :s ::significant-string)\n :ret ::byte-stream\n :fn (fn [{:keys [args ret]}]\n (instance? java.io.ByteArrayInputStream ret)))\n\n;;\n;; the actual fn\n;;\n(defn string->stream\n \"Given a string, return a java.io.ByteArrayInputStream\"\n ([s] {:pre [(s/valid? ::significant-string s)]\n :post [(s/valid? ::byte-stream %)]}\n (string->stream s \"UTF-8\"))\n ([s encoding]\n (-> s\n (.getBytes encoding)\n (java.io.ByteArrayInputStream.))))\n\n;; note, the post condition in this example is redundant with the :fn spec.\n;; and given we aren't using the args value in the :fn spec I would drop that one \n;; in practical use.\n\n"], :macro true, :notes nil, :arglists ["fn-sym & specs"], :doc "Takes a symbol naming a function, and one or more of the following:\n\n :args A regex spec for the function arguments as they were a list to be\n passed to apply - in this way, a single spec can handle functions with\n multiple arities\n :ret A spec for the function's return value\n :fn A spec of the relationship between args and ret - the\n value passed is {:args conformed-args :ret conformed-ret} and is\n expected to contain predicates that relate those values\n\n Qualifies fn-sym with resolve, or using *ns* if no resolution found.\n Registers an fspec in the global registry, where it can be retrieved\n by calling get-spec with the var or fully-qualified symbol.\n\n Once registered, function specs are included in doc, checked by\n instrument, tested by the runner clojure.spec.test.alpha/check, and (if\n a macro) used to explain errors during macroexpansion.\n\n Note that :fn specs require the presence of :args and :ret specs to\n conform values, and so :fn specs will be ignored if :args or :ret\n are missing.\n\n Returns the qualified fn-sym.\n\n For example, to register function specs for the symbol function:\n\n (s/fdef clojure.core/symbol\n :args (s/alt :separate (s/cat :ns string? :n string?)\n :str string?\n :sym symbol?)\n :ret symbol?)", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/fdef"}, :clojure.spec.alpha/explain* {:ns "clojure.spec.alpha", :name "explain*", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["spec path via in x"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/explain*"}, :clojure.core/transient {:added "1.1", :ns "clojure.core", :name "transient", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/persistent! :clojure.core/conj! :clojure.core/assoc! :clojure.core/pop! :clojure.core/dissoc! :clojure.core/disj!], :line 3342, :examples [";; As seen on http://clojure.org/transients\n;; array is initially made transient, modified, then finally made persistent.\n;; See assoc! for further discussion of why it must be done this way.\n;; Also see one example for conj! that contains a detailed example\n;; of a wrong result that can occur if you do not use its return value.\n\n(defn vrange2 [n]\n (loop [i 0 v (transient [])]\n (if (< i n)\n (recur (inc i) (conj! v i))\n (persistent! v))))\n\nuser=> (vrange2 10)\n[0 1 2 3 4 5 6 7 8 9]" "user> (def foo (transient [1 2 3]))\n#'user/foo\nuser> (get foo 0)\n1\nuser> (count foo)\n3\nuser> (nth foo 0)\n1\nuser> (def bar (transient {:honda 7 :kagawa 23 :ienaga 14}))\n#'user/bar\nuser> (get bar :kagawa)\n23\nuser> (count bar)\n3\n\n;; There is a known bug in Clojure 1.3 thru 1.6 where contains? always returns\n;; false for transients. http://dev.clojure.org/jira/browse/CLJ-700\n;; contains? works fine for persistent data structures.\nuser> (contains? bar :kagawa) ; Caution! \nfalse\nuser> (def bar2 (persistent! bar))\n#'user/bar2\nuser> (contains? bar2 :kagawa) ; Caution!\ntrue\n"], :notes nil, :arglists ["coll"], :doc "Returns a new, transient version of the collection, in constant time.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/transient"}, :clojure.core/select-keys {:added "1.0", :ns "clojure.core", :name "select-keys", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/get :clojure.core/keys :clojure.core/dissoc :clojure.core/hash-map], :line 1540, :examples ["(select-keys {:a 1 :b 2} [:a])\n;;=> {:a 1}\n\n(select-keys {:a 1 :b 2} [:a :c])\n;;=> {:a 1}\n\n(select-keys {:a 1 :b 2 :c 3} [:a :c])\n;;=> {:c 3, :a 1}" "user=> (select-keys [1 2 3] [0 0 2])\n{0 1, 2 3}" ";; Extract letters at even indexes from a word into a map:\n(let [word \"hello\"] \n (select-keys (vec word) (filter even? (range (count word)))))\n;; {0 \\h, 2 \\l, 4 \\o}" ";; select-keys can be useful for grabbing environment variables.\n;; it will not error or set a key to nil if some are missing.\n\n;; in the shell/terminal\nexport HTTP_PORT=8000\nexport HTTP_HOST=localhost\n\n;; in the clojure source code\n(ns myapp.core\n (:require [environ.core :as environ]))\n \n(def config (select-keys environ/env [:http-port\n :http-host\n :http-timeout]))\n\n;; notice http-timeout is omitted from the map\n(println config)\n;;=> {:http-port 8000, :http-host localhost}"], :notes ["Why does `select-keys` return a map with keys in reverse order of the keyseq vector?\n\nJay Fields has a [good blog post](http://blog.jayfields.com/2011/01/clojure-select-keys-select-values-and.html) on `select-keys` with implementations of `select-values` (which is what I was really after)." "I think @gknapp is correct. `select-keys` returns a map with keys in the order of the keyseq vector. Perhaps this has changed since his comment, and the documentation needs to be updated. \n \n```clojure\nuser=> (select-keys {:a 1 :b 2 :c 3} [:a :c])\n{:a 1, :c 3}\nuser=> (select-keys {:a 1 :b 2 :c 3} [:c :a])\n{:c 3, :a 1}\n```\n\n" "Wouldn't the following signature be better for partial application? \n\n (select-keys keyseq map)\n\n (def stooges [{:name \"Larry\" :birthday \"Oct 05\"} \n {:name \"Curly\" :birthday \"Jun 19\"} \n {:name \"Moe\" :birthday \"Oct 22\"}])\n\nTacit style is about consistent order (general to specific), not concision:\n\n (map (partial select-keys [:name]) stooges) ;tacit\n (map #(select-keys % [:name]) stooges)" "If you are looking for a `select-vals` or `select-values` alternative of this function, you can do the following:\n\n
" "`select-keys` will return in the order provided for `array-maps`. However, `array-maps` turn into `hash-maps` at a certain threshold, which are un-ordered. So generally, when you need certain ordering, use a sequence instead." "VERY IMPORTANT!!!\n\n`select-keys` returns a map. Maps DO NOT guarantee ordering of their key/value pairs. If you depend on order, do not rely on `select-keys`.\n\nYou might think the order is preserved, only because maps of 8 elements or less in Clojure are implemented with an `array-map` which preserves insertion order, but maps beyond that will use a `hash-map` which does not guarantee ordering. And this is an implementation details, in future release of Clojure, the threshold or type of implementation for maps could change to any other which could even break the ordering for small maps."], :arglists ["map keyseq"], :doc "Returns a map containing only those entries in map whose key is in keys", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/select-keys"}, :clojure.spec.alpha/Specize {:ns "clojure.spec.alpha", :name "Specize", :file "clojure/spec/alpha.clj", :type "var", :column 1, :see-alsos nil, :line 121, :examples nil, :notes nil, :arglists [], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/Specize"}, :clojure.zip/edit {:added "1.0", :ns "clojure.zip", :name "edit", :file "clojure/zip.clj", :type "function", :column 1, :see-alsos [:clojure.zip/root :clojure.zip/zipper :clojure.zip/replace], :line 210, :examples ["(require '[clojure.xml :as xml]\n '[clojure.zip :as zip])\n\n;; get xml with content added to root child\n(let [root (zip/xml-zip (xml/parse-str \"\"))\n child (zip/down root)\n new-child (zip/edit child #(assoc-in % [:content] \"content\"))\n new-root (zip/root new-child)]\n (xml/emit-str new-root))\n;;=> \"content\""], :notes nil, :arglists ["loc f & args"], :doc "Replaces the node at this loc with the value of (f node args)", :library-url "https://github.com/clojure/clojure", :href "/clojure.zip/edit"}, :clojure.test/file-position {:added "1.1", :ns "clojure.test", :name "file-position", :file "clojure/test.clj", :type "function", :column 1, :see-alsos nil, :line 282, :examples ["(clojure.test/file-position 0)\n; => [\"test.clj\" 282]\n\n(take 5 (map clojure.test/file-position (range)))\n; => ([\"test.clj\" 282]\n; [\"test.clj\" 282]\n; [\"core.clj\" 2747]\n; [\"LazySeq.java\" 40]\n; [\"LazySeq.java\" 49])\n"], :deprecated "1.2", :notes nil, :arglists ["n"], :doc "Returns a vector [filename line-number] for the nth call up the\n stack.\n\n Deprecated in 1.2: The information needed for test reporting is\n now on :file and :line keys in the result map.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/file-position"}, :clojure.core/unchecked-add {:added "1.0", :ns "clojure.core", :name "unchecked-add", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/unchecked-dec :clojure.core/unchecked-inc :clojure.core/unchecked-negate :clojure.core/unchecked-divide :clojure.core/unchecked-subtract :clojure.core/unchecked-multiply :clojure.core/unchecked-remainder :clojure.core/+ :clojure.core/+'], :line 1198, :examples [";; can't interchange INTs with LONGs, only F(int, int) or F(long, long)\n;; F is a function, not an operator.\n;; overflow very easily as shown below.\n\nuser=> (unchecked-add Integer/MAX_VALUE 0)\n2147483647\n\nuser=> (unchecked-add Integer/MAX_VALUE 1)\n-2147483648\n\nuser=> (unchecked-add Integer/MAX_VALUE Integer/MAX_VALUE)\n-2\n\nuser=> (unchecked-add Integer/MAX_VALUE Long/MAX_VALUE)\njava.lang.IllegalArgumentException: No matching method found: unchecked_add (NO_SOURCE_FILE:0)\n\nuser=> (unchecked-add Integer/MAX_VALUE Long/MAX_VALUE)\njava.lang.IllegalArgumentException: No matching method found: unchecked_add (NO_SOURCE_FILE:0)\n\nuser=> (unchecked-add Long/MAX_VALUE Long/MAX_VALUE)\n-2\n\nuser=> (unchecked-add 5 Long/MAX_VALUE)\njava.lang.IllegalArgumentException: No matching method found: unchecked_add (NO_SOURCE_FILE:0)\n\nuser=> (unchecked-add 5555555555 Long/MAX_VALUE)\n-9223372031299220254"], :notes nil, :arglists ["x y"], :doc "Returns the sum of x and y, both long.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-add"}, :clojure.core/take-last {:added "1.1", :ns "clojure.core", :name "take-last", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/last :clojure.core/butlast :clojure.core/drop-last :clojure.core/subvec], :line 2941, :examples ["user=> (take-last 2 [1 2 3 4])\n(3 4)\n\nuser=> (take-last 2 [4])\n(4)\n\nuser=> (take-last 2 [])\nnil\n\nuser=> (take-last 2 nil)\nnil\n\nuser=> (take-last 0 [1])\nnil\n\nuser=> (take-last -1 [1])\nnil"], :notes ["Unlike \"drop-last\" (but like \"last\"), \"take-last\" is not lazy:\n\n
\n(def bomb (take-last 1 (range))) ;; infinite evaluation, never returns\n(def lazy-bomb (drop-last 1 (range))) ;; good, but don't use!\n
"], :arglists ["n coll"], :doc "Returns a seq of the last n items in coll. Depending on the type\n of coll may be no better than linear time. For vectors, see also subvec.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/take-last"}, :clojure.inspector/get-child {:ns "clojure.inspector", :name "get-child", :file "clojure/inspector.clj", :type "var", :column 1, :see-alsos nil, :line 32, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.inspector/get-child"}, :clojure.core/dosync {:added "1.0", :ns "clojure.core", :name "dosync", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/sync :clojure.core/ref :clojure.core/locking], :line 5076, :examples [";; Keep dosync body free of side-effects:\n(defn my-thread-unsafe-fn [important-ref]\n (let [start-work (ref false)]\n (dosync\n (when (not @important-ref)\n ;\"If a conflict occurs between 2 transactions \n ;trying to modify the same reference, \n ;one of them will be retried.\"\n ;http://clojure.org/concurrent_programming\n (ref-set important-ref true)\n (ref-set start-work true)))\n (when @start-work \n ;launch side-effects here\n )))\n" ";; Create 2 bank accounts\n(def acc1 (ref 100))\n(def acc2 (ref 200))\n\n;; How much money is there?\n(println @acc1 @acc2)\n;; => 100 200\n\n;; Either both accounts will be changed or none\n(defn transfer-money [a1 a2 amount]\n (dosync\n (alter a1 - amount)\n (alter a2 + amount)\n amount)) ; return amount from dosync block and function (just for fun)\n\n;; Now transfer $20\n(transfer-money acc1 acc2 20)\n;; => 20\n\n;; Check account balances again\n(println @acc1 @acc2)\n;; => 80 220\n\n;; => We can see that transfer was successful"], :macro true, :notes nil, :arglists ["& exprs"], :doc "Runs the exprs (in an implicit do) in a transaction that encompasses\n exprs and any nested calls. Starts a transaction if none is already\n running on this thread. Any uncaught exception will abort the\n transaction and flow out of dosync. The exprs may be run more than\n once, but any effects on Refs will be atomic.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/dosync"}, :clojure.core/prefer-method {:added "1.0", :ns "clojure.core", :name "prefer-method", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/prefers :clojure.core/get-method :clojure.core/methods], :line 1803, :examples ["(def m {:os ::osx})\n\n(defmulti ex :os)\n\n(defmethod ex ::unix\n [_]\n \"unix\")\n\n(derive ::osx ::unix)\n\n(ex m)\n;;=> \"unix\"\n\n(defmethod ex ::bsd\n [_]\n \"bsd\")\n\n(derive ::osx ::bsd)\n\n;; which one to choose ::unix or ::bsd ?? -> Conflict!!!\n(ex m)\n;;=> IllegalArgumentException Multiple methods in multimethod 'ex' match...\n\n(prefer-method ex ::unix ::bsd)\n\n(ex m)\n;;=> \"unix\"\n\n"], :notes nil, :arglists ["multifn dispatch-val-x dispatch-val-y"], :doc "Causes the multimethod to prefer matches of dispatch-val-x over dispatch-val-y \n when there is a conflict", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/prefer-method"}, :clojure.core.logic.fd/interval->= {:ns "clojure.core.logic.fd", :name "interval->=", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 51, :examples nil, :notes nil, :arglists ["i j"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/interval->="}, :clojure.test/inc-report-counter {:added "1.1", :ns "clojure.test", :name "inc-report-counter", :file "clojure/test.clj", :type "function", :column 1, :see-alsos nil, :line 314, :examples nil, :notes nil, :arglists ["name"], :doc "Increments the named counter in *report-counters*, a ref to a map.\n Does nothing if *report-counters* is nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/inc-report-counter"}, :clojure.core/find-var {:added "1.0", :ns "clojure.core", :name "find-var", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 2015, :examples ["user=> (find-var 'clojure.core/map)\n#'clojure.core/map\nuser=> (find-var 'clojure.core/qwerty)\nnil\nuser=> (find-var 'map)\nIllegalArgumentException Symbol must be namespace-qualified clojure.lang.Var.find (Var.java:150)\n"], :notes ["For namespaces other than those in Clojure, you must do `(require 'the-ns)` first, followed by `(find-var 'the-ns/the-name)`. Failing to do this leads to `IllegalArgumentException` thrown complaining about no such namespace."], :arglists ["sym"], :doc "Returns the global var named by the namespace-qualified symbol, or\n nil if no var with that name.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/find-var"}, :clojure.core/*clojure-version* {:added "1.0", :ns "clojure.core", :name "*clojure-version*", :file "clojure/core.clj", :type "var", :column 3, :see-alsos [:clojure.core/clojure-version], :dynamic true, :line 7069, :examples ["user=> *clojure-version*\n{:interim true, :major 1, :minor 2, :incremental 0, :qualifier \"master\"}"], :notes nil, :arglists [], :doc "The version info for Clojure core, as a map containing :major :minor \n :incremental and :qualifier keys. Feature releases may increment \n :minor and/or :major, bugfix releases will increment :incremental. \n Possible values of :qualifier include \"GA\", \"SNAPSHOT\", \"RC-x\" \"BETA-x\"", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*clojure-version*"}, :clojure.string/split-lines {:added "1.2", :ns "clojure.string", :name "split-lines", :file "clojure/string.clj", :type "function", :column 1, :see-alsos [:clojure.string/split], :line 228, :examples ["user=> (clojure.string/split-lines \"test \\n string\")\n[\"test \" \" string\"]" "; ignores trailing newlines\nuser=> (clojure.string/split-lines \"test\\n\\n\")\n[\"test\"]" ";; About ignoring trailing newlines: split-lines is implemented something like:\nuser=> (clojure.string/split s #\"\\r?\\n\")\n\n;; To always get all the lines, you need to use split instead,\n;; and supply a negative third argument:\nuser=> (clojure.string/split \"\\ntest\\n\\n\" #\"\\r?\\n\" -1)\n;;=> [\"\" \"test\" \"\" \"\"]"], :notes nil, :arglists ["s"], :doc "Splits s on \\n or \\r\\n.", :library-url "https://github.com/clojure/clojure", :href "/clojure.string/split-lines"}, :clojure.core/char-array {:added "1.1", :ns "clojure.core", :name "char-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/into-array :clojure.core/to-array :clojure.core/chars], :line 5301, :examples ["user> (char-array \"asdf\")\n#\n\nuser> (seq (char-array \"asdf\"))\n(\\a \\s \\d \\f)\n\nuser> (seq (char-array 10))\n(\\^@ \\^@ \\^@ \\^@ \\^@ \\^@ \\^@ \\^@ \\^@ \\^@)" ";; `slurp` is polymorphic and supports many types. Sometimes you \n;; need to `slurp` a generic argument that could be already a string\n;; (perhaps it was loaded somewhere else). Use `char-array` to convert\n;; the string into a format suitable for `slurp`:\n\n(defn fetch [x]\n (slurp (if (string? x) (char-array x) x)))\n \n(take 10 (fetch \"http://clojure.org\"))\n;;(\\h \\t \\t \\p \\: \\/ \\/ \\c \\l \\o)\n(take 10 (fetch \"Also loading from a string\"))\n;; (\\A \\l \\s \\o \\space \\l \\o \\a \\d \\i)"], :notes nil, :arglists ["size-or-seq" "size init-val-or-seq"], :doc "Creates an array of chars", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/char-array"}, :clojure.core/bounded-count {:added "1.9", :ns "clojure.core", :name "bounded-count", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/counted?], :line 7384, :examples [";;;; Length of a vector can be determined in constant time\n;;;; so this always returns the actual length of the vector\n\n(bounded-count 5 [1 2 3 4])\n;;=> 4\n(bounded-count 5 [1 2 3 4 5])\n;;=> 5\n(bounded-count 5 [1 2 3 4 5 6])\n;;=> 6\n\n;;;; Length of a lazy seq cannot be determined in constant time\n;;;; so this counts at most the first 5 elements\n\n(bounded-count 5 (map identity [1 2 3 4]))\n;;=> 4\n(bounded-count 5 (map identity [1 2 3 4 5]))\n;;=> 5\n(bounded-count 5 (map identity [1 2 3 4 5 6]))\n;;=> 5" ";;;; This would run forever\n\n(count (range))\n\n;;;; But this doesn't\n\n(bounded-count 10000 (range))\n;;=> 10000\n"], :notes nil, :arglists ["n coll"], :doc "If coll is counted? returns its count, else will count at most the first n\n elements of coll using its seq", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bounded-count"}, :clojure.core/vector? {:added "1.0", :ns "clojure.core", :name "vector?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/set? :clojure.core/vec :clojure.core/map? :clojure.core/list? :clojure.core/sequential?], :line 174, :examples [";; this is the idiomatic vector \n(vector? [1 2 3])\n;;=> true\n\n;; a list is not a vector\n(vector? '(1 2 3))\n;;=> false\n\n;; a list may be converted into a vector\n(vector? (vec '(1 2 3)))\n;;=> true\n\n;; a map is not a vector\n(vector? {:a 1 :b 2 :c 3})\n;;=> false\n\n;; a set is not a vector\n(vector? #{:a :b :c})\n;;=> false\n\n(first {:a 1 :b 2 :c 3})\n;;=> [:c 3]\n(vector? (first {:a 1 :b 2 :c 3}))\n;;=> true" ";; an quoted vector is still a vector\n(vector? '[])\n;;=> true" ";; Be careful while traversing data:\n;; map entries are vectors!\n\nuser=> (vector? (first {:a 1}))\ntrue\n\nuser=> (vector? (clojure.lang.MapEntry. :a 1))\ntrue\n\nuser=> (clojure.walk/postwalk\n #(cond-> % (vector? %) set)\n {:a [1 1 2 3]})\n; Unhandled java.lang.ClassCastException\n; class clojure.lang.PersistentHashSet cannot be cast to class\n; java.util.Map$Entry (clojure.lang.PersistentHashSet is in unnamed module of\n; loader 'app'; java.util.Map$Entry is in module java.base of loader\n; 'bootstrap')\n\nuser=> (clojure.walk/postwalk\n #(cond-> %\n (and (vector? %)\n (not (map-entry? %)))\n set)\n {:a [1 1 2 3]})\n{:a #{1 3 2}}"], :notes nil, :arglists ["x"], :doc "Return true if x implements IPersistentVector", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/vector_q"}, :clojure.core/random-sample {:added "1.7", :ns "clojure.core", :name "random-sample", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/rand :clojure.core/shuffle :clojure.core/rand-nth :clojure.core/rand-int], :line 7673, :examples [";; The output of random-sample is a sequence.\n;; Each element of the original collection has probability \"prob\"\n;; of being included in the output sequence.\n\n(random-sample 0.5 [1 2 3 4 5])\n;;=> (1 2 4)\n\n\n;; random-sample can operate on an infinite sequence,\n;; producing an infinite sequence.\n\n(take 10 (random-sample 0.1 (repeat :foo)))\n;;=> (:foo :foo :foo :foo :foo :foo :foo :foo :foo :foo)\n\n(take 10 (random-sample 0.01 (range)))\n;;=> (57 113 281 286 352 497 727 768 957 960)"], :notes nil, :arglists ["prob" "prob coll"], :doc "Returns items from coll with random probability of prob (0.0 -\n 1.0). Returns a transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/random-sample"}, :clojure.pprint/pprint-tab {:added "1.2", :ns "clojure.pprint", :name "pprint-tab", :file "clojure/pprint/pprint_base.clj", :type "function", :column 1, :see-alsos nil, :line 356, :examples nil, :notes nil, :arglists ["kind colnum colinc"], :doc "Tab at this point in the pretty printing stream. kind specifies whether the tab\nis :line, :section, :line-relative, or :section-relative. \n\nColnum and colinc specify the target column and the increment to move the target\nforward if the output is already past the original target.\n\nThis function is intended for use when writing custom dispatch functions.\n\nOutput is sent to *out* which must be a pretty printing writer.\n\nTHIS FUNCTION IS NOT YET IMPLEMENTED.", :library-url "https://github.com/clojure/clojure", :href "/clojure.pprint/pprint-tab"}, :clojure.core.async/sub* {:ns "clojure.core.async", :name "sub*", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["p v ch close?"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/sub*"}, :clojure.test/testing-contexts-str {:added "1.1", :ns "clojure.test", :name "testing-contexts-str", :file "clojure/test.clj", :type "function", :column 1, :see-alsos nil, :line 307, :examples nil, :notes nil, :arglists [""], :doc "Returns a string representation of the current test context. Joins\n strings in *testing-contexts* with spaces.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/testing-contexts-str"}, :clojure.spec.alpha/maybe-impl {:ns "clojure.spec.alpha", :name "maybe-impl", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos [:clojure.spec.alpha/?], :line 1446, :examples nil, :notes nil, :arglists ["p form"], :doc "Do not call this directly, use '?'", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/maybe-impl"}, :clojure.core.logic/log {:ns "clojure.core.logic", :name "log", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1288, :examples ["(run* [q]\n (log \"* running program\")\n (fresh [c d]\n (conde\n [(log \"** in first clause\")\n (== c 0)]\n [(log \"** in second clause\")\n (== c 10)]\n [(log \"** in third clause\")\n (== d 2)\n (is c d (fn [a] (* a 2)))])\n (log \"ok finishing. \")\n (== c q)))\n;; =>\n;; * running program\n;; ** in first clause\n;; ok finishing. \n;; ** in second clause\n;; ok finishing. \n;; ** in third clause\n;; ok finishing. \n"], :macro true, :notes nil, :arglists ["& s"], :doc "Goal for println", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/log"}, :clojure.core/butlast {:added "1.0", :ns "clojure.core", :name "butlast", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/first :clojure.core/rest :clojure.core/last :clojure.core/next :clojure.core/drop-last :clojure.core/take-last :clojure.core/pop], :line 272, :examples ["user=> (butlast [1 2 3])\n(1 2)\nuser=> (butlast (butlast [1 2 3]))\n(1)\nuser=> (butlast (butlast (butlast [1 2 3])))\nnil" ";really slow reverse\n;put the last item of the list at the start of a new list, and recur over all but the last item of the list.\n;butlast acts similar to next in that it returns null for a 1-item list.\n\n(defn my-reverse [xs]\n (when xs\n (cons (last xs) (my-reverse (butlast xs)))))" ";; A version of (into) that doesn't require (comp)\n;; for transducers arguments.\n\n(defn into* [to & args]\n (into to\n (apply comp (butlast args))\n (last args)))\n\n(into* [] (range 10))\n;; [0 1 2 3 4 5 6 7 8 9]\n\n(into* [] (map inc) (range 10))\n;; [1 2 3 4 5 6 7 8 9 10]\n\n(into* [] (map inc) (filter odd?) (range 10))\n;; [1 3 5 7 9]" ";; `butlast` (linear time) vs. `drop-last` (lazy, efficient, more flexible, \n;; constant time(?)) vs. `pop` (fast but requires a vector).\n\n(def r (range 10000))\n\n(time (butlast r)) ;;=> \"Elapsed time: 6.379 msecs\"\n(time (drop-last r)) ;;=> \"Elapsed time: 0.0475 msecs\"\n(time (drop-last 2 r)) ;;=> \"Elapsed time: 0.0569 msecs\"\n(time (drop-last 0 r)) ;;=> \"Elapsed time: 0.098 msecs\"\n(time (drop-last -1 r)) ;;=> \"Elapsed time: 0.0615 msecs\"\n\n(def r-vec (vec r)) ;; to work like `butlast` pop needs a vector \n(time (pop r-vec)) ;;=> \"Elapsed time: 0.062 msecs\""], :notes ["When using a vector, `pop` is faster than `butlast`." "`pop` will throw exception if the vector is empty, whereas `butlast` will return `nil`" "In my example, `but-last` is ~100 x slower than `drop-last`. `butlast` cannot remove multiple elements from the end, but `drop-last` can. `butlast` seems eager, and `drop-last` seems lazy. 'butlast' will return nil when empty, and `drop-last` will return `'()` when empty. "], :arglists ["coll"], :doc "Return a seq of all but the last item in coll, in linear time", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/butlast"}, :clojure.java.shell/*sh-env* {:ns "clojure.java.shell", :name "*sh-env*", :file "clojure/java/shell.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 19, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.java.shell/*sh-env*"}, :clojure.core.logic/annotate {:ns "clojure.core.logic", :name "annotate", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 547, :examples nil, :notes nil, :arglists ["k v"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/annotate"}, :clojure.spec.alpha/form {:ns "clojure.spec.alpha", :name "form", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 173, :examples nil, :notes nil, :arglists ["spec"], :doc "returns the spec as data", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/form"}, :clojure.core.logic.pldb/empty-db {:ns "clojure.core.logic.pldb", :name "empty-db", :file "clojure/core/logic/pldb.clj", :type "var", :column 1, :see-alsos nil, :line 6, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/empty-db"}, :clojure.core.logic.fd/bounded-listo {:ns "clojure.core.logic.fd", :name "bounded-listo", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 1085, :examples nil, :notes nil, :arglists ["l n"], :doc "Ensure that the list l never grows beyond bound n.\n n must have been assigned a domain.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/bounded-listo"}, :clojure.test.tap/print-tap-diagnostic {:added "1.1", :ns "clojure.test.tap", :name "print-tap-diagnostic", :file "clojure/test/tap.clj", :type "function", :column 1, :see-alsos nil, :line 51, :examples nil, :notes nil, :arglists ["data"], :doc "Prints a TAP diagnostic line. data is a (possibly multi-line)\n string.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test.tap/print-tap-diagnostic"}, :clojure.core/interpose {:added "1.0", :ns "clojure.core", :name "interpose", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/interleave :clojure.string/join], :line 5206, :examples [";; The quintessential interpose example:\nuser> (def my-strings [\"one\" \"two\" \"three\"])\n\nuser> (interpose \", \" my-strings)\n=> (\"one\" \", \" \"two\" \", \" \"three\")\n\nuser> (apply str (interpose \", \" my-strings))\n=> \"one, two, three\"\n\n;; Might use clojure.string/join if the plan is to join\n(require '[clojure.string :as str])\nuser> (str/join \", \" my-strings)\n=> \"one, two, three\"" ";; This example converts what would be comma-separated values into pipe '|'\n;; separated values for alternate database loads. By switching delimiters, \n;; quotes can be eliminated from each sequence element, which are not \n;; needed for some databases.\n\n(def test-data-in '((\"43\" \"MORRISON, VAN X DMD\" \"43 ROADWAY\" \\;)\n (\"25\" \"JANE SMITH N\" \"25 GARDEN PATH\" \\!)))\n\n(def test-data-out (map #(concat (interpose \\| %) (list \\| \"\\n\"))\n test-data-in))\n\ntest-data-out\n\n=> ((\"43\" \\| \"MORRISON, VAN X DMD\" \\| \"43 ROADWAY\" \\| \\; \\| \"\\n\")\n (\"25\" \\| \"JANE SMITH N\" \\| \"25 GARDEN PATH\" \\| \\! \\| \"\\n\"))\n\n(doseq [in-seq test-data-out]\n (doseq [val in-seq]\n (spit \"temp1.csv\" val :append true)))\n\n;; cat temp1.csv:\n\n;; 43|MORRISON, VAN X DMD|43 ROADWAY|;|\n;; 25|JANE SMITH N|25 GARDEN PATH|!|"], :notes nil, :arglists ["sep" "sep coll"], :doc "Returns a lazy seq of the elements of coll separated by sep.\n Returns a stateful transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/interpose"}, :clojure.core/proxy-mappings {:added "1.0", :ns "clojure.core", :name "proxy-mappings", :file "clojure/core_proxy.clj", :type "function", :column 1, :see-alsos nil, :line 323, :examples ["(def my-proxy\n (proxy [java.lang.Object] []\n (equals [_] false)\n (toString [] \"I'm an object\")))\n;; => #'user/my-proxy\n\n(proxy-mappings my-proxy)\n;; => {\"equals\" #function[user/fn--43785/fn--43786],\n;; \"toString\" #function[user/fn--43785/fn--43788]}\n\n(let [to-string-fn (-> my-proxy proxy-mappings (get \"toString\"))]\n (to-string-fn :foo))\n;; => \"I'm an object\"\n"], :notes nil, :arglists ["proxy"], :doc "Takes a proxy instance and returns the proxy's fn map.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/proxy-mappings"}, :clojure.core/bit-shift-right {:added "1.0", :ns "clojure.core", :name "bit-shift-right", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/bit-shift-left :clojure.core/bit-xor :clojure.core/bit-or :clojure.core/bit-and :clojure.core/bit-set :clojure.core/bit-test :clojure.core/bit-flip :clojure.core/bit-and-not :clojure.core/bit-clear :clojure.core/unsigned-bit-shift-right], :line 1362, :examples [";; Convert number into list of bits:\n(defn bits [n s]\n (take s\n (map\n (fn [i] (bit-and 0x01 i))\n (iterate\n (fn [i] (bit-shift-right i 1))\n n))))\n;; #'user/bits\n\n(map (fn [n] (bits n 3)) (range 8))\n;;=> ((0 0 0) (1 0 0) (0 1 0) (1 1 0) (0 0 1) (1 0 1) (0 1 1) (1 1 1))\n" "(bit-shift-right 2r1101 0) ;;=> 13\n(bit-shift-right 2r1101 1) ;;=> 6\n(bit-shift-right 2r1101 2) ;;=> 3\n(bit-shift-right 2r1101 3) ;;=> 1\n(bit-shift-right 2r1101 4) ;;=> 0" ";; Warning: bit-shift-right upcasts arguments to Long and returns Long\n(format \"0x%x\" (byte -128))\n; => \"0x80\"\n(format \"0x%x\" (bit-shift-right (byte -128) 1)) ; You'd expect 0x40?\n; => \"0xffffffffffffffc0\"\n; You'd expect 0x40, but (byte -128) was converted to (long -128) and then\n; right-shifted, with the negative sign bit of 1 propagated.\n\n; This can't be avoided by using unsigned-bit-shift-right:\n(format \"0x%x\" (unsigned-bit-shift-right (byte -128) 1))\n; => \"0x7fffffffffffffc0\"\n\n; If you want unsigned \"byte\" operations, upcast the byte yourself via bit-and:\n(format \"0x%x\" (bit-shift-right (bit-and 0xff (byte -128)) 1))\n; => \"0x40\"\n\n; This works because the output of bit-and is always Long:\n(type (bit-and 0xff (byte -128)))\n; => java.lang.Long\n; Note that bit-and returns Long even if both arguments are smaller:\n(type (bit-and (short 0xff) (byte -128)))\n; => java.lang.Long" ";; floating point bit-shifting\n;; thanks to Gary Fredericks: https://github.com/gfredericks/doubles\n(defn bit-shift-double [x shifts]\n (let [x-long (Double/doubleToRawLongBits x)]\n (Double/longBitsToDouble\n (bit-or (bit-and 1 x-long)\n (bit-shift-left (- (bit-shift-right x-long 52) shifts) 52)\n (bit-and 0xfffffffffffff x-long)))))"], :notes ["From the IRC channel, a way to get zero-fill bit-shift-right:\r\n\r\n
\r\n\r\nThere's also an open ticket for a [built-in version](http://dev.clojure.org/jira/browse/CLJ-827)." "unsigned-bit-shift-right was added in Clojure 1.6.0. Click the link in the See Also section above."], :arglists ["x n"], :doc "Bitwise shift right", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-shift-right"}, :clojure.core/every? {:added "1.0", :ns "clojure.core", :name "every?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/some :clojure.core/not-any? :clojure.core/not-every?], :line 2672, :examples ["user=> (every? even? '(2 4 6))\ntrue\nuser=> (every? even? '(1 2 3))\nfalse" ";; you can use every? with a set as the predicate to return true if \n;; every member of a collection is in the set\nuser=> (every? #{1 2} [1 2 3])\nfalse\nuser=> (every? #{1 2} [1 2])\ntrue\n\n;; or use a hash-map as the predicate with every? to return true \n;; if every member of a collection is a key within the map\nuser=> (every? {1 \"one\" 2 \"two\"} [1 2])\ntrue\nuser=> (every? {1 \"one\" 2 \"two\"} [1 2 3])\nfalse" ";; this is kind of weird IMO... but it works that way (the same for vectors)\n;; See: https://en.wikipedia.org/wiki/Vacuous_truth\nuser=> (every? true? '())\ntrue\nuser=> (every? false? '())\ntrue\n\n;; and similarly\nuser=> (every? map? '())\ntrue\nuser=> (every? vector? '())\ntrue\nuser=> (every? string? '())\ntrue\nuser=> (every? number? '())\ntrue\n\n;; and even\nuser=> (every? :foo nil)\ntrue\n\n;; As such a better description of every? would be\n\n;; Returns false if there exists a value x in coll \n;; such that (pred? x) is false, else true.\" \n" ";; every? can replace clojure.set/subset? if and only if\n;; the sets do not contain false / nil values\n\n(subset? #{1} #{1 2}) ;;=> true\n(every? #{1 2} #{1} ) ;;=> true ✔\n\n(subset? #{1 3} #{1 2}) ;;=> false\n(every? #{1 2} #{1 3}) ;;=> false ✔\n\n;; however, invoking a set with a value returns the matched element,\n;; causing the comparison below to fail\n\n(subset? #{true false} #{true false}) ;;=> true\n(every? #{true false} #{true false}) ;;=> false ✘ 😦\n"], :notes nil, :tag "java.lang.Boolean", :arglists ["pred coll"], :doc "Returns true if (pred x) is logical true for every x in coll, else\n false.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/every_q"}, :clojure.core/subs {:added "1.0", :ns "clojure.core", :name "subs", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.string/replace :clojure.string/split :clojure.string/replace-first :clojure.core/re-find :clojure.core/re-seq :clojure.core/re-matches], :line 4981, :examples ["user=> (subs \"Clojure\" 1) \n\"lojure\"\nuser=> (subs \"Clojure\" 1 3)\n\"lo\"\n\n\n;; String indexes have to be between 0 and (.length s)\n\nuser=> (subs \"Clojure\" 1 20)\njava.lang.StringIndexOutOfBoundsException: String index out of range: 20 (NO_SOURCE_FILE:0)\n" ";; Note that subs uses method java.lang.String/substring\n;; http://docs.oracle.com/javase/6/docs/api/java/lang/String.html#substring%28int,%20int%29\n\n;; See this link for more details:\n\n;; https://dzone.com/articles/changes-stringsubstring-java-7\n\n;; This link was the original, but seems to no longer exist as of Nov 2017:\n;; http://www.javaadvent.com/2012/12/changes-to-stringsubstring-in-java-7.html\n\n;; Briefly, before Java version 7u6, Java's substring method was\n;; guaranteed to work in O(1) time, by creating a String that refers\n;; to the original string's characters, rather than copying them.\n\n;; After Java 7u6, substring was changed to copy the string's original\n;; characters, thus taking time linear in the length of the substring,\n;; but it never refers to the original string.\n\n;; The potential disadvantage of the pre-version-7u6 behavior is that\n;; if you read in one or more strings with a large total size, and then\n;; use methods based on substring to keep only a small subset of that,\n;; e.g., because you parsed and found a small collection of substrings of\n;; interest for your computation, the large strings will still have\n;; references to them, and thus cannot be garbage collected, even if you\n;; have no other references to them.\n\n;; You can use the Java constructor (String. s) to guarantee that you\n;; copy a string s. (String. (subs s 5 20)) will copy the substring once\n;; pre-version-7u6, but it will copy the substring twice\n;; post-version-7u6.\n\n;; I believe java.util.regex.Matcher method group, and\n;; java.util.regex.Pattern method split, also have the same\n;; behavior as substring.\n\n;; This affects the behavior of Clojure functions such as:\n\n;; In clojure.core:\n;; subs, re-find, re-matches, re-seq\n;; In clojure.string:\n;; replace replace-first split\n" ";; Suppose you want to shorten a string of blanks [outdent]\n;; Starting with a string of length 5\n;; [Here I do not use blanks to illustrate what is happening]\n(def s5 \"abcdef\")\n;; and reducing its length by 2\n(subs s5 (min 2 (count s5))) \n;=> \"cdef\"\n(subs s5 (min 10 (count s5))) \n;=> \"\""], :notes nil, :arglists ["s start" "s start end"], :doc "Returns the substring of s beginning at start inclusive, and ending\n at end (defaults to length of string), exclusive.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/subs"}, :clojure.core/memfn {:added "1.0", :ns "clojure.core", :name "memfn", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos nil, :line 3871, :examples ["user=> (def *files* (file-seq (java.io.File. \"/tmp/\")))\n#'user/*files*\nuser=> (count (filter (memfn isDirectory) *files*))\n68\nuser=> (count (filter #(.isDirectory %) *files*))\n68\n" "user=> ;; you must pass arguments to your method to add up to the expected arity\n\nuser=> (def starts-with (memfn startsWith prefix))\n#'user/starts-with\nuser=> (starts-with \"pikachu\" \"pika\")\ntrue\nuser=> (starts-with \"pikachu\" \"bulba\")\nfalse" "(set! *warn-on-reflection* true)\n\n;; memfn is inherently subject to reflective calls\n\n(time (dotimes [n 100000] (mapv (memfn toLowerCase) [\"A\" \"B\" \"C\"])))\n;; Reflection warning, call to toLowerCase can't be resolved\n;; \"Elapsed time: 794.081758 msecs\"\n\n;; But accepts and propagate type hints to avoid it\n\n(time (dotimes [n 100000] (mapv (memfn ^String toLowerCase) [\"A\" \"B\" \"C\"])))\n;; \"Elapsed time: 33.708462 msecs\""], :macro true, :notes nil, :arglists ["name & args"], :doc "Expands into code that creates a fn that expects to be passed an\n object and any args and calls the named instance method on the\n object passing the args. Use when you want to treat a Java method as\n a first-class fn. name may be type-hinted with the method receiver's\n type in order to avoid reflective calls.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/memfn"}, :clojure.core/+' {:added "1.0", :ns "clojure.core", :name "+'", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/+ :clojure.core/unchecked-add], :line 972, :examples ["(+')\n;;=> 0\n\n(+' 1)\n;;=> 1\n\n(+' -10)\n;;=> -10\n\n(+' 1 2)\n;;=> 3\n\n(+' 1 2 3)\n;;=> 6\n\n(apply + (range 10000000000000 10000000001000))\n;; ArithmeticException: integer overflow\n\n(apply +' (range 10000000000000 10000000001000))\n;;=> 1000000000499500" "(class 1)\n;; => java.lang.Long\n\n(+ 1 Long/MAX_VALUE)\n;; => java.lang.ArithmeticException: integer overflow\n;; Numbers.java:1388 clojure.lang.Numbers.throwIntOverflow\n;; Numbers.java:1687 clojure.lang.Numbers.add\n\n(+' 1 Long/MAX_VALUE)\n;; => 9223372036854775808N\n\n(class (+' 1 Long/MAX_VALUE))\n;; => clojure.lang.BigInt\n"], :notes nil, :arglists ["" "x" "x y" "x y & more"], :doc "Returns the sum of nums. (+') returns 0. Supports arbitrary precision.\n See also: +", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/+'"}, :clojure.core/newline {:added "1.0", :ns "clojure.core", :name "newline", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 3697, :examples [";; This is equivalent to System.out.println() in Java\nuser=> (newline)\n\nnil\n; Calling println w/o args is equivalent.\nuser=> (println)\n\nnil\nuser=>"], :notes nil, :arglists [""], :doc "Writes a platform-specific newline to *out*", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/newline"}, :clojure.core/class? {:added "1.0", :ns "clojure.core", :name "class?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/class], :line 5443, :examples ["user=> (class? 1)\nfalse\n\nuser=> (class? java.lang.String)\ntrue\n\nuser=> (class? [])\nfalse"], :notes nil, :arglists ["x"], :doc "Returns true if x is an instance of Class", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/class_q"}, :clojure.test/assert-predicate {:added "1.1", :ns "clojure.test", :name "assert-predicate", :file "clojure/test.clj", :type "function", :column 1, :see-alsos nil, :line 436, :examples nil, :notes nil, :arglists ["msg form"], :doc "Returns generic assertion code for any functional predicate. The\n 'expected' argument to 'report' will contains the original form, the\n 'actual' argument will contain the form with all its sub-forms\n evaluated. If the predicate returns false, the 'actual' form will\n be wrapped in (not...).", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/assert-predicate"}, :clojure.core/*e {:added "1.0", :ns "clojure.core", :name "*e", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [:clojure.repl/pst], :dynamic true, :line 6294, :examples ["user=> (ns-refers) ;;Oops! we missed a namespace (ns-refers 'user)\n; Evaluation aborted.\n\nuser=> *e\n#"], :notes nil, :arglists [], :doc "bound in a repl thread to the most recent exception caught by the repl", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*e"}, :clojure.core/pvalues {:added "1.0", :ns "clojure.core", :name "pvalues", :file "clojure/core.clj", :static true, :type "macro", :column 1, :see-alsos [:clojure.core/pmap :clojure.core/future :clojure.core/pcalls], :line 7044, :examples [";; expressions are calculated in parallel\n\nuser=> (pvalues (expensive-calc-1) (expensive-calc-2))\n(2330 122)\n" ";; pvalues is implemented using Clojure futures. See examples for 'future'\n;; for discussion of an undesirable 1-minute wait that can occur before\n;; your standalone Clojure program exits if you do not use shutdown-agents."], :macro true, :notes nil, :arglists ["& exprs"], :doc "Returns a lazy sequence of the values of the exprs, which are\n evaluated in parallel", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/pvalues"}, :clojure.test/*load-tests* {:added "1.1", :ns "clojure.test", :name "*load-tests*", :file "clojure/test.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 245, :examples [";; Assuming \"mynamespace\" is available from the classpath and\n;; contains a mix of production and test code, the following prevents\n;; macros like \"deftest\" from producing test functions,\n;; removing them from any compiled AOT artifact:\n\n(require '[clojure.test :as t])\n(binding [t/*load-tests* false]\n (compile 'mynamespace))\n"], :notes ["In modern times, `*load-tests*` is almost never required, as build tools such as Leiningen or `clojure.tools.deps` enforce a conventional separation of tests from production code, preventing their presence in production artifacts."], :arglists [], :doc "True by default. If set to false, no test functions will\n be created by deftest, set-test, or with-test. Use this to omit\n tests when compiling or loading production code.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/*load-tests*"}, :clojure.core/sort-by {:added "1.0", :ns "clojure.core", :name "sort-by", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/sort :clojure.core/compare], :line 3119, :examples ["user=> (sort-by count [\"aaa\" \"bb\" \"c\"])\n(\"c\" \"bb\" \"aaa\")\n\nuser=> (sort-by first [[1 2] [2 2] [2 3]]) \n([1 2] [2 2] [2 3])\n\nuser=> (sort-by first > [[1 2] [2 2] [2 3]]) \n([2 2] [2 3] [1 2])" "user=> (sort-by :rank [{:rank 2} {:rank 3} {:rank 1}])\n({:rank 1} {:rank 2} {:rank 3})" "(def x [{:foo 2 :bar 11}\n {:bar 99 :foo 1}\n {:bar 55 :foo 2}\n {:foo 1 :bar 77}])\n\n;sort by :foo, and where :foo is equal, sort by :bar\n(sort-by (juxt :foo :bar) x)\n;=>({:foo 1, :bar 77} {:bar 99, :foo 1} {:foo 2, :bar 11} {:bar 55, :foo 2})" "(def x [{:foo 2 :bar 11}\n {:bar 99 :foo 1}\n {:bar 55 :foo 2}\n {:foo 1 :bar 77}])\n; sort-by given key order (:bar)\n(def order [55 77 99 11])\n(sort-by \n #((into {} (map-indexed (fn [i e] [e i]) order)) (:bar %)) \n x)\n;=> ({:bar 55, :foo 2} {:foo 1, :bar 77} {:bar 99, :foo 1} {:foo 2, :bar 11})" ";sort entries in a map by value\nuser=> (sort-by val > {:foo 7, :bar 3, :baz 5})\n([:foo 7] [:baz 5] [:bar 3])" ";; Warning: You can sort a Java array and get back a sorted immutable Clojure\n;; data structure, but it will also change the input Java array, by sorting it.\n;; Copy the array before sorting if you want to avoid this.\n\nuser=> (def x (to-array [32 -5 4 11]))\n#'user/x\n\nuser=> (seq x)\n(32 -5 4 11)\n\nuser=> (def y (sort-by - x))\n#'user/y\n\n;; Return sorted sequence\nuser=> y\n(32 11 4 -5)\n\n;; but also modifies x, because it used the array to do the sorting.\nuser=> (seq x)\n(32 11 4 -5)\n\n;; One way to avoid this is copying the array before sorting:\nuser=> (def y (sort-by - (aclone x)))\n#'user/y" ";;; from the joy of clojure 2nd\n;;; function as arguments\n\n(def plays [{:band \"Burial\", :plays 979, :loved 9}\n {:band \"Eno\", :plays 2333, :loved 15}\n {:band \"Bill Evans\", :plays 979, :loved 9}\n {:band \"Magma\", :plays 2665, :loved 31}])\n\n(def sort-by-loved-ratio (partial sort-by #(/ (:plays %) (:loved %))))\n\n(sort-by-loved-ratio plays)\n\n;=> ({:band \"Magma\", :plays 2665, :loved 31}\n {:band \"Burial\", :plays 979, :loved 9}\n {:band \"Bill Evans\", :plays 979, :loved 9}\n {:band \"Eno\", :plays 2333, :loved 15})\n\n\n;;; others.\n(sort-by second [[:a 7], [:c 13], [:b 21]])\n;;=> ([:a 7] [:c 13] [:b 21])\n\n(sort-by str [\"z\" \"x\" \"a\" \"aa\" 1 5 8])\n;;=> (1 5 8 \"a\" \"aa\" \"x\" \"z\")\n\n(sort-by :age [{:age 99}, {:age 13}, {:age 7}])\n;;=> ({:age 7} {:age 13} {:age 99})" ";; you can pass a comparator to specify the order to sort in\n\n;; typical sort, low to high\n(sort-by :value [{:value 1 :label \"a\"} {:value 3 :label \"c\"} {:value 2 :label \"b\"}])\n;=> ({:value 1, :label \"a\"} {:value 2, :label \"b\"} {:value 3, :label \"c\"})\n\n;; override the default comparator to sort high to low\n(sort-by :value #(> %1 %2) [{:value 1 :label \"a\"} {:value 3 :label \"c\"} {:value 2 :label \"b\"}])\n;=> ({:value 3 :label \"c\"} {:value 2, :label \"b\"} {:value 1, :label \"a\"})\n\n;; sort-by behavior when :value is absent\n(sort-by :value [{:value 1 :label \"a\"} {:label \"c\"} {:value 2 :label \"b\"}])\n=> ({:label \"c\"} {:value 1, :label \"a\"} {:value 2, :label \"b\"})\n\n;; now if you provide custom comparator when :value is absent you will get NullPointerException\n(sort-by :value #(> %1 %2) [{:value 1 :label \"a\"} {:label \"c\"} {:value 2 :label \"b\"}])\n=> Execution error (NullPointerException) at user/eval1515$fn (form-init71750676547201835.clj:1).\nnull\n\n;; make above working by simple or; considering absence of \"value\" as invaluable or highest value :)\n(sort-by :value #(> (or %1 Integer/MAX_VALUE) (or %2 Integer/MAX_VALUE)) [{:value 1 :label \"a\"} {:label \"c\"} {:value 2 :label \"b\"}])\n=> ({:label \"c\"} {:value 2, :label \"b\"} {:value 1, :label \"a\"})" ";; to sort by nested hash-map values\n;; with the help of get-in and custom comparator\n\n> (sort-by #(get-in (val %) [:price]) {:chair {:price 10} :table {:price 9} :lamp {:price 9}})\n;;=> ([:table {:price 9}] [:lamp {:price 9}] [:chair {:price 10}])\n" ";; sort-by descending (reverse)\n\nuser=> (sort-by :rank #(compare %2 %1) [{:rank 2} {:rank 3} {:rank 1}])\n({:rank 3} {:rank 2} {:rank 1})" ";; Warning: sort-by will not apply the keyfn on coll's of length 1\n\nuser=> (sort-by (fn [i] (nth i) 4) [[1 2 3]])\n([1 2 3])\n\nuser=> (nth [1 2 3] 4)\n; IndexOutOfBoundsException clojure.lang.PersistentVector.arrayFor (PersistentVector.java:158)..." ";; Using comp as a way to sort descending\n(def unordered '({:created_at 1612637437}\n {:created_at 1610998684}\n {:created_at 1622245799}))\n\n(sort-by (comp - :created_at) unordered)\n;;=> ({:created_at 1622245799} {:created_at 1612637437} {:created_at 1610998684})\n\n;; Note: using the negative - as a comparator won't work\n;; so you need to combine the functions\n;; same example without comp:\n(sort-by #(- (:created_at %)) unordered)\n;;=> ({:created_at 1622245799} {:created_at 1612637437} {:created_at 1610998684})"], :notes nil, :arglists ["keyfn coll" "keyfn comp coll"], :doc "Returns a sorted sequence of the items in coll, where the sort\n order is determined by comparing (keyfn item). If no comparator is\n supplied, uses compare. comparator must implement\n java.util.Comparator. Guaranteed to be stable: equal elements will\n not be reordered. If coll is a Java array, it will be modified. To\n avoid this, sort a copy of the array.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/sort-by"}, :clojure.spec.alpha/fspec-impl {:ns "clojure.spec.alpha", :name "fspec-impl", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 1740, :examples nil, :notes nil, :arglists ["argspec aform retspec rform fnspec fform gfn"], :doc "Do not call this directly, use 'fspec'", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/fspec-impl"}, :clojure.core/restart-agent {:added "1.2", :ns "clojure.core", :name "restart-agent", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/agent-error :clojure.core/agent], :line 2177, :examples ["(deftest t-rstart\n (future (println \"running in a thread...\"))\n (let [agt (agent 0)\n\n ; This doesn't work\n h01 (fn [a e]\n (println :10 \"agent error found:\" )\n (println :11 \"restarting agent...\")\n (restart-agent a 100)\n (Thread/sleep 100)\n (println :12 \"agent restarted, state=\" @a))\n\n ; This works. Need to call restart-agent in a separate thread\n h02 (fn [a e]\n (println :20 \"agent error found:\" )\n (future\n (println :21 \"restarting agent...\")\n (restart-agent a 200)\n (println :22 \"agent restarted, state=\" @a))) ;=> 200\n ]\n (set-error-handler! agt h02)\n (send agt inc)\n (Thread/sleep 100) (println :01 @agt) ;=> 1\n (Thread/sleep 100) (send agt #(/ % 0))\n (Thread/sleep 100) (println :02 @agt) ;=> 200\n (Thread/sleep 100) (send agt inc)\n (Thread/sleep 100) (println :03 @agt) ;=> 201\n))\n\n; Output\n; running in a thread...\n; :01 1\n; :20 agent error found:\n; :21 restarting agent...\n; :22 agent restarted, state= 200\n; :02 200\n; :03 201\n"], :notes nil, :arglists ["a new-state & options"], :doc "When an agent is failed, changes the agent state to new-state and\n then un-fails the agent so that sends are allowed again. If\n a :clear-actions true option is given, any actions queued on the\n agent that were being held while it was failed will be discarded,\n otherwise those held actions will proceed. The new-state must pass\n the validator if any, or restart will throw an exception and the\n agent will remain failed with its old state and error. Watchers, if\n any, will NOT be notified of the new state. Throws an exception if\n the agent is not failed.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/restart-agent"}, :clojure.pprint/simple-dispatch {:added "1.2", :ns "clojure.pprint", :name "simple-dispatch", :file "clojure/pprint/dispatch.clj", :type "function", :column 1, :see-alsos [:clojure.pprint/set-pprint-dispatch :clojure.pprint/with-pprint-dispatch], :line 151, :examples nil, :notes nil, :arglists ["object"], :doc "The pretty print dispatch function for simple data structure format.", :library-url "https://github.com/clojure/clojure", :href "/clojure.pprint/simple-dispatch"}, :clojure.core.logic.pldb/contains-lvar? {:ns "clojure.core.logic.pldb", :name "contains-lvar?", :file "clojure/core/logic/pldb.clj", :type "function", :column 1, :see-alsos nil, :line 35, :examples nil, :notes nil, :arglists ["x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/contains-lvar_q"}, :clojure.core/rem {:added "1.0", :ns "clojure.core", :name "rem", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/quot :clojure.core/mod], :line 1269, :examples ["user=> (rem 10 9)\n1\nuser=> (rem 2 2)\n0" ";; rem and mod are commonly used to get the remainder.\n;; mod means Knut's mod (truncating towards negativity). \n;; rem implements ANSI C's % operator\n;; Absolute value stays the same, always the distance\n;; towards zero.\n;; sign depends on dividend. \n\n\nuser=> (rem -10 3)\n-1\nuser=> (rem 10 -3)\n1\nuser=> (rem -10 -3)\n-1\nuser=> (rem 10 3)\n1\n\nuser=> (mod -10 3)\n2\nuser=> (mod 10 -3)\n-2\nuser=> (mod -10 -3)\n-1"], :notes nil, :arglists ["num div"], :doc "remainder of dividing numerator by denominator.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/rem"}, :clojure.core/doall {:added "1.0", :ns "clojure.core", :name "doall", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/dorun :clojure.core/doseq :clojure.core/run!], :line 3148, :examples [";; Nothing is printed because map returns a lazy-seq\nuser=> (def foo (map println [1 2 3]))\n#'user/foo\n\n;; doall forces the seq to be realized\nuser=> (def foo (doall (map println [1 2 3])))\n1\n2\n3\n#'user/foo\n\n;; where\n(doall (map println [1 2 3]))\n1\n2\n3\n(nil nil nil)" ";;map a function which makes database calls to either retrieve or \n;;create and retrieves records from the database over a vector of values. \n;;The function returns a map of fields and values\nuser=> (map #(db/make-n-get-or-get :person {:name %}) [\"Fred\" \"Ethel\" \"Lucy\" \"Ricardo\"])\nJdbcSQLException The object is already closed [90007-170] org.h2.message.DbE\nxception.getJdbcSQLException (DbException.java:329)\n\n;;database connection was closed before we got a chance to do our transactions\n;;lets wrap it in doall\nuser=> (doall (map #(db/make-n-get-or-get :person {:name %}) \n[\"Fred\" \"Ethel\" \"Lucy\" \"Ricardo\"]))\nDEBUG :db insert into person values name = 'Fred'\nDEBUG :db insert into person values name = 'Ethel'\nDEBUG :db insert into person values name = 'Lucy'\nDEBUG :db insert into person values name = 'Ricardo'\n({:name \"Fred\"} {:name \"Ethel\"} {:name \"Lucy\"} {:name \"Ricardo\"})\n\n;;notice that unlike using dorun, this returns a list of maps" ";; The (doall n coll) form only forces the first n (or more) items in coll to\n;; be realized, but still returns the entire coll.\n(def pr-123 (lazy-seq (cons (pr 1)\n (lazy-seq (cons (pr 2)\n (lazy-seq (cons (pr 3) nil)))))))\n#'user/pr-123\n\n;; Since doall returns the collection, be careful not to let the REPL realize\n;; the whole thing, as it would if we were to call (doall 1 pr-123) instead.\nuser=> (do (doall 1 pr-123) (println))\n12\nnil\n;; The 1 is triggered when (seq pr-123) is called, then the 2 is triggered\n;; when (next pr-123) is called (both inside dorun, via doall).\n\nuser=> pr-123\n3(nil nil nil)\n;; The 3 is finally triggered when the REPL realizes the entirety of pr-123\n\n;; pr-123 is built of nested lazy-seq's because (map pr coll) isn't very lazy:\n(do (doall 1 (map pr (range 100))) (println))\n012345678910111213141516171819202122232425262728293031\nnil\n;; Due to occult clojure.lang.RT/JVM internals (?), (next coll) on this sort\n;; of coll realizes the items in batches of 32 each.\n" ";; #'for is create lazy-seq\n(def x (for [i (range 10)]\n i)\n\n(type x) ;;=> clojure.lang.LazySeq\n\n;; doall return evaluated value\n(doall x) ;;=> (0 1 2 3 4 ...)\n\n\n;; Notice!\n;; but it is clojure.lang.LazySeq\n(type (doall x)) ;;=> clojure.lang.LazySeq\n\n;; if you want to get list ...\n(into-array x)\n(type (into-array x)) ;;=> [Ljava.lang.Long;"], :notes ["Shouldn't we use seq instead of coll in the function signature since we should really pass a sequence?" "'seq' is a function; using it in the function args as a value would shadow the function (and thereby making the function seq unusable in that scope)"], :arglists ["coll" "n coll"], :doc "When lazy sequences are produced via functions that have side\n effects, any effects other than those needed to produce the first\n element in the seq do not occur until the seq is consumed. doall can\n be used to force any effects. Walks through the successive nexts of\n the seq, retains the head and returns it, thus causing the entire\n seq to reside in memory at one time.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/doall"}, :clojure.core.logic/pred {:ns "clojure.core.logic", :name "pred", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1336, :examples ["user> (run* [q] (pred q symbol?))\n()\nuser> (run* [q] (== q 'x) (pred q symbol?))\n(x)\nuser> (run* [q] (== q 1) (pred q symbol?))\n()\nuser> (run* [q] (== q 1) (pred q number?))\n(1)" "Example From PC3\n\nuser> (defn indexed [coll] (map-indexed vector coll))\n#'user/indexed\n\nuser> (indexed \"abcde\")\n([0 \\a] [1 \\b] [2 \\c] [3 \\d] [4 \\e])\n\n(defn index-filter [pred coll]\n (when pred\n (for [[idx elt] (indexed coll) :when (pred elt)] idx)))\n\n(index-filter #{\\a \\b} \"abcdbbb\")\n-> (0 1 4 5 6)\n\n;;; NOTES\n;; 'for' used destructuring above. 'for' is not a loop - \n;; it's 'list comprehension'.\n;; 'pred' is a predicate and a lisp form (i.e., 'keyword') in core.logic\n;; - https://clojuredocs.org/clojure.core.logic/pred\n;; It's from https://clojuredocs.org/clojure.core.logic\n;; and NOT included in core\n;; https://github.com/clojure/core.logic\n;; for forms accept bindings (':let') , filters (with ':when')\n;; and restraints (':when') .\n" "user> (use '[clojure.core.logic :only [run* membero pred]])\n\n;; The position of the pred expression matters:\n\nuser> (run* [q]\n (pred q keyword?)\n (membero q [1 :a :b])\n (membero q [1 :a :c]))\n;; => ()\n\nuser> (run* [q]\n (membero q [1 :a :b])\n (membero q [1 :a :c])\n (pred q keyword?))\n;; => (:a)\n"], :macro true, :notes nil, :arglists ["v f"], :doc "Check a predicate against the value logic var. Non-relational.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/pred"}, :clojure.core/enumeration-seq {:added "1.0", :ns "clojure.core", :name "enumeration-seq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 5731, :examples ["user=> (enumeration-seq (java.util.StringTokenizer. \"exciting example\"))\n(\"exciting\" \"example\")\n" ";; A parallel distinct, using ConcurrentHashMap as a\n;; set of keys to get rid of duplicates. \n;; Keys at the end can be retrieved as an enumeration, \n;; and from that as a sequence, thanks to enumeration-seq\n\n(import '[java.util.concurrent ConcurrentHashMap])\n(require '[clojure.core.reducers :refer [fold]])\n\n(defn parallel-distinct [v]\n (let [m (ConcurrentHashMap.)\n combinef (fn ([] m) ([_ _]))\n reducef (fn [^ConcurrentHashMap m k] (.put m k 1) m)]\n (fold combinef reducef v)\n (enumeration-seq (.keys m))))\n\n(defn many-repeating-numbers [n]\n (into [] (take n (apply concat (repeat (range 10))))))\n\n(parallel-distinct (many-repeating-numbers 1e6))\n;; (0 1 2 3 4 5 6 7 8 9)"], :notes nil, :arglists ["e"], :doc "Returns a seq on a java.util.Enumeration", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/enumeration-seq"}, :clojure.core/eduction {:added "1.7", :ns "clojure.core", :name "eduction", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/transduce :clojure.core/reduce :clojure.core/reductions :clojure.core/sequence], :line 7694, :examples [";; `eduction` calls the stack of transformers on each element, each time.\n;; `->>` calls the transformer named 'left' on a collection, then the transformer\n;; named 'right' on the result, etc.\n\n(def cnt (atom nil))\n\n;; inc with debugging output\n(defn inc-with-print [fn-id coll-idx x]\n (printf \";; fn-id: %s; coll-idx: %s; cnt: %s; x: %s\\n\" fn-id coll-idx @cnt x)\n (swap! cnt inc)\n (inc x))\n\n(reset! cnt 0)\n(eduction\n (map-indexed (fn [coll-idx x] (inc-with-print \" left\" coll-idx x)))\n (map-indexed (fn [coll-idx x] (inc-with-print \"right\" coll-idx x)))\n (range 3))\n\n;; fn-id: left; coll-idx: 0; cnt: 0; x: 0\n;; fn-id: right; coll-idx: 0; cnt: 1; x: 1\n;; fn-id: left; coll-idx: 1; cnt: 2; x: 1\n;; fn-id: right; coll-idx: 1; cnt: 3; x: 2\n;; fn-id: left; coll-idx: 2; cnt: 4; x: 2\n;; fn-id: right; coll-idx: 2; cnt: 5; x: 3\n;;=> (2 3 4)\n\n(reset! cnt 0)\n(->> (range 3)\n (map-indexed (fn [coll-idx x] (inc-with-print \" left\" coll-idx x)))\n (map-indexed (fn [coll-idx x] (inc-with-print \"right\" coll-idx x))))\n\n;; fn-id: left; coll-idx: 0; cnt: 0; x: 0\n;; fn-id: left; coll-idx: 1; cnt: 1; x: 1\n;; fn-id: left; coll-idx: 2; cnt: 2; x: 2\n;; fn-id: right; coll-idx: 0; cnt: 3; x: 1\n;; fn-id: right; coll-idx: 1; cnt: 4; x: 2\n;; fn-id: right; coll-idx: 2; cnt: 5; x: 3\n;;=> (2 3 4)" ";; eduction: just run an xform over a collection\n\n(eduction (map inc) [1 2 3]) ; => (2 3 4)\n(eduction (filter even?) (range 5)) ; => (0 2 4)\n\n;; several transducers can be given, without using 'comp'\n(eduction (filter even?) (map inc)\n (range 5)) ; => (1 3 5)\n\n" ";; This will run out of memory eventually,\n;; because the entire seq is realized, \n;; because the head of the lazy seq is retained.\n(let \n [s (range 100000000)] \n (do (apply print s) (first s)))\n\n;; This iterates through the lazy seq without realizing the seq.\n(let \n [s (eduction identity (range 100000000))] \n (do (apply print s) (first s)))\n\n" ";; Result of eduction is of the `clojure.core.Eduction` type which acts as a\n;; lazy collection that re-executes all the steps again and again. This could be\n;; useful when you don't want to store the collection separately.\n;;\n;; Eductions can be efficiently used with `reduce` and `transduce`.\n\n(defn inc-with-print [x]\n (println \";;\" x)\n (inc x))\n\n(def ed (eduction (map inc-with-print) (map inc-with-print) (range 3)))\n\n(defn identity-with-print [x]\n (println \"identity:\" x)\n x)\n\n(map identity-with-print ed)\n;; 0\n;; 1\n;; 1\n;; 2\n;; 2\n;; 3\n;; identity: 2\n;; identity: 3\n;; identity: 4\n;; => (2 3 4)\n\n(defn sum-with-print [x y]\n (println \"sum:\" x \"+\" y)\n (+ x y))\n\n(reduce sum-with-print ed)\n;; 0\n;; 1\n;; 1\n;; 2\n;; sum: 2 + 3\n;; 2\n;; 3\n;; sum: 5 + 4\n;; => 9\n\n;; The above line does not work in Clojure 1.10.1\n;; Execution error (ClassCastException) at user/eval193 (REPL:1).\n;; clojure.core.Eduction cannot be cast to clojure.lang.IReduce\n\n\n(transduce (map identity-with-print) + ed)\n;; 0\n;; 1\n;; identity: 2\n;; 1\n;; 2\n;; identity: 3\n;; 2\n;; 3\n;; identity: 4\n;; => 9\n"], :notes ["`eduction` is particularly useful as an adapter for collection-processing functions that don’t have a transducers arity. For example, you might want to transform a collection before passing it to `frequencies`. `eduction` makes that possible and efficient:\n\n
\n\nSo `eduction` turns out to be quite powerful in that it brings the benefits of transducers to all collection-processing functions, even those that predate transducers: `first`, `last`, `group-by`, `run!`, `str/join`, …\n" "Interesting background about `sequence` versus `eduction`: https://groups.google.com/d/msg/clojure/9I6MtgOTD0w/NiG5PimBCP8J" "`eduction` does not cache the result while `sequence` does. `eduction` is intended to be used when you are eventually going to `reduce` over the sequence.\n\nhttps://groups.google.com/d/msg/clojure/9I6MtgOTD0w/NiG5PimBCP8J"], :arglists ["xform* coll"], :doc "Returns a reducible/iterable application of the transducers\n to the items in coll. Transducers are applied in order as if\n combined with comp. Note that these applications will be\n performed every time reduce/iterator is called.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/eduction"}, :clojure.string/ends-with? {:added "1.8", :ns "clojure.string", :name "ends-with?", :file "clojure/string.clj", :type "function", :column 1, :see-alsos [:clojure.string/starts-with? :clojure.string/includes?], :line 366, :examples ["(use 'clojure.string)\n\n(ends-with? \"Minsun\" \"sun\")\n;;=> true\n(ends-with? \"Minsun\" \"suns\")\n;;=> false\n(ends-with? \"Minsun\" \"un\")\n;;=> true"], :notes nil, :arglists ["s substr"], :doc "True if s ends with substr.", :library-url "https://github.com/clojure/clojure", :href "/clojure.string/ends-with_q"}, :clojure.core.async/pipeline-blocking {:ns "clojure.core.async", :name "pipeline-blocking", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos [:clojure.core.async/pipeline-async :clojure.core.async/pipeline], :line 553, :examples ["(require '[clojure.core.async :as a :refer [chan to-chan pipeline-blocking (inspect-tree '(a (1 2) b (3 4) c (5 6)))\n\n;; you can also visualize complex nested maps\nuser=> (inspect-tree {:a {:aa [1 2 3]\n :ab 3}\n :b 1\n :c {:ca {:caa [{:foo 1}\n {:foo 2}]}}})\n"], :notes nil, :arglists ["data"], :doc "creates a graphical (Swing) inspector on the supplied hierarchical data", :library-url "https://github.com/clojure/clojure", :href "/clojure.inspector/inspect-tree"}, :clojure.core/agent-error {:added "1.2", :ns "clojure.core", :name "agent-error", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/agent :clojure.core/restart-agent :clojure.core/set-error-handler!], :line 2169, :examples ["(def tdate (agent (java.util.Date.)))\n\n@tdate\n=> #\n\n(send tdate inc) ;;this has no meaning, rendering a (silent) error\n\n(agent-error tdate)\n=> #"], :notes nil, :arglists ["a"], :doc "Returns the exception thrown during an asynchronous action of the\n agent if the agent is failed. Returns nil if the agent is not\n failed.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/agent-error"}, :clojure.test/deftest {:added "1.1", :ns "clojure.test", :name "deftest", :file "clojure/test.clj", :type "macro", :column 1, :see-alsos [:clojure.test/run-all-tests :clojure.test/run-tests :clojure.test/is :clojure.test/are :clojure.test/testing :clojure.test/test-var], :line 622, :examples [";successful test example\n(ns testing)\n(use 'clojure.test)\n\n\n(deftest addition\n (is (= 4 (+ 2 2)))\n (is (= 7 (+ 3 4))))\n=> #'testing/addition\n\n(deftest subtraction\n (is (= 1 (- 4 3)))\n (is (= 3 (- 7 4))))\n=> #'testing/subtraction\n\n;composing tests\n(deftest arithmetic\n (addition)\n (subtraction))\n=> #'testing/arithmetic\n\n(run-tests 'testing)\n\n=> Testing testing\n\nRan 6 tests containing 10 assertions.\n0 failures, 0 errors.\n{:type :summary, :test 6, :pass 10, :fail 0, :error 0}" ";failure test example\n\n;there is nesting, so when a leaf test fails so does its parents, in this example 2 tests fail, though there was only one real error.\n\n(ns testing)\n(use 'clojure.test)\n\n\n(deftest addition\n (is (= 4 (+ 2 2)))\n (is (= 7 (+ 3 4))))\n=> #'testing/addition\n\n(deftest subtraction\n (is (= 1 (- 4 3)))\n (is (= 6 (- 7 4)))) ;error\n=> #'testing/subtraction\n\n;composing tests\n(deftest arithmetic\n (addition)\n (subtraction))\n=> #'testing/arithmetic\n\n(run-tests 'testing)\n\n=> Testing testing\n\nFAIL in (arithmetic subtraction) (NO_SOURCE_FILE:669)\nexpected: (= 6 (- 7 4))\n actual: (not (= 6 3))\n\nFAIL in (subtraction) (NO_SOURCE_FILE:669)\nexpected: (= 6 (- 7 4))\n actual: (not (= 6 3))\n\nRan 6 tests containing 10 assertions.\n2 failures, 0 errors.\n{:type :summary, :test 6, :pass 8, :fail 2, :error 0}"], :macro true, :notes nil, :arglists ["name & body"], :doc "Defines a test function with no arguments. Test functions may call\n other tests, so tests may be composed. If you compose tests, you\n should also define a function named test-ns-hook; run-tests will\n call test-ns-hook instead of testing all vars.\n\n Note: Actually, the test body goes in the :test metadata on the var,\n and the real function (the value of the var) calls test-var on\n itself.\n\n When *load-tests* is false, deftest is ignored.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/deftest"}, :clojure.core/*fn-loader* {:ns "clojure.core", :name "*fn-loader*", :type "var", :see-alsos nil, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*fn-loader*"}, :clojure.walk/macroexpand-all {:added "1.1", :ns "clojure.walk", :name "macroexpand-all", :file "clojure/walk.clj", :type "function", :column 1, :see-alsos [:clojure.core/macroexpand-1 :clojure.core/macroexpand], :line 126, :examples ["user=> (use 'clojure.walk)\nuser=> (macroexpand-all '(-> c (+ 3) (* 2)))\n(* (+ c 3) 2)" "user=> (use 'clojure.walk)\n\n; tryclj.com and lazybot on #clojure get the following wrong\nuser=> (let [-> inc] (-> 5)) \n6\n\n; Below macroexpansion is supposed to result in equivalent code to the above\nuser=> (macroexpand-all '(let [-> inc] (-> 5)))\n(let* [-> inc] 5)\nuser=> (let* [-> inc] 5)\n5\n\n; However, as is clear above, it does not" ";; differences between macroexpand-1, macroexpand and macroexpand-all \n\n(require '[clojure.pprint :as pp]\n '[clojure.walk :as walk])\n\n(alter-var-root #'pp/*print-suppress-namespaces* (constantly true))\n\n\n(defmacro plus [n1 n2]\n `(+ ~n1 ~n2))\n\n(pp/pprint (macroexpand-1 '(plus 3 4))) ;=> (+ 3 4)\n(pp/pprint (macroexpand '(plus 3 4))) ;=> (+ 3 4)\n\n\n(defmacro pl [p1 p2]\n `(plus ~p1 ~p2))\n\n(pp/pprint (macroexpand-1 '(pl 3 4))) ;=> (plus 3 4)\n(pp/pprint (macroexpand '(pl 3 4))) ;=> (+ 3 4)\n\n\n(defmacro minus [m1 m2]\n `(- ~m1 ~m2))\n\n(defmacro calc [c1 c2]\n `(pl ~c1 (minus ~c1 ~c2)))\n\n(pp/pprint (macroexpand-1 '(calc 20 30)))\n;=> (pl 20 (minus 20 30))\n\n(pp/pprint (macroexpand '(calc 20 30)))\n;=> (+ 20 (minus 20 30))\n\n(pp/pprint (walk/macroexpand-all '(calc 20 30)))\n;=> (+ 20 (- 20 30))" "; macroexpand-all can give different results to what is generated in a real\n; evaluation. Here is a code sample that should normally evaluates to `dummy`, \n; but `macroexpand-all` generates code that evaluates to `nil`.\n\n(defmacro d []\n (let [probably-dummy# (-> &env keys first)]\n `(quote ~probably-dummy#)))\n\n(letfn [(dummy [] true)]\n (d))\n; => dummy\n\n(clojure.walk/macroexpand-all\n '(letfn [(dummy [] true)]\n (d)))\n; => (letfn* [dummy (fn* dummy ([] true))] (quote nil))\n\n(eval \n (clojure.walk/macroexpand-all\n '(letfn [(dummy [] true)]\n (d))))\n; => nil"], :notes ["DO NOT USE THIS FUNCTION, it doesn't handle special forms at all, and, as such, does not in fact expand into the ultimate macroexpansion of the form.\r\n\r\nFor example,\r\n
\r\nShowing an utter unawareness of proper handling of special forms\r\n\r\nDO NOT USE THIS FUNCTION" "@Sgeo - `let` is just a macro for `let*`:\r\n\r\n (clojure.repl/source let) =>\r\n\r\n (defmacro let\r\n \"binding => binding-form init-expr\r\n\r\n Evaluates the exprs in a lexical context in which the symbols in\r\n the binding-forms are bound to their respective init-exprs or parts\r\n therein.\"\r\n {:added \"1.0\", :special-form true, :forms '[(let [bindings*] exprs*)]}\r\n [bindings & body]\r\n (assert-args let\r\n (vector? bindings) \"a vector for its binding\"\r\n (even? (count bindings)) \"an even number of forms in binding vector\")\r\n `(let* ~(destructure bindings) ~@body))" "(quote (let [a 1] a)) is '(let [a 1] a) which evaluates to a list containing the symbol let, a vector [a 1], and a symbol a. In this context, the (let [a 1] a) is not code, but mere data, and as such, should not be macroexpanded at all, anymore than a string like \"(-> a b c)\" should be macroexpanded into \"(c (b a))\" (and yes, I know that's not the exact macroexpansion)."], :arglists ["form"], :doc "Recursively performs all possible macroexpansions in form.", :library-url "https://github.com/clojure/clojure", :href "/clojure.walk/macroexpand-all"}, :clojure.main/repl-caught {:ns "clojure.main", :name "repl-caught", :file "clojure/main.clj", :type "function", :column 1, :see-alsos nil, :line 348, :examples nil, :notes nil, :arglists ["e"], :doc "Default :caught hook for repl", :library-url "https://github.com/clojure/clojure", :href "/clojure.main/repl-caught"}, :clojure.core.logic/rem-attr {:ns "clojure.core.logic", :name "rem-attr", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 440, :examples nil, :notes nil, :arglists ["s x attr"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/rem-attr"}, :clojure.core.logic.fd/ext-dom-fd {:ns "clojure.core.logic.fd", :name "ext-dom-fd", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 597, :examples nil, :notes nil, :arglists ["a x dom domp"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/ext-dom-fd"}, :clojure.java.io/make-parents {:added "1.2", :ns "clojure.java.io", :name "make-parents", :file "clojure/java/io.clj", :type "function", :column 1, :see-alsos [:clojure.java.io/file], :line 438, :examples ["(let [file-name \"path/to/whatever.txt\"]\n (make-parents file-name)\n (spit file-name \"whatever\"))"], :notes nil, :arglists ["f & more"], :doc "Given the same arg(s) as for file, creates all parent directories of\n the file they represent.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/make-parents"}, :clojure.java.shell/with-sh-env {:added "1.2", :ns "clojure.java.shell", :name "with-sh-env", :file "clojure/java/shell.clj", :type "macro", :column 1, :see-alsos [:clojure.java.shell/sh], :line 28, :examples ["(require '[clojure.java.shell :as shell :refer [sh]])\n\n(shell/with-sh-env {:debug \"true\"}\n (sh \"env\"))\n\n;; {:exit 0, :out \"debug=true\\n\", :err \"\"}\n"], :macro true, :notes nil, :arglists ["env & forms"], :doc "Sets the environment for use with sh, see sh for details.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.shell/with-sh-env"}, :clojure.core.logic.pldb/rel-indexes {:ns "clojure.core.logic.pldb", :name "rel-indexes", :file "clojure/core/logic/pldb.clj", :type "function", :column 1, :see-alsos nil, :line 28, :examples nil, :notes nil, :arglists ["rel"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/rel-indexes"}, :clojure.core.async/Mix {:ns "clojure.core.async", :name "Mix", :file "clojure/core/async.clj", :type "var", :column 1, :see-alsos nil, :line 729, :examples nil, :notes nil, :arglists [], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/Mix"}, :clojure.core.async/unsub-all {:ns "clojure.core.async", :name "unsub-all", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 911, :examples nil, :notes nil, :arglists ["p" "p topic"], :doc "Unsubscribes all channels from a pub, or a topic of a pub", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/unsub-all"}, :clojure.main/stack-element-str {:added "1.3", :ns "clojure.main", :name "stack-element-str", :file "clojure/main.clj", :type "function", :column 1, :see-alsos nil, :line 62, :examples nil, :notes nil, :arglists ["el"], :doc "Returns a (possibly unmunged) string representation of a StackTraceElement", :library-url "https://github.com/clojure/clojure", :href "/clojure.main/stack-element-str"}, :clojure.core.logic.fd/interval-> {:ns "clojure.core.logic.fd", :name "interval->", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 48, :examples nil, :notes nil, :arglists ["i j"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/interval->"}, :clojure.core/*compile-path* {:added "1.0", :ns "clojure.core", :name "*compile-path*", :type "var", :see-alsos nil, :examples [";; Assuming \"mypath\" exists on disk, the following AOT-compiles any form\n;; inside \"eval\" into the folder specified by \"*compile-path*\".\n\n(binding [*compile-files* true \n *compile-path* \"mypath\"]\n (eval '(+ 1 1)))\n;; 2"], :notes nil, :arglists [], :doc "Specifies the directory where 'compile' will write out .class\n files. This directory must be in the classpath for 'compile' to\n work.\n\n Defaults to \"classes\"", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*compile-path*"}, :clojure.core.logic/defna {:ns "clojure.core.logic", :name "defna", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos [:clojure.core.logic/defnc :clojure.core.logic/defne :clojure.core.logic/defnu], :line 1728, :examples nil, :macro true, :notes nil, :arglists ["& rest"], :doc "Define a soft cut goal. See conda.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/defna"}, :clojure.core/mix-collection-hash {:added "1.6", :ns "clojure.core", :name "mix-collection-hash", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 5175, :examples nil, :notes nil, :arglists ["hash-basis count"], :doc "Mix final collection hash for ordered or unordered collections.\n hash-basis is the combined collection hash, count is the number\n of elements included in the basis. Note this is the hash code\n consistent with =, different from .hashCode.\n See http://clojure.org/data_structures#hash for full algorithms.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/mix-collection-hash"}, :clojure.core/with-open {:added "1.0", :ns "clojure.core", :name "with-open", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/slurp :clojure.java.io/input-stream], :line 3831, :examples [";; Opens the file 'myfile.txt' and prints out the contents. The \n;; 'with-open' ensures that the reader is closed at the end of the \n;; form. \n;; \n;; Please note that reading a file a character at a time is not \n;; very efficient.\n\nuser=> (with-open [r (clojure.java.io/input-stream \"myfile.txt\")] \n (loop [c (.read r)] \n (if (not= c -1)\n (do \n (print (char c)) \n (recur (.read r))))))\n" "(defn write-csv-file\n \"Writes a csv file using a key and an s-o-s (sequence of sequences)\"\n [out-sos out-file]\n\n (spit out-file \"\" :append false)\n (with-open [out-data (io/writer out-file)]\n (csv/write-csv out-data out-sos)))\n\n" ";; Try to read 3 lines of text from a test file and return them (to the REPL)\n;; as a list:\n(with-open [r (clojure.java.io/reader \"test-0.txt\")]\n (binding [*in* r] (repeatedly 3 read-line)))\n\n;; The above returns a lazy seq without reading any lines while *in* is bound\n;; to the file, resulting in the original *in* (usually stdin) being read.\n;; To fix, wrap the body within the *in* binding in (doall ...):\n(with-open [r (clojure.java.io/reader \"test-0.txt\")]\n (binding [*in* r] (doall (repeatedly 3 read-line))))\n\n;; That ensures the sequence will be fully realized with the binding of *in*\n;; still in effect, thus reading all 3 lines from the test file." ";Process multiple files with a transducer as if it's one file\n;Not lazy, but processes a line at a time\n\n(defn process-file\n [t file]\n (with-open [rdr (io/reader file)]\n (into []\n t\n (line-seq rdr))))\n\n(defn process-files\n [t files]\n (into []\n (comp (mapcat (fn [file] (process-file t file))))\n files))\n\n(apply + (process-files (comp (map count))\n [\"test-0.txt\" \"test-1.txt\" \"test-2.txt\"]))"], :macro true, :notes nil, :arglists ["bindings & body"], :doc "bindings => [name init ...]\n\n Evaluates body in a try expression with names bound to the values\n of the inits, and a finally clause that calls (.close name) on each\n name in reverse order.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/with-open"}, :clojure.spec.alpha/registry {:ns "clojure.spec.alpha", :name "registry", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 351, :examples nil, :notes nil, :arglists [""], :doc "returns the registry map, prefer 'get-spec' to lookup a spec by name", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/registry"}, :clojure.core/type {:added "1.0", :ns "clojure.core", :name "type", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/class :clojure.core/supers :clojure.core/instance?], :line 3466, :examples [";; Checking numbers\nuser=> (type 10)\njava.lang.Long\n\nuser=> (type 10.0)\njava.lang.Double\n\nuser=> (type nil)\nnil\n\n;; Checking collections\nuser=> (type [10 20])\nclojure.lang.PersistentVector\n\nuser=> (type '(10 20))\nclojure.lang.PersistentList\n\n\n;; Checking other, but somewhat intuitive, forms\nuser=> (type \"A string\")\njava.lang.String\n\nuser=> (type :a)\nclojure.lang.Keyword\n\nuser=> (type Thread)\njava.lang.Class\n\n\n;; Checking a symbol\nuser=> (type 'whatever)\nclojure.lang.Symbol\n\n;; A surprise attack yields\nuser=> (type clojure.lang.Symbol)\n;; not such a surprising response\njava.lang.Class\n\n\n;; Checking a function\nuser=> (defn foo [] (\"any string\"))\n#'user/foo\nuser=> (type foo)\nuser$foo\n\n\n;; Checking a macro\nuser=> (type clojure.core/fn)\njava.lang.Exception: Can't take value of a macro: #'clojure.core/fn (NO_SOURCE_FILE:94)\n\n" ";This example demonstrates how to add type information to regular clojure maps\n(defn purchase-order [id date amount]\n ^{:type ::PurchaseOrder} ;metadata\n {:id id :date date :amount amount})\n\n(def my-order (purchase-order 10 (java.util.Date.) 100.0))\n\nmy-order\n=> {:id 10, :date #, :amount 100.0}\n\n(type my-order)\n=> PurchaseOrder"], :notes nil, :arglists ["x"], :doc "Returns the :type metadata of x, or its Class if none", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/type"}, :clojure.core.logic/cgoal {:ns "clojure.core.logic", :name "cgoal", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2187, :examples nil, :notes nil, :arglists ["c"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/cgoal"}, :clojure.core.logic/u# {:ns "clojure.core.logic", :name "u#", :file "clojure/core/logic.clj", :type "var", :column 1, :see-alsos nil, :line 1150, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/u#"}, :clojure.core/vector {:added "1.0", :ns "clojure.core", :name "vector", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/vec :clojure.core/vector? :clojure.core/vector-of :clojure.core/pop :clojure.core/into], :line 353, :examples [";; create an empty vector the long way\nuser=> (vector)\n[]\n\n;; create an empty vector the short way\nuser=> []\n[]\n\n;; you can even create vectors with nil values\nuser=> (vector nil)\n[nil]\n\n;; create a vector the long way\nuser=> (vector 1 2 3)\n[1 2 3]\n\n;; create a vector the short way\nuser=> [1 2 3]\n[1 2 3]\n\n;; checking for the 2 results above\nuser=> (class (vector 1 2 3))\nclojure.lang.PersistentVector\n\nuser=> (class [1 2 3])\nclojure.lang.PersistentVector\n\nuser=> (= (vector 1 2 3) [1 2 3])\ntrue\n\n" ";; Destructuring with a vector, inside a \"let\" form, a simple case (a symbol\n;; for each element):\n\n;; destructuring with an inline vector\nuser=> (let [[first-element second-element third-element fourth-element] \n [10 20 30 40]] \n (str \"first=\" first-element \" second=\" second-element \n \" third=\" third-element \" fourth=\" fourth-element))\n\"first=10 second=20 third=30 fourth=40\"\n;; notice how 4 symbols were created pointing to the scalars 10, 20, 30 and 40\n\n\n;; destructuring with a symbol to a vector\nuser=> (def my-vector [1 2 3 4])\n#'user/my-vector\n\nuser=> (let [[first-element second-element third-element fourth-element] my-vector] \n (str \"first=\" first-element \" second=\" second-element \n \" third=\" third-element \" fourth=\" fourth-element))\n\"first=1 second=2 third=3 fourth=4\"" ";; Destructuring with a vector, inside a \"let\" form, more complex cases:\n\nuser=> (let [[first-element second-element & the-rest] my-vector] \n (str \"first=\" first-element \" second=\" second-element \" \n the-rest=\" the-rest))\n\"first=1 second=2 the-rest=(3 4)\"\n;; notice how \"the-rest\" is a sequence\n\nuser=> (let [[first-element second-element third-element fourth-element \n :as everything] \n my-vector] \n (str \"first=\" first-element \" second=\" second-element \" \n third=\" third-element \" fourth=\" fourth-element \" \n everything=\" everything))\n\"first=1 second=2 third=3 fourth=4 everything=[1 2 3 4]\"\n;; notice how \"everything\" is the whole vector" ";; Create pairs from a seq\n;; (1 2 3 4) -> ([1 2] [2 3] [3 4])\n\n\n(def inp (list 1 2 3 4))\n;; (1 2 3 4)\n(map vector inp (drop 1 inp))\n;; ([1 2] [2 3] [3 4])" ";; Vectors in Clojure are heterogeneous\nuser=> (def my-vector [1 \"a\" :b])\n\nuser=> my-vector\n[1 \"a\" :b]\n" "user=> (vector {:a 1 :b 2 :c 3})\n;; [{:a 1, :b 2, :c 3}]\n\nuser=> (vec {:a 1 :b 2 :c 3})\n;; [[:a 1] [:b 2] [:c 3]]"], :notes nil, :arglists ["" "a" "a b" "a b c" "a b c d" "a b c d e" "a b c d e f" "a b c d e f & args"], :doc "Creates a new vector containing the args.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/vector"}, :clojure.core/spit {:added "1.2", :ns "clojure.core", :name "spit", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/slurp :clojure.java.io/writer :clojure.core/load-file :clojure.java.io/make-parents], :line 6954, :examples ["user=> (spit \"flubber.txt\" \"test\")\nnil\nuser=> (slurp \"flubber.txt\")\n\"test\"" "user=> (spit \"event.log\" \"test 1\\n\" :append true)\nnil\n\nuser=> (spit \"event.log\" \"test 2\\n\" :append true)\nnil\n\nuser=> (println (slurp \"event.log\"))\ntest 1\ntest 2\n\nnil\n" "(defn append-to-file\n \"Uses spit to append to a file specified with its name as a string, or\n anything else that writer can take as an argument. s is the string to\n append.\" \n [file-name s]\n (spit file-name s :append true))" ";;Create a record and save a log message to a log file\n;;Constructor with side effects\n\n;;define a Person record\n(defrecord Person [fname lname])\n\n;;define a function to save a log message into the log.txt using spit and :append\n(defn log-entry [msg] (spit \"log.txt\" (apply str msg \"\\n\") :append true))\n\n;;build the constructor which: 1) log the message; 2)create a Person\n(defn make-person [fname lname]\n (log-entry (apply str \"[log] New Person created : \" lname \",\" fname))\n (->Person fname lname))\n\n;;create a person\n(def person (make-person \"John\" \"Smith\"))\n\n;;print the content of the log.txt to the console\n(println (slurp \"log.txt\"))" "; ClojureCLR doesn't use :append, use this instead\n(spit \"hi.txt\" \"Test 1\\n\" :file-mode System.IO.FileMode/Append)\n"], :notes ["The only valid options for `spit` are `:append` and `:encoding`." "Valid options include:\n\n :append true to open stream in append mode\n :encoding string name of encoding to use, e.g. \\\"UTF-8\\\"."], :arglists ["f content & options"], :doc "Opposite of slurp. Opens f with writer, writes content, then\n closes f. Options passed to clojure.java.io/writer.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/spit"}, :clojure.core/bit-and {:added "1.0", :ns "clojure.core", :name "bit-and", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/bit-or], :line 1293, :examples [";; bits can be entered using radix notation\n;; but they are long integers so by default they\n;; display in decimal.\n(bit-and 2r1100 2r1001)\n;;=> 8\n;; 8 = 2r1000\n\n;; here we see the same bits entered in decimal\n(bit-and 12 9)\n;;=> 8" ";; bits can be entered in hexidecimal\n(bit-and 0x08 0xFF)\n;;=> 8\n\n;; bits can be show with Integer/toHexString\n(Integer/toHexString (bit-and 0x0108 0xFFFF))\n;;=> \"108\"" ";; bits can also be shown with Integer/toBinaryString\n\n(Integer/toBinaryString 235)\n;;=> \"11101011\"\n\n(Integer/toBinaryString 199)\n;;=> \"11000111\"\n\n(bit-and 235 199)\n;;=> 195\n\n(Integer/toBinaryString 195)\n;;=> \"11000011\"\n\n;; 11101011 = 235\n;;& 11000111 = 199\n;;==========\n;; 11000011 = 195" ";; here is the truth table for AND \n(Integer/toBinaryString (bit-and 2r1100 2r1010) )\n;;=> \"1000\"\n;; or 2r1000"], :notes nil, :arglists ["x y" "x y & more"], :doc "Bitwise and", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-and"}, :clojure.core/await {:added "1.0", :ns "clojure.core", :name "await", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/await-for], :line 3274, :examples [";; construct a simple agent\n(def *agnt* (agent {}))\n\n(send-off *agnt* (fn [state] \n (Thread/sleep 10000)\n (assoc state :done true)))\n;;=> \n\n;; blocks till the agent action is finished\n(await *agnt*) \n;;=> nil" "(import '(java.io BufferedWriter FileWriter))\n\n;; Generally the agent can be sent messages asynchronously, send and forget.\n;; In some cases a rendezvous is needed, e.g. in the case of an output file.\n\n(def write-out \n (agent {:handle (clojure.java.io/writer \"results.txt\" )\n :last-msg [\"init\"]}\n :validator (fn [state] \n (and (contains? state :handle) (contains? state :last-msg))) \n :error-handler (fn [result] \n (println \"invalid result\") )))\n\n(defn write-a-line [state msg nap] \n (.write (:handle state) (str msg \" line \" \"\\n\")) \n (let [new-state (update-in state [:last-msg] into [msg])]\n (println \"message : \" msg \" : \" new-state)\n (Thread/sleep nap)\n new-state))\n\n\n\n;; these all have the same return value\n(send-off write-out write-a-line \"first\" 2000)\n(send-off write-out write-a-line \"second\" 1000)\n(send-off write-out write-a-line \"third\" 5000)\n(send-off write-out write-a-line \"fourth\" 1000)\n@write-out\n;;=> {:handle #, :last-msg [\"init\"]}\n\n(time (await write-out))\n;; 9000.307 msecs\n\n;; here we can see that the await causes the thread to block\n;; until the agent's queue is empty.\n@write-out\n;;=> {:handle #, \n;; :last-msg [\"init\" \"first\" \"second\" \"third\" \"fourth\"]}\n\n;; But wait the \"result.txt\" file is empty!\n;; We need to close the file handle.\n;; And now that we know the agent's queue is empty we\n;; are free to close it.\n;; This could do this in the current thread with the dereferenced\n;; agents :handle '(.close (:handle @write-out))' \n;; but it is probably better to be formal and let the agent do it.\n(defn close-the-agent [state] \n (.close (:handle state)) \n state)\n\n(send-off write-out close-the-agent)\n\n;; And the contents of \"result.txt\" are: (less the leading '; ')\n; first line\n; second line\n; third line\n; fourth line"], :notes [" ;;It is not actually allowed to await on an action dispatched from an agent to an agent\n\n (def m (agent 0))\n (def n (agent 0))\n\n (defn step \n [agent1 agent2]\n (try (await (send agent2 inc))\n (catch Exception e (println e)))\n agent1)\n\n ;;Evaluating this throws an error saying \"Can't await in agent action\"\n (send m #(step % n))\n "], :arglists ["& agents"], :doc "Blocks the current thread (indefinitely!) until all actions\n dispatched thus far, from this thread or agent, to the agent(s) have\n occurred. Will block on failed agents. Will never return if\n a failed agent is restarted with :clear-actions true or shutdown-agents was called.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/await"}, :clojure.zip/insert-child {:added "1.0", :ns "clojure.zip", :name "insert-child", :file "clojure/zip.clj", :type "function", :column 1, :see-alsos [:clojure.zip/zipper :clojure.zip/append-child], :line 216, :examples ["(use 'clojure.zip) ;;warnings OK\n\n(def zp (zipper vector? seq (fn [_ c] c) [[1 2 3] [4 [5 6] 7] [8 9]]) )\n\n(root (insert-child (-> zp down right) 42))\n=>([1 2 3] (42 4 [5 6] 7) [8 9])\n\n\n(def zp2 (zipper vector? seq (fn [_ c] c) [74 75])\n\n(root (insert-right (-> zp down right) zp2))\n=>([1 2 3] [4 [5 6] 7] [[74 75] nil] [8 9])\n\n(root (insert-left (-> zp down right) zp2))\n=>([1 2 3] [[74 75] nil] [4 [5 6] 7] [8 9])\n\n\n\n"], :notes nil, :arglists ["loc item"], :doc "Inserts the item as the leftmost child of the node at this loc,\n without moving", :library-url "https://github.com/clojure/clojure", :href "/clojure.zip/insert-child"}, :clojure.core.logic.pldb/facts-using-index {:ns "clojure.core.logic.pldb", :name "facts-using-index", :file "clojure/core/logic/pldb.clj", :type "function", :column 1, :see-alsos nil, :line 19, :examples nil, :notes nil, :arglists ["dbs kname index val"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/facts-using-index"}, :clojure.core/loaded-libs {:added "1.0", :ns "clojure.core", :name "loaded-libs", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 6104, :examples [";; Show the list of loaded libs (files named after the \"ns\"\n;; declaration they contain) and created namespaces (\"ns\" only). \n;; \"ns\" side effects into loaded-libs, \"create-ns\" (or \"in-ns\") does not:\n\n(ns a)\n(ns b) \n(every? (loaded-libs) ['a 'b])\n;; true\n\n(create-ns 'x)\n(create-ns 'y)\n(not-every? (loaded-libs) ['x 'y])\n;; true"], :notes ["Trivia: the concept of \"library\" goes all the way back to Clojure contrib and was initially inspired by other packaging systems (it was even named \"Jewels\" at some point, possibly inspired by Ruby Gems). Check the following:\n\n* https://groups.google.com/d/msg/clojure/fjDJfAsxwRo/-5hE4yDMVTQJ\n* https://github.com/clojure/clojure-contrib/blob/da367723d33b20cb89e4aac7dc4221a0138c2f8f/jewel.clj"], :arglists [""], :doc "Returns a sorted set of symbols naming the currently loaded libs", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/loaded-libs"}, :clojure.core.logic/-reify* {:ns "clojure.core.logic", :name "-reify*", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 259, :examples nil, :notes nil, :arglists ["s v"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/-reify*"}, :clojure.core.logic/predc {:ns "clojure.core.logic", :name "predc", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2687, :examples nil, :notes nil, :arglists ["x p" "x p pform"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/predc"}, :clojure.core/deliver {:added "1.1", :ns "clojure.core", :name "deliver", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/promise], :line 7127, :examples ["user=> (def x (promise))\n#'user/x\n;; Trying to deref at this point will make your repl wait forever\n\n\nuser=> (deliver x 100)\n#<core$promise$reify__5534@4369a50b: 100>\n\n;; the promise has been delivered, deref x will return immediately\nuser=> @x\n100\n" ";; Create a promise\nuser> (def p (promise))\n#'user/p ; p is our promise\n\n;; Check if was delivered/realized\nuser> (realized? p)\nfalse ; No yet\n\n;; Delivering the promise\nuser> (deliver p 42)\n#\n\n;; Check again if it was delivered\nuser> (realized? p)\ntrue ; Yes!\n\n;; Deref to see what has been delivered\nuser> @p\n42\n\n;; Note that @ is shorthand for deref\nuser> (deref p)\n42" ";; Illustrates how threads can work together via promises\n;; First, an example to show a future that delivers\n\nuser=> (def p (promise))\n#'user/p\n\n;; future that will deliver the promise from another thread after 10 sec delay\nuser=> (future\n (Thread/sleep 10000)\n (deliver p 123))\n#future[{:status :pending, :val nil} 0x9a51df1]\n\n;; within 10 seconds dereference p, and wait for delivery of the value\nuser=> @p\n123\n\n\n;; Now, an example to show a future that blocks while waiting for a promise\n;; to be delivered -- this is used to achieve callback-style functionality\n\n;; redefine p\nuser=> (def p (promise))\n#'user/p\n\n;; create a new 'callback' thread that will wait for a promise to be delivered\nuser=> (future\n (println \"About to block while waiting for 'p'\")\n (println \"Now I can do some work with the value \" @p))\nAbout to block while waiting for 'p'\n#future[{:status :pending, :val nil} 0x1737df29]\n\n;; deliver the promise, triggering the blocking callback thread\nuser=> (deliver p 123)\nNow I can do some work with the value 123\n#promise[{:status :ready, :val 123} 0x674a4c4a]" ";; `deliver` returns the promise and can be dereffed directly.\n\n(def my-prom (promise)) \nmy-prom ;;=> #promise[{:status :pending, :val nil} 0x2570a72d]\n@(deliver my-prom \"Huzzah!\") ;;=> \"Huzzah!\"\nmy-prom ;;=> #promise[{:status :ready, :val nil} 0x2570a72d]\n@my-prom ;;=> \"Huzzah!\""], :notes ["As of Clojure 1.3 `deliver` does not throw an exception when it is called multiple times on the same promise. See [CLJ-1038](http://dev.clojure.org/jira/browse/CLJ-1038)."], :arglists ["promise val"], :doc "Delivers the supplied value to the promise, releasing any pending\n derefs. A subsequent call to deliver on a promise will have no effect.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/deliver"}, :clojure.xml/emit-element {:ns "clojure.xml", :name "emit-element", :file "clojure/xml.clj", :type "function", :column 1, :see-alsos [:clojure.core/with-out-str :clojure.xml/element], :line 95, :examples ["(use 'clojure.xml)\n\n;;If just a string it's text inside or something. just print it\n(emit-element \"hello\")\nhello\n\n;;we want a map with a tag\n(emit-element {:tag :hello})\n\n\n;;strings works as well (since we're using the \"name\" function)\n(emit-element {:tag \"hello\"})\n\n\n;;:attrs is for all the attributes\n(emit-element {:tag :hello :attrs {:place \"world\"}})\n\n\n;;:content is for all the children in the element\n(emit-element {:tag :parent :attrs {:id \"22\" :name \"fritz\"} :content [\n {:tag :child :attrs {:id \"56\"}} \n {:tag :child :attrs {:id \"57\"}]}))\n\n\n\n\n\n;; also, look out for not supplying :content with another xml-ish map\n;; or at minimum a vector containing the string you want to put as the content:\n(emit-element {:tag :hello :content \"world\"})\n\njava.lang.NullPointerException (NO_SOURCE_FILE:0)\n\n(emit-element {:tag :hello :content [\"world\"])\nworld\n"], :notes ["you can catch the printed code with the macro
with-out-str
if you want to catch it in variables."], :arglists ["e"], :library-url "https://github.com/clojure/clojure", :href "/clojure.xml/emit-element"}, :clojure.core/instance? {:added "1.0", :ns "clojure.core", :name "instance?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/type :clojure.core/supers :clojure.core/doto :clojure.core/class :clojure.core/satisfies? :clojure.core/isa?], :line 139, :examples ["user=> (instance? Long 1)\ntrue\nuser=> (instance? Integer 1)\nfalse\nuser=> (instance? Number 1)\ntrue\nuser=> (instance? String 1)\nfalse\nuser=> (instance? String \"1\")\ntrue\n" "user=> (def al (new java.util.ArrayList))\n#'user/al\nuser=> (instance? java.util.Collection al)\ntrue\nuser=> (instance? java.util.RandomAccess al)\ntrue\nuser=> (instance? java.lang.String al)\nfalse" ";; Some things are more than what they seem to be at first glance\nuser=> (instance? clojure.lang.IFn +)\ntrue\nuser=> (instance? clojure.lang.Keyword :a)\ntrue\nuser=> (instance? clojure.lang.IFn :a)\ntrue\nuser=> (instance? clojure.lang.IFn {:a 1})\ntrue\n" ";; If `c` is specified with a literal class name, this is a Java\n;; class name. If any of the namespace components of the class\n;; include dashes, the dashes have to be replaced with underscores:\n\n(ns foo-bar)\n(defrecord Box [x])\n(def box (Box. 42))\n\n(instance? foo-bar.Box box)\n;=> CompilerException java.lang.ClassNotFoundException: foo-bar.Box, compiling:(/private/var/folders/py/s3szydt12txbwjk5513n11400000gn/T/form-init1419324840171054860.clj:1:1)\n(instance? foo_bar.Box box)\n;=> true\n\n;; This rule doesn't apply to the last component of the class name:\n\n(defrecord My-Box [x]) ; not an idiomatic choice\n(def mybox (My-Box. 42))\n\n(instance? foo_bar.My-Box mybox)\n;=> true\n"], :notes nil, :arglists ["c x"], :doc "Evaluates x and tests if it is an instance of the class\n c. Returns true or false", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/instance_q"}, :clojure.core/reverse {:added "1.0", :ns "clojure.core", :name "reverse", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/rseq], :line 947, :examples ["user=> (reverse '(1 2 3))\n(3 2 1)\n" "(reverse \"clojure\")\n; (\\e \\r \\u \\j \\o \\l \\c)\n\n(apply str (reverse \"clojure\"))\n; \"erujolc\"" ";; Comparison between `reverse` and `rseq` for a vector.\n\n(def nums (vec (range 1000000)))\n(time (reverse nums))\n;; \"Elapsed time: 30.1222 msecs\"\n(time (rseq nums))\n;; \"Elapsed time: 0.0664 msecs\""], :notes ["If you've got a vector rseq is a good option instead of reverse." "For vectors, `rseq` is to `reverse` what `peek` is to `last`. `rseq` reverses in constant time (!) where `reverse` is in linear time, as it appears to pull everything into a new seq, one at a time instead of ... reversing the keys? I don't know the implementation details, but I do know that `rseq` is magnitudes faster than `reverse` for vectors and sorted maps. "], :arglists ["coll"], :doc "Returns a seq of the items in coll in reverse order. Not lazy.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reverse"}, :clojure.core/release-pending-sends {:added "1.0", :ns "clojure.core", :name "release-pending-sends", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 2133, :examples [";; release-pending-sends makes sense when an agent produces\n;; additional actions and there is no need to wait for the update\n;; of the current agent's state.\n\n(require '[clojure.string :refer [split]])\n(def alpha (mapv agent (repeat 26 0))) ; one for each letter of the alphabet\n(def others (agent 0))\n(def words (agent {}))\n\n(def war-and-peace \"http://www.gutenberg.org/files/2600/2600-0.txt\")\n(def book (slurp war-and-peace)) ; a large book\n\n(send-off words\n (fn [state]\n (doseq [letter book\n :let [l (Character/toLowerCase letter)\n idx (- (int l) (int \\a))]] ; get the index of the correct agent\n (send (get alpha idx others) inc)) ; send an increment for each letter\n (release-pending-sends) ; release those sends\n (merge-with + state ; move on to calculate word frequencies\n (frequencies (split book #\"\\s+\")))))\n\n(apply await alpha) ; give it some time\n(map deref alpha) ; see each letter frequency in the book\n;; (202719 34657 61621 118297 313572\n;; 54901 51327 167415 172257 2575 20432\n;; 96530 61648 184185 190083 45533 2331\n;; 148431 162897 226414 64400 27087\n;; 59209 4384 46236 2388)\n"], :notes nil, :arglists [""], :doc "Normally, actions sent directly or indirectly during another action\n are held until the action completes (changes the agent's\n state). This function can be used to dispatch any pending sent\n actions immediately. This has no impact on actions sent during a\n transaction, which are still held until commit. If no action is\n occurring, does nothing. Returns the number of actions dispatched.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/release-pending-sends"}, :clojure.core/*verbose-defrecords* {:ns "clojure.core", :name "*verbose-defrecords*", :file "clojure/core_print.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 39, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*verbose-defrecords*"}, :clojure.core/sequential? {:added "1.0", :ns "clojure.core", :name "sequential?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/seq? :clojure.core/coll? :clojure.core/seqable?], :line 6250, :examples ["user=> (sequential? '(1 2 3))\ntrue\n\nuser=> (sequential? [1 2 3])\ntrue\n\nuser=> (sequential? (range 1 5))\ntrue\n\nuser=> (sequential? '())\ntrue\n\nuser=> (sequential? [])\ntrue\n\nuser=> (sequential? nil)\nfalse\n\nuser=> (sequential? 1)\nfalse\n\nuser=> (sequential? \"abc\")\nfalse\n\nuser=> (sequential? {:a 2 :b 1})\nfalse\n\nuser=> (sequential? #{1 2 3})\nfalse" ";; Be careful while traversing data:\n;; map entries are vectors and thus sequential!\n\nuser=> (sequential? (first {:a 1}))\ntrue\n\nuser=> (sequential? (clojure.lang.MapEntry. :a 1))\ntrue\n\nuser=> (vector? (first {:a 1}))\ntrue\n\nuser=> (vector? (clojure.lang.MapEntry. :a 1))\ntrue\n\nuser=> (clojure.walk/postwalk\n #(cond-> % (sequential? %) set)\n {:a [1 1 2 3]})\n; Unhandled java.lang.ClassCastException\n; class clojure.lang.PersistentHashSet cannot be cast to class\n; java.util.Map$Entry (clojure.lang.PersistentHashSet is in unnamed module of\n; loader 'app'; java.util.Map$Entry is in module java.base of loader\n; 'bootstrap')\n\nuser=> (clojure.walk/postwalk\n #(cond-> %\n (and (sequential? %)\n (not (map-entry? %)))\n set)\n {:a [1 1 2 3]})\n{:a #{1 3 2}}\n"], :notes ["Of the four key collection types, vectors and lists are ordered (aka sequential). Sets and maps are not."], :arglists ["coll"], :doc "Returns true if coll implements Sequential", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/sequential_q"}, :clojure.java.javadoc/*remote-javadocs* {:ns "clojure.java.javadoc", :name "*remote-javadocs*", :file "clojure/java/javadoc.clj", :type "var", :column 1, :see-alsos [:clojure.java.javadoc/add-remote-javadoc], :dynamic true, :line 29, :examples ["(require '[clojure.java.javadoc :as javadoc])\n\n(def clojure-javadoc\n \"https://javadoc.io/doc/org.clojure/clojure/latest/\")\n\n;; Altering the Javadoc remote locations for the current thread.\n;; Use javadoc/add-remote-javadoc to alter permanently.\n\n(binding [javadoc/*remote-javadocs*\n (ref {\"clojure.\" clojure-javadoc})]\n (javadoc/javadoc []))"], :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.java.javadoc/*remote-javadocs*"}, :clojure.string/includes? {:added "1.8", :ns "clojure.string", :name "includes?", :file "clojure/string.clj", :type "function", :column 1, :see-alsos [:clojure.core/re-matches :clojure.string/index-of], :line 372, :examples [";; String-oriented alternative to regular-expression functions in core\n(clojure.string/includes? \"clojure\" \"cl\")\n;;=> true\n\n;; Does *not* work with regular expressions!\n(clojure.string/includes? \"clojure\" #\"cl\")\n;;=> java.util.regex.Pattern cannot be cast to java.lang.CharSequence\n;; (java.lang.ClassCastException)" "\n;; Be careful when you uses with maps \n(includes? (str (:name {})) \"Bob Alice\")\n;;=> false\n\n(includes? (:name {}) \"Bob Alice\")\n;;=> Execution error (NullPointerException) at user/eval63454 (REPL:1).\n;;Cannot invoke \"Object.toString()\" because \"s\" is null"], :notes nil, :arglists ["s substr"], :doc "True if s includes substr.", :library-url "https://github.com/clojure/clojure", :href "/clojure.string/includes_q"}, :clojure.core/recur {:ns "clojure.core", :name "recur", :type "var", :see-alsos [:clojure.core/loop :clojure.core/trampoline], :examples ["(def factorial\n (fn [n]\n (loop [cnt n\n acc 1]\n (if (zero? cnt)\n acc\n (recur (dec cnt) (* acc cnt))\n; in loop cnt will take the value (dec cnt)\n; and acc will take the value (* acc cnt)\n))))" "; A loop that sums the numbers 10 + 9 + 8 + ...\n\n; Set initial values count (cnt) from 10 and down\n(loop [sum 0\n cnt 10]\n ; If count reaches 0 then exit the loop and return sum\n (if (= cnt 0)\n sum\n ; Otherwise add count to sum, decrease count and \n ; use recur to feed the new values back into the loop\n (recur (+ cnt sum) (dec cnt))))" "(loop [i 0] \n (when (< i 5) \n (println i) \n (recur (inc i)); loop i will take this value\n))" "(defn compute-across [func elements value]\n (if (empty? elements)\n value\n (recur func (rest elements) (func value (first elements)))))\n\n(defn total-of [numbers]\n (compute-across + numbers 0))\n\n(defn larger-of [x y]\n (if (> x y) x y))\n\n(defn greatest-of [numbers]\n (compute-across larger-of numbers (first numbers)))" "; Note that recur can be surprising when using variadic functions.\n\n(defn foo [& args]\n (let [[x & more] args]\n (prn x)\n (if more (recur more) nil)))\n\n(defn bar [& args]\n (let [[x & more] args]\n (prn x)\n (if more (bar more) nil)))\n\n; The key thing to note here is that foo and bar are identical, except\n; that foo uses recur and bar uses \"normal\" recursion. And yet...\n\nuser=> (foo :a :b :c)\n:a\n:b\n:c\nnil\n\nuser=> (bar :a :b :c)\n:a\n(:b :c)\nnil\n\n; The difference arises because recur does not gather variadic/rest args\n; into a seq." ";;This will generate the first 1000 Fibonacci numbers \n;;(using incrementing and decrementing): \n\n(loop [res [0 1]]\n (if (>= (count res) 1000)\n res\n (recur (conj res (+' (inc (last res)) (dec (last (butlast res))))))))" ";; The recursion point can be a 'loop' or a 'fn' method.\n\n(loop [n (bigint 5), accumulator 1]\n (if (zero? n)\n accumulator ; we're done\n (recur (dec n) (* accumulator n))))\n;;=> 120N\n\n\n((fn factorial\n ([n] (factorial n 1))\n\n ([n accumulator]\n (if (zero? n)\n accumulator ; we're done\n (recur (dec n) (* accumulator n)))))\n\n (bigint 5))\n;;=> 120N" ";; Trailing position could be multiple\n(loop [x 1]\n (println \"x= \" x)\n (cond\n (> x 10) (println \"ending at \" x )\n (even? x) (recur (* 2 x))\n :else (recur (+ x 1))))"], :notes nil, :arglists [], :doc "Evaluates the exprs in order, then, in parallel, rebinds the bindings of\nthe recursion point to the values of the exprs. See\nhttp://clojure.org/special_forms for more information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/recur"}, :clojure.core/swap-vals! {:added "1.9", :ns "clojure.core", :name "swap-vals!", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/swap! :clojure.core/reset! :clojure.core/compare-and-set! :clojure.core/atom], :line 2357, :examples [";; You can use `swap-vals` to perform an atomic `deref`\n;; and `swap!` without a race condition.\n\n(def queue (atom '(1 2 3)))\n(let [head (ffirst (swap-vals! queue pop))]\n (println head) ;; 1\n (println @queue)) ;; (2 3)"], :notes nil, :arglists ["atom f" "atom f x" "atom f x y" "atom f x y & args"], :doc "Atomically swaps the value of atom to be:\n (apply f current-value-of-atom args). Note that f may be called\n multiple times, and thus should be free of side effects.\n Returns [old new], the value of the atom before and after the swap.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/swap-vals!"}, :clojure.core.async/pub {:ns "clojure.core.async", :name "pub", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos [:clojure.core.async/sub], :line 843, :examples ["user=> (def c (chan 1))\n#'user/c\n\nuser=> (def sub-c (pub c :route))\n#'user/sub-c\n\nuser=> (def cx (chan 1))\n#'user/cx\n\nuser=> (sub sub-c :up-stream cx)\n#\n\nuser=> (def cy (chan 1))\n#'user/cy\n\nuser=> (sub sub-c :down-stream cy)\n#\n\nuser=> (go-loop [_ (\n\nuser=> (go-loop [_ (\n\nuser=> (put! c {:route :up-stream :data 123})\ntrue\nGot something coming up!\n\nuser=> (put! c {:route :down-stream :data 123})\nGot something going down!\ntrue\n" "(def news (chan 1))\n(def shouter (pub news :topics))\n\n(def alice (chan 1))\n(def bob (chan 1))\n(def clyde (chan 1))\n\n(sub shouter :celebrity-gossip alice)\n(sub shouter :space-x bob)\n(sub shouter :space-x clyde)\n\n(go-loop [heard ( nil\n:alice - Alice says Hi!\n:bob - Bob says Hi!\n:alice - Alice says Hi again" "(defn pub-test\n \"Check how one topic subscription can block others.\"\n [bufsize]\n (let [out (chan)\n out-pub (if (zero? bufsize)\n (async/pub out first)\n (async/pub out first (fn [topic] (async/buffer bufsize))))\n blocking-sub (chan)\n blocked-sub (chan)]\n (async/sub out-pub :blocking blocking-sub)\n (async/sub out-pub :blocked blocked-sub)\n ; no sub so doesn't block pub:\n (doseq [n (range 5)] (async/put! out [:ignored n]))\n ; blocking-sub blocks blocked-sub until consumed or buffered:\n (doseq [n (range 5)] (async/put! out [:blocking n]))\n (doseq [n (range 5)] (async/put! out [:blocked n]))\n ; don't consume last three put!s on blocking-sub:\n (dotimes [n 2] (async/take! blocking-sub tap>))\n ; close!ing blocking-sub here unblocks blocked-sub\n ; (async/close! blocking-sub)\n (dotimes [n 5] (async/take! blocked-sub tap>))))\n\n(pub-test 0) ; blocks because 5 pub - 0 buffer - 1 on inner chan - 2 take > 0 left\n[:blocking 0]\n[:blocking 1]\n=> nil\n(pub-test 1) ; blocks because 5 - 1 - 1 - 2 > 0\n[:blocking 0]\n[:blocking 1]\n=> nil\n(pub-test 2) ; doesn't block because 5 - 2 - 1 - 2 = 0\n[:blocking 0]\n[:blocking 1]\n[:blocked 0]\n[:blocked 1]\n[:blocked 2]\n[:blocked 3]\n[:blocked 4]\n=> nil" "(def news (chan 1))\n\n(def shouter (pub news :topics))\n\n(def alice (chan 1))\n(def bob (chan 1))\n(def clyde (chan 1))\n\n(sub shouter :gossip alice)\n(sub shouter :space bob)\n(sub shouter :space clyde)\n\n(go-loop []\n (prn \"Alice heard: \" (> java.lang.Integer \n clojure.reflect/type-reflect\n :members \n (filter #(instance? clojure.reflect.Field %)) \n (filter #(:public (:flags %)))\n (filter #(:static (:flags %)))\n (map #(vector (:name %) (:type %)))\n (sort)\n (pprint))\n\n;;=> ([BYTES int]\n;; [MAX_VALUE int]\n;; [MIN_VALUE int]\n;; [SIZE int]\n;; [TYPE java.lang.Class])" ";;;; List class hierarchy for a particular class \n\n(defn class-hierarchy [clazz]\n (let [refl (fn [c] (assoc (clojure.reflect/type-reflect c) :name c))]\n (loop [type (refl clazz) hierarchy '()]\n (let [parent (->> type\n :bases\n (map refl)\n (remove #(:interface (:flags %)))\n first)]\n (if parent\n (recur parent (conj hierarchy (:name type)))\n (conj hierarchy java.lang.Object))))))\n\n(pprint (class-hierarchy javax.security.auth.login.CredentialNotFoundException))\n;;=> (java.lang.Object\n;; java.lang.Throwable\n;; java.lang.Exception\n;; java.security.GeneralSecurityException\n;; javax.security.auth.login.LoginException\n;; javax.security.auth.login.CredentialException\n;; javax.security.auth.login.CredentialNotFoundException)\n\n(pprint (class-hierarchy javax.swing.JPasswordField$AccessibleJPasswordField))\n;;=> (java.lang.Object\n;; javax.accessibility.AccessibleContext\n;; java.awt.Component$AccessibleAWTComponent\n;; java.awt.Container$AccessibleAWTContainer\n;; javax.swing.JComponent$AccessibleJComponent\n;; javax.swing.text.JTextComponent$AccessibleJTextComponent\n;; javax.swing.JTextField$AccessibleJTextField\n;; javax.swing.JPasswordField$AccessibleJPasswordField)\n" "(require '(clojure [reflect :as cr] [pprint :as pp]))\n\n;; Let us see what is available in the DynamicClassLoader\n(->> clojure.lang.DynamicClassLoader \n cr/type-reflect\n :members\n (sort-by :name)\n (pp/print-table [:name :flags :parameter-types]))\n;| :name | :flags | :parameter-types |\n;|---------------------------------+-----------------------------+--------------------------------------------|\n;| EMPTY_URLS | #{:static :final} | |\n;| addURL | #{:public} | [java.net.URL] |\n;| classCache | #{:static} | |\n;| clojure.lang.DynamicClassLoader | #{:public} | [java.lang.ClassLoader] |\n;| clojure.lang.DynamicClassLoader | #{:public} | [] |\n;| constantVals | #{} | |\n;| defineClass | #{:public} | [java.lang.String byte<> java.lang.Object] |\n;| findClass | #{:protected} | [java.lang.String] |\n;| findInMemoryClass | #{:static} | [java.lang.String] |\n;| getConstants | #{:public} | [int] |\n;| loadClass | #{:synchronized :protected} | [java.lang.String boolean] |\n;| registerConstants | #{:public} | [int java.lang.Object<>] |\n;| rq | #{:static :final} | |"], :notes nil, :arglists ["typeref & options"], :doc "Alpha - subject to change.\n Reflect on a typeref, returning a map with :bases, :flags, and\n :members. In the discussion below, names are always Clojure symbols.\n\n :bases a set of names of the type's bases\n :flags a set of keywords naming the boolean attributes\n of the type.\n :members a set of the type's members. Each member is a map\n and can be a constructor, method, or field.\n\n Keys common to all members:\n :name name of the type \n :declaring-class name of the declarer\n :flags keyword naming boolean attributes of the member\n\n Keys specific to constructors:\n :parameter-types vector of parameter type names\n :exception-types vector of exception type names\n\n Key specific to methods:\n :parameter-types vector of parameter type names\n :exception-types vector of exception type names\n :return-type return type name\n\n Keys specific to fields:\n :type type name\n\n Options:\n\n :ancestors in addition to the keys described above, also\n include an :ancestors key with the entire set of\n ancestors, and add all ancestor members to\n :members.\n :reflector implementation to use. Defaults to JavaReflector,\n AsmReflector is also an option.", :library-url "https://github.com/clojure/clojure", :href "/clojure.reflect/type-reflect"}, :clojure.core/ensure-reduced {:added "1.7", :ns "clojure.core", :name "ensure-reduced", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/reduced :clojure.core/reduced? :clojure.core/unreduced :clojure.core/reduce], :line 2849, :examples ["(ensure-reduced :foo)\n;;=> object[clojure.lang.Reduced 0x7dc19a70 {:status :ready, :val :foo}]\n\n(ensure-reduced (reduced :foo))\n;;=> object[clojure.lang.Reduced 0x45385f75 {:status :ready, :val :foo}]" ";; If our reducing function's short-circuit coincides with our transducer's\n;; short-circuit, `reduced` could lead to the reduction returning a Reduced:\n\n(defn conj-till-neg\n ([coll] coll)\n ([coll x] (cond-> (conj coll x) (neg? x) reduced)))\n\n(defn take-till-odd [rf]\n (fn new-rf\n ([result] (rf result))\n ([result x] (cond-> (rf result x) (odd? x) reduced))))\n\n(transduce take-till-odd conj-till-neg [] [6 4 2 -1 -2])\n;; => #\n\n;; So we can change `reduced` to `ensure-reduced` to avoid doubling up:\n(defn take-till-odd [rf]\n (fn new-rf\n ([result] (rf result))\n ([result x] (cond-> (rf result x) (odd? x) ensure-reduced))))\n\n(transduce take-till-odd conj-till-neg [] [6 4 2 -1 -2])\n;; => [6 4 2 -1]\n"], :notes nil, :arglists ["x"], :doc "If x is already reduced?, returns it, else returns (reduced x)", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ensure-reduced"}, :clojure.core.async/close! {:ns "clojure.core.async", :name "close!", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos [:clojure.core.async/chan], :line 177, :examples ["(let [c (chan 2) ]\n (>!! c 1)\n (>!! c 2)\n (close! c)\n (println (!! c 1))" ";; Below example demonstrates go processes can take values (which were already put)\n;; from the unbuffered channel even after closing it.\n\n (let [c (chan)]\n (go (>! c 1))\n (go (>! c 2))\n ;; channel is closed even before \"2\" value is taken out. \n (go ( channel-state-map. A\n channel-state-map is a map of attrs -> boolean, where attr is one or\n more of :mute, :pause or :solo. Any states supplied are merged with\n the current state.\n\n Note that channels can be added to a mix via toggle, which can be\n used to add channels in a particular (e.g. paused) state.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/toggle"}, :clojure.core.logic/seqc {:ns "clojure.core.logic", :name "seqc", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2887, :examples nil, :notes nil, :arglists ["v"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/seqc"}, :clojure.core/*print-level* {:added "1.0", :ns "clojure.core", :name "*print-level*", :file "clojure/core_print.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 27, :examples ["user=> *print-level*\nnil\nuser=> [1 [2 [3]]]\n[1 [2 [3]]]\n\nuser=> (set! *print-level* 2)\n2\nuser=> [1 [2 [3]]]\n[1 [2 #]]"], :notes nil, :arglists [], :doc "*print-level* controls how many levels deep the printer will\n print nested objects. If it is bound to logical false, there is no\n limit. Otherwise, it must be bound to an integer indicating the maximum\n level to print. Each argument to print is at level 0; if an argument is a\n collection, its items are at level 1; and so on. If an object is a\n collection and is at a level greater than or equal to the value bound to\n *print-level*, the printer prints '#' to represent it. The root binding\n is nil indicating no limit.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*print-level*"}, :clojure.core.async/take {:ns "clojure.core.async", :name "take", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 980, :examples nil, :notes nil, :arglists ["n ch" "n ch buf-or-n"], :doc "Returns a channel that will return, at most, n items from ch. After n items\n have been returned, or ch has been closed, the return channel will close.\n\n The output channel is unbuffered by default, unless buf-or-n is given.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/take"}, :clojure.core/map-indexed {:added "1.2", :ns "clojure.core", :name "map-indexed", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/map :clojure.core/keep-indexed], :line 7283, :examples ["user=> (map-indexed (fn [idx itm] [idx itm]) \"foobar\")\n([0 \\f] [1 \\o] [2 \\o] [3 \\b] [4 \\a] [5 \\r])\n" ";; or simply\nuser=> (map-indexed vector \"foobar\")\n([0 \\f] [1 \\o] [2 \\o] [3 \\b] [4 \\a] [5 \\r])" "(map-indexed hash-map \"foobar\")\n;;=> ({0 \\f} {1 \\o} {2 \\o} {3 \\b} {4 \\a} {5 \\r})" ";; a simple example\n(map-indexed #(when (< % 2) (str % %2)) [:a :b :c])\n;;=> (\"0:a\" \"1:b\" nil)\n\n(keep-indexed #(when (< % 2) (str % %2)) [:a :b :c])\n;;=> (\"0:a\" \"1:b\")" ";; Join the index and elements with list\n(map-indexed list [:a :b :c])\n;;=> ((0 :a) (1 :b) (2 :c))" "(= (map-indexed #(when (= 2 %2) [%1 \"Hi\"]) [1 1 2 2]) \n '(nil nil [2 \"Hi\"] [3 \"Hi\"])) ;;=>true"], :notes nil, :arglists ["f" "f coll"], :doc "Returns a lazy sequence consisting of the result of applying f to 0\n and the first item of coll, followed by applying f to 1 and the second\n item in coll, etc, until coll is exhausted. Thus function f should\n accept 2 arguments, index and item. Returns a stateful transducer when\n no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/map-indexed"}, :clojure.core.logic/->SubstValue {:ns "clojure.core.logic", :name "->SubstValue", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 197, :examples nil, :notes nil, :arglists ["v doms eset"], :doc "Positional factory function for class clojure.core.logic.SubstValue.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/->SubstValue"}, :clojure.core/shuffle {:added "1.2", :ns "clojure.core", :name "shuffle", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/rand-nth :clojure.core/random-sample], :line 7274, :examples [";; Make five permutations of the [1 2 3] vector.\n;; Always returns a vector.\n(repeatedly 5 (partial shuffle [1 2 3]))\n;;=> ([2 3 1] [2 1 3] [2 3 1] [3 2 1] [3 1 2])\n\n(shuffle (list 1 2 3))\n;;=> [2 1 3]"], :notes nil, :arglists ["coll"], :doc "Return a random permutation of coll", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/shuffle"}, :clojure.zip/make-node {:added "1.0", :ns "clojure.zip", :name "make-node", :file "clojure/zip.clj", :type "function", :column 1, :see-alsos nil, :line 83, :examples [";; Useful to perform operations on locations without knowing the\n;; internals of the zipper. For example, here's a generic remove-child to remove\n;; the first children from a node\n(require '[clojure.zip :as zip])\n\n(def vzip\n (zip/vector-zip\n [[1 2]\n [3 4 [5 10 [11 12]]]\n [13 14]]))\n\n(defn remove-child [loc]\n (zip/replace loc \n (zip/make-node loc (zip/node loc) (rest (zip/children loc)))))\n\n(-> vzip zip/down zip/rightmost remove-child zip/root)\n;; [[1 2] [3 4 [5 10 [11 12]]] [14]]"], :notes nil, :arglists ["loc node children"], :doc "Returns a new branch node, given an existing node and new\n children. The loc is only used to supply the constructor.", :library-url "https://github.com/clojure/clojure", :href "/clojure.zip/make-node"}, :clojure.core/val {:added "1.0", :ns "clojure.core", :name "val", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/vals :clojure.core/key :clojure.core/keys], :line 1574, :examples [";; emulate 'vals'\n(map val {:a 1 :b 2})\n;;=> (1 2)\n" "(val (first {:one :two}))\n;;=> :two" ";syntactic sugar for (val)\n(:doc (meta #'meta))" ";; extracts the key of a map entry\n(val (clojure.lang.MapEntry. :a :b))\n;;=> :b"], :notes ["This is my first attempt at using this site to gain an understanding of a closure function. Two of the examples above seem incorrect. \r\n\r\nExample 3(?) seems to have nothing to do with val \r\n\r\n(notice the lack of example identifiers)\r\n"], :arglists ["e"], :doc "Returns the value in the map entry.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/val"}, :clojure.core/list* {:added "1.0", :ns "clojure.core", :name "list*", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 648, :examples [";; `list*` function:\nuser=> (list* 1 [2 3])\n(1 2 3)\nuser=> (list* 1 2 [3 4])\n(1 2 3 4)\n\n;; compared to regular `list` function:\nuser=> (list 1 [2 3])\n(1 [2 3])\nuser=> (list 1 2 [3 4])\n(1 2 [3 4])\n\n;; Corner cases:\nuser=> (list* nil [1 2])\n(nil 1 2)\nuser=> (list* 1 nil)\n(1)\nuser=> (list* () [1 2])\n(() 1 2)\nuser=> (list* 1 ())\n(1)\n" ";;Prepend a map to a list\nuser=> (list* {:name \"Anne\"} [{:city \"NJ\"}]) \n({:name \"Anne\"} {:city \"NJ\"})" ";; Useful if you want to get all the arguments of a function into a list (actually a seq, but that is not important)\n(defn args-to-list [a b c & args]\n (list* a b c args))\n\nuser=> (args-to-list 1 2 3 4 5 6)\n(1 2 3 4 5 6)\n\n;; same as list, but it expects the last element to be a sequence which is then unpacked \n\n;; Example usage in the wild\n(defn my-max\n ([a] a)\n ([a b] (if (> a b) a b))\n ([a b & args] (reduce my-max (list* a b args))))\n\n" ";; `list*` function:\nuser=> (list* 1 '(2 3))\n(1 2 3)\n\nuser=> (list* 1 2 '(3 4))\n(1 2 3 4)" ";; `list*` function:\n(list* \"Superman\" '(\"Batman\" \"Ironman\"))\n=> (\"Superman\" \"Batman\" \"Ironman\")\n\n(list* '(\"Batman\" \"Ironman\") '(\"Superman\" \"Hulk\"))\n=> ((\"Batman\" \"Ironman\") \"Superman\" \"Hulk\")\n\n(list* '(\"Batman\" \"Ironman\") \"Superman\")\n=> ((\"Batman\" \"Ironman\") \\S \\u \\p \\e \\r \\m \\a \\n)"], :notes ["The doc string mentions returning a new list, but it should say a new sequence. Surprisingly, `list*` typically does not return an actual list. Instead, it usually returns a Cons, which works as a seq, but is not strictly a list. \n\n```\n(list? (list* 1 '(2 3)))\n;=> false\n\n(type (list* 1 '(2 3)))\n;=> clojure.lang.Cons\n\n(first (list* 1 '(2 3)))\n;=> 1\n\n(peek (list* 1 '(2 3)))\nClassCastException clojure.lang.Cons cannot be cast to clojure.lang.IPersistentStack\n\n(list? (list* '(2 3)))\n;=> true\n\n(list? (into () (list* 1 '(2 3))))\n;=> true\n```\n\nI think `seq*` would have been a better name for this function."], :arglists ["args" "a args" "a b args" "a b c args" "a b c d & more"], :doc "Creates a new seq containing the items prepended to the rest, the\n last of which will be treated as a sequence.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/list*"}, :clojure.core/unchecked-subtract {:added "1.0", :ns "clojure.core", :name "unchecked-subtract", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/unchecked-add :clojure.core/unchecked-dec :clojure.core/unchecked-inc :clojure.core/unchecked-negate :clojure.core/unchecked-divide :clojure.core/unchecked-subtract :clojure.core/unchecked-multiply :clojure.core/unchecked-remainder :clojure.core/- :clojure.core/-'], :line 1212, :examples [";; can't interchange INTs with LONGs, only F(int, int) or F(long, long)\n;; F is a function, not an\n;; overflow very easily as shown below.\n\n(unchecked-subtract Long/MIN_VALUE 5555555554)\nuser=> 9223372031299220254\n\n;; it promotes to long\n(unchecked-subtract Long/MIN_VALUE (int 1))\nuser=> 9223372036854775807\n\n(unchecked-subtract Integer/MIN_VALUE Long/MIN_VALUE)\nuser=> 9223372034707292160\n\n(unchecked-subtract Long/MIN_VALUE Long/MIN_VALUE)\nuser=> 0\n\n(unchecked-subtract Integer/MIN_VALUE Integer/MIN_VALUE)\nuser=> 0\n\n(unchecked-subtract Integer/MIN_VALUE 0)\nuser=> -2147483648\n\n;; Again, promote to long\n(unchecked-subtract Integer/MIN_VALUE 1)\nuser=> -2147483649\n\n;; To prevent long promotion, see unchecked-subtract-int "], :notes nil, :arglists ["x y"], :doc "Returns the difference of x and y, both long.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-subtract"}, :clojure.core.logic/empty-s {:ns "clojure.core.logic", :name "empty-s", :file "clojure/core/logic.clj", :type "var", :column 1, :see-alsos nil, :line 537, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/empty-s"}, :clojure.core/dotimes {:added "1.0", :ns "clojure.core", :name "dotimes", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/repeat :clojure.core/for :clojure.core/doseq], :line 3313, :examples ["user=> (dotimes [n 5] (println \"n is\" n))\nn is 0\nn is 1\nn is 2\nn is 3\nn is 4\nnil" "user=> (dotimes [n 10] \n (println (map #(* % (inc n)) (range 1 11))))\n\n(1 2 3 4 5 6 7 8 9 10)\n(2 4 6 8 10 12 14 16 18 20)\n(3 6 9 12 15 18 21 24 27 30)\n(4 8 12 16 20 24 28 32 36 40)\n(5 10 15 20 25 30 35 40 45 50)\n(6 12 18 24 30 36 42 48 54 60)\n(7 14 21 28 35 42 49 56 63 70)\n(8 16 24 32 40 48 56 64 72 80)\n(9 18 27 36 45 54 63 72 81 90)\n(10 20 30 40 50 60 70 80 90 100)\nnil" "user=> (dotimes [x 8] (print x) \n (dotimes [y x] (print (get (vec \"Clojure\") y))) \n (newline))\n0\n1C\n2Cl\n3Clo\n4Cloj\n5Cloju\n6Clojur\n7Clojure\nnil\n\n;ranges with dotimes\n\n(dotimes [y 5] \n (println (map #(inc %) (range (inc y)))))\n\n(1)\n(1 2)\n(1 2 3)\n(1 2 3 4)\n(1 2 3 4 5)\nnil\n\n;factorials using ranges by dotimes\n\n(dotimes [y 5] \n (println \"factorial\" (inc y) \" = \" (apply * (map #(inc %) (range (inc y))))))\n\nfactorial 1 = 1\nfactorial 2 = 2\nfactorial 3 = 6\nfactorial 4 = 24\nfactorial 5 = 120\nnil\n"], :macro true, :notes ["`dotimes` always returns `nil` no matter what is returned by the body the last time through the loop."], :arglists ["bindings & body"], :doc "bindings => name n\n\n Repeatedly executes body (presumably for side-effects) with name\n bound to integers from 0 through n-1.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/dotimes"}, :clojure.core.logic.fd/->fd {:ns "clojure.core.logic.fd", :name "->fd", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 1147, :examples nil, :notes nil, :arglists ["vars exprs"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/->fd"}, :clojure.core/update-in {:added "1.0", :ns "clojure.core", :name "update-in", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/assoc-in :clojure.core/get-in :clojure.core/fnil :clojure.core/update :clojure.core/associative?], :line 6172, :examples ["(def users [{:name \"James\" :age 26} {:name \"John\" :age 43}])\n;;=> #'user/users\n\n;; similar to assoc-in but does not simply replace the item.\n;; the specified function is performed on the matching item.\n;; here the age of the second (index 1) user is incremented.\n(update-in users [1 :age] inc)\n;;=> [{:name \"James\", :age 26} {:name \"John\", :age 44}]\n" "(def p {:name \"James\" :age 26})\n;;=> #'user/p\n\n(update-in p [:age] inc)\n;;=> {:name \"James\", :age 27}\n\n;; remember, the value of p hasn't changed!\n(update-in p [:age] + 10)\n;;=> {:name \"James\", :age 36}\n\n;; Here we see that the keyed object is \n;; the first argument in the function call.\n;; i.e. :age (- 26 10) => 16\n(update-in p [:age] - 10)\n;;=> {:name \"James\", :age 16}" "(defn char-cnt [s]\n \"Counts occurence of each character in s\"\n (reduce\n (fn [m k]\n (update-in m [k] (fnil inc 0)))\n {}\n s))\n;; Note use of fnil above \n;; - returns 0 if nil is passed to inc (avoids null pointer exception)\n\n(char-cnt \"foo-bar\")\n;;=> {\\r 1, \\a 1, \\b 1, \\- 1, \\o 2, \\f 1}\n" ";; f has args\n;; The keyed value is placed as the first argument\n;; :a (/ 3 4 5) => 3/20 \n(update-in {:a 3} [:a] / 4 5)\n;;=> {:a 3/20}" ";; be careful with that empty path sequence, it's seldom what you want\n(update-in {} [] (constantly {:k :v}))\n;;=> {nil {:k :v}}\n\n;; In general, you find that for a non-empty path\n;; (get-in (update-in m path (constantly v)) path) \n;; is equal to v.\n;; Surprisingly this does not hold true in case of an empty path." ";;You can use update-in in a nested map too, in order to update more than\n;;one value:\n\n(def m {:1 {:value 0, :active false}, :2 {:value 0, :active false}})\n\n(update-in m [:1] assoc :value 1 :active true)\n;;=>{:1 {:value 1, :active true}, :2 {:value 0, :active false}}" ";; We may dig into multiple levels with `update-in`:\n(def player1 {:name \"Player 1\" :attribs {:str 10 :int 11 :wis 9}})\n\n(update-in player1 [:attribs :str] inc)\n;; {:name \"Player 1\", :attribs {:str 11, :int 11, :wis 9}}\n\n(update-in player1 [:attribs :str] * 2)\n;; {:name \"Player 1\", :attribs {:str 20, :int 11, :wis 9}}\n\n;; We can see one level via `update`...\n\n(update player1 :attribs #(update % :str inc))\n;; {:name \"Player 1\", :attribs {:str 11, :int 11, :wis 9}}" "user=> (update-in {:a {:b 3}} [:a :b] inc)\n\n;;=> {:a {:b 4}}" ";; can also use in []\n\nuser=> (update-in [1 2 [1 2 3]] [2 0] inc)\n;;=> [1 2 [2 2 3]]" ";; can mix associative types as well\n\nuser=> (update-in [1 {:a 2 :b 3 :c 4}] [1 :c] (fnil inc 5))\n;; => [1 {:a 2, :b 3, :c 5}]\nuser=> (update-in [1 {:a 2 :b 3 :c 4}] [1 :d] (fnil inc 5))\n;; => [1 {:a 2, :b 3, :c 4, :d 6}]\n\n;; but of course vector indices must be appropriate types\n\nuser=> (update-in [1 {:a 2 :b 3 :c 4}] [:b :c] (fnil inc 5))\nIllegalArgumentException Key must be integer clojure.lang.APersistentVector.assoc (APersistentVector.java:345)" "(def ds [{:id 1.0 :name \"name1\"}\n {:id 2.0 :name \"name2\"}\n {:id 3.0 :name \"name3\"}])\n\n(map (fn [x] (update-in x [:name] #(if (= \"name2\" %) % \"not 2\"))) ds)\n\n;; | :id | :name |\n;; |-----+-------|\n;; | 1.0 | not 2 |\n;; | 2.0 | name2 |\n;; | 3.0 | not 2 |\n"], :notes nil, :arglists ["m ks f & args"], :doc "'Updates' a value in a nested associative structure, where ks is a\n sequence of keys and f is a function that will take the old value\n and any supplied args and return the new value, and returns a new\n nested structure. If any levels do not exist, hash-maps will be\n created.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/update-in"}, :clojure.core/range {:added "1.0", :ns "clojure.core", :name "range", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/take :clojure.core/iterate], :line 3019, :examples [";; default value of 'end' is infinity\nuser=> (range)\n(0 1 2 3 4 5 6 7 8 9 10 ... 12770 12771 12772 12773 ... n)\n\n;; Since clojure 1.2:\nuser=> (take 10 (range))\n(0 1 2 3 4 5 6 7 8 9)\n\nuser=> (range 10)\n(0 1 2 3 4 5 6 7 8 9)\n\nuser=> (range -5 5)\n(-5 -4 -3 -2 -1 0 1 2 3 4)\n\nuser=> (range -100 100 10)\n(-100 -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90)\n\nuser=> (range 0 4 2)\n(0 2)\n\nuser=> (range 0 5 2)\n(0 2 4)\n\nuser=> (range 0 6 2)\n(0 2 4)\n\nuser=> (range 0 7 2)\n(0 2 4 6)\n\nuser=> (range 100 0 -10)\n(100 90 80 70 60 50 40 30 20 10)\n\nuser=> (range 10 -10 -1)\n(10 9 8 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9)\n \n\n" ";; Since clojure 1.2:\n\nuser=> (take 10 (range))\n(0 1 2 3 4 5 6 7 8 9)\n" ";; finite range over java Integers\nuser=> (take 5 (range 42 (java.lang.Integer/MAX_VALUE)))\n(42 43 44 45 46)\n\n;; infinite range starting at a certain point\nuser=> (take 5 (drop 42 (range)))\n(42 43 44 45 46)\n" ";; Using a double as the value of step can produce an unexpected extra value.\n;; In the second example below, there's an extra final value that's almost = 0.8.\n\n(range 0 0.8 1/10)\n(0 1/10 1/5 3/10 2/5 1/2 3/5 7/10)\n\nuser=> (range 0 0.8 0.1)\n(0 0.1 0.2 0.30000000000000004 0.4 0.5 0.6 0.7 0.7999999999999999)\n\n;; It's difficult to guess when this behavior will occur, unless you know\n;; whether the double representation of step plus what \"should\" be the\n;; last number is in fact less than end. From the second example above, you \n;; can see that the extra value won't be included if you replace 0.8 by a \n;; number in 0.1, ..., 0.7 (e.g. since 0.7 is not less than 0.7) but you \n;; wouldn't necessarily know that you will get the extra value for end = 0.9,\n;; 1.0, 1.1, but not for end = 1.2.\n" "user=> (range 0 0)\n()\n\nuser=> (range 0 1)\n(0)"], :notes nil, :arglists ["" "end" "start end" "start end step"], :doc "Returns a lazy seq of nums from start (inclusive) to end\n (exclusive), by step, where start defaults to 0, step to 1, and end to\n infinity. When step is equal to 0, returns an infinite sequence of\n start. When start is equal to end, returns empty list.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/range"}, :clojure.core/future-done? {:added "1.1", :ns "clojure.core", :name "future-done?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/future :clojure.core/future-cancel :clojure.core/future? :clojure.core/future-cancelled?], :line 6536, :examples ["user=> (def f (future (Thread/sleep 5000) (inc 0)))\n\nuser=> (future-done? f) \nfalse\n\nuser=> (Thread/sleep 5000)\nnil\n\nuser=> (future-done? f)\ntrue\n\n" ";; beware of cancellation !!!\n\nuser=> (def f (future (Thread/sleep 5000) (inc 0)))\n#'user/f\n\nuser=> (future-cancel f) \ntrue\n\nuser=> (future-cancelled? f) \ntrue\n\nuser=> (future-done? f) \ntrue\n\nuser=> @f \njava.util.concurrent.CancellationException (NO_SOURCE_FILE:0)" ";; removed unhelpful example"], :notes ["Future \"done\" returns true even for abnormal termination like being cancelled or throwing an exception.\r\n\r\nhttp://download.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html#isDone()"], :arglists ["f"], :doc "Returns true if future f is done", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/future-done_q"}, :clojure.core/doseq {:added "1.0", :ns "clojure.core", :name "doseq", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/doall :clojure.core/dorun :clojure.core/for :clojure.core/dotimes :clojure.core/run!], :line 3216, :examples [";; Multiplies every x by every y.\n\n(doseq [x [-1 0 1]\n y [1 2 3]] \n (prn (* x y)))\n-1 ; x -1 y 1\n-2 ; x -1 y 2\n-3 ; x -1 y 3\n0 ; x 0 y 1\n0 ; x 0 y 2\n0 ; x 0 y 3\n1 ; x 1 y 1\n2 ; x 1 y 2\n3 ; x 1 y 3\nnil\n\n;; Notice that y is iterated over for every x. x could be seen as the 'outer' loop" "user=> (doseq [[x y] (map list [1 2 3] [1 2 3])] \n (prn (* x y)))\n1\n4\n9\nnil\n\n;; where\nuser=> (map list [1 2 3] [1 2 3])\n((1 1) (2 2) (3 3))" "user=> (doseq [[[a b] [c d]] (map list (sorted-map :1 1 :2 2) (sorted-map :3 3 :4 4))]\n (prn (* b d)))\n3\n8\nnil\n\n;; where\nuser=> (map list (sorted-map :1 1 :2 2) (sorted-map :3 3 :4 4))\n(([:1 1] [:3 3]) ([:2 2] [:4 4]))" "user=> (doseq [[k v] (map identity {:1 1 :2 2 :3 3})] \n (prn k v))\n:1 1\n:2 2\n:3 3\nnil\n\n;; where\nuser=> (map identity {:1 1 :2 2 :3 3})\n([:1 1] [:2 2] [:3 3])\n\n;; or simply\nuser=> (doseq [[k v] {:1 1 :2 2 :3 3}]\n (prn k v))\n:1 1\n:3 3\n:2 2\nnil" ";; Multiple sequences results in a Cartesian cross of their values.\nuser=> (doseq [a [1 2]\n b [3 4]]\n (println a b))\n1 3\n1 4\n2 3\n2 4\nnil" ";; Keywords :let, :when, and :while are supported, the same as \"for\"\nuser=> (doseq [x (range 6)\n :when (odd? x)\n :let [y (* x x)] ]\n (println [x y]) )\n[1 1]\n[3 9]\n[5 25]\nnil\n\nuser=> (doseq [x (range 99)\n :let [y (* x x)] \n :while (< y 30)\n ]\n (println [x y]) )\n[0 0]\n[1 1]\n[2 4]\n[3 9]\n[4 16]\n[5 25]\nnil\nuser=> \n" ";; ClojureCLR example\n;; Prints names of running processes\n\nuser=> (doseq [x (System.Diagnostics.Process/GetProcesses)] \n (println (.get_ProcessName x)))\navgnt\nSearchIndexer\nsvchost\nchrome\naudiodg\nsvchost\nmbamscheduler\nspoolsv\nnvxdsync\navwebg7\nGoogleCrashHandler64\nsvchost\nCCleaner64\nViakaraokeSrv\n..." ";; simplest use\n\nuser=> (doseq [x [1 2 3 4 5]] (prn x))\n1\n2\n3\n4\n5\nnil" ";;looping over a collection \n\n;;define CarMaker record\n(defrecord CarMaker [cm-name])\n\n;;define CarModel record\n(defrecord CarModel [model-name cmaker doors color])\n\n;;create a car-makes\n(def car-maker {\"cm1\" (->CarMaker \"Renault\")})\n\n;;createa models and add an CarMaker identifier to which model\n(def models {\n \"m1\" (->CarModel \"Megane\" \"cm1\" 3 \"Black\")\n \"m2\" (->CarModel \"Zoe\" \"cm1\" 5 \"White\")\n })\n;;println all model-name in the collection\n(doseq [[k v] models] (println (:model-name (get models k))))" ";;doseq on vector\n(def my-vector [1 2 3 \"a\" \"b\" \"c\" :a :b :c])\n(doseq [v my-vector] (println v))\n\n;;doseq on hash-map\n(def my-map {:a \"A\" :b \"B\" :c \"C\" :d 1 :e 2 :f 3})\n(doseq [[k v] my-map] (println k \"->\" v))" "user=> (doseq [y (range 10)] \n (dotimes [z y] (print (inc z)))\n (newline))\n\n1\n12\n123\n1234\n12345\n123456\n1234567\n12345678\n123456789\nnil" ";; nothing will print\n(doseq [x []\n y [1 2 3]]\n (prn x y))\n\n;; if any bindings have empty sequences, the body will never execute\n"], :macro true, :notes nil, :arglists ["seq-exprs & body"], :doc "Repeatedly executes body (presumably for side-effects) with\n bindings and filtering as provided by \"for\". Does not retain\n the head of the sequence. Returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/doseq"}, :clojure.core/aset-int {:added "1.0", :ns "clojure.core", :name "aset-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 3946, :examples [";; create an array of 10 ints and set one of the values to 31415\n\nuser=> (def is (int-array 10))\n#'user/is\nuser=> (vec is)\n[0 0 0 0 0 0 0 0 0 0]\nuser=> (aset-int is 3 31415)\n31415\nuser=> (vec is)\n[0 0 0 31415 0 0 0 0 0 0]\nuser=>"], :notes ["See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax."], :arglists ["array idx val" "array idx idx2 & idxv"], :doc "Sets the value at the index/indices. Works on arrays of int. Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aset-int"}, :clojure.test/with-test-out {:added "1.1", :ns "clojure.test", :name "with-test-out", :file "clojure/test.clj", :type "macro", :column 1, :see-alsos nil, :line 273, :examples nil, :macro true, :notes nil, :arglists ["& body"], :doc "Runs body with *out* bound to the value of *test-out*.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/with-test-out"}, :clojure.core/print-dup {:ns "clojure.core", :name "print-dup", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [:clojure.core/print-ctor :clojure.core/print-method], :line 3666, :examples [";; print-dup can be used for basic serialization\n;; the following methods write/read clojure forms to/from a file\n\n(defn to-file\n \"Save a clojure form to a file\"\n [#^java.io.File file form]\n (with-open [w (java.io.FileWriter. file)]\n (print-dup form w)))\n \n(defn from-file\n \"Load a clojure form from file.\"\n [#^java.io.File file]\n (with-open [r (java.io.PushbackReader. (java.io.FileReader. file))]\n (read r)))" ";; print-dup is a multimethod, you can extend it to support new types.\n;; The following statement adds print-dup support to \n;; the java.util.Date class\n(defmethod print-dup java.util.Date [o w]\n (print-ctor o (fn [o w] (print-dup (.getTime o) w)) w)) "], :notes ["This is a multimethod that can be implemented to define the printing of various values when \\*print-dup\\* is bound to true."], :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/print-dup"}, :clojure.core.logic/composeg* {:ns "clojure.core.logic", :name "composeg*", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1060, :examples nil, :macro true, :notes nil, :arglists ["g0" "g0 & gs"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/composeg*"}, :clojure.core/delay {:added "1.0", :ns "clojure.core", :name "delay", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/force :clojure.core/realized? :clojure.core/memoize :clojure.core/future :clojure.core/delay?], :line 746, :examples [";; In this example you can see that the first time the delay is forced\n;; the println is executed however the second dereference shows just the\n;; precomputed value.\n\nuser=> (def my-delay (delay (println \"did some work\") 100))\n#'user/my-delay\n\nuser=> @my-delay\ndid some work\n100\n\nuser=> @my-delay\n100\n" ";; Note that the implementation of deref for delays makes it impossible for the\n;; body of the delay to be executed more than once, even if the derefs occur\n;; from multiple threads near the same time, because it is a synchronized method\n;; in Java." ";; test example" ";; If you are coming from OOP background, think about a OOP pattern - singleton.\n;; delay and singleton can serve the same purpose. "], :macro true, :notes nil, :arglists ["& body"], :doc "Takes a body of expressions and yields a Delay object that will\n invoke the body only the first time it is forced (with force or deref/@), and\n will cache the result and return it on all subsequent force\n calls. See also - realized?", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/delay"}, :clojure.core.logic/assoc-dom {:ns "clojure.core.logic", :name "assoc-dom", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 30, :examples nil, :notes nil, :arglists ["x k v"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/assoc-dom"}, :clojure.core/isa? {:added "1.0", :ns "clojure.core", :name "isa?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/derive :clojure.core/instance? :clojure.core/underive :clojure.core/ancestors :clojure.core/parents :clojure.core/descendants :clojure.core/make-hierarchy], :line 5564, :examples ["user=> (import 'java.util.PriorityQueue)\njava.util.PriorityQueue\n\nuser=> (bases PriorityQueue)\n(java.util.AbstractQueue java.io.Serializable)\n\nuser=> (import 'java.util.AbstractQueue)\njava.util.AbstractQueue\n\nuser=> (isa? PriorityQueue AbstractQueue)\ntrue\n\nuser=> (bases AbstractQueue)\n(java.util.AbstractCollection java.util.Queue)\n\nuser=> (isa? PriorityQueue java.util.AbstractCollection)\ntrue\n\nuser=> (isa? PriorityQueue java.util.Queue)\ntrue\n\nuser=> (isa? java.util.PriorityQueue java.util.TreeMap)\nfalse" "user=> (derive ::Feline ::Animal)\nnil\nuser=> (derive ::Cat ::Feline)\nnil\n\nuser=> (derive ::Lion ::Feline)\nnil\n\nuser=> (isa? ::Lion ::Feline)\ntrue\n\nuser=> (isa? ::Lion ::Animal)\ntrue\n\nuser=> (isa? ::Tuna ::Feline)\nfalse" ";; you can use vectors to test multiple child/parent pairs\n\nuser=> (derive ::child-1 ::parent-1)\nnil\n\nuser=> (derive ::child-2 ::parent-2)\nnil\n\nuser=> (isa? [::child-1 ::child-2] [::parent-1 ::parent-2])\ntrue"], :notes nil, :arglists ["child parent" "h child parent"], :doc "Returns true if (= child parent), or child is directly or indirectly derived from\n parent, either via a Java type inheritance relationship or a\n relationship established via derive. h must be a hierarchy obtained\n from make-hierarchy, if not supplied defaults to the global\n hierarchy", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/isa_q"}, :clojure.core/eval {:added "1.0", :ns "clojure.core", :name "eval", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/read-string], :line 3210, :examples ["user=> (def *foo* \"(println [1 2 3])\")\n#'user/*foo*\n\nuser=> *foo*\n\"(println [1 2 3])\"\n\nuser=> (eval *foo*) ; Notice eval'ing a string does not work.\n\"(println [1 2 3])\"\n\nuser=> (eval (read-string *foo*))\n[1 2 3]\nnil" "user=> (eval '(let [a 10] (+ 3 4 a)))\n17\n" "(def x '(+ 2 3))\n(println x) \n=> (+ 2 3)\n(println (eval x))\n=> 5"], :notes ["In normal code, `eval` is rarely used." "Once you get used to eval you will use it more often. You can make nifty things with it."], :arglists ["form"], :doc "Evaluates the form data structure (not text!) and returns the result.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/eval"}, :clojure.test/report {:added "1.1", :ns "clojure.test", :name "report", :file "clojure/test.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 324, :examples nil, :notes nil, :arglists [], :doc "Generic reporting function, may be overridden to plug in\n different report formats (e.g., TAP, JUnit). Assertions such as\n 'is' call 'report' to indicate results. The argument given to\n 'report' will be a map with a :type key. See the documentation at\n the top of test_is.clj for more information on the types of\n arguments for 'report'.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/report"}, :clojure.core/*source-path* {:ns "clojure.core", :name "*source-path*", :type "var", :see-alsos nil, :examples [";; Contains the name (not the full path, for that see \n;; https://clojuredocs.org/clojure.core/*file*) \n;; of the compilation unit that is currently being compiled.\n;; Given a file named \"examples/example.clj\" is available in the \"examples\" \n;; folder starting at \".\":\n\n(ns examples.example)\n(when *compile-files* \n (println \"Compiling:\" *source-path*))\n\n;; If we start a REPL adding \".\" as part of the classpath,\n;; we can see the following:\n\n(binding [*compile-path* \".\"]\n (compile 'examples.example))\n;; Compiling: example.clj\n;; examples.example\n"], :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*source-path*"}, :clojure.core.logic/fk {:ns "clojure.core.logic", :name "fk", :file "clojure/core/logic.clj", :type "var", :column 1, :see-alsos nil, :line 19, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/fk"}, :clojure.core/munge {:ns "clojure.core", :name "munge", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos [:clojure.repl/demunge :clojure.core/namespace-munge], :line 129, :examples ["user> (defn foo [] (println \"foo\"))\n#'user/foo\n\nuser> foo\n#\n\nuser> (munge foo)\n\"user_DOLLARSIGN_foo_CIRCA_a0dc71\"" "(doseq [c (remove #(Character/isLetterOrDigit ^char %) (map char (range 32 127)))]\n (println c \"->\" (munge c)))\n;; Prints:\n ->\n! -> _BANG_\n\" -> _DOUBLEQUOTE_\n# -> _SHARP_\n$ -> $\n% -> _PERCENT_\n& -> _AMPERSAND_\n' -> _SINGLEQUOTE_\n( -> (\n) -> )\n* -> _STAR_\n+ -> _PLUS_\n, -> ,\n- -> _\n. -> .\n/ -> _SLASH_\n: -> _COLON_\n; -> ;\n< -> _LT_\n= -> _EQ_\n> -> _GT_\n? -> _QMARK_\n@ -> _CIRCA_\n[ -> _LBRACK_\n\\ -> _BSLASH_\n] -> _RBRACK_\n^ -> _CARET_\n_ -> _\n` -> `\n{ -> _LBRACE_\n| -> _BAR_\n} -> _RBRACE_\n~ -> _TILDE_"], :notes nil, :arglists ["s"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/munge"}, :clojure.datafy/nav {:ns "clojure.datafy", :name "nav", :file "clojure/datafy.clj", :type "function", :column 1, :see-alsos nil, :line 30, :examples nil, :notes nil, :arglists ["coll k v"], :doc "Returns (possibly transformed) v in the context of coll and k (a\n key/index or nil). Callers should attempt to provide the key/index\n context k for Indexed/Associative/ILookup colls if possible, but not\n to fabricate one e.g. for sequences (pass nil). nav returns the\n value of clojure.core.protocols/nav.", :library-url "https://github.com/clojure/clojure", :href "/clojure.datafy/nav"}, :clojure.core.logic.fd/-lb {:ns "clojure.core.logic.fd", :name "-lb", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["this"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/-lb"}, :clojure.core.logic.fd/-keep-before {:ns "clojure.core.logic.fd", :name "-keep-before", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["this n"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/-keep-before"}, :clojure.core/simple-symbol? {:added "1.9", :ns "clojure.core", :name "simple-symbol?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/symbol? :clojure.core/qualified-symbol?], :line 1627, :examples ["(simple-symbol? 'symbol)\n;;=> true\n\n(simple-symbol? 'clojure.core/symbol)\n;;=> false\n\n(simple-symbol? \"string\")\n;;=> false\n(simple-symbol? 42)\n;;=> false\n(simple-symbol? nil)\n;;=> false"], :notes nil, :arglists ["x"], :doc "Return true if x is a symbol without a namespace", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/simple-symbol_q"}, :clojure.core.logic.fd/to-vals {:ns "clojure.core.logic.fd", :name "to-vals", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 668, :examples nil, :notes nil, :arglists ["dom"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/to-vals"}, :clojure.core.async/alt!! {:ns "clojure.core.async", :name "alt!!", :file "clojure/core/async.clj", :type "macro", :column 1, :see-alsos [:clojure.core.async/alt! :clojure.core.async/alts!! :clojure.core.async/alts!], :line 340, :examples [";; This example is taken from Timothy Baldridge's `core.async` course on Udemy\n;; https://www.udemy.com/communicating-sequential-processes-with-coreasync/learn/v4/overview\n\n;; Create two channels, c1 and c2\n(let [c1 (chan 1)\n c2 (chan 1)]\n ;; Put a value in each channel\n (>!! c1 42)\n (>!! c2 44)\n (thread\n ;; Take a value from one of the channels.\n ;; - If the value is taken from c1, return the keyword :c1 and channel c1\n ;; - Analogously for c2\n (let [[v c] (alt!! [c1] [:c1 c1]\n [c2] [:c2 c2])]\n ;; Print the returned keyword and whether the value was taken from c1 or c2\n (println \"Value: \" v)\n (println \"Chan 1?: \" (= c1 c))\n (println \"Chan 1?: \" (= c2 c)))))"], :macro true, :notes nil, :arglists ["& clauses"], :doc "Like alt!, except as if by alts!!, will block until completed, and\n not intended for use in (go ...) blocks.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/alt!!"}, :clojure.core.async/!!], :line 106, :examples ["user=> (>!! c \"Blocking - not in go-block\")\ntrue\nuser=> ( (def a (agent 0))\n=> #'user/a\nuser> a\n=> #agent[{:status :ready, :val 0} 0x591e4e8e]\nuser> (add-watch a :key (fn [k r os ns] (print k r os ns)))\n=> #agent[{:status :ready, :val 0} 0x591e4e8e]\nuser> (send a inc)\n=> #agent[{:status :ready, :val 1} 0x591e4e8e]\n:key #agent[{:status :ready, :val 1} 0x591e4e8e] 0 1\nuser> (send a inc)\n:key #agent[{:status :ready, :val 2} 0x591e4e8e] 1 2\n=> #agent[{:status :ready, :val 2} 0x591e4e8e]\n" "(def a (atom {}))\n\n(add-watch a :watcher\n (fn [key atom old-state new-state]\n (prn \"-- Atom Changed --\")\n (prn \"key\" key)\n (prn \"atom\" atom)\n (prn \"old-state\" old-state)\n (prn \"new-state\" new-state)))\n\n(reset! a {:foo \"bar\"})\n\n;; \"-- Atom Changed --\"\n;; \"key\" :watcher\n;; \"atom\" #\n;; \"old-state\" {}\n;; \"new-state\" {:foo \"bar\"}\n;; {:foo \"bar\"}" ";; The name of my account can change, and I want to update another atom accordingly.\n;; I just take the fourth argument that contains the new state and I ignore the other arguments.\n\n(let [account (atom {:name \"pending\" \n :funds 100.50 \n :profit-loss 23.45})\n label-account-name (atom \"no-name-yet\")]\n (add-watch account :listener-one #(reset! label-account-name (:name %4)))\n (println \"Before swap:\" @label-account-name)\n (swap! account assoc :name \"CFD\")\n (println \"After swap:\" @label-account-name))\n\n;; Before swap: no-name-yet\n;; After swap: CFD" ";; ClojureScript: Log the new value of the ref to console whenever it changes\n\n(def a (atom nil))\n\n(add-watch a :logger #(-> %4 clj->js js/console.log))\n\n(reset! a (my-app/initial-state))"], :notes ["One \"gotcha\" is that atoms `add-watch`es do not always guarantee order semantics. So if you have a watch put `[old-val new-val]` on a channel, and your atom operation is something like `(swap! a inc)`, you may see values in your channel like this:\n\n```\n[0 1]\n[2 3]\n[1 2]\n[3 4]\n[6 7]\n[4 5]\n```\n\nThis is because the watches are dispatched in different threads.\n\n[Source](https://groups.google.com/d/msg/clojure/RI1Pq3E3188/YyqyGq36f1oJ)"], :arglists ["reference key fn"], :doc "Adds a watch function to an agent/atom/var/ref reference. The watch\n fn must be a fn of 4 args: a key, the reference, its old-state, its\n new-state. Whenever the reference's state might have been changed,\n any registered watches will have their functions called. The watch fn\n will be called synchronously, on the agent's thread if an agent,\n before any pending sends if agent or ref. Note that an atom's or\n ref's state may have changed again prior to the fn call, so use\n old/new-state rather than derefing the reference. Note also that watch\n fns may be called from multiple threads simultaneously. Var watchers\n are triggered only by root binding changes, not thread-local\n set!s. Keys must be unique per reference, and can be used to remove\n the watch with remove-watch, but are otherwise considered opaque by\n the watch mechanism.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/add-watch"}, :clojure.core/some {:added "1.0", :ns "clojure.core", :name "some", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/every? :clojure.core/not-any? :clojure.core/keep :clojure.core/keep-indexed :clojure.core/some-fn :clojure.core/some-> :clojure.core/contains? :clojure.core/some? :clojure.core/if-some :clojure.core/when-some], :line 2692, :examples [";; 2 is even, so `some` stops there, 3 and 4 are never tested\n(some even? '(1 2 3 4))\n;;=> true\n\n;; they are all odd, so not true, i.e. nil\n(some even? '(1 3 5 7))\n;;=> nil" "(some true? [false false false])\n;;=> nil\n\n(some true? [false true false])\n;;=> true\n\n(some true? [true true true])\n;;=> true\n" "(some #(= 5 %) [1 2 3 4 5])\n;;=> true\n\n(some #(= 5 %) [6 7 8 9 10])\n;;=> nil\n\n(some #(not= 5 %) [1 2 3 4 5])\n;;=> true\n\n(some #(not= 5 %) [6 7 8 9 10])\n;;=> true" ";; the first logical true value is returned, i.e. anything but nil and false\n;; when return nil if its predicate is logical false.\n(some #(when (even? %) %) '(1 2 3 4))\n;;=> 2" ";; a hash acts as a function returning nil when the\n;; key is not present and the key value otherwise.\n(some {2 \"two\" 3 \"three\"} [nil 3 2])\n;;=> \"three\"\n\n;; there is nothing special about the 'nil' in the collection,\n;; it is still being used as a key to find its corresponding value in the hash.\n(some {nil \"nothing\" 2 \"two\" 3 \"three\"} [nil 3 2])\n;;=> \"nothing\"\n\n;; the hash (as function) returns a nil for the key of '3',\n;; therefore 'some' keeps inspecting the collection,\n;; returning the next logical true value.\n(some {2 \"two\" 3 nil} [nil 3 2])\n;;=> \"two\"" ";; `some` can be used in place of `(first (filter ...))` in most cases.\n(first (filter even? [1 2 3 4]))\n;;=> 2\n\n;; `some` returns exactly one item or `nil` if nothing is found.\n(some #(when (even? %) %) [1 2 3 4])\n;;=> 2\n" ";; find whether a word is in a list of words.\n(def word \"foo\")\n(def words [\"bar\" \"baz\" \"foo\" \"\"])\n(some (partial = word) words)\n;;=> true" ";; here we see sets being used as a predicate\n;; the first member of the collection that appears in the set is returned\n\n(some #{2} (range 0 10)) ;;=> 2\n(some #{6 2 4} (range 0 10)) ;;=> 2\n(some #{2 4 6} (range 3 10)) ;;=> 4\n(some #{200} (range 0 10)) ;;=> nil\n\n" ";; be careful, 'nil' can occasionally be returned on success.\n(#{nil} nil)\n;;=> nil \n\n;; almost as troublesome is returning a false\n(#{false} false)\n;;=> false" ";; if you have a case where the predicate arguments are fixed/known, \n;; but the predicate function isn't:\n;; coll can supply the predicate function instead of the predicate arguments\n\n;; define the function 'not equal' (ne)\n(defn ne [n1 n2] (not= n1 n2))\n;;=> #'user/ne\n\n(some #(% 3 7) (list ne))\n;;=>true\n\n(some #(% 3 3) (list ne))\n;;=>nil\n\n\n" ";; extending the previous example: supplying multiple functions.\n(defn ne [n1 n2] (not= n1 n2)) \n;;=> #'user/ne\n\n;; function to check if the sum is less than 'limit'\n(defn sumlt [limit n1 n2] (> limit (+ n1 n2))) \n;;=>'user/sumlt\n\n(some #(% 3 7) (list ne #(sumlt 10 %1 %2))) \n;;=>true\n\n(some #(% 3 3) (list ne #(sumlt 10 %1 %2))) \n;;=>true\n\n(some #(% 7 7) (list ne #(sumlt 10 %1 %2))) \n;;=>nil\n\n;; same, but one of the functions returns a value instead a boolean.\n(some #(% 3 7) (list ne (fn [n1 n2] (+ n1 n2)))) \n;;=>true\n\n(some #(% 7 7) (list ne (fn [n1 n2] (+ n1 n2)))) \n;;=>14\n\n;; the importance of order of the function list.\n(some #(% 7 7) (list ne #(sumlt 10 %1 %2) (fn [n1 n2] (+ n1 n2)))) \n;;=>14\n\n(some #(% 7 7) (list ne (fn [n1 n2] (+ n1 n2)) #(sumlt 10 %1 %2))) \n;;=>14\n\n(some #(% 3 3) (list ne #(sumlt 10 %1 %2) (fn [n1 n2] (+ n1 n2)))) \n;;=>true\n\n(some #(% 3 3) (list ne (fn [n1 n2] (+ n1 n2)) #(sumlt 10 %1 %2))) \n;;=>6\n" ";;if you want to return the element the caused the predicate to return true\n;;use the \"and\" function on the predicate and the argument:\n\n(some #(and (even? %) %) [1 3 5 7 8 2])\n;;=> 8" ";; As an alternative to the above usage of `and`, I prefer to use `if`\n;; in such cases; I think it’s slightly clearer:\n\n(some #(if (even? %) %) [1 3 5 7 8 2])\n;;=> 8" ";; `some` can be an alternative for `apply or`\n(def v [nil false 5 nil 7])\n\n;; (apply or v)\n;; java runtime exception because or is macro\n\n(some identity v)\n;;=> 5\n\n;; Source - lamdaisland episode\n;; https://lambdaisland.com/episodes/clojure-core-some"], :notes ["Be careful about using sets as predicates if you don't know what is in the set.\r\nIn particular,
(#{nil} nil)
is
nil
and
(#{false} false)
is
false
Consider using
contains?
instead."], :arglists ["pred coll"], :doc "Returns the first logical true value of (pred x) for any x in coll,\n else nil. One common idiom is to use a set as pred, for example\n this will return :fred if :fred is in the sequence, otherwise nil:\n (some #{:fred} coll)", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/some"}, :clojure.core/unchecked-divide-int {:added "1.0", :ns "clojure.core", :name "unchecked-divide-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/quot], :line 1233, :examples [";; like http://clojuredocs.org/clojure.core/quot, (unchecked-divide-int m n) is the value of m/n, rounded down to the nearest integer.\n\n(unchecked-divide-int 3 2)\n;; => 1\n\n(unchecked-divide-int 2 4)\n;; => 0\n\n(unchecked-divide-int 4 2)\n;; => 2\n\n(unchecked-divide-int 0 4)\n;; => 0\n\n(unchecked-divide-int 1 0)\n;; => ArithmeticException / by zero clojure.lang.Numbers.unchecked_int_divide (Numbers.java:1698)"], :notes nil, :arglists ["x y"], :doc "Returns the division of x by y, both int.\n Note - uses a primitive operator subject to truncation.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-divide-int"}, :clojure.core.logic.fd/IIntervals {:ns "clojure.core.logic.fd", :name "IIntervals", :file "clojure/core/logic/fd.clj", :type "var", :column 1, :see-alsos nil, :line 20, :examples nil, :notes nil, :arglists [], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/IIntervals"}, :clojure.core/unchecked-dec-int {:added "1.0", :ns "clojure.core", :name "unchecked-dec-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/unchecked-inc-int], :line 1163, :examples ["(unchecked-dec-int 42);; => 41\n(unchecked-dec-int 42.2);; => 41\n(unchecked-dec-int Integer/MIN_VALUE);; => 2147483647"], :notes nil, :arglists ["x"], :doc "Returns a number one less than x, an int.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-dec-int"}, :clojure.core/dorun {:added "1.0", :ns "clojure.core", :name "dorun", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/doall :clojure.core/doseq :clojure.core/run!], :line 3133, :examples ["user=> (dorun 5 (repeatedly #(println \"hi\")))\nhi\nhi\nhi\nhi\nhi\nhi\nnil" "user=> (let [x (atom 0)]\n (dorun (take 10 (repeatedly #(swap! x inc))))\n @x)\n10" "user=> (dorun (map #(println \"hi\" %) [\"mum\" \"dad\" \"sister\"]))\nhi mum\nhi dad\nhi sister\nnil" ";;map a function which makes database calls over a vector of values \nuser=> (map #(db/insert :person {:name %}) [\"Fred\" \"Ethel\" \"Lucy\" \"Ricardo\"])\nJdbcSQLException The object is already closed [90007-170] org.h2.message.DbE\nxception.getJdbcSQLException (DbException.java:329)\n\n;;database connection was closed before we got a chance to do our transactions\n;;lets wrap it in dorun\nuser=> (dorun (map #(db/insert :person {:name %}) [\"Fred\" \"Ethel\" \"Lucy\" \"Ricardo\"]))\nDEBUG :db insert into person values name = 'Fred'\nDEBUG :db insert into person values name = 'Ethel'\nDEBUG :db insert into person values name = 'Lucy'\nDEBUG :db insert into person values name = 'Ricardo'\nnil"], :notes ["`clojure.core/run!` can take the place of `(dorun (map ...))`."], :arglists ["coll" "n coll"], :doc "When lazy sequences are produced via functions that have side\n effects, any effects other than those needed to produce the first\n element in the seq do not occur until the seq is consumed. dorun can\n be used to force any effects. Walks through the successive nexts of\n the seq, does not retain the head and returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/dorun"}, :clojure.core/ns-publics {:added "1.0", :ns "clojure.core", :name "ns-publics", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/ns-map :clojure.core/ns-interns :clojure.core/resolve], :line 4189, :examples [";; create the namespace and switch to it\nuser=> (in-ns 'demo.ns)\n#\n\n;; Make sure all of the good stuff in clojure.core is usable here, too.\ndemo.ns=> (clojure.core/use 'clojure.core)\nnil\n\n;; define some public functions\ndemo.ns=> (defn public-fn1 [x y] (+ x y))\n#'demo.ns/public-fn1\ndemo.ns=> (defn public-fn2 [t] (* t t t))\n#'demo.ns/public-fn2\n\n;; define a private function with defn-\ndemo.ns=> (defn- private-fn [s] (/ s 5))\n#'demo.ns/private-fn\n\n;; Switch back to the user namespace\ndemo.ns=> (in-ns 'user)\n#\n\n;; Get a map of all intern mappings for namespace demo.ns\nuser=> (ns-interns 'demo.ns)\n{public-fn1 #'demo.ns/public-fn1, private-fn #'demo.ns/private-fn, public-fn2 #'demo.ns/public-fn2}\n\n;; Now get a map of only the public mappings. No private-fn here.\nuser=> (ns-publics 'demo.ns)\n{public-fn1 #'demo.ns/public-fn1, public-fn2 #'demo.ns/public-fn2}\n" ";; See also http://clojure.org/namespaces for information on namespaces in Clojure and how to inspect and manipulate them"], :notes nil, :arglists ["ns"], :doc "Returns a map of the public intern mappings for the namespace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ns-publics"}, :clojure.spec.alpha/& {:ns "clojure.spec.alpha", :name "&", :file "clojure/spec/alpha.clj", :type "macro", :column 1, :see-alsos nil, :line 653, :examples ["(require '[clojure.spec.alpha :as s])\n\n(s/conform\n (s/cat :tag keyword? :children (s/& (s/+ integer?) #(-> % count (>= 2))))\n [:a 3])\n;=> :clojure.spec.alpha/invalid\n(s/conform\n (s/cat :tag keyword? :children (s/& (s/+ integer?) #(-> % count (>= 2))))\n [:a 3 4 5])\n;=> {:tag :a, :children [3 4 5]}\n"], :macro true, :notes nil, :arglists ["re & preds"], :doc "takes a regex op re, and predicates. Returns a regex-op that consumes\n input as per re but subjects the resulting value to the\n conjunction of the predicates, and any conforming they might perform.", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/&"}, :clojure.core.logic/run-constraints {:ns "clojure.core.logic", :name "run-constraints", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2105, :examples nil, :notes nil, :arglists ["xcs"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/run-constraints"}, :clojure.core/ex-data {:added "1.4", :ns "clojure.core", :name "ex-data", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/ex-info :clojure.core/try :clojure.core/throw :clojure.core/catch :clojure.core/finally :clojure.core/ex-message :clojure.core/ex-cause], :line 4792, :examples ["(try\n (let [response (http/post\n \"http://localhost:8080/v1/leads\"\n {:form-params {:foo \"somethingBad\"}})]\n (prn \"This is the response\" response))\n (catch Exception e\n (prn \"This is the error\" (ex-data e))))\n\n-------\n\n> \"This is the error\" {:status 500, :headers {\"Content-Type\" \"application/json; \ncharset=utf-8\", \"Content-Length\" \"73\", \"Server\" \"http-kit\", \"Date\" \"Mon, 10 Oct 2016\n 16:53:12 GMT\"}, :body \"{\\\"type\\\":\\\"unknown-\nexception\\\",\\\"class\\\":\\\"java.lang.IllegalArgumentException\\\"}\", :request-time 7,\n :trace-redirects [\"http://localhost:8080/v1/leads\"], :orig-content-encoding nil}" ";; See also: Throwable->map"], :notes nil, :arglists ["ex"], :doc "Returns exception data (a map) if ex is an IExceptionInfo.\n Otherwise returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ex-data"}, :clojure.core.reducers/append! {:added "1.5", :ns "clojure.core.reducers", :name "append!", :file "clojure/core/reducers.clj", :type "function", :column 1, :see-alsos nil, :line 275, :examples nil, :notes nil, :arglists ["acc x"], :doc ".adds x to acc and returns acc", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.reducers/append!"}, :clojure.pprint/code-dispatch {:added "1.2", :ns "clojure.pprint", :name "code-dispatch", :file "clojure/pprint/dispatch.clj", :type "function", :column 1, :see-alsos [:clojure.pprint/set-pprint-dispatch :clojure.pprint/with-pprint-dispatch], :line 453, :examples nil, :notes nil, :arglists ["object"], :doc "The pretty print dispatch function for pretty printing Clojure code.", :library-url "https://github.com/clojure/clojure", :href "/clojure.pprint/code-dispatch"}, :clojure.main/repl-exception {:ns "clojure.main", :name "repl-exception", :file "clojure/main.clj", :type "function", :column 1, :see-alsos nil, :line 172, :examples nil, :notes nil, :arglists ["throwable"], :doc "Returns the root cause of throwables", :library-url "https://github.com/clojure/clojure", :href "/clojure.main/repl-exception"}, :clojure.core/drop {:added "1.0", :ns "clojure.core", :name "drop", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/take :clojure.core/drop-last :clojure.core/drop-while :clojure.core/nthnext :clojure.core/nthrest], :line 2909, :examples [";; although negative (or zero) drop-item-counts are accepted they do nothing\n(drop -1 [1 2 3 4])\n;;=> (1 2 3 4) \n\n(drop 0 [1 2 3 4])\n;;=> (1 2 3 4) \n\n(drop 2 [1 2 3 4])\n;;=> (3 4) \n\n;; dropping more items than are present is allowed, and all items are dropped.\n(drop 5 [1 2 3 4])\n;;=> ()" ";; similar to subvec but lazy and with seqs\n(take 3 (drop 5 (range 1 11)))\n;;=> (6 7 8)"], :notes nil, :arglists ["n" "n coll"], :doc "Returns a lazy sequence of all but the first n items in coll.\n Returns a stateful transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/drop"}, :clojure.zip/up {:added "1.0", :ns "clojure.zip", :name "up", :file "clojure/zip.clj", :type "function", :column 1, :see-alsos [:clojure.zip/down :clojure.zip/left :clojure.zip/right :clojure.zip/next :clojure.zip/seq-zip :clojure.zip/zipper], :line 123, :examples nil, :notes nil, :arglists ["loc"], :doc "Returns the loc of the parent of the node at this loc, or nil if at\n the top", :library-url "https://github.com/clojure/clojure", :href "/clojure.zip/up"}, :clojure.core/ident? {:added "1.9", :ns "clojure.core", :name "ident?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/simple-ident? :clojure.core/qualified-ident? :clojure.core/keyword? :clojure.core/symbol?], :line 1612, :examples ["(ident? :hello)\n;;=> true\n\n(ident? 'abc)\n;;=> true\n\n(ident? \"hi\")\n;;=> false\n\n(ident? 123)\n;;=> false"], :notes nil, :arglists ["x"], :doc "Return true if x is a symbol or keyword", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ident_q"}, :clojure.core/ancestors {:added "1.0", :ns "clojure.core", :name "ancestors", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/parents :clojure.core/derive :clojure.core/underive :clojure.core/descendants :clojure.core/make-hierarchy :clojure.core/isa? :clojure.core/supers], :line 5598, :examples [";; make up a hierarchy a beagle is a sporting breed is a dog is a quadraped is an \n;; animal\n\nuser=> (derive ::quadruped ::animal)\nnil\nuser=> (derive ::dog ::quadruped)\nnil\nuser=> (derive ::sporting_breed ::dog)\nnil\nuser=> (derive ::beagle ::sporting_breed)\nnil\nuser=> (ancestors ::beagle)\n#{:user/dog :user/sporting_breed :user/animal :user/quadruped}\nuser=>" ";; use ancestors to show which classes ArrayList derives from and which\n;; interfaces it implements\n\nuser=> (ancestors java.util.ArrayList)\n#{java.util.Collection java.util.AbstractList java.io.Serializable java.lang.Cloneable java.util.List java.lang.Object java.util.AbstractCollection java.util.RandomAccess java.lang.Iterable}\nuser=>" ";; use ancestors in defrecords to show which defprotocols implements\nuser=> (defprotocol Fly\n (fly [this]))\n\nuser=> (defrecord Bird [name] Fly\n (fly [this] (str (:name this) \" flies....\")))\n\nuser=> (ancestors Bird)\n;; #{clojure.lang.IPersistentCollection \n;; user.Fly \n;; clojure.lang.IHashEq clojure.lang.ILookup \n;; java.util.Map java.lang.Iterable \n;; java.io.Serializable \n;; java.lang.Object \n;; clojure.lang.IMeta \n;; clojure.lang.Seqable \n;; clojure.lang.IRecord \n;; clojure.lang.IObj \n;; clojure.lang.Associative \n;; clojure.lang.Counted \n;; clojure.lang.IKeywordLookup \n;; clojure.lang.IPersistentMap}"], :notes nil, :arglists ["tag" "h tag"], :doc "Returns the immediate and indirect parents of tag, either via a Java type\n inheritance relationship or a relationship established via derive. h\n must be a hierarchy obtained from make-hierarchy, if not supplied\n defaults to the global hierarchy", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ancestors"}, :clojure.spec.alpha/and-spec-impl {:ns "clojure.spec.alpha", :name "and-spec-impl", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 1146, :examples nil, :notes nil, :arglists ["forms preds gfn"], :doc "Do not call this directly, use 'and'", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/and-spec-impl"}, :clojure.core.logic/all {:ns "clojure.core.logic", :name "all", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos [:clojure.core.logic/fresh :clojure.core/every?], :line 1268, :examples nil, :macro true, :notes nil, :arglists ["" "& goals"], :doc "Like fresh but does does not create logic variables.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/all"}, :clojure.core/neg? {:added "1.0", :ns "clojure.core", :name "neg?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/pos? :clojure.core/zero?], :line 1254, :examples ["user=> (neg? -1)\ntrue\nuser=> (neg? 0)\nfalse\nuser=> (neg? 1)\nfalse" "user=> (neg? -0.1)\ntrue\nuser=> (neg? 0.1)\nfalse" "user=> (neg? 1/2)\n;; false\n\nuser=> (neg? -1/2)\n;; true\n\nuser=> (neg? {})\n;; Execution error (ClassCastException) at user/eval3801 (REPL:1).\n;; clojure.lang.PersistentArrayMap cannot be cast to java.lang.Number"], :notes nil, :arglists ["num"], :doc "Returns true if num is less than zero, else false", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/neg_q"}, :clojure.core/EMPTY-NODE {:ns "clojure.core", :name "EMPTY-NODE", :file "clojure/gvec.clj", :type "var", :column 1, :see-alsos nil, :line 19, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/EMPTY-NODE"}, :clojure.core.async/partition-by {:ns "clojure.core.async", :name "partition-by", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 1163, :examples ["; Source: 4clojure (https://www.4clojure.com/problem/31)\n(partition-by identity [1 1 2 1 1 1 3 3])\n=> ((1 1) (2) (1 1 1) (3 3))"], :deprecated "0.1.319.0-6b1aca-alpha", :notes nil, :arglists ["f ch" "f ch buf-or-n"], :doc "Deprecated - this function will be removed. Use transducer instead", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/partition-by"}, :clojure.xml/emit {:ns "clojure.xml", :name "emit", :file "clojure/xml.clj", :type "function", :column 1, :see-alsos [:clojure.core/with-out-str], :line 111, :examples ["(use 'clojure.xml)\n;;attrs stores the attributes of a tag and content contains the children\n(emit {:tag :parent :attrs {:value \"Hello\"} :content[\n\t{:tag :child1 :attrs {:value \"World\"}}\n\t{:tag :child2 :attrs {:value \"Clojure\"}}\n\t]})\n\n;; prints this to *out*:\n\n\n\n\n"], :notes ["this one have a problem when trying to export xml with string containing & etc (should be escaped). Contribs prxml has this functionality." "A 1.3 compatible version of prxml can be found here:\r\n\r\nhttps://github.com/weissjeffm/clojure.prxml"], :arglists ["x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.xml/emit"}, :clojure.core/delay? {:added "1.0", :ns "clojure.core", :name "delay?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/delay], :line 755, :examples ["user=> (def v (delay (do (println \"start sleeping\") \n (Thread/sleep 1000) \n 10)))\n#'user/v\nuser=> (delay? v)\ntrue\nuser=> (force v)\nstart sleeping\n10\nuser=> (delay? v)\ntrue\nuser=> (force v)\n10\nuser=> "], :notes nil, :arglists ["x"], :doc "returns true if x is a Delay created with delay", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/delay_q"}, :clojure.core/-cache-protocol-fn {:ns "clojure.core", :name "-cache-protocol-fn", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos nil, :line 575, :examples nil, :notes nil, :arglists ["pf x c interf"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/-cache-protocol-fn"}, :clojure.core/doubles {:added "1.0", :ns "clojure.core", :name "doubles", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/double-array], :line 5378, :examples [";; double-array will convert where possible\n(double-array [1 2 3]);; => [1.0, 2.0, 3.0]\n\n;; doubles will not\n(try (doubles [1 2 3])\n (catch ClassCastException e (ex-message e)))\n;; => \"clojure.lang.PersistentVector cannot be cast to [D\"" ";; Casting avoids expensive reflection, so to see the benefit, enable warning:\n(set! *warn-on-reflection* true)\n\n;; We'll def a double-array but won't type-hint the var:\n(def my-array (double-array [10.0 20.0 30.0 40.0 50.0 60.0]))\n\n;; and try to amap over it without using `doubles` or type hinting amap's args:\n(amap my-array i _ (unchecked-inc ^double (aget my-array i)))\n;; Reflection warning… call to static method alength on clojure.lang.RT can't be resolved (argument types: unknown).\n;; Reflection warning… call to static method aclone on clojure.lang.RT can't be resolved (argument types: unknown).\n;; Reflection warning… call to static method aget on clojure.lang.RT can't be resolved (argument types: unknown, int).\n;; Reflection warning… call to static method aset on clojure.lang.RT can't be resolved (argument types: unknown, int, double).\n;; => [11.0, 21.0, 31.0, 41.0, 51.0, 61.0]\n\n;; We can use `doubles` to avoid reflection:\n(amap (doubles my-array) i _ (unchecked-inc ^double (aget (doubles my-array) i)))\n;; => [11.0, 21.0, 31.0, 41.0, 51.0, 61.0]\n\n;; Just as we can type hint in place:\n(amap ^doubles my-array i _ (unchecked-inc ^double (aget ^doubles my-array i)))\n;; => [11.0, 21.0, 31.0, 41.0, 51.0, 61.0]\n\n;; Or type hint the var:\n(def ^\"[D\" my-array (double-array [10 20 30 40 50 60]))\n(amap my-array i _ (unchecked-inc ^double (aget my-array i)))\n;; => [11.0, 21.0, 31.0, 41.0, 51.0, 61.0]\n"], :notes ["Anybody know what this is used for?\r\nAll I could find is that you can cast an existing double-array to another \r\ndouble-array???\r\n\r\n
user=> (doubles [1 2 3 4 5])\r\njava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to [D (NO_SOURCE_FILE:0)\r\nuser=> (doubles (int-array [2 3 2]))\r\njava.lang.ClassCastException: [I cannot be cast to [D (NO_SOURCE_FILE:0)\r\nuser=> (doubles (float-array [2 3 2]))\r\njava.lang.ClassCastException: [F cannot be cast to [D (NO_SOURCE_FILE:0)\r\nuser=> (doubles (double-array [2 3 2]))\r\n#\r\nuser=> (type (double-array [2 3 2]))\r\n[D\r\nuser=> (type (doubles (double-array [2 3 2])))\r\n[D\r\nuser=>\r\n
\r\n"], :arglists ["xs"], :doc "Casts to double[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/doubles"}, :clojure.java.javadoc/*feeling-lucky* {:ns "clojure.java.javadoc", :name "*feeling-lucky*", :file "clojure/java/javadoc.clj", :type "var", :column 1, :see-alsos [:clojure.java.javadoc/*feeling-lucky-url*], :dynamic true, :line 17, :examples [";; If true, clojure.java.javadoc/javadoc opens a browser using\n;; *feeling-lucky-url* when it can’t find the proper documentation URL\n;; for a class.\n\n;; opens a browser with *feeling-lucky-url*\n(clojure.java.javadoc/javadoc inc)\n\n;; prints \"Could not find Javadoc for clojure.core$inc\"\n(binding [clojure.java.javadoc/*feeling-lucky* false] \n (clojure.java.javadoc/javadoc inc))"], :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.java.javadoc/*feeling-lucky*"}, :clojure.core.logic.pldb/with-db {:ns "clojure.core.logic.pldb", :name "with-db", :file "clojure/core/logic/pldb.clj", :type "macro", :column 1, :see-alsos nil, :line 12, :examples nil, :macro true, :notes nil, :arglists ["db & body"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/with-db"}, :clojure.core/if-not {:added "1.0", :ns "clojure.core", :name "if-not", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/if :clojure.core/when-not], :line 767, :examples ["user=> (defn has-neg [coll] \n (if-not (empty? coll) ;; = (if (not (empty? coll)) ...\n (or (neg? (first coll)) (recur (rest coll)))))\n#'user/has-neg\n\nuser=> (has-neg [])\nnil \n\nuser=> (has-neg [1 2 -3 4])\ntrue" "user=> (if-not (zero? 0) :then :else)\n:else" ";; See examples for \"if\" explaining Clojure's idea of logical true\n;; and logical false."], :macro true, :notes nil, :arglists ["test then" "test then else"], :doc "Evaluates test. If logical false, evaluates and returns then expr, \n otherwise else expr, if supplied, else nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/if-not"}, :clojure.core.logic.fd/unify-with-domain* {:ns "clojure.core.logic.fd", :name "unify-with-domain*", :file "clojure/core/logic/fd.clj", :type "var", :column 1, :see-alsos nil, :line 34, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/unify-with-domain*"}, :clojure.zip/insert-right {:added "1.0", :ns "clojure.zip", :name "insert-right", :file "clojure/zip.clj", :type "function", :column 1, :see-alsos nil, :line 193, :examples [";;; zip is not default required in clj\n(require '[clojure.zip :as zip])\n\n(def root-tree (zip/seq-zip '(:root (:1st-left-child ) (:1st-right-child\n))))\n\n;;; get the location , in this case is the root of the tree\n(def location (-> root-tree zip/next))\n\n\n(zip/insert-right location :inserted)\n\n;; = > [:root\n;; {:changed? true,\n;; :l [],\n;; :pnodes [(:root (:1st-left-child) (:1st-right-child))],\n;; :ppath nil,\n;; :r (:inserted (:1st-left-child) (:1st-right-child))}]"], :notes nil, :arglists ["loc item"], :doc "Inserts the item as the right sibling of the node at this loc,\n without moving", :library-url "https://github.com/clojure/clojure", :href "/clojure.zip/insert-right"}, :clojure.java.io/delete-file {:added "1.2", :ns "clojure.java.io", :name "delete-file", :file "clojure/java/io.clj", :type "function", :column 1, :see-alsos [:clojure.java.io/file :clojure.java.io/copy], :line 430, :examples [";; create a file using spit, then show its contents using slurp\n;; delete it and verify that it has been deleted by trying to print its\n;; contents again\n\nuser=> (require '[clojure.java.io :as io])\nnil\nuser=> (spit \"stuff.txt\" \"blurp\")\nnil\nuser=> (println (slurp \"stuff.txt\"))\nblurp\nnil\nuser=> (io/delete-file \"stuff.txt\")\ntrue\nuser=> (println (slurp \"stuff.txt\"))\njava.io.FileNotFoundException: stuff.txt (The system cannot find the file specif\nied) (NO_SOURCE_FILE:0)\nuser=>" "(require '[clojure.java.io :as io])\n\nuser> (io/delete-file \"d:/code/python/file-which-does-not-exist.py\")\nIOException Couldn't delete d:/code/python/exist.py \nclojure.java.io/delete-file (io.clj:426)\n\nuser> (io/delete-file \"d:/code/python/file-which-does-not-exist.py\" true)\ntrue"], :notes nil, :arglists ["f & [silently]"], :doc "Delete file f. If silently is nil or false, raise an exception on failure, else return the value of silently.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/delete-file"}, :clojure.core/load {:added "1.0", :ns "clojure.core", :name "load", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/load-file :clojure.core/*read-eval* :clojure.core/load-string], :line 6109, :examples [";; file located at src/address_book/core.clj and current namespace\n;; located at root of the classpath, such as \"user\".\n\n(load \"address_book/core\")" ";; Loading from root of the classpath, such as user namespace\n\n(ns user)\n(load \"/clojure/set\")\n;; nil\n\n;; Loading \"clojure/xml.clj\" from a relative location in the classpath \n;; does not want the \"/\"\n\n(ns clojure.set)\n(load \"xml\")\n;; nil"], :notes nil, :arglists ["& paths"], :doc "Loads Clojure code from resources in classpath. A path is interpreted as\n classpath-relative if it begins with a slash or relative to the root\n directory for the current namespace otherwise.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/load"}, :clojure.core.logic/ext-run-csg {:ns "clojure.core.logic", :name "ext-run-csg", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1152, :examples nil, :notes nil, :arglists ["u v"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/ext-run-csg"}, :clojure.core/char {:added "1.1", :ns "clojure.core", :name "char", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/char? :clojure.core/int :clojure.core/chars :clojure.core/char-array], :line 3510, :examples [";; can coerce an int (or similar)\nuser=> (char 97)\n\\a\n\n;; a byte can be coerced to a char\nuser=> (let [bytes-array (.getBytes \"abc\")]\n (char (first bytes-array)))\n\\a\n\n;; char is just a function\nuser=> (map char [65 66 67 68])\n(\\A \\B \\C \\D)" "(->> [67 108 111 106 117 114 101]\n (map char)\n (apply str))\n\n\"Clojure\"" ";; backslash\nuser=> (char 92)\n\\\\\n\n;; String madness:\nuser=> (map str [\\n \\newline \\\\])\n[\"n\" \"\\n\" \"\\\\\"]\n\n;; convert back to int:\nuser=> (int \\\\)\n92\n\n;; whoops! this will expect additional input because it char's the bracket\nuser=> (char \\)\n #=> \n\n;; don't you dare this!\nuser=> (char \\ )\n\\space\n\n;; make it readable\nuser=> (char \\space)\n\\space\n\n;; it gets uglier! Mark the text to see the difference\nuser=> \\\n #=>\n\nuser=> \\ \n\\space\n\n;; MaDnEsS!1!\nuser=> \\\\\\\\\\\\\\\\\n\\\\\n\\\\\n\\\\\n\\\\" ";; string to code round trip\n;; input string\n(def in-string \"鬼\")\n;; single char from string\n(def in-char (.charAt in-string 0)) ;;=> \\鬼\n;; code from char\n(def code (int in-char)) ;;=> 39740\n;; char from code\n(def out-char (char code)) ;;=> \\鬼\n;; back to input string\n(def out-string (str out-char)) ;;=> \"鬼\"\n" "(defn u-sub-char\n \"If n is a single-digit integer in [0, ..., 9], returns the\n Unicode supscript character for n. Returns nil for other numbers.\"\n [n]\n (if (and (>= n 0) (<= n 9))\n (char (+ 0x2080 n))\n nil))"], :notes nil, :arglists ["x"], :doc "Coerce to char", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/char"}, :clojure.core.logic/matche {:ns "clojure.core.logic", :name "matche", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos [:clojure.core.logic/conde], :line 1705, :examples [";; Taken from: https://github.com/frenchy64/Logic-Starter/wiki#matche\n;; These are equivalent:\n(run* [q]\n (conde\n ((== 'extra q) succeed)\n ((== 'virgin q) succeed)\n ((== 'olive q) succeed)\n ((== 'oil q) succeed)))\n;=> (extra virgin olive oil)\n\n(run* [q]\n (matche [q]\n (['extra] succeed)\n (['virgin] succeed)\n (['olive] succeed)\n (['oil] succeed)))\n;=> (extra virgin olive oil)\n\n;; Wild Cards and destructuring: https://github.com/frenchy64/Logic-Starter/wiki#matche-sugar-combining-wildcards-and-destructuring\n(run* [q]\n (fresh [a o]\n (== a [1 2 3 4 5])\n (matche [a]\n ([ [1 . _] ]\n (== q \"first\"))\n ([ [_ . o] ]\n (== q [\"second\" o])))))\n;=> (\"first\" \n; [\"second\" (2 3 4 5)])\n\n;; Implicit Variables: https://github.com/frenchy64/Logic-Starter/wiki#matche-sugar-implicit-variables\n(run* [q]\n (fresh [a o]\n (== a [1 2 3 4 5])\n (matche [a]\n ([ [1 . o] ]\n (== q [\"one\" o]))\n ([ [1 2 . ?o] ]\n (== q [\"two\" ?o]))\n ([ [o . ?o] ]\n (== q [\"third\" o ?o])))))\n;=> ([\"one\" (2 3 4 5)] \n; [\"two\" (3 4 5)] \n; [\"third\" 1 (2 3 4 5)] "], :macro true, :notes nil, :arglists ["xs & cs"], :doc "Pattern matching macro. All patterns will be tried.\n See conde.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/matche"}, :clojure.core/extend-type {:added "1.2", :ns "clojure.core", :name "extend-type", :file "clojure/core_deftype.clj", :type "macro", :column 1, :see-alsos [:clojure.core/extend :clojure.core/extend-protocol :clojure.core/defprotocol], :line 836, :examples [";;; This is a library for the shopping result.\n\n(defrecord Banana [qty])\n\n;;; 'subtotal' differ from each fruit.\n\n(defprotocol Fruit\n (subtotal [item]))\n\n(extend-type Banana\n Fruit\n (subtotal [item]\n (* 158 (:qty item))))\n\n;;; Please see the term of 'reify'."], :macro true, :notes nil, :arglists ["t & specs"], :doc "A macro that expands into an extend call. Useful when you are\n supplying the definitions explicitly inline, extend-type\n automatically creates the maps required by extend. Propagates the\n class as a type hint on the first argument of all fns.\n\n (extend-type MyType \n Countable\n (cnt [c] ...)\n Foo\n (bar [x y] ...)\n (baz ([x] ...) ([x y & zs] ...)))\n\n expands into:\n\n (extend MyType\n Countable\n {:cnt (fn [c] ...)}\n Foo\n {:baz (fn ([x] ...) ([x y & zs] ...))\n :bar (fn [x y] ...)})", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/extend-type"}, :clojure.spec.alpha/spec-impl {:ns "clojure.spec.alpha", :name "spec-impl", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 908, :examples nil, :notes nil, :arglists ["form pred gfn cpred?" "form pred gfn cpred? unc"], :doc "Do not call this directly, use 'spec'", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/spec-impl"}, :clojure.core.logic/appendo {:ns "clojure.core.logic", :name "appendo", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1772, :examples ["(run* [q]\n (appendo [:a :b] [:c :d :e] q)) ;; ((:a :b :c :d :e))\n(run* [q]\n (appendo [:a :b] q [:a :b :c :d :e])) ;; ((:c :d :e))\n"], :notes nil, :arglists ["x y z"], :doc "A relation where x, y, and z are proper collections,\n such that z is x appended to y", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/appendo"}, :clojure.core.protocols/Navigable {:ns "clojure.core.protocols", :name "Navigable", :file "clojure/core/protocols.clj", :type "var", :column 1, :see-alsos nil, :line 194, :examples nil, :notes nil, :arglists [], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.protocols/Navigable"}, :clojure.core.reducers/drop {:added "1.5", :ns "clojure.core.reducers", :name "drop", :file "clojure/core/reducers.clj", :type "function", :column 1, :see-alsos nil, :line 215, :examples ["Clojure 1.10.3\nuser=> (def coll (range 10))\n#'user/coll\nuser=> coll\n(0 1 2 3 4 5 6 7 8 9)\nuser=> (drop 4 coll)\n(4 5 6 7 8 9)"], :notes nil, :arglists ["n" "n coll"], :doc "Elides the first n values from the reduction of coll.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.reducers/drop"}, :clojure.walk/postwalk-replace {:added "1.1", :ns "clojure.walk", :name "postwalk-replace", :file "clojure/walk.clj", :type "function", :column 1, :see-alsos [:clojure.walk/prewalk-replace :clojure.core/replace :clojure.walk/postwalk], :line 118, :examples ["(use 'clojure.walk)\n\n(postwalk-replace {:a 1 :b 2} [:a :b])\n;=> [1 2]\n\n(postwalk-replace {:a 1 :b 2} [:a :b :c])\n;=> [1 2 :c]\n\n(postwalk-replace {:a 1 :b 2} [:a :b [:a :b] :c])\n;=> [1 2 [1 2] :c]" "(postwalk-replace {nil :NIL} {:a 1, :b nil, :c 3, nil 4})\n;=> {:NIL 4, :a 1, :b :NIL, :c 3}"], :notes nil, :arglists ["smap form"], :doc "Recursively transforms form by replacing keys in smap with their\n values. Like clojure/replace but works on any data structure. Does\n replacement at the leaves of the tree first.", :library-url "https://github.com/clojure/clojure", :href "/clojure.walk/postwalk-replace"}, :clojure.test/compose-fixtures {:added "1.1", :ns "clojure.test", :name "compose-fixtures", :file "clojure/test.clj", :type "function", :column 1, :see-alsos [:clojure.test/join-fixtures], :line 689, :examples nil, :notes nil, :arglists ["f1 f2"], :doc "Composes two fixture functions, creating a new fixture function\n that combines their behavior.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/compose-fixtures"}, :clojure.core.async/unmix* {:ns "clojure.core.async", :name "unmix*", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["m ch"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/unmix*"}, :clojure.core/unchecked-negate {:added "1.0", :ns "clojure.core", :name "unchecked-negate", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/unchecked-add :clojure.core/unchecked-dec :clojure.core/unchecked-inc :clojure.core/unchecked-negate :clojure.core/unchecked-divide :clojure.core/unchecked-subtract :clojure.core/unchecked-multiply :clojure.core/unchecked-remainder :clojure.core/-], :line 1184, :examples [";; *Almost* always the same as \"-\"\nuser=> (= (- 2) (unchecked-negate 2))\ntrue\nuser=> (= (- (Long/MAX_VALUE)) (unchecked-negate (Long/MAX_VALUE)))\ntrue\n\n;; Except when it's not, because (- (Long/MIN_VALUE)) overflows:\nuser=> (= (- (Long/MIN_VALUE)) (unchecked-negate (Long/MIN_VALUE)))\nArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1501)\n\n;; Indeed:\nuser=> (unchecked-negate (Long/MIN_VALUE))\n-9223372036854775808\n\n;; Careful!\nuser=> (= (Long/MIN_VALUE) (unchecked-negate (Long/MIN_VALUE)))\ntrue"], :notes nil, :arglists ["x"], :doc "Returns the negation of x, a long.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-negate"}, :clojure.core/remove-tap {:added "1.10", :ns "clojure.core", :name "remove-tap", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/tap> :clojure.core/add-tap], :line 7879, :examples nil, :notes nil, :arglists ["f"], :doc "Remove f from the tap set.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/remove-tap"}, :clojure.core/gensym {:added "1.0", :ns "clojure.core", :name "gensym", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 604, :examples ["user=> (gensym \"foo\")\nfoo2020\n\nuser=> (gensym \"foo\")\nfoo2027\n\nuser=> (gensym \"foo\")\n;; ...\n" "user=> (gensym)\nG__2034\n\nuser=> (let [my-unique-sym (gensym)]\n my-unique-sym)\nG__2075\n" ";; syntax-reader uses gensym for non-namespace-qualified symbols ending with '#'\n;; http://clojure.org/reader\n\nuser=> `(name0#) ; gensym, form is useful in defmacro\n(name0__1206__auto__)\n\nuser=> `(user/name1#) ; no gensym, namespace-qualified\n(user/name1#)\n\nuser=> `(:key0#) ; no gensym, keyword\n(:key0#)\n\nuser=> `(::key1#) ; no gensym, keyword\n(:user/key1#)\n" ";; syntax-reader gensyms are only generated once, at read time\n;; so recursive macros get the same generated symbol for all levels of recursion\n\n(defmacro reader-gensym-macro [[x & more :as xs] acc]\n (if (seq xs)\n `(let [x# ~x]\n (reader-gensym-macro ~more (conj ~acc x#)))\n acc))\n\n(reader-gensym-macro [1 2] []) ;; => [2 2]\n\n;; using the function `gensym` can overcome this problem\n;; so recursive macros get a different generated symbol for each level of recursion\n\n(defmacro function-gensym-macro [[x & more :as xs] acc]\n (if (seq xs)\n (let [gx (gensym 'x)]\n `(let [~gx ~x]\n (function-gensym-macro ~more (conj ~acc ~gx))))\n acc))\n\n(function-gensym-macro [1 2] []) ;; => [1 2]"], :notes ["The
(. clojure.lang.RT (nextID))
present gensym's source code (https://github.com/clojure/clojure/blob/clojure-1.5.1/src/jvm/clojure/lang/RT.java#L468) uses java.util.concurrent.atomic.AtomicInteger (and has for the past 6 years, if you trust the Git history)."], :arglists ["" "prefix-string"], :doc "Returns a new symbol with a unique name. If a prefix string is\n supplied, the name is prefix# where # is some unique number. If\n prefix is not supplied, the prefix is 'G__'.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/gensym"}, :clojure.core/boolean-array {:added "1.1", :ns "clojure.core", :name "boolean-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 5285, :examples [";; create an array of Java boolean's using boolean-array\n;; and demonstrate that it can be used for input into the standard\n;; Java Arrays.fill function\n\nuser=> (def bs (boolean-array (map even? (range 3 10))))\n#'user/bs\nuser=> (type bs)\n[Z\nuser=> (vec bs)\n[false true false true false true false]\nuser=> (java.util.Arrays/fill bs 3 7 false)\nnil\nuser=> (vec bs)\n[false true false false false false false]\nuser=>"], :notes nil, :arglists ["size-or-seq" "size init-val-or-seq"], :doc "Creates an array of booleans", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/boolean-array"}, :clojure.zip/append-child {:added "1.0", :ns "clojure.zip", :name "append-child", :file "clojure/zip.clj", :type "function", :column 1, :see-alsos [:clojure.zip/insert-child], :line 223, :examples [";; \"append-child\" adds a new child as the rightmost element. \n;; \"insert-child\" does the same, but leftmost. The node needs to be a branch.\n\n(require '[clojure.zip :as zip])\n\n(def vzip\n (zip/vector-zip\n [[1 2]\n [3 4 [5 10 [11 12]]]\n [13 14]])) \n\n(-> vzip zip/down zip/rightmost (zip/append-child 'INS) zip/up zip/node)\n;; [[1 2] [3 4 [5 10 [11 12]]] [13 14 INS]]\n\n(-> vzip zip/down zip/rightmost (zip/insert-child 'INS) zip/up zip/node)\n;; [[1 2] [3 4 [5 10 [11 12]]] [INS 13 14]]\n\n(-> vzip zip/down zip/rightmost zip/down (zip/append-child 'INS))\n;; Exception called children on a leaf node\n" "(use 'clojure.zip)\n;; def a tree struct\n;; .\n;; / \\\n;; . 0\n;; / \\\n;; 1 2\n(def tree\n (vector-zip\n [[1 2] 0]))\n\n(-> tree\n down\n (append-child 3))\n;; .\n;; / \\\n;; x 0\n;; /|\\\n;; 1 2 3\n;;\n;; 3 inserted, location x unchanged"], :notes nil, :arglists ["loc item"], :doc "Inserts the item as the rightmost child of the node at this loc,\n without moving", :library-url "https://github.com/clojure/clojure", :href "/clojure.zip/append-child"}, :clojure.core/keep {:added "1.2", :ns "clojure.core", :name "keep", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/keep-indexed :clojure.core/map :clojure.core/filter :clojure.core/remove], :line 7313, :examples ["(keep even? (range 1 10))\n;;=> (false true false true false true false true false)\n" ";; comparisons among keep, filter, map and for.\n\n(keep #(if (odd? %) %) (range 10))\n;;=> (1 3 5 7 9)\n\n(map #(if (odd? %) %) (range 10))\n;;=> (nil 1 nil 3 nil 5 nil 7 nil 9)\n\n(for [ x (range 10) :when (odd? x)] x)\n;;=> (1 3 5 7 9)\n\n(filter odd? (range 10))\n;;=> (1 3 5 7 9)" ";; Sieve of Eratosthenes by using 'keep'.\n\n(defn keep-mcdr [f coll]\n (lazy-seq\n (when-let [x (first coll)]\n (cons x (keep-mcdr f (f x (rest coll)))))))\n\n(defn prime-number [n]\n (cons 1\n\t(keep-mcdr\n\t (fn[x xs] (if (not-empty xs)\n\t\t (keep #(if-not (zero? (rem % x)) %)\n\t\t\t xs)))\n\t (range 2 n))))\n\n(prime-number 100)\n;;=> (1 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97)\n" "(keep seq [() [] '(1 2 3) [:a :b] nil])\n;;=> ((1 2 3) (:a :b))" ";; `keep` is useful with maps:\n\n(keep {:a 1, :b 2, :c 3} [:a :b :d])\n;;=> (1 2)\n" ";; A set will work as a predicate for another set.\n(keep #{0 1 2 3} #{2 3 4 5})\n;;=> (3 2)" ";; keep returns the results of predicates, \n;; filter returns the original values of collection\n\n(keep (fn [[k _]] (#{:a :b} k)) {:a 1 :b 2 :c 3})\n;;=> (:a :b)\n\n(filter (fn [[k _]] (#{:a :b} k)) {:a 1 :b 2 :c 3})\n;;=> ([:a 1] [:b 2])" ";; keep rejects nil from results\n\n(keep #(when (number? %) %) [1 \"a\" 2 \"c\"])\n;; => (1 2)\n\n(map #(when (number? %) %) [1 \"a\" 2 \"c\"])\n;; => (1 nil 2 nil)\n\n(remove nil? (map #(when (number? %) %) [1 \"a\" 2 \"c\"]))\n;; => (1 2)"], :notes ["Note the difference between `filter` and `keep`. `filter` returns the original items in a collection that satisfy the predicate. `keep` returns the non-nil *results* of the given function." "`keep` is like a `map` that filters out `nil` values produced by `f` and could be defined as:\n
\n" "Note that, unlike `map`, `keep` doesn’t accept multiple collections:\n\n```clojure\n(filter identity (map get [{:a 1} {:b 2} {:d 3}] [:a :b :c]))\n; => (1 2)\n\n(keep get [{:a 1} {:b 2} {:d 3}] [:a :b :c])\n; => ArityException Wrong number of args (3) passed to: core/keep\n```" "It's useful to consider `filter` and `remove` as a pair of complementary/similar functions that both return the original items, whereas `keep` is rather specialized/different."], :arglists ["f" "f coll"], :doc "Returns a lazy sequence of the non-nil results of (f item). Note,\n this means false return values will be included. f must be free of\n side-effects. Returns a transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/keep"}, :clojure.core/char-name-string {:added "1.0", :ns "clojure.core", :name "char-name-string", :file "clojure/core_print.clj", :type "var", :column 1, :see-alsos [:clojure.core/char-escape-string], :line 342, :examples ["user=> (char-name-string \\newline)\n\"newline\"" "(map char-name-string [\\backspace \\tab \\newline \\formfeed \\return \\space])\n;;=> (\"backspace\" \"tab\" \"newline\" \"formfeed\" \"return\" \"space\")"], :notes nil, :tag "java.lang.String", :arglists [], :doc "Returns name string for char or nil if none", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/char-name-string"}, :clojure.zip/vector-zip {:added "1.0", :ns "clojure.zip", :name "vector-zip", :file "clojure/zip.clj", :type "function", :column 1, :see-alsos [:clojure.zip/seq-zip :clojure.zip/xml-zip :clojure.zip/next :clojure.zip/end?], :line 44, :examples ["\n(require '[clojure.zip :as zip])\n\n(defn zip-map [f loc]\n \" Map f over every node of the zipper.\n The function received has the form (f node-value loc),\n the node value and its location\"\n (loop [z loc]\n (if (zip/end? z)\n (zip/root z) ; perhaps you can call zip/seq-zip or zip/vector-zip?\n (recur (zip/next (zip/edit z f z))))))\n\n;; Multiply by 100 every node in the tree\nuser=> (zip-map (fn [n nx] (if (vector? n) n (* n 100) )) (zip/vector-zip '[5 [10 20 30] [1 2 3] ]))\n;; Be careful! the returned result by zip/root is not a zipper anymore!\n[500 [1000 2000 3000] [100 200 300]]\n" ";; It may not be obvious however it is worth pointing out that \n;; this implementation assumes that all vectors are branches, \n;; and all non vector data is therefore a leaf node. \n\n;; A vector \"Tree\" [5 [10 20 30] [1 2 3]]) can be visualised as\n;;\n;; --- ♦ ---\n;; / | \\\n;; 5 ♦ ♦\n;; / | \\ / | \\\n;; 10 20 30 1 2 3\n\n;; If you want to put data into a branch node for example a binary tree\n;; you can not use the default zip/vector-zip. Rather you need use zip/zipper\n;; and give a new children function to specify where the children are.\n;; See: https://stackoverflow.com/questions/26268098/can-someone-give-an-example-of-how-edit-function-for-clojure-zip-works"], :notes nil, :arglists ["root"], :doc "Returns a zipper for nested vectors, given a root vector", :library-url "https://github.com/clojure/clojure", :href "/clojure.zip/vector-zip"}, :clojure.core.protocols/InternalReduce {:ns "clojure.core.protocols", :name "InternalReduce", :file "clojure/core/protocols.clj", :type "var", :column 1, :see-alsos nil, :line 19, :examples nil, :notes ["http://muhammadkhojaye.blogspot.com"], :arglists [], :doc "Protocol for concrete seq types that can reduce themselves\n faster than first/next recursion. Called by clojure.core/reduce.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.protocols/InternalReduce"}, :clojure.zip/leftmost {:added "1.0", :ns "clojure.zip", :name "leftmost", :file "clojure/zip.clj", :type "function", :column 1, :see-alsos [:clojure.zip/rightmost], :line 174, :examples nil, :notes nil, :arglists ["loc"], :doc "Returns the loc of the leftmost sibling of the node at this loc, or self", :library-url "https://github.com/clojure/clojure", :href "/clojure.zip/leftmost"}, :clojure.spec.alpha/conform {:ns "clojure.spec.alpha", :name "conform", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos [:clojure.spec.alpha/unform :clojure.spec.alpha/explain :clojure.spec.alpha/gen], :line 160, :examples ["(require '[clojure.spec.alpha :as s])\n\n;; define spec as a sequential concatenation of two more specs:\n;; number? and pos? and one of possible units (:meters :miles)\n;; :amount and :unit are the names we are giving to each position\n(s/def ::distance (s/cat :amount (s/and number? pos?)\n :unit #{:meters :miles}))\n\n(s/conform ::distance [3 :meters])\n;; => {:amount 3, :unit :meters}\n\n(s/conform ::distance [3 :steps])\n;; => :clojure.spec.alpha/invalid"], :notes nil, :arglists ["spec x"], :doc "Given a spec and a value, returns :clojure.spec.alpha/invalid \n\tif value does not match spec, else the (possibly destructured) value.", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/conform"}, :clojure.core.logic/->PMap {:ns "clojure.core.logic", :name "->PMap", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2518, :examples nil, :notes nil, :arglists [""], :doc "Positional factory function for class clojure.core.logic.PMap.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/->PMap"}, :clojure.core.logic.pldb/db-retraction {:ns "clojure.core.logic.pldb", :name "db-retraction", :file "clojure/core/logic/pldb.clj", :type "function", :column 1, :see-alsos [:clojure.core.logic.pldb/db-fact], :line 100, :examples ["; db-retraction is the reverse operation to db-fact. \n; You can think of db-rel as learning a fact and db-retraction as unlearning it.\n\n; Step 1: define a relation\n(db-rel user x)\n\n; Step 2: create a simple DB\n(def my-db (-> empty-db\n (db-fact user \"me\")\n (db-fact user \"you\")))\n;; => {\"user/user_1\" {:clojure.core.logic.pldb/unindexed #{(\"you\") (\"me\")}}}\n\n;; Step 3: retract from \"me\" being a user.\n(db-retraction my-db user \"me\")\n;; => {\"user/user_1\" {:clojure.core.logic.pldb/unindexed #{(\"you\")}}}"], :notes nil, :arglists ["db rel & args"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/db-retraction"}, :clojure.java.io/make-input-stream {:added "1.2", :ns "clojure.java.io", :name "make-input-stream", :type "function", :see-alsos [:clojure.java.io/IOFactory], :examples nil, :notes nil, :arglists ["x opts"], :doc "Creates a BufferedInputStream. See also IOFactory docs.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/make-input-stream"}, :clojure.core.logic/conde {:ns "clojure.core.logic", :name "conde", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos [:clojure.core.logic/conda], :line 1175, :examples [";; conde accepts vectors of goals.\n;; makes 'or' of all the goals represented by each vector\n;; Where within each of those goals all condition must be met \n\n(run*\n [x y]\n (conde\n \t [(conso x y [1 2 3 4]) (== x 1)] ;; (conso x y [1 2 3 4]) and (== x 1)\n \t \t ;; OR\n \t [(== x y) (== x 2)])) \t ;; (== x y) and (== x 2)\n\n;; ([1 (2 3 4)] [2 2])"], :macro true, :notes nil, :arglists ["& clauses"], :doc "Logical disjunction of the clauses. The first goal in\n a clause is considered the head of that clause. Interleaves the\n execution of the clauses.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/conde"}, :clojure.core.logic/update-dom {:ns "clojure.core.logic", :name "update-dom", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 480, :examples nil, :notes nil, :arglists ["s x dom f" "s x dom f seenset"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/update-dom"}, :clojure.core/boolean? {:added "1.9", :ns "clojure.core", :name "boolean?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/true?], :line 519, :examples ["(boolean? true)\n;;=> true\n(boolean? false)\n;;=> true\n(boolean? (new Boolean \"true\"))\n;;=> true\n(boolean? (new Boolean \"false\"))\n;;=> true\n\n(boolean? nil)\n;;=> false"], :notes nil, :arglists ["x"], :doc "Return true if x is a Boolean", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/boolean_q"}, :clojure.core/or {:added "1.0", :ns "clojure.core", :name "or", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/and :clojure.core/if :clojure.core/some-fn], :line 854, :examples ["user> (or true false false)\ntrue\n\nuser> (or true true true)\ntrue\n\nuser> (or false false false)\nfalse\n\nuser> (or nil nil)\nnil\n\nuser> (or false nil)\nnil\n\nuser> (or true nil)\ntrue\n\n;; or doesn't evaluate if the first value is true\nuser> (or true (println \"foo\"))\ntrue\n\n;; order matters\nuser> (or (println \"foo\") true)\nfoo\ntrue\n\n;; does not coerce a given value to a boolean true, returns the value\nuser> (or false 42)\n42\n\nuser> (or false 42 9999)\n42\n\nuser> (or 42 9999)\n42" ";; See examples for \"if\" explaining Clojure's idea of logical true\n;; and logical false." ";;evaluates last expression for this case\nuser> (or nil false)\nfalse\n\nuser> (or false nil)\nnil" ";; Defaulted value\nuser> (or nil \"crazy default value\")\ncrazy default value\n\nuser> (or \"value\" \"not useful default value\")\nvalue" ";; It cares about function's return. Example:\n;; println returns 'nil', so the next param will be evaluated.\n(or (println \"Clojure\") true \"Code\" false)\nClojure\n;;=>true\n" ";; `or` is a macro, so can't be given where a fn is expected\n(map or [true false] [false false])\n;; => Syntax error compiling at…\n;; => Can't take value of a macro: #'clojure.core/or\n\n;; wrap in a fn instead\n(map #(or %1 %2) [true false] [false false])\n;; => (true false)"], :macro true, :notes nil, :arglists ["" "x" "x & next"], :doc "Evaluates exprs one at a time, from left to right. If a form\n returns a logical true value, or returns that value and doesn't\n evaluate any of the other expressions, otherwise it returns the\n value of the last expression. (or) returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/or"}, :clojure.core/refer {:added "1.0", :ns "clojure.core", :name "refer", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/refer-clojure :clojure.core/ns], :line 4217, :examples ["user=> (refer 'clojure.string :only '[capitalize trim])\nnil\n\nuser=> (capitalize (trim \" hOnduRAS \"))\n\"Honduras\"" "user=> (refer 'clojure.string\n :rename '{capitalize cap, trim trm})\nWARNING: replace already refers to: #'clojure.core/replace in namespace: user, being replaced by: #'clojure.string/replace\nWARNING: reverse already refers to: #'clojure.core/reverse in namespace: user, being replaced by: #'clojure.string/reverse\nnil\n\nuser=> (cap (trm \" hOnduRAS \"))\n\"Honduras\"\n\nuser=> (join \\, [1 2 3])\n\"1,2,3\"" ";;; `:only' accepts only original names.\n;; wrong\nuser=> (refer 'clojure.string\n :rename '{capitalize cap, trim trm}\n :only '[cap trm])\nIllegalAccessError cap does not exist clojure.core/refer (core.clj:3849)\n\n;; right\nuser=> (refer 'clojure.string\n :rename '{capitalize cap, trim trm}\n :only '[capitalize trim])\nnil\n\n;; work well\nuser=> (cap (trm \" hOnduRAS \"))\n\"Honduras\"\n\n;; and also, cannot use either of them.\nuser=> (join \\, [1 2 3])\nCompilerException java.lang.RuntimeException: Unable to resolve symbol: join in this context, compiling:(NO_SOURCE_PATH:1:1)"], :notes ["Warning: the referral of a var isn't transitive. \n\n`refer` only works with a var's original namespace.\n\nIf you refer `A/foo` from `B`, you can't then refer `B/foo` from `C`.\n\n`foo` it will appear in `B`'s `ns-map`, but not `ns-publics` or `ns-interns`, unintuitively."], :arglists ["ns-sym & filters"], :doc "refers to all public vars of ns, subject to filters.\n filters can include at most one each of:\n\n :exclude list-of-symbols\n :only list-of-symbols\n :rename map-of-fromsymbol-tosymbol\n\n For each public interned var in the namespace named by the symbol,\n adds a mapping from the name of the var to the var to the current\n namespace. Throws an exception if name is already mapped to\n something else in the current namespace. Filters can be used to\n select a subset, via inclusion or exclusion, or to provide a mapping\n to a symbol different from the var's name, in order to prevent\n clashes. Use :use in the ns macro in preference to calling this directly.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/refer"}, :clojure.stacktrace/print-trace-element {:added "1.1", :ns "clojure.stacktrace", :name "print-trace-element", :file "clojure/stacktrace.clj", :type "function", :column 1, :see-alsos nil, :line 26, :examples ["(clojure.stacktrace/print-trace-element (Exception. \"foo\"))\n; \n;=> nil"], :notes nil, :arglists ["e"], :doc "Prints a Clojure-oriented view of one element in a stack trace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.stacktrace/print-trace-element"}, :clojure.core/.. {:added "1.0", :ns "clojure.core", :name "..", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/-> :clojure.core/doto], :line 1659, :examples ["user> (.. \"fooBAR\" (toLowerCase) (contains \"ooba\"))\ntrue\n\n;; use macroexpand to see how the form above will appear\nuser> (macroexpand '(.. \"fooBAR\" (toLowerCase) (contains \"ooba\")))\n(. (. \"fooBAR\" (toLowerCase)) (contains \"ooba\"))" "user=> (.. \"abc\" toUpperCase (equals \"ABC\"))\n;;=> true" ";; With .. you do not need to add a . to your method.\n(.. \"fooBAR\" (toLowerCase) (contains \"ooba\"))\n\n;; Which you do if using -> instead.\n(-> \"fooBAR\" (.toLowerCase) (.contains \"ooba\"))"], :macro true, :notes nil, :arglists ["x form" "x form & more"], :doc "form => fieldName-symbol or (instanceMethodName-symbol args*)\n\n Expands into a member access (.) of the first member on the first\n argument, followed by the next member on the result, etc. For\n instance:\n\n (.. System (getProperties) (get \"os.name\"))\n\n expands to:\n\n (. (. System (getProperties)) (get \"os.name\"))\n\n but is easier to write, read, and understand.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/_.."}, :clojure.core.reducers/fold {:added "1.5", :ns "clojure.core.reducers", :name "fold", :file "clojure/core/reducers.clj", :type "function", :column 1, :see-alsos [:clojure.core/pmap :clojure.core/reduce], :line 51, :examples ["(require '[clojure.core.reducers :as reducers])\n(defn diddly ([xs x] (conj xs x)) ([] []))\n(reducers/fold diddly '(1 2 3 4 5 6)) \n;; [1 2 3 4 5 6] \n\n\n;; CAUTION! This example is buggy, as diddly can NOT be used as combinef\n;; Correct combinef can be `into` as combinef is operating on 2 vectors" ";; word-frequencies on large text\n(require '[clojure.core.reducers :as r] '[clojure.string :as s])\n\n(defn count-occurrences [words]\n (r/fold\n (r/monoid #(merge-with + %1 %2) (constantly {}))\n (fn [m [k cnt]] (assoc m k (+ cnt (get m k 0))))\n (r/map #(vector % 1) words)))\n\n(defn word-count [s]\n (count-occurrences (s/split s #\"\\s+\")))\n\n(def war-and-peace \"http://www.gutenberg.org/files/2600/2600-0.txt\")\n(def book (slurp war-and-peace))\n\n(def freqs (word-count book))\n(freqs \"Andrew\")\n;; 700" ";; One pitfall of clojure.core.reducers/fold is that the reducing function must\n;; take either three or two arguments according to whether the foldable\n;; collection is a map or not!\n\n(require '[clojure.core.reducers :as r])\n\n(def my-vector (vec (range 10000)))\n(def my-map (into {} (map (juxt (comp keyword str) identity)) my-vector))\n\n;; Identity folds for vector and map. Notice the differing arities of reducef.\n\n(->> my-vector\n (r/fold (r/monoid into vector)\n (fn [ret v] (conj ret v))) ; <- arity 2\n (= my-vector))\n\n(->> my-map\n (r/fold (r/monoid merge hash-map)\n (fn [ret k v] (assoc ret k v))) ; <- arity 3\n (= my-map))\n\n;; Caution: this behaviour is not documented. It breaks down as soon as you wrap\n;; the map in a reducer/folder.\n" ";; This example demonstrates how the partition size used to parallelize\n;; fold can be modified. \n(require '[clojure.core.reducers :as r])\n\n(defn simple-fold \n [partition-size]\n (r/fold partition-size\n + ;; function that returns the init value. (x) => 0\n +\n (r/filter odd?\n (r/map inc\n (r/filter number?\n (range 10000))))))\n\n;; Default partition size.\n(simple-fold 512) \n;;=> 25000000\n\n;; Raises the number of elements from coll that will be processed in each partition.\n(simple-fold 1000) \n;; => 25000000\n\n;; Partition each element to be processed separately.\n(simple-fold 1) \n;; =>> 25000000\n\n;; All of the above return the same result, but they utilize different\n;; sized partitions to achieve parallelization."], :notes nil, :arglists ["reducef coll" "combinef reducef coll" "n combinef reducef coll"], :doc "Reduces a collection using a (potentially parallel) reduce-combine\n strategy. The collection is partitioned into groups of approximately\n n (default 512), each of which is reduced with reducef (with a seed\n value obtained by calling (combinef) with no arguments). The results\n of these reductions are then reduced with combinef (default\n reducef). combinef must be associative, and, when called with no\n arguments, (combinef) must produce its identity element. These\n operations may be performed in parallel, but the results will\n preserve order.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.reducers/fold"}, :clojure.core/long-array {:added "1.0", :ns "clojure.core", :name "long-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/longs :clojure.core/int-array :clojure.core/float-array :clojure.core/double-array :clojure.core/boolean-array], :line 5340, :examples [";; create a long array using long-array and show it can be used\n;; with the standard Java Arrays functions binarySearch and fill\n;; note the needed coercions\n\nuser=> (def is (long-array (range 3 20)))\n#'user/is\nuser=> (vec is)\n[3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19]\nuser=> (java.util.Arrays/binarySearch is (long 10))\n7\nuser=> (java.util.Arrays/fill is 3 8 (long 99))\nnil\nuser=> (vec is)\n[3 4 5 99 99 99 99 99 11 12 13 14 15 16 17 18 19]\nuser=>"], :notes nil, :arglists ["size-or-seq" "size init-val-or-seq"], :doc "Creates an array of longs", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/long-array"}, :clojure.core/bit-flip {:added "1.0", :ns "clojure.core", :name "bit-flip", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 1343, :examples ["user=> (bit-flip 2r1011 2)\n15 \n;; 15 = 2r1111\n\n(bit-flip 2r1111 2)\n11 \n;; 11 = 2r1011"], :notes nil, :arglists ["x n"], :doc "Flip bit at index n", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-flip"}, :clojure.core/name {:added "1.0", :ns "clojure.core", :name "name", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/namespace], :line 1589, :examples [";; the name of the keyword is without the ':'\n;; \"str\" will retain the ':'.\n(name :x)\n;;=> \"x\"\n\n(name \"x\")\n;;=> \"x\"\n\n;; returns the symbol name as a string without the namespace.\n(name 'x)\n;;=> \"x\"\n\n(name 'user/x)\n;;=> \"x\"\n\n;; throws an error for invalid types, no nil punning\n(name nil)\n;;=> Error: Doesn't support name:\n\n(name 2)\n;;=> Error: Doesn't support name: 2" ";; Note that for namespaced keywords, `name` only returns the name part.\n(name :my-ns/my-name)\n;;=> \"my-name\"\n\n(name :ns/deep/key)\n;;=> \"deep/key\"\n;; For more info see: `keyword` and `keyword?`...\n(name :'//-,)\n;;=> \"/-\"\n(name :/)\n;;=> \"/\"\n(name ://)\n;;=> RuntimeException Invalid token: :// clojure.lang.Util.runtimeException (Util.java:221)\n;;=> RuntimeException Unmatched delimiter: ) clojure.lang.Util.runtimeException (Util.java:221)\n(name :///)\n;;=> \"//\"\n(namespace :///)\n;;=> \"\"\n\n;; If you want the namespace part, you can use (namespace):\n(namespace :my-ns/my-key)\n;;=> \"my-ns\"\n\n;; Using (str) will give you both parts, but also includes the leading colon.\n(str :my-ns/my-key)\n;;=> \":my-ns/my-key\"" ";; To get full key\n(defn keyname [key] (str (namespace key) \"/\" (name key)))\n\n(keyname :ns/key)\n=> \"ns/key\"\n\n(keyname :ns/deep/key)\n=> \"ns/deep/key\"\n\n;; Just for fun\n(string/replace :key/val #\"^:\" \"\")\n=> \"key/val\"" ";; `name` (and `namespace`) \"knows\" how a keyword was built:\n\n(name (keyword \"a/b\" \"c\"))\n;;=> \"c\"\n\n(name (keyword \"a\" \"b/c\"))\n;;=> \"b/c\"\n" ";; To get the fully qualified name of the keyword, we can use symbol.\n\n(str (symbol :a/b))\n;;=> \"a/b\"\n" "; Preserves capitals\n\n(name :pageQuery)\n; => \"pageQuery\""], :notes nil, :tag "java.lang.String", :arglists ["x"], :doc "Returns the name String of a string, symbol or keyword.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/name"}, :clojure.core/re-seq {:added "1.0", :ns "clojure.core", :name "re-seq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/re-find :clojure.core/re-groups :clojure.core/re-pattern :clojure.core/re-matcher :clojure.core/re-matches :clojure.string/split :clojure.core/subs], :line 4874, :examples ["user=> (re-seq #\"\\d\" \"clojure 1.1.0\")\n(\"1\" \"1\" \"0\")\n" ";; Get a sequence of words out of a string.\nuser=> (re-seq #\"\\w+\" \"mary had a little lamb\")\n(\"mary\" \"had\" \"a\" \"little\" \"lamb\")\n" ";; Parenthesized groups in the regex cause each returned match to be a\n;; vector of matched strings. See re-find for more examples.\nuser=> (def line \" RX pkts:18 err:5 drop:48\")\n#'user/line\n\nuser=> (re-seq #\"(\\S+):(\\d+)\" line)\n([\"pkts:18\" \"pkts\" \"18\"] [\"err:5\" \"err\" \"5\"] [\"drop:48\" \"drop\" \"48\"])\n" ";; Note: See clojure.core/subs for discussion of behavior of substrings\n;; holding onto references of the original strings, which can\n;; significantly affect your memory usage in some cases." ";; separate with Camel case words and digits and\n;; join with single white-space character\n\nuser=> (clojure.string/join \" \" (re-seq #\"[A-Z][a-z]+|[0-9]+\" \"ManishKumar12332\"))\n\"Manish Kumar 12332\"" ";; re-seq requires the string to be in memory. What if the string is in a file\n;; many GB in size? You can roll a \"line-seq of re-seq each line\" or use:\n\n(defn restream-seq\n[^java.util.regex.Pattern re ^java.io.InputStream is]\n (let [s (java.util.Scanner. is)]\n ((fn step []\n (if-let [token (.findInLine s re)]\n (cons token (lazy-seq (step)))\n (when (.hasNextLine s) (.nextLine s) (step)))))))\n\n;; first 10 digits of Pi out of the book (1M available)\n(let [pi-book \"http://www.gutenberg.org/files/50/50.txt\"]\n (with-open [is (.openStream (java.net.URL. pi-book))]\n (doall\n (sequence\n (comp cat (map str) (take 10))\n (restream-seq #\"\\d{10}\" is)))))\n; (\"1\" \"4\" \"1\" \"5\" \"9\" \"2\" \"6\" \"5\" \"3\" \"5\")"], :notes nil, :arglists ["re s"], :doc "Returns a lazy sequence of successive matches of pattern in string,\n using java.util.regex.Matcher.find(), each such match processed with\n re-groups.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/re-seq"}, :clojure.core/aset-byte {:added "1.0", :ns "clojure.core", :name "aset-byte", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 3976, :examples [";; create an array of 10 bytes and set one of the values to 127\n\nuser=> (def bs (byte-array 10))\n#'user/bs\nuser=> (vec bs)\n[0 0 0 0 0 0 0 0 0 0]\nuser=> (aset-byte bs 2 127)\n127\nuser=> (vec bs)\n[0 0 127 0 0 0 0 0 0 0]\nuser=>"], :notes ["See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax."], :arglists ["array idx val" "array idx idx2 & idxv"], :doc "Sets the value at the index/indices. Works on arrays of byte. Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aset-byte"}, :clojure.core.logic/matchu {:ns "clojure.core.logic", :name "matchu", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1744, :examples nil, :macro true, :notes nil, :arglists ["xs & cs"], :doc "Define a committed choice goal. See condu.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/matchu"}, :clojure.core/merge {:added "1.0", :ns "clojure.core", :name "merge", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/merge-with :clojure.core/hash-map :clojure.core/assoc], :line 3041, :examples ["(merge {:a 1 :b 2 :c 3} {:b 9 :d 4})\n;;=> {:d 4, :a 1, :b 9, :c 3}" "(merge {:a 1} nil) ;=> {:a 1}\n(merge nil {:a 1}) ;=> {:a 1}\n(merge nil nil) ;=> nil\n" ";; `merge` can be used to support the setting of default values\n(merge {:foo \"foo-default\" :bar \"bar-default\"} \n {:foo \"custom-value\"})\n;;=> {:foo \"custom-value\" :bar \"bar-default\"}\n\n;; This is useful when a function has a number of options\n;; with default values.\n(defn baz [& options]\n (let [options (merge {:opt1 \"default-1\" :opt2 \"default-2\"} \n (first options))]\n options))\n\n(baz {:opt1 \"custom-1\" :opt3 \"custom-3\"})\n;;=> {:opt3 \"custom-3\" :opt1 \"custom-1 :opt2 \"default-2\"}\n" ";; For recursively merging deeply-nested maps:\n\n(defn deep-merge [v & vs]\n (letfn [(rec-merge [v1 v2]\n (if (and (map? v1) (map? v2))\n (merge-with deep-merge v1 v2)\n v2))]\n (if (some identity vs)\n (reduce #(rec-merge %1 %2) v vs)\n (last vs))))\n\n(deep-merge {:a {:b true}} {:a {:b false}} {:a {:b nil}})\n;; {:a {:b nil}}\n\n(deep-merge {:a 1} nil)\n;; nil ;; note that this isn't consistent with the regular merge function\n\n;; Source: https://gist.github.com/danielpcox/c70a8aa2c36766200a95#gistcomment-2677502" ";; latest comment under above gist provides another\n;; simpler and more consistent version of deep-merge\n;; Source: https://gist.github.com/danielpcox/c70a8aa2c36766200a95#gistcomment-2759497\n\n(defn deep-merge [a & maps]\n (if (map? a)\n (apply merge-with deep-merge a maps)\n (apply merge-with deep-merge maps)))\n\n(deep-merge {:a {:b true}} {:a {:b false}} {:a {:b nil}})\n;; => {:a {:b nil}}\n\n(deep-merge {:a 1} nil)\n;; => {:a 1}\n" "(merge {:x 1 :y 2} {:y 3 :z 4})\n;; => {:x 1, :y 3, :z 4}" ";; Looking at the source code, merge starts with the \n;; original collection and uses conj which adds elements \n;; as is into the collection, so merge can be used\n;; with more than just maps--i.e. using a vector returns a vector.\n\n(merge [:a \"Whoa\"] [:c \"Crash Bandicoot\"])\n;; => [:a \"Whoa\" [:c \"Crash Bandicoot\"]]\n(merge [:a \"Whoa\"] \"Crash Bandicoot\")\n;; => [:a \"Whoa\" \"Crash Bandicoot\"]"], :notes ["### When to use assoc, conj, merge\n\n`assoc`, `conj` & `merge` behave very differently for different data structures\n\nIf you are writing a function that can handle multiple kinds of collections, then your choice will make a big difference.\n\nTreat merge as a maps-only function (its similar to conj for other collections).\n\nMy opinion:\n\n* `assoc` - use when you are 'changing' existing key/value pairs\n* `conj` - use when you are 'adding' new key/value pairs\n* `merge` - use when you are combining two or more maps\n\nRef : https://stackoverflow.com/a/3204346"], :arglists ["& maps"], :doc "Returns a map that consists of the rest of the maps conj-ed onto\n the first. If a key occurs in more than one map, the mapping from\n the latter (left-to-right) will be the mapping in the result.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/merge"}, :clojure.core/byte-array {:added "1.1", :ns "clojure.core", :name "byte-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/bytes :clojure.core/byte], :line 5293, :examples [";; create an array of bytes\n;; and demonstrate that you can use it in the standard Java fill function\n;; note the needed byte coercion in the fill function call\n\nuser=> (def bees (byte-array 10))\n#'user/bees\n\nuser=> (for [i (range 10)](aset-byte bees i (* i i)))\n(0 1 4 9 16 25 36 49 64 81)\n\nuser=> (vec bees)\n[0 1 4 9 16 25 36 49 64 81]\n\nuser=> (java.util.Arrays/fill bees (byte 122))\nnil\nuser=> (vec bees)\n[122 122 122 122 122 122 122 122 122 122]\nuser=>" ";; copied from the example in clojure.core/byte\nuser=> (def x (byte-array [(byte 0x43) \n (byte 0x6c)\n (byte 0x6f)\n (byte 0x6a)\n (byte 0x75)\n (byte 0x72)\n (byte 0x65)\n (byte 0x21)]))\n#'user/x\n\nuser=> (String. x)\n\"Clojure!\"" ";; NOTE: equality uses identity, not value semantics.\nuser=> (= (byte-array 10) (byte-array 10))\nfalse\nuser=> (java.util.Arrays/equals (byte-array 10) (byte-array 10))\ntrue\n\nuser=> (def a (byte-array [(byte 0x43)]))\n#'user/a\nuser=> (def b (byte-array [(byte 0x43)]))\n#'user/b\nuser=> (= a b)\nfalse\nuser=> (java.util.Arrays/equals a b)\ntrue"], :notes ["The maximum size of a byte-array is Integer/MAX_VALUE, as arrays are int-indexed in Java. However, it is possible to pass a value that is larger than this, resulting in a cast that will wrap around. This incorrect usage will not give any indication of error." "To type hint a byte array, use this non-obvious syntax:\n\n
"], :notes nil, :tag "java.lang.String", :arglists ["s"], :doc "Removes all trailing newline \\n or return \\r characters from\n string. Similar to Perl's chomp.", :library-url "https://github.com/clojure/clojure", :href "/clojure.string/trim-newline"}, :clojure.core/accessor {:added "1.0", :ns "clojure.core", :name "accessor", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/get], :line 4071, :examples ["(defstruct car-struct :make :model :year :color)\n\n(def car (struct car-struct \"Toyota\" \"Prius\" 2010))\n\n(def make (accessor car-struct :make))\n\nuser=> (make car) ; Same as both (car :make) and (:make car)\n\"Toyota\" \n\n"], :notes nil, :arglists ["s key"], :doc "Returns a fn that, given an instance of a structmap with the basis,\n returns the value at the key. The key must be in the basis. The\n returned function should be (slightly) more efficient than using\n get, but such use of accessors should be limited to known\n performance-critical areas.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/accessor"}, :clojure.core/char? {:added "1.0", :ns "clojure.core", :name "char?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/char], :line 153, :examples ["user=> (char? \\a)\ntrue\n\nuser=> (char? 22)\nfalse\n\nuser=> (char? \"a\")\nfalse\n\nuser=> (char? (first \"abc\"))\ntrue"], :notes nil, :arglists ["x"], :doc "Return true if x is a Character", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/char_q"}, :clojure.core.logic/-fnm {:ns "clojure.core.logic", :name "-fnm", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1628, :examples nil, :macro true, :notes nil, :arglists ["fn-gen t as & cs"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/-fnm"}, :clojure.core.logic.fd/sorted-set->domain {:ns "clojure.core.logic.fd", :name "sorted-set->domain", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 148, :examples nil, :notes nil, :arglists ["s"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/sorted-set->domain"}, :clojure.core.logic/force-ans {:ns "clojure.core.logic", :name "force-ans", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2273, :examples nil, :notes nil, :arglists ["x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/force-ans"}, :clojure.xml/startparse-sax {:ns "clojure.xml", :name "startparse-sax", :file "clojure/xml.clj", :type "function", :column 1, :see-alsos nil, :line 75, :examples nil, :notes nil, :arglists ["s ch"], :library-url "https://github.com/clojure/clojure", :href "/clojure.xml/startparse-sax"}, :clojure.core/assoc! {:added "1.1", :ns "clojure.core", :name "assoc!", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/dissoc! :clojure.core/transient :clojure.core/conj! :clojure.core/pop! :clojure.core/disj! :clojure.core/persistent!], :line 3368, :examples [";; The key concept to understand here is that transients are \n;; not meant to be `bashed in place`; always use the value \n;; returned by either assoc! or other functions that operate\n;; on transients.\n\n(defn merge2\n \"An example implementation of `merge` using transients.\"\n [x y]\n (persistent! (reduce\n (fn [res [k v]] (assoc! res k v))\n (transient x)\n y)))\n\n;; Why always use the return value, and not the original? Because the return\n;; value might be a different object than the original. The implementation\n;; of Clojure transients in some cases changes the internal representation\n;; of a transient collection (e.g. when it reaches a certain size). In such\n;; cases, if you continue to try modifying the original object, the results\n;; will be incorrect. See one example for conj! that contains a detailed\n;; example of a wrong result that can occur if you do not use its return value.\n\n;; Think of transients like persistent collections in how you write code to\n;; update them, except unlike persistent collections, the original collection\n;; you passed in should be treated as having an undefined value. Only the return\n;; value is predictable." "(def m (assoc! (transient {}) :x 1 :y 2))\n\n(:x m)\n;; 1\n\n(:y m)\n;; 2\n\n(count m)\n;; 2"], :notes nil, :arglists ["coll key val" "coll key val & kvs"], :doc "When applied to a transient map, adds mapping of key(s) to\n val(s). When applied to a transient vector, sets the val at index.\n Note - index must be <= (count vector). Returns coll.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/assoc!"}, :clojure.core.async/partition {:ns "clojure.core.async", :name "partition", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 1138, :examples nil, :deprecated "0.1.319.0-6b1aca-alpha", :notes nil, :arglists ["n ch" "n ch buf-or-n"], :doc "Deprecated - this function will be removed. Use transducer instead", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/partition"}, :clojure.core/>= {:added "1.0", :ns "clojure.core", :name ">=", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/<= :clojure.core/> :clojure.core/=], :line 1085, :examples ["user=> (>= 2 1)\ntrue\nuser=> (>= 2 2)\ntrue\nuser=> (>= 1 2)\nfalse\nuser=> (>= 6 5 4 3 2)\ntrue" "user=> (>= 1/2 1/3 1/4)\ntrue\n\nuser=> (<= 1/4 1/3 1/4)\nfalse\n\nuser=> (>= 1/2 0.5)\ntrue"], :notes nil, :arglists ["x" "x y" "x y & more"], :doc "Returns non-nil if nums are in monotonically non-increasing order,\n otherwise false.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/>="}, :clojure.core.logic/unify-with-map* {:ns "clojure.core.logic", :name "unify-with-map*", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 911, :examples nil, :notes nil, :arglists ["u v s"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/unify-with-map*"}, :clojure.core/rest {:added "1.0", :ns "clojure.core", :name "rest", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/next :clojure.core/first :clojure.core/drop :clojure.core/pop :clojure.core/nthrest :clojure.core/nthnext], :line 66, :examples ["(rest [1 2 3 4 5]) ;;=> (2 3 4 5)\n(rest [\"a\" \"b\" \"c\" \"d\" \"e\"]) ;;=> (\"b\" \"c\" \"d\" \"e\")" ";; For the most part rest must take a collection as its argument.\n;; It always returns a seq.\n(rest '())\n;;=> ()" ";; There is one case where the input is not required to be a collection.\n;; But, 'rest' still returns a list.\n(rest nil)\n;;=> ()" ";; A simple (re-)implementation of 'map' using 'rest' for recursing over a collection. \n;; Note that (seq coll) is used as the test.\n(defn my-map [func coll]\n (when-let [s (seq coll)]\n (cons (func (first s))\n (my-map func (rest s)))))\n\n(my-map #(* % %) [2 3 5 7 11 13])\n;;=> (4 9 25 49 121 169)" ";; Any collection can be used\n(rest '(1 2 3 4 5)) ;;=> (2 3 4 5)\n(rest [1 2 3 4 5]) ;;=> (2 3 4 5)\n(rest #{1 2 3 4 5}) ;;=> (2 3 4 5)\n\n(rest {1 nil 2 nil 3 nil 4 nil 5 nil}) ;;=> ([2 nil] [3 nil] [4 nil] [5 nil])" ";; Difference between next and rest:\n(rest [:a])\n;; => ()\n(next [:a])\n;; => nil\n\n(rest [])\n;; => ()\n(next [])\n;; => nil\n\n(rest nil)\n;; => ()\n(next nil)\n;; => nil"], :notes ["rest is generally preferred over [next](../clojure.core/next). See the Clojure.org documentation on writing [lazy](http://clojure.org/lazy) functions.\r\n\r\nAlso, the topic is covered on StackOverflow.com: [rest vs. next](http://stackoverflow.com/questions/4288476/clojure-rest-vs-next).\r\n"], :tag "clojure.lang.ISeq", :arglists ["coll"], :doc "Returns a possibly empty seq of the items after the first. Calls seq on its\n argument.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/rest"}, :clojure.core.logic.fd/binops {:ns "clojure.core.logic.fd", :name "binops", :file "clojure/core/logic/fd.clj", :type "var", :column 1, :see-alsos nil, :line 1111, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/binops"}, :clojure.core/dissoc! {:added "1.1", :ns "clojure.core", :name "dissoc!", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/assoc! :clojure.core/conj!], :line 3381, :examples [";; dissoc! works on a transient map\n\n;; WARNING: Below is an example of what is called \"bashing in place\" of\n;; a transient, and is _NOT_ the correct way to use transients. See assoc!\n;; examples for some discussion of the reason.\n;; Also see one example for conj! that contains a detailed example\n;; of a wrong result that can occur if you do not use its return value.\n\n(let [my-map (transient {:x 1 :y 2 :z 3})]\n (dissoc! my-map :x) ; mistake is to use my-map below, not dissoc! return val\n (persistent! my-map)) ; returns persistent map {:y 2 :z 3}\n\n\n;; Here is a correct way to do the operation described above:\n\n(let [my-map (transient {:x 1 :y 2 :z 3})\n x (dissoc! my-map :x)] ; after this, don't use my-map again, only x\n (persistent! x)) ; returns persistent map {:y 2 :z 3}"], :notes nil, :arglists ["map key" "map key & ks"], :doc "Returns a transient map that doesn't contain a mapping for key(s).", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/dissoc!"}, :clojure.core.logic/answer-cache {:ns "clojure.core.logic", :name "answer-cache", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1844, :examples nil, :notes nil, :arglists [""], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/answer-cache"}, :clojure.core/floats {:added "1.0", :ns "clojure.core", :name "floats", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/float-array], :line 5368, :examples [";; float-array will convert where possible\n(float-array [1 2 3]);; => [1.0, 2.0, 3.0]\n\n;; floats will not\n(try (floats [1 2 3])\n (catch ClassCastException e (ex-message e)))\n;; => \"clojure.lang.PersistentVector cannot be cast to [F\"" ";; Casting avoids expensive reflection, so to see the benefit, enable warning:\n(set! *warn-on-reflection* true)\n\n;; We'll def a float-array but won't type-hint the var:\n(def my-array (float-array [10.0 20.0 30.0 40.0 50.0 60.0]))\n\n;; and try to amap over it without using `floats` or type hinting:\n(amap my-array i _ (unchecked-float (unchecked-inc (aget my-array i))))\n;; Reflection warning… call to static method alength on clojure.lang.RT can't be resolved (argument types: unknown).\n;; Reflection warning… call to static method aclone on clojure.lang.RT can't be resolved (argument types: unknown).\n;; Reflection warning… call to static method aget on clojure.lang.RT can't be resolved (argument types: unknown, int).\n;; Reflection warning… call to static method aset on clojure.lang.RT can't be resolved (argument types: unknown, int, float).\n;; => [11.0, 21.0, 31.0, 41.0, 51.0, 61.0]\n\n;; We can use `floats` to avoid reflection:\n(amap (floats my-array) i _ (unchecked-float (unchecked-inc (aget (floats my-array) i))))\n;; => [11.0, 21.0, 31.0, 41.0, 51.0, 61.0]\n\n;; Just as we can type hint in place:\n(amap ^floats my-array i _ (unchecked-float (unchecked-inc (aget ^floats my-array i))))\n;; => [11.0, 21.0, 31.0, 41.0, 51.0, 61.0]\n\n;; Or type hint the var:\n(def ^\"[F\" my-array (float-array [10 20 30 40 50 60]))\n(amap my-array i _ (unchecked-float (unchecked-inc (aget my-array i))))\n;; => [11.0, 21.0, 31.0, 41.0, 51.0, 61.0]\n"], :notes nil, :arglists ["xs"], :doc "Casts to float[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/floats"}, :clojure.core/descendants {:added "1.0", :ns "clojure.core", :name "descendants", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/ancestors], :line 5614, :examples [";; simple example a toy poodle is a poodle is a dog is an animal\n\nuser=> (derive ::dog ::animal)\nnil\nuser=> (derive ::poodle ::dog)\nnil\nuser=> (derive ::toy_poodle ::poodle)\nnil\nuser=> (descendants ::animal)\n#{:user/toy_poodle :user/poodle :user/dog}\nuser=>" ";; You can combine `descendants` with `parents` to only get the immediate children.\n\n(filter #(contains? (parents h %) tag)\n (descendants h tag))"], :notes nil, :arglists ["tag" "h tag"], :doc "Returns the immediate and indirect children of tag, through a\n relationship established via derive. h must be a hierarchy obtained\n from make-hierarchy, if not supplied defaults to the global\n hierarchy. Note: does not work on Java type inheritance\n relationships.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/descendants"}, :clojure.core/hash-set {:added "1.0", :ns "clojure.core", :name "hash-set", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/sorted-set :clojure.core/set], :line 389, :examples [";; Any duplicates are squashed (no error)\n(hash-set 1 2 1 3 1 4 1 5)\n;;=> #{1 4 3 2 5}\n\n;; There is an equivalent reader macro '#{...}'\n(= (hash-set :c :a :b) #{:b :a :c})\n;;=> true \n\n;; A string can be treated as a sequence to produce\n;; a set of the characters found in the string.\n(apply hash-set (seq \"Lorem ipsum dolor sit amet\"))\n;;=> #{\\space \\a \\d \\e \\i \\L \\l \\m \\o \\p \\r \\s \\t \\u}\n\n;; or simply (see \"set\")\n(set \"Lorem ipsum dolor sit amet\")\n;;=> #{\\space \\a \\d \\e \\i \\L \\l \\m \\o \\p \\r \\s \\t \\u}" ";; The \"equivalent\" reader macro throws an error when receiving duplicates, however:\n#{ 1 2 1 }\n;;=> Duplicate key: 1"], :notes nil, :arglists ["" "& keys"], :doc "Returns a new hash set with supplied keys. Any equal keys are\n handled as if by repeated uses of conj.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/hash-set"}, :clojure.core/ref-history-count {:added "1.1", :ns "clojure.core", :name "ref-history-count", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/ref-min-history :clojure.core/ref-max-history :clojure.core/ref], :line 2463, :examples ["user=> (def store (ref {}))\n#'user/store\nuser=> (ref-history-count store)\n0\nuser=> (ref-max-history store)\n10\nuser=> (ref-min-history store)\n0" ";; ref must have a :min-history of >0 to use the history queue\n\n(def r (ref 42 :min-history 2));; => #'user/r\n(ref-history-count r);; => 0\n(dosync (alter r inc));; => 43\n(ref-history-count r);; => 1\n(dosync (alter r inc));; => 44\n(ref-history-count r);; => 2"], :notes nil, :arglists ["ref"], :doc "Returns the history count of a ref", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ref-history-count"}, :clojure.core.logic.pldb/db-fact {:ns "clojure.core.logic.pldb", :name "db-fact", :file "clojure/core/logic/pldb.clj", :type "function", :column 1, :see-alsos nil, :line 79, :examples nil, :notes nil, :arglists ["db rel & args"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/db-fact"}, :clojure.core/disj {:added "1.0", :ns "clojure.core", :name "disj", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/dissoc :clojure.core/disj! :clojure.set/difference :clojure.core/conj], :line 1518, :examples ["user=> (disj #{1 2 3}) ; disjoin nothing \n#{1 2 3} \n\nuser=> (disj #{1 2 3} 2) ; disjoin 2\n#{1 3} \n\nuser=> (disj #{1 2 3} 4) ; disjoin non-existent item\n#{1 2 3} \n\nuser=> (disj #{1 2 3} 1 3) ; disjoin several items at once\n#{2}" "user=> (apply disj #{1 2 3} [1 3]) ; disjoin keys in a coll\n#{2}"], :notes nil, :arglists ["set" "set key" "set key & ks"], :doc "disj[oin]. Returns a new set of the same (hashed/sorted) type, that\n does not contain key(s).", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/disj"}, :clojure.core.logic/occurs-check {:ns "clojure.core.logic", :name "occurs-check", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 216, :examples nil, :notes nil, :arglists ["s u v"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/occurs-check"}, :clojure.core.logic.pldb/db-retractions {:ns "clojure.core.logic.pldb", :name "db-retractions", :file "clojure/core/logic/pldb.clj", :type "function", :column 1, :see-alsos nil, :line 128, :examples nil, :notes nil, :arglists ["base-db & retractions"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/db-retractions"}, :clojure.core.async/untap* {:ns "clojure.core.async", :name "untap*", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["m ch"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/untap*"}, :clojure.java.io/input-stream {:added "1.2", :ns "clojure.java.io", :name "input-stream", :file "clojure/java/io.clj", :type "function", :column 1, :see-alsos [:clojure.java.io/reader :clojure.java.io/output-stream :clojure.java.io/IOFactory :clojure.core/with-open :clojure.java.io/make-input-stream], :line 121, :examples ["(require '(clojure.java [io :as io]))\n\n;; A common task it to load a file into a byte array.\n(defn file->bytes [file]\n (with-open [xin (io/input-stream file)\n xout (java.io.ByteArrayOutputStream.)]\n (io/copy xin xout)\n (.toByteArray xout)))\n;=> #'boot.user/file->bytes\n\n(file->bytes (io/file \"/foo-pc\" \"junk.txt\"))\n;=> #object[\"[B\" 0x7813db81 \"[B@7813db81\"]\n\n\n" "(require '[clojure.java.io :as io])\n\n;; these return a java.io.BufferedInputStream for a local file:\n(io/input-stream \"file.txt\")\n(io/input-stream \"/home/user/file.txt\")\n(io/input-stream \"file:///home/user/file.txt\")\n(io/input-stream (java.io.File. \"/home/user/file.txt\"))\n(io/input-stream (java.io.FileInputStream. \"file.txt\"))\n(io/input-stream (java.net.URL. \"file:///home/user/file.txt\"))\n(io/input-stream (java.net.URI. \"file:///home/user/file.txt\"))\n\n;; these return a java.io.BufferedInputStream for a remote resource:\n(io/input-stream \"http://clojuredocs.org/\")\n(io/input-stream (java.net.URL. \"http://clojuredocs.org\"))\n(io/input-stream (java.net.URI. \"http://clojuredocs.org\"))\n(let [socket (java.net.Socket. \"clojuredocs.org\" 80)\n out (java.io.PrintStream. (.getOutputStream socket))]\n (.println out \"GET /index.html HTTP/1.0\")\n (.println out \"Host: clojuredocs.org\\n\\n\")\n (io/input-stream socket))\n\n;; these return a java.io.BufferedInputStream from an in-memory source:\n(io/input-stream (.getBytes \"text\"))\n(io/input-stream (java.io.ByteArrayInputStream. (.getBytes \"text\")))\n(io/input-stream (byte-array [116 101 120 116]))\n"], :notes nil, :tag "java.io.InputStream", :arglists ["x & opts"], :doc "Attempts to coerce its argument into an open java.io.InputStream.\n Default implementations always return a java.io.BufferedInputStream.\n\n Default implementations are defined for InputStream, File, URI, URL,\n Socket, byte array, and String arguments.\n\n If the argument is a String, it tries to resolve it first as a URI, then\n as a local file name. URIs with a 'file' protocol are converted to\n local file names.\n\n Should be used inside with-open to ensure the InputStream is properly\n closed.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/input-stream"}, :clojure.core.logic/add-var {:ns "clojure.core.logic", :name "add-var", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 178, :examples nil, :notes nil, :arglists ["cs x c"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/add-var"}, :clojure.core/cons {:added "1.0", :ns "clojure.core", :name "cons", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/conj :clojure.core/seq], :line 22, :examples [";; prepend 1 to a list\n(cons 1 '(2 3 4 5 6))\n;;=> (1 2 3 4 5 6)\n\n;; notice that the first item is not expanded\n(cons [1 2] [4 5 6])\n;;=> ([1 2] 4 5 6)" ";; may return results of different types but always a seq\n(map (juxt identity type seq? list?)\n [(cons 1 nil)\n (cons 1 '())])\n;; => ([(1) clojure.lang.PersistentList true true] \n;; [(1) clojure.lang.Cons true false])\n" ";; Cons new-element into nested structures \"cons-in\"\n\n(def db {:users [{:name \"Eduardo\"}]})\n(def new-element {:name \"Eva\"})\n\n(assoc db :users (cons new-element (:users db)))\n;; => {:users ({:name \"Eva\"} {:name \"Eduardo\"})}" "(defn zeros [] \n (lazy-seq (cons 0 (zeros))))\n;; \"cons\" does not realize second parameter, \n;; opening the world for recursive functions that create lazy sequences\n\n(first (zeroes))\n0\n\n(first (rest (zeroes)))\n0\n\n(first (rest (rest (zeroes))))\n0\n\n;; example stolen from youtuber : \n;; https://youtu.be/iaph8m63HQw?list=PLAC43CFB134E85266" ";; this example might not work\n;; conj behave differently with \"set\" like structures.\n\n(def a-set #{1 2 3})\n\n(conj a-set 3) ;; will add 3 to the set\n;; => #{1 3 2}\n\n(conj a-set 4)\n;; => #{1 4 3 2}\n\n(first (conj a-set 4))\n;; => 1"], :notes ["useful for creating lazy sequences, because it does not need to realize the param \"seq\" (it just appends the whole thing to param \"x\"\n\nhttp://stackoverflow.com/questions/12389303/clojure-cons-vs-conj-with-lazy-seq"], :arglists ["x seq"], :doc "Returns a new seq where x is the first element and seq is\n the rest.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/cons"}, :clojure.core/counted? {:added "1.0", :ns "clojure.core", :name "counted?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/bounded-count], :line 6262, :examples ["user=> (counted? [:a :b :c])\ntrue\n\nuser=> (counted? '(:a :b :c))\ntrue\n\nuser=> (counted? {:a 1 :b 2 :c 3})\ntrue\n\nuser=> (counted? #{:a :b :c})\ntrue\n\nuser=> (counted? \"asdf\")\nfalse\n\nuser=> (counted? (into-array Integer/TYPE [1 2 3]))\nfalse" ";; Lazy sequences are not counted?\n(counted? (map inc (range 5)))\n;;=> false"], :notes nil, :arglists ["coll"], :doc "Returns true if coll implements count in constant time", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/counted_q"}, :clojure.core.async/promise-chan {:ns "clojure.core.async", :name "promise-chan", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos [:clojure.core.async/chan], :line 90, :examples [";; You can use promise-chan to program in an async style very similar\n;; to promise programming\n\n(defn inc-async\n \"Increment num asynchronously, will pretend like it can take\n between 0 and 2 seconds to do so for demo purpose, as if this\n was a remote call. Returns a promise-chan which will have the\n result delivered to it when completed.\"\n [num]\n (let [ret (promise-chan)]\n (go\n ( 11\n\n;; Similar to `promise` and `future`, after a value has been delivered to the\n;; promise-chan, taking from it will continue to return that value immediately\n;; over and over\n\n(def inc-promise (inc-async 10))\n\n( 11\n( 11\n( 11\n\n;; That means unlike other channels, only one value can be put into a promise-chan, and \n;; taking from it afterwards will always return that value which is cached by the \n;; promise-chan, similar to what a promise or a future would.\n\n;; This makes using `promise-chan` very similar to async/await style of programming.\n;; You can create an async function by having a function return a promise-chan\n;; where it will `put!` (deliver) the value to it asynchronously as I showed with\n;; inc-async.\n\n;; You can then use `go` blocks like you'd mark `async` functions, and inside them\n;; use `\n{:message \"Hello\"}\n\n;; exceptions default datafy impl is `Throwable->map`\n(datafy (ex-info \"An Exception\" {:msg \"something went wrong\"}))\n{:cause \"An Exception\",\n :data {:msg \"something went wrong\"}\n :via\n [{:type clojure.lang.ExceptionInfo,\n :message \"An Exception\",\n :data {:msg \"something went wrong\"},\n :at [user$eval16337 invokeStatic \"form-init3462716552974711523.clj\" 120]}],\n :trace\n [[user$eval16337 invokeStatic \"form-init3462716552974711523.clj\" 120]\n [user$eval16337 invoke \"form-init3462716552974711523.clj\" 120]\n [clojure.lang.Compiler eval \"Compiler.java\" 7181]\n ,,,\n [clojure.lang.AFn run \"AFn.java\" 22]\n [java.lang.Thread run \"Thread.java\" 833]]}" ";; add a (bogus) Datafy implementation for java.util.Date\n\n(require '[clojure.core.protocols :as p])\n(require '[clojure.datafy :as d])\n\n(extend-protocol p/Datafiable\n java.util.Date\n (datafy [d]\n {:type 'Date\n :timestamp (.getTime d)}))\n\n(d/datafy (java.util.Date.))\n;;=> {:type Date, :timestamp 1641145865991}\n" ";; adding a data representation to a java.io.File\n\n(require '[clojure.core.protocols :as p])\n(require '[clojure.datafy :as d])\n\n(extend-protocol p/Datafiable\n java.io.File\n (datafy [f]\n ;; keep the file-object as the metadata\n\n ;; This actually doesn't work\n ;; with-meta throws following exception\n ;; class java.io.File cannot be cast to class clojure.lang.IPersistentMap\n ;; see with-meta docs -> https://clojuredocs.org/clojure.datafy/datafy\n (with-meta \n {:exists (.exists f)\n :length (.length f)\n :last-modified (.lastModified f)\n :path (.toString f)}\n f)))\n\n(d/datafy (java.io.File. \"/home/alfred/todo.txt\"))\n;;=> {:exists true,\n;; :length 28850,\n;; :last-modified 1641082627553,\n;; :path \"/home/alfred/todo.txt\"}"], :notes nil, :arglists ["x"], :doc "Attempts to return x as data.\n datafy will return the value of clojure.core.protocols/datafy. If\n the value has been transformed and the result supports\n metadata, :clojure.datafy/obj will be set on the metadata to the\n original value of x, and :clojure.datafy/class to the name of the\n class of x, as a symbol.", :library-url "https://github.com/clojure/clojure", :href "/clojure.datafy/datafy"}, :clojure.core.async/unique {:ns "clojure.core.async", :name "unique", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 1120, :examples ["()"], :deprecated "0.1.319.0-6b1aca-alpha", :notes nil, :arglists ["ch" "ch buf-or-n"], :doc "Deprecated - this function will be removed. Use transducer instead", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/unique"}, :clojure.template/do-template {:ns "clojure.template", :name "do-template", :file "clojure/template.clj", :type "macro", :column 1, :see-alsos nil, :line 45, :examples [";; Because it is expanded at compile time, you can also use special \n;; forms as in full blown macros:\n\nuser=> (use 'clojure.template)\nuser=> (do-template [a b] (def a b) d 1 e 2 f 3)\n#'user/f\nuser=> d\n1\nuser=> e\n2\nuser=> f\n3\n\n;; and if you are curious why\nuser=> (use 'clojure.walk)\nuser=> (macroexpand-all '(do-template [a b] (def a b) d 1 e 2 f 3))\n(do (def d 1) (def e 2) (def f 3))\n\n"], :macro true, :notes nil, :arglists ["argv expr & values"], :doc "Repeatedly copies expr (in a do block) for each group of arguments\n in values. values are automatically partitioned by the number of\n arguments in argv, an argument vector as in defn.\n\n Example: (macroexpand '(do-template [x y] (+ y x) 2 4 3 5))\n ;=> (do (+ 4 2) (+ 5 3))", :library-url "https://github.com/clojure/clojure", :href "/clojure.template/do-template"}, :clojure.core.logic.fd/distinctc {:ns "clojure.core.logic.fd", :name "distinctc", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 1042, :examples nil, :notes nil, :arglists ["v*"], :doc "The real distinct constraint. v* can be seq of logic vars and\n values or it can be a logic var itself. This constraint does not \n run until v* has become ground. When it has become ground we group\n v* into a set of logic vars and a sorted set of known singleton \n values. We then construct the individual constraint for each var.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/distinctc"}, :clojure.core/with-redefs {:added "1.3", :ns "clojure.core", :name "with-redefs", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/with-redefs-fn :clojure.core/alter-var-root :clojure.core/with-bindings], :line 7518, :examples ["user=> [(type []) (class [])]\n[clojure.lang.PersistentVector clojure.lang.PersistentVector]\n\nuser=> (with-redefs [type (constantly java.lang.String)\n class (constantly 10)]\n [(type [])\n (class [])])\n[java.lang.String 10]" "(ns http)\n\n(defn post [url]\n {:body \"Hello world\"})\n\n(ns app\n (:require [clojure.test :refer [deftest is run-tests]]))\n\n(deftest is-a-macro\n (with-redefs [http/post (fn [url] {:body \"Goodbye world\"})]\n (is (= {:body \"Goodbye world\"} (http/post \"http://service.com/greet\")))))\n\n(run-tests) ;; test is passing" ";; be careful, with-redefs can permanently change a var if applied concurrently:\n\nuser> (defn ten [] 10)\n#'user/ten\nuser> (doall (pmap #(with-redefs [ten (fn [] %)] (ten)) (range 20 100)))\n...\nuser> (ten)\n79" ";; redefine var\n(def foo 1)\n#'user/foo\n(with-redefs [foo 2] foo)\n2\n\n;; redefine private var\n(ns first)\n(def ^:private foo 1)\n#'first/foo\n\n(ns second)\n(with-redefs [first/foo 2] @#'first/foo)\n2\n\n;; @#' is the macros of (deref (var first/foo))\n(with-redefs [first/foo 2] (deref (var first/foo))\n2" ";; Vars return to their previous value outside of `with-redefs` body\n\n(with-redefs [first last] (first [1 2]))\n;; => 2\n((with-redefs [first last] #(first [1 2])))\n;; => 1" ";; Macros are not stored in vars, so `with-redefs` doesn't work on them.\n(defmacro a [] 1)\n=> #'user/a\n(a)\n=> 1\n(with-redefs [a (constantly 2)] (a))\n=> 1"], :macro true, :notes nil, :arglists ["bindings & body"], :doc "binding => var-symbol temp-value-expr\n\n Temporarily redefines Vars while executing the body. The\n temp-value-exprs will be evaluated and each resulting value will\n replace in parallel the root value of its Var. After the body is\n executed, the root values of all the Vars will be set back to their\n old values. These temporary changes will be visible in all threads.\n Useful for mocking out functions during testing.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/with-redefs"}, :clojure.core/hash {:added "1.0", :ns "clojure.core", :name "hash", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/get :clojure.core/hash-ordered-coll :clojure.core/hash-unordered-coll], :line 5165, :examples ["user=> (hash \"a\")\n1455541201\nuser=> (.hashCode \"a\") ; notice that this is different than (hash \"a\")\n97\nuser=> (hash 1)\n1392991556\nuser=> (.hashCode 1) ; notice that this is different than (hash 1)\n1\nuser=> (hash nil)\n0\nuser=> (hash [1 2 3])\n30817\nuser=> (hash [1 2 3 4])\n955331" ";; In most cases, hash is _consistent_ with =, meaning that for two values x, y,\n;; if (= x y), then (= (hash x) (hash y)). This is a property of hash that\n;; is relied upon for hash-based lookup of keys in maps and\n;; elements in sets to work correctly.\n\n;; There are some pairs of Java objects x, y where even though (= x y) is true,\n;; (= (hash x) (hash y)) is _not_ true.\n\n;; Search for the word \"consistent\" in this article for some categories of such\n;; objects: https://clojure.org/guides/equality\n\n;; In particular, the section titled \"Equality and hash\":\n;; https://clojure.org/guides/equality#equality_and_hash" ";; Equality is measured by the content\n;; Hashes of lists AND vectors are equal by content\n=> (= (hash '(1 2 3)) (hash [1 2 3]))\ntrue\n\n;; Also works with clojure-\"Objects\" like LazySeq\n=> (= (hash [1 2 3]) (hash (map identity [1 2 3])))\ntrue\n\n;; but not with sets\n=> (= (hash [1 2 3]) (hash (set [1 2 3])))\nfalse"], :notes ["Despite what the doc-string says values returned by `(hash)` are different from `(.hashCode)` for more than just `Integer`, `Short`, `Byte` and Clojure collections.\n\nThe list also includes: Keywords, Symbols, Functions, Sequences, `String`, `Long` and `BigInteger` (as of Clojure 1.7.0)."], :arglists ["x"], :doc "Returns the hash code of its argument. Note this is the hash code\n consistent with =, and thus is different than .hashCode for Integer,\n Short, Byte and Clojure collections.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/hash"}, :clojure.core.logic.fd/->MultiIntervalFD {:ns "clojure.core.logic.fd", :name "->MultiIntervalFD", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 477, :examples nil, :notes nil, :arglists ["min max is"], :doc "Positional factory function for class clojure.core.logic.fd.MultiIntervalFD.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/->MultiIntervalFD"}, :clojure.core/bit-clear {:added "1.0", :ns "clojure.core", :name "bit-clear", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/bit-set], :line 1331, :examples ["user=> (bit-clear 2r1011 3) ; index is 0-based\n3 \n;; 3 = 2r0011\n\n;; the same in decimal\nuser=> (bit-clear 11 3) \n3"], :notes nil, :arglists ["x n"], :doc "Clear bit at index n", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-clear"}, :clojure.set/rename-keys {:added "1.0", :ns "clojure.set", :name "rename-keys", :file "clojure/set.clj", :type "function", :column 1, :see-alsos [:clojure.set/rename], :line 78, :examples ["user=> (rename-keys {:a 1, :b 2} {:a :new-a, :b :new-b})\n{:new-a 1, :new-b 2}\n\n\n;; The behavior when the second map contains a key not in the first is interesting.\n;; I suspect you shouldn't depend on it. (Clojure 1.1 - no longer happens in 1.2.1)\n\nuser=> (rename-keys {:a 1} {:b :new-b})\n{ :a 1, :new-b nil}\n" ";; You need to be careful about key collisions. You probably shouldn't \n;; depend on the exact behavior.\nuser=> (rename-keys {:a 1 :b 2} {:a :b})\n{:b 1}\n" ";; Key collisions no longer reproducible in Clojure 1.10.0\nuser=> (rename-keys {:a 1 :b 2} {:a :b :b :a})\n{:b 1, :a 2}" ";; Note that rename-keys in the clojure.set namespace. In order to use it, you\n;; must require the namespace\n\nuser=> (require '[clojure.set :as set])\nuser=> (set/rename-keys {:a 1 :b 2} {:a :new-a})\n=> {:new-a 1 :b 2}\n\n;; Alternatively, you can use rename-keys by simply doing clojure.set/rename-keys" "doesn't works on nested (as one might expect)\nuser=> \n(rename-keys\n {:user {:name \"john\"}}\n {:user {:name :nickname}}) => {{:name :nickname} {:name \"john\"}}"], :notes nil, :arglists ["map kmap"], :doc "Returns the map with the keys in kmap renamed to the vals in kmap", :library-url "https://github.com/clojure/clojure", :href "/clojure.set/rename-keys"}, :clojure.core.reducers/foldcat {:added "1.5", :ns "clojure.core.reducers", :name "foldcat", :file "clojure/core/reducers.clj", :type "function", :column 1, :see-alsos [:clojure.core.reducers/fold], :line 281, :examples [";; Worth remembering that parallel fold in Clojure is enabled for: \n;; vectors, maps and clojure.core.reducers.Cat objects.\n;; r/foldcat returns a \"Cat\", so it can be parallel folded again:\n\n(r/fold + \n (r/foldcat \n (r/filter even? \n (r/foldcat \n (r/map inc (into [] (range 100000)))))))\n;; 2500050000" ";; One non-obvious thing about clojure.core.reducers/foldcat is its return type,\n;; which is either clojure.core.reducers.Cat or java.util.ArrayList (!)\n;; depending on the size of the source collection.\n\n(require '[clojure.core.reducers :as r])\n\n(def small-vector (vec (range 10)))\n(def big-vector (vec (range 100000)))\n\n(type (r/foldcat (r/filter odd? small-vector))) ;;=> java.util.ArrayList\n(type (r/foldcat (r/filter odd? big-vector))) ;;=> clojure.core.reducers.Cat\n\n;; Both return types are suited for further reduce-like processing, but they are\n;; not general-purpose data types like proper Clojure collections.\n"], :notes nil, :arglists ["coll"], :doc "Equivalent to (fold cat append! coll)", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.reducers/foldcat"}, :clojure.spec.alpha/assert* {:ns "clojure.spec.alpha", :name "assert*", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 1959, :examples nil, :notes nil, :arglists ["spec x"], :doc "Do not call this directly, use 'assert'.", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/assert*"}, :clojure.core.async/unmix-all {:ns "clojure.core.async", :name "unmix-all", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos [:clojure.core.async/unmix :clojure.core.async/admix :clojure.core.async/mix :clojure.core.async/toggle :clojure.core.async/solo-mode], :line 816, :examples nil, :notes nil, :arglists ["mix"], :doc "removes all inputs from the mix", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/unmix-all"}, :clojure.core/short {:added "1.0", :ns "clojure.core", :name "short", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/int :clojure.core/byte :clojure.core/shorts :clojure.core/short-array :clojure.core/unchecked-short], :line 3498, :examples ["user=> (class (short 1))\njava.lang.Short" "(short 123)\n;;=> 123\n\n(short 1.23)\n;;=> 1\n\n(short 1.2345678901234567890)\n;;=> 1\n\n(short -1.23)\n;;=> -1\n\n;; Casting a string does not work\n(short \"123\")\n;;=> Execution error (ClassCastException) at user/eval169 (REPL:1).\n;;java.lang.String cannot be cast to java.lang.Number\n\n;; Use Java interop instead\n(Short/parseShort \"123\")\n;;=> 123\n\n;; Content originally posted by u/didibus on https://clojuredocs.org/clojure.core/num"], :notes nil, :arglists ["x"], :doc "Coerce to short", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/short"}, :clojure.core/alter {:added "1.0", :ns "clojure.core", :name "alter", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/ref :clojure.core/commute :clojure.core/ref-set], :line 2443, :examples [";; alter is a way to change the value of a reference.\n\n;; Here we're defining a ref named 'names' and setting its value to\n;; an empty vector.\n(def names (ref []))\n;;=> #'user/names\n\n;; A function to add a name to the vector (notice the meat's wrapped\n;; in a dosync\n(defn add-name [name]\n (dosync\n (alter names conj name)))\n;;=> #'user/add-name\n\n(add-name \"zack\")\n;;=> [\"zack\"]\n\n(add-name \"shelley\")\n;;=> [\"zack\" \"shelley\"]\n\n;; Notice that the var 'names' points to the reference that we created\n(println names)\n;; #\n\n;; To get the actual value of the ref, you use the '@' symbol, or deref\n(println @names)\n;; [zack shelley]\n\n(println (deref names))\n;; [zack shelley]"], :notes ["I was fooling around with how exactly ref works with maps. Since the example here uses a vector, I thought maybe some of you might want to see a short example using a map.\r\n\r\nIn an aggregator I'm working on, I want to keep a record of how many sources and how many articles I've aggregated. Instead of using an atom for each, I'll reference a map called \"counts.\" Here's a simple little function that increments and returns the new value of the counter stored in the map:\r\n\r\n
(def counts (ref {:articles 0 :sources 0}))\r\n(defn inc-ref [ref type]\r\n\"increment a map value with key type stored in ref\"\r\n\t(dosync\r\n\t (alter ref assoc type (inc (type @ref)))\r\n\t (type @ref)))\r\nuser> (inc-ref counts :sources)\r\n=>1\r\nuser> counts\r\n=>{:articles 0, :sources 1}\r\n
\r\n\r\nand if you wanted to be able to add counters dynamically (one of the advantages of using a map in this context) you could redefine the function employ an optional argument, which if present instructs the function to create a new key-value pair using the name and initial value provided:\r\n\r\n
" "In the previous example at row 07 has a reference to 'name @ref':\r\n
(alter ref assoc type (inc (name @ref)))
\r\nmaybe is incorrect and the correct mode is: \r\n
(alter ref assoc type (inc (type @ref)))
"], :arglists ["ref fun & args"], :doc "Must be called in a transaction. Sets the in-transaction-value of\n ref to:\n\n (apply fun in-transaction-value-of-ref args)\n\n and returns the in-transaction-value of ref.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/alter"}, :clojure.core/definline {:added "1.0", :ns "clojure.core", :name "definline", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/defmacro], :line 5229, :examples nil, :macro true, :notes ["Note that, as for macros, the arguments to definline are potentially subject to double evaluation if they are used more than once in the body. For example:\r\n\r\n
\r\n\r\n" "Any non-like-a-function behaviour should be avoided, because otherwise function will behave differently depending on whether it's inlined or not:\r\n\r\n user=> (definline bad-if [cond then] `(if ~cond ~then))\r\n #'user/bad-if\r\n user=> (bad-if nil (do (prn :side-effect) :not-returned))\r\n nil\r\n user=> (let [bad-if bad-if] (bad-if nil (do (prn :side-effect) :not-returned)))\r\n :side-effect\r\n nil\r\n"], :arglists ["name & decl"], :doc "Experimental - like defmacro, except defines a named function whose\n body is the expansion, calls to which may be expanded inline as if\n it were a macro. Cannot be used with variadic (&) args.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/definline"}, :clojure.spec.alpha/inst-in-range? {:ns "clojure.spec.alpha", :name "inst-in-range?", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 1884, :examples nil, :notes nil, :arglists ["start end inst"], :doc "Return true if inst at or after start and before end", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/inst-in-range_q"}, :clojure.core/var? {:added "1.0", :ns "clojure.core", :name "var?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/def :clojure.core/var :clojure.core/var-get :clojure.core/var-set :clojure.core/with-local-vars], :line 4975, :examples ["(def my-symbol)\n(var? #'my-symbol)\n=> true\n\n(var? (var my-symbol))\n=> true\n\n(var? (def my-symbol2))\n=> true" "=> *clojure-version*\n{:major 1, :minor 5, :incremental 0, :qualifier \"RC17\"}\n=> var?\n#\n=> (var?)\n;ArityException Wrong number of args (0) passed to: core$var-QMARK- clojure.lang.AFn.throwArity (AFn.java:437)\n=> (var? 1)\nfalse\n=> (var? defn)\n;CompilerException java.lang.RuntimeException: Can't take value of a macro: #'clojure.core/defn, compiling:(NO_SOURCE_PATH:1:1) \n=> (var? #'defn)\ntrue\n=> (var? #'defn 1 2 3 4)\n;ArityException Wrong number of args (5) passed to: core$var-QMARK- clojure.lang.AFn.throwArity (AFn.java:437)\n=> (var? (var defn))\ntrue\n=> (var? apply)\nfalse\n=> (var? #'apply)\ntrue\n"], :notes nil, :arglists ["v"], :doc "Returns true if v is of type clojure.lang.Var", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/var_q"}, :clojure.core/bit-and-not {:added "1.0", :ns "clojure.core", :name "bit-and-not", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 1320, :examples ["user=> (bit-and-not 2r1100 2r1001) ; (and X (not Y))\n4\n;; 4 = 2r0100" ";; here is the truth table for AND-NOT (which is not the same as NAND) \n(Integer/toBinaryString (bit-and-not 2r1100 2r1010) )\n;;=> \"100\"\n;; or 2r0100\n\n;; NAND would be...\n(Integer/toBinaryString (bit-not (bit-and 2r1100 2r1010)) )\n;;=> \"11111111111111111111111111110111\"\n;; which is clearly not the same\n\n;; this operation is material non-implication\n(= (bit-and-not 2r1100 2r1010) (bit-and 2r1100 (bit-not 2r1010)) )\n;;=> true\n" ";;flip the bits of a seq\n(map (fn [n] (bit-and-not 0xff n)) (range 1 10)) ; ~n & 0xff\n;;=> (254 253 252 251 250 249 248 247 246)\n"], :notes nil, :arglists ["x y" "x y & more"], :doc "Bitwise and with complement", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-and-not"}, :clojure.core/methods {:added "1.0", :ns "clojure.core", :name "methods", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/get-method :clojure.core/remove-method :clojure.core/prefer-method :clojure.core/prefers], :line 1811, :examples ["user=> (use 'clojure.pprint)\nuser=> (pprint (methods print-dup))\n{nil #,\n java.lang.String #,\n java.lang.Boolean #,\n clojure.lang.IPersistentList\n #,\n java.sql.Timestamp\n #,\n java.util.UUID #,\n clojure.lang.Var #,\n clojure.lang.PersistentVector\n #,\n java.util.Calendar\n #,\n java.util.Map #,\n java.lang.Class #,\n java.util.regex.Pattern #,\n java.lang.Number #,\n java.lang.Long #,\n clojure.lang.Namespace #,\n java.math.BigDecimal #,\n clojure.lang.Symbol #,\n clojure.lang.Keyword #,\n clojure.lang.LazilyPersistentVector\n #,\n java.util.Collection #,\n java.lang.Double #,\n clojure.lang.Fn #,\n clojure.lang.IRecord #,\n clojure.lang.PersistentHashSet\n #,\n clojure.lang.IPersistentCollection\n #,\n clojure.lang.BigInt #,\n clojure.lang.ISeq #,\n java.util.Date #,\n clojure.lang.PersistentHashMap\n #,\n clojure.lang.IPersistentMap\n #,\n clojure.lang.Ratio #,\n java.lang.Character #}" "user=> (defmulti do-math (fn [operation x y] operation))\n\n#'user/do-math\n\nuser=> (defmethod do-math :add [_ x y] (+ x y))\n... (defmethod do-math :subtract [_ x y] (- x y))\n... (defmethod do-math :hypotenuse [_ x y] (Math/sqrt (+ (* x x) (* y y))))\n\n#multifn[do-math 0x3a1c348]\n\nuser=> (methods do-math)\n\n{:hypotenuse #function[user/eval42540$fn--42541],\n :add #function[user/eval42521$fn--42522],\n :subtract #function[user/eval42525$fn--42526]}\n"], :notes ["Not the most useful output format I've ever seen. :-)"], :arglists ["multifn"], :doc "Given a multimethod, returns a map of dispatch values -> dispatch fns", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/methods"}, :clojure.inspector/inspect-table {:added "1.0", :ns "clojure.inspector", :name "inspect-table", :file "clojure/inspector.clj", :type "function", :column 1, :see-alsos [:clojure.pprint/print-table :clojure.inspector/inspect-tree], :line 100, :examples ["(use 'clojure.inspector)\n(inspect-table [{:a 1 :b 2 :c 3}{:a 4 :b 5 :c 6}])" ";; display every element type alongside value in table\nuser=> (inspect-table\n (map #(vector (type %) %)\n [1 \"something\" \\c (java.io.File. \"/tmp/x\") 0.12 1234]))"], :notes nil, :arglists ["data"], :doc "creates a graphical (Swing) inspector on the supplied regular\n data, which must be a sequential data structure of data structures\n of equal length", :library-url "https://github.com/clojure/clojure", :href "/clojure.inspector/inspect-table"}, :clojure.core/pos-int? {:added "1.9", :ns "clojure.core", :name "pos-int?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/neg-int? :clojure.core/nat-int? :clojure.core/int?], :line 1408, :examples ["(pos-int? 1)\n;;=> true\n(pos-int? 9223372036854775807)\n;;=> true\n\n;;;; false for non-positive values\n\n(pos-int? 0)\n;;=> false\n(pos-int? -1)\n;;=> false\n\n;;;; false for decimal values\n\n(pos-int? 1.0)\n;;=> false\n(pos-int? 1/2)\n;;=> false\n\n;;;; false for BigInt values\n\n(pos-int? 1N)\n;;=> false\n(pos-int? 9223372036854775808)\n;;=> false"], :notes nil, :arglists ["x"], :doc "Return true if x is a positive fixed precision integer", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/pos-int_q"}, :clojure.core.logic/lvars {:ns "clojure.core.logic", :name "lvars", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 729, :examples nil, :notes nil, :arglists ["n"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/lvars"}, :clojure.core/get-method {:added "1.0", :ns "clojure.core", :name "get-method", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/remove-method :clojure.core/methods], :line 1817, :examples [";; define a multi-method, then demonstrate that you may use \n;; get-method in the same way you can call the method directly\n\nuser=> (defmulti tos :Ob)\n#'user/tos\nuser=> (defn line [p1 p2] {:Ob :line :p1 p1 :p2 p2})\n#'user/line\nuser=> (defn circle [cent rad] {:Ob :circle :cent cent :rad rad})\n#'user/circle\nuser=> (defmethod tos :line [l] (str \"Line:\" (l :p1) (l :p2)))\n#\nuser=> (defmethod tos :circle [c] (str \"Circle:\" (c :cent) (c :rad)))\n#\nuser=> (println (tos (circle [2 3] 3.3)))\nCircle:[2 3]3.3\nnil\nuser=> (println (tos (line [1 1][0 0])))\nLine:[1 1][0 0]\nnil\nuser=> (println ((get-method tos :line) (line [1 2][3 4]) ))\nLine:[1 2][3 4]\nnil\nuser=>"], :notes nil, :arglists ["multifn dispatch-val"], :doc "Given a multimethod and a dispatch value, returns the dispatch fn\n that would apply to that value, or nil if none apply and no default", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/get-method"}, :clojure.core/reset-vals! {:added "1.9", :ns "clojure.core", :name "reset-vals!", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 2383, :examples [";; An atom is defined\n(def open-sockets (atom []))\n;;=> #'user/open-sockets\n\n;; Conjoin a value or two onto the atom\n(swap! open-sockets conj socket)\n;;=> [<< stream: 1 >> << stream: 2 >>]\n\n;; Knock the first socket out of open-sockets\n(reset-vals! open-sockets (subvec @open-sockets 1))\n;;=> [[<< stream: 1 >> << stream: 2 >>][<< stream: 2 >>]]\n\n;; Knock the last socket out of open-sockets\n(reset-vals! open-sockets (pop @open-sockets))\n;;=> [[<< stream: 2 >>] []]"], :notes nil, :arglists ["atom newval"], :doc "Sets the value of atom to newval. Returns [old new], the value of the\n atom before and after the reset.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reset-vals!"}, :clojure.core/unchecked-short {:added "1.3", :ns "clojure.core", :name "unchecked-short", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/short], :line 3522, :examples ["(unchecked-short 1)\n;;=> 1\n(unchecked-short 1N)\n;;=> 1\n(unchecked-short 1.1)\n;;=> 1\n(unchecked-short 1.9)\n;;=> 1\n(unchecked-short 5/3)\n;;=> 1\n\n(unchecked-short -1)\n;;=> -1\n(unchecked-short -1N)\n;;=> -1\n(unchecked-short -1.1)\n;;=> -1\n(unchecked-short -1.9)\n;;=> -1\n(unchecked-short -5/3)\n;;=> -1\n\n;;;; Note that (unchecked-short) does not range check its argument\n;;;; so integer overflow or rounding may occur. \n;;;; Use (short) if you want to throw an exception in such cases.\n\n(unchecked-short 32768)\n;;=> -32768\n(unchecked-short -32769)\n;;=> 32767\n\n(short 32768)\n;;=> IllegalArgumentException Value out of range for short: 32768\n(short -32769)\n;;=> IllegalArgumentException Value out of range for short: -32769\n\n(unchecked-short 1.0E4)\n;;=> 10000\n(unchecked-short 1.0E5)\n;;=> -31072\n\n(short 1.0E4)\n;;=> 10000\n(short 1.0E5)\n;;=> IllegalArgumentException Value out of range for short: 100000.0\n"], :notes nil, :arglists ["x"], :doc "Coerce to short. Subject to rounding or truncation.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-short"}, :clojure.core/hash-ordered-coll {:added "1.6", :ns "clojure.core", :name "hash-ordered-coll", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/hash-unordered-coll :clojure.core/hash], :line 5186, :examples [";;;; Clojure's (hash-ordered-coll) produces the same hash code regardless\n;;;; of collection type when both of the following two conditions are met:\n;;;; (1) collections contain the same elements\n;;;; (2) collection elements are ordered the same when returned by .iterator()\n\n(hash-ordered-coll [1 2])\n;;=> 156247261\n(hash-ordered-coll '(1 2))\n;;=> 156247261\n(hash-ordered-coll (sorted-set 1 2))\n;;=> 156247261\n(hash-ordered-coll (doto (new java.util.ArrayList) (.add 1) (.add 2)))\n;;=> 156247261\n(hash-ordered-coll (doto (new java.util.TreeSet) (.add 1) (.add 2)))\n;;=> 156247261\n\n(hash-ordered-coll [2 1])\n;;=> -1994590503\n(hash-ordered-coll '(2 1))\n;;=> -1994590503\n(hash-ordered-coll (sorted-set-by > 2 1))\n;;=> -1994590503\n(hash-ordered-coll (doto (new java.util.ArrayList) (.add 2) (.add 1)))\n;;=> -1994590503\n(hash-ordered-coll (doto (new java.util.TreeSet >) (.add 2) (.add 1)))\n;;=> -1994590503\n\n;;;; Notice that this differs from (hash) which \n;;;; (1) doesn't rely on element order as returned by .iterator()\n;;;; (2) falls back on Java's .hashCode() for non-Clojure collections\n\n(hash [1 2])\n;;=> 156247261\n(hash '(1 2))\n;;=> 156247261\n(hash (sorted-set 1 2))\n;;=> 460223544\n(hash (sorted-set-by > 2 1))\n;;=> 460223544\n(hash (doto (new java.util.ArrayList) (.add 1) (.add 2)))\n;;=> 994\n(hash (doto (new java.util.TreeSet) (.add 1) (.add 2)))\n;;=> 3\n" ";;;;\n;;;; Only accepts implementations of java.lang.Iterable\n;;;;\n\n(hash-ordered-coll true)\n;;=> ClassCastException java.lang.Boolean cannot be cast to java.lang.Iterable\n(hash-ordered-coll 1)\n;;=> ClassCastException java.lang.Long cannot be cast to java.lang.Iterable\n(hash-ordered-coll \\c)\n;;=> ClassCastException java.lang.Character cannot be cast to java.lang.Iterable\n\n;;;;\n;;;; Being seqable is not sufficient!\n;;;;\n\n(hash-ordered-coll \"12\")\n;;=> ClassCastException java.lang.String cannot be cast to java.lang.Iterable\n(hash-ordered-coll (int-array [1 2]))\n;;=> ClassCastException [I cannot be cast to java.lang.Iterable\n(hash-ordered-coll nil)\n;;=> NullPointerException"], :notes nil, :arglists ["coll"], :doc "Returns the hash code, consistent with =, for an external ordered\n collection implementing Iterable.\n See http://clojure.org/data_structures#hash for full algorithms.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/hash-ordered-coll"}, :clojure.spec.alpha/check-asserts {:ns "clojure.spec.alpha", :name "check-asserts", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 1950, :examples nil, :notes ["You can also **enable check-asserts globally** using deps.edn you can add it to a profile. It is a jvm option. In your **deps.edn** you can add this:\n\n```\n:aliases {:dev {:jvm-opts [\"-Dclojure.spec.check-asserts=true\"]}}\n```"], :arglists ["flag"], :doc "Enable or disable spec asserts that have been compiled\nwith '*compile-asserts*' true. See 'assert'.\n\nInitially set to boolean value of clojure.spec.check-asserts\nsystem property. Defaults to false.", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/check-asserts"}, :clojure.core.logic/build {:ns "clojure.core.logic", :name "build", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 271, :examples nil, :notes nil, :arglists ["s u"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/build"}, :clojure.stacktrace/print-throwable {:added "1.1", :ns "clojure.stacktrace", :name "print-throwable", :file "clojure/stacktrace.clj", :type "function", :column 1, :see-alsos [:clojure.stacktrace/print-stack-trace :clojure.stacktrace/print-cause-trace], :line 38, :examples [";; let's make an exception\n(def anex (try (/ 1 0) (catch Exception ex ex)))\n\n;; now print the exception\n(clojure.stacktrace/print-throwable anex)\n;; java.lang.ArithmeticException: Divide by zero\n;=> nil\n\n;; and catch it in a string\n(def msg (with-out-str (clojure.stacktrace/print-throwable anex)))\n;=> #'boot.user/msg\n\nmsg\n;=> \"java.lang.ArithmeticException: Divide by zero\"\n\n"], :notes nil, :arglists ["tr"], :doc "Prints the class and message of a Throwable. Prints the ex-data map\n if present.", :library-url "https://github.com/clojure/clojure", :href "/clojure.stacktrace/print-throwable"}, :clojure.core/odd? {:added "1.0", :ns "clojure.core", :name "odd?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/even?], :line 1394, :examples ["user=> (odd? 1)\ntrue\nuser=> (odd? 2)\nfalse\nuser=> (odd? 0)\nfalse" "user=> (filter odd? (range 15))\n(1 3 5 7 9 11 13)"], :notes nil, :arglists ["n"], :doc "Returns true if n is odd, throws an exception if n is not an integer", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/odd_q"}, :clojure.core/if-some {:added "1.6", :ns "clojure.core", :name "if-some", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/when-some :clojure.core/if-let :clojure.core/some], :line 1876, :examples ["(if-some [a 10] :true :false) ; => :true\n(if-some [a true] :true :false) ; => :true\n(if-some [a false] :true :false) ; => :true\n(if-some [a nil] :true :false) ; => :false\n\n;; for comparison\n(if-let [a 10] :true :false) ; => :true\n(if-let [a true] :true :false) ; => :true \n(if-let [a false] :true :false) ; => :false\n(if-let [a nil] :true :false) ; => :false\n"], :macro true, :notes ["See [this Jira ticket](http://dev.clojure.org/jira/browse/CLJ-1343) for some background on this.\n\n (if-some [var test] then else)\n\nis essentially equivalent to:\n\n (if-let [var (not (nil? test))] then else)\n" "> `(if-some [var test] then else)`\n>\n> is essentially equivalent to:\n>\n> `(if-let [var (not (nil? test))] then else)`\n\nThis is incorrect. Notice that `nil?` will return a boolean. This equivalency would only be true if `test` is a boolean value."], :arglists ["bindings then" "bindings then else & oldform"], :doc "bindings => binding-form test\n\n If test is not nil, evaluates then with binding-form bound to the\n value of test, if not, yields else", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/if-some"}, :clojure.core.logic/env-locals {:ns "clojure.core.logic", :name "env-locals", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1625, :examples nil, :notes nil, :arglists ["& syms"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/env-locals"}, :clojure.core/vary-meta {:added "1.0", :ns "clojure.core", :name "vary-meta", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/with-meta :clojure.core/alter-meta!], :line 675, :examples ["user=> (meta (vary-meta 'foo assoc :a 1))\n{:a 1}\n" ";; continuing from the previous with-meta example\nuser=> (def wm (with-meta [1 2 3] {:my \"meta\"}))\n#'user/wm\n\nuser=> wm\n[1 2 3]\n\nuser=> (meta wm)\n{:my \"meta\"}\n\nuser=> (def new-wm (vary-meta wm assoc :your \"new meta\"))\n#'user/new-wm\n\nuser=> new-wm\n[1 2 3]\n\nuser=> (meta new-wm)\n{:my \"meta\", :your \"new meta\"}\n\n"], :notes nil, :arglists ["obj f & args"], :doc "Returns an object of the same type and value as obj, with\n (apply f (meta obj) args) as its metadata.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/vary-meta"}, :clojure.core/alength {:added "1.0", :ns "clojure.core", :name "alength", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/into-array], :line 3898, :examples ["user=> (def my-array (into-array Integer/TYPE [1 2 3]))\n#'user/my-array\n\nuser=> (alength my-array)\n3" "2D simple array example\nuser=> (def a (to-array-2d [[1 2] [3 4 5] [1]]))\n#'user/a\nuser=> (alength a)\n3\n"], :notes nil, :arglists ["array"], :doc "Returns the length of the Java array. Works on arrays of all\n types.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/alength"}, :clojure.core/re-pattern {:added "1.0", :ns "clojure.core", :name "re-pattern", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/re-find :clojure.string/replace :clojure.string/replace-first], :line 4839, :examples ["user=> (re-pattern \"\\\\d+\")\n#\"\\d+\"\n\nuser=> (re-find (re-pattern \"\\\\d+\") \"abc123def\") \n\"123\"\n\n;; If you want to construct a regex pattern dynamically at run time,\n;; then you need to use re-pattern to convert a string to a pattern\n;; that can be used for matching. But if your pattern is one you\n;; write into the source code, it is more convenient to use the\n;; #\"pattern\" syntax. The previous example can be written as follows.\nuser=> (re-find #\"\\d+\" \"abc123def\") \n\"123\"\n\n;; Below are two examples that are equivalent in the patterns they\n;; use, but the #\"pattern\" syntax helps significantly, because it lets\n;; us avoid the requirement to escape every \\ character with another \\\n;; character. See the example with embedded comments below for more\n;; detail on what the pattern matches.\nuser=> (re-find #\"\\\\\\d+\\s+\\S+\" \"\\\\ it sh0uld match in \\\\5 here somewhere.\")\n\"\\\\5 here\"\n\nuser=> (re-find (re-pattern \"\\\\\\\\\\\\d+\\\\s+\\\\S+\")\n \"\\\\ it sh0uld match in \\\\5 here somewhere.\")\n\"\\\\5 here\"\n\n;; If you want to embed (ignored) whitespace and comments from #\n;; characters until end-of-line in your regex patterns, start the\n;; pattern with (?x)\nuser=> (re-find #\"(?x) # allow embedded whitespace and comments\n \\\\ # backslash\n \\d+ # one or more digits\n \\s+ # whitespace\n \\S+ # non-whitespace\"\n \"\\\\ it sh0uld match in \\\\5 here somewhere.\")\n\"\\\\5 here\"\n\n;; Other pattern flags like Java's DOTALL, MULTILINE and UNICODE_CASE\n;; pattern matching modes, can be set by combining these embedded flags\n\n;; (?d) Unix lines (only match \\newline)\n;; (?i) Case-insensitive\n;; (?u) Unicode-aware Case\n;; (?m) Multiline\n;; (?s) Dot matches all (including newline)\n;; (?x) Ignore Whitespace and comments\n\nuser=> (re-seq #\"(?ix) test #Case insensitive and comments allowed\"\n \"Testing,\\n testing,\\n 1 2 3\")\n(\"Test\" \"test\")\n"], :notes ["You can access documentation for the regex pattern \"language\" using (javadoc java.util.regex.Pattern) at the repl prompt. it should take you here: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/regex/Pattern.html"], :tag "java.util.regex.Pattern", :arglists ["s"], :doc "Returns an instance of java.util.regex.Pattern, for use, e.g. in\n re-matcher.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/re-pattern"}, :clojure.core/zipmap {:added "1.0", :ns "clojure.core", :name "zipmap", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/interleave :clojure.core/into], :line 3071, :examples ["user=> (zipmap [:a :b :c :d :e] [1 2 3 4 5])\n{:a 1, :b 2, :c 3, :d 4, :e 5}\n" ";; 4 is not included in the result\nuser=> (zipmap [:a :b :c] [1 2 3 4])\n{:a 1, :b 2, :c 3}\n\n;; :c is not included in the result\nuser=> (zipmap [:a :b :c] [1 2])\n{:a 1, :b 2}" "user=> (pprint \n (zipmap [:html :body :div] (repeat {:margin 0 :padding 0})))\n{:html {:margin 0, :padding 0},\n :body {:margin 0, :padding 0},\n :div {:margin 0, :padding 0}}" ";; transform a CSV file to an array of maps using the header line as keys\nuser=> (defn csv-map\n \"ZipMaps header as keys and values from lines.\"\n [head & lines]\n (map #(zipmap (map keyword head) %1) lines))\n\nuser=> (apply csv-map [[\"FirstName\", \"LastName\"], [\"John\", \"Doe\"], [\"Jill\", \"Doh\"]])\n({:FirstName \"John\", :LastName \"Doe\"}, {:FirstName \"Jill\", :LastName \"Doh\"})" ";; initialize with 0 for all values\nuser=> (zipmap [:a :b :c] (repeat 0))\n{:a 0, :b 0, :c 0}" ";; Note that if the keys are not unique, you can potentially lose data:\nuser=> (zipmap [:a :b :c :a] [1 2 3 4])\n{:a 4, :b 2, :c 3}\n" ";; Note the generated map is meant to be un-ordered and can be noticed only for sizes greater than 8\n\n;; Ordered as key coll argument\nuser=> (zipmap [:key1 :key2 :key3 :key4 :key5 :key6 :key7 :key8] [1 2 3 4 5 6 7 8])\n{:key1 1, :key2 2, :key3 3, :key4 4, :key5 5, :key6 6, :key7 7, :key8 8}\n\n;; Un-ordered\nuser=> (zipmap [:key1 :key2 :key3 :key4 :key5 :key6 :key7 :key8 :key9] [1 2 3 4 5 6 7 8 9])\n{:key3 3, :key2 2, :key8 8, :key6 6, :key9 9, :key7 7, :key4 4, :key1 1, :key5 5}\n" ";; Alternative logic for `cond` scenarios\n\n;; `zipmap` returns a map paring each value in the range (1-4) to a percentage (50%)\n(def rates\n (conj {0 0/100}\n (zipmap (range 1 5) (repeat 50/100))\n {5 90/100}))\n;; => {0 0, 1 1/2, 2 1/2, 3 1/2, 4 1/2, 5 9/10}\n\n(* 2.0 (rates 3))\n;; => 1.0"], :notes ["`zipmap` always leave last key & val if keys are duplicated\nlike the last example code.\n\nYou can know them from source code which `assoc` key & val to result map in left-to-right order."], :arglists ["keys vals"], :doc "Returns a map with the keys mapped to the corresponding vals.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/zipmap"}, :clojure.core/method-sig {:ns "clojure.core", :name "method-sig", :file "clojure/core_proxy.clj", :type "function", :column 1, :see-alsos nil, :line 20, :examples [";;;; (method-sig) turns java.lang.reflect.Method into a vector \n;;;; of the form [name (param-types) return-type]\n\n(->> String .getMethods (filter #(= (.getName %) \"indexOf\")))\n;;=> (#object[java.lang.reflect.Method 0x4a499a6c \"public int java.lang.String.indexOf(java.lang.String,int)\"]\n;; #object[java.lang.reflect.Method 0x29b045b3 \"public int java.lang.String.indexOf(int)\"]\n;; #object[java.lang.reflect.Method 0x55ce8ae4 \"public int java.lang.String.indexOf(java.lang.String)\"]\n;; #object[java.lang.reflect.Method 0x33a58323 \"public int java.lang.String.indexOf(int,int)\"])\n\n(->> String .getMethods (filter #(= (.getName %) \"indexOf\")) (map method-sig))\n;;=> ([\"indexOf\" (java.lang.String int) int]\n;; [\"indexOf\" (int) int]\n;; [\"indexOf\" (java.lang.String) int]\n;; [\"indexOf\" (int int) int])"], :notes nil, :arglists ["meth"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/method-sig"}, :clojure.java.io/make-writer {:added "1.2", :ns "clojure.java.io", :name "make-writer", :type "function", :see-alsos [:clojure.java.io/writer], :examples nil, :notes nil, :arglists ["x opts"], :doc "Creates a BufferedWriter. See also IOFactory docs.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/make-writer"}, :clojure.core/*3 {:added "1.0", :ns "clojure.core", :name "*3", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [:clojure.core/*1 :clojure.core/*2], :dynamic true, :line 6289, :examples ["user=> \"Hello!\"\n\"Hello!\"\n\nuser=> \"Hello World!\"\n\"Hello World!\"\n\nuser=> \"Hi Everyone!\"\n\"Hi Everyone!\"\n\nuser=> [*1 *2 *3]\n[\"Hi Everyone!\" \"Hello World!\" \"Hello!\"]\n" "user=> (range 5)\n(0 1 2 3 4)\nuser=> (last *1)\n4\nuser=> (last *2)\n4\nuser=> (last *3)\n4\n"], :notes nil, :arglists [], :doc "bound in a repl thread to the third most recent value printed", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*3"}, :clojure.core.logic/permuteo {:ns "clojure.core.logic", :name "permuteo", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1781, :examples ["(run* [q]\n (permuteo [:c q :a] [:b :a :c])) ;; :b"], :notes nil, :arglists ["xl yl"], :doc "A relation that will permute xl into the yl. May not\n terminate if xl is not ground.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/permuteo"}, :clojure.core.logic.fd/domc {:ns "clojure.core.logic.fd", :name "domc", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 718, :examples nil, :notes nil, :arglists ["x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/domc"}, :clojure.core/*2 {:added "1.0", :ns "clojure.core", :name "*2", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [:clojure.core/*1 :clojure.core/*3], :dynamic true, :line 6284, :examples ["user=> \"Hello!\"\n\"Hello!\"\n\nuser=> \"Hello World!\"\n\"Hello World!\"\n\nuser=> [*1 *2]\n[\"Hello World!\" \"Hello!\"]\n"], :notes nil, :arglists [], :doc "bound in a repl thread to the second most recent value printed", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*2"}, :clojure.spec.alpha/regex-spec-impl {:ns "clojure.spec.alpha", :name "regex-spec-impl", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 1692, :examples nil, :notes nil, :arglists ["re gfn"], :doc "Do not call this directly, use 'spec' with a regex op argument", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/regex-spec-impl"}, :clojure.core/pos? {:added "1.0", :ns "clojure.core", :name "pos?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/neg? :clojure.core/zero? :clojure.core/nat-int? :clojure.core/pos-int?], :line 1247, :examples ["user=> (pos? 1)\ntrue\nuser=> (pos? 0)\nfalse\nuser=> (pos? -1)\nfalse" "user=> (pos? 0.1)\ntrue\nuser=> (pos? -0.1)\nfalse" "user=> (pos? 1/2)\n;; true\n\nuser=> (pos? -1/2)\n;; false\n\nuser=> (pos? {})\n;; Execution error (ClassCastException) at user/eval3795 (REPL:1).\n;; clojure.lang.PersistentArrayMap cannot be cast to java.lang.Number"], :notes nil, :arglists ["num"], :doc "Returns true if num is greater than zero, else false", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/pos_q"}, :clojure.core.logic.fd/ISortedDomain {:ns "clojure.core.logic.fd", :name "ISortedDomain", :file "clojure/core/logic/fd.clj", :type "var", :column 1, :see-alsos nil, :line 23, :examples nil, :notes nil, :arglists [], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/ISortedDomain"}, :clojure.core.reducers/mapcat {:added "1.5", :ns "clojure.core.reducers", :name "mapcat", :file "clojure/core/reducers.clj", :type "function", :column 1, :see-alsos [:clojure.core.reducers/map], :line 138, :examples nil, :notes nil, :arglists ["f" "f coll"], :doc "Applies f to every value in the reduction of coll, concatenating the result\n colls of (f val). Foldable.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.reducers/mapcat"}, :clojure.zip/root {:added "1.0", :ns "clojure.zip", :name "root", :file "clojure/zip.clj", :type "function", :column 1, :see-alsos [:clojure.zip/edit], :line 137, :examples nil, :notes nil, :arglists ["loc"], :doc "zips all the way up and returns the root node, reflecting any\n changes.", :library-url "https://github.com/clojure/clojure", :href "/clojure.zip/root"}, :clojure.core/char-escape-string {:added "1.0", :ns "clojure.core", :name "char-escape-string", :file "clojure/core_print.clj", :type "var", :column 1, :see-alsos [:clojure.core/char-name-string :clojure.string/escape], :line 200, :examples [";; simple examples\n\nuser=> (char-escape-string \\newline)\n\"\\\\n\"\nuser=> (char-escape-string \\c) ; no escape sequence for 'c'\nnil\nuser=> (char-escape-string \\tab)\n\"\\\\t\"\nuser=> (char-escape-string \\backspace)\n\"\\\\b\"\nuser=>" "(require '[clojure.string :as s])\n\n;; Would like to print \"s\" as shown literally:\n(def s \"Type backslash-t '\\t' followed by backslash-n '\\n'\")\n\n;; This doesn't work, as \\t and \\n are interpreted:\n(println s)\n;; Type backslash-t ' ' followed by backslash-n '\n;; '\n\n;; Use with escape to print literally:\n(println (s/escape s char-escape-string))\n;; Type backslash-t '\\t' followed by backslash-n '\\n'"], :notes nil, :tag "java.lang.String", :arglists [], :doc "Returns escape string for char or nil if none", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/char-escape-string"}, :clojure.core/nthrest {:added "1.3", :ns "clojure.core", :name "nthrest", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/drop :clojure.core/nthnext :clojure.core/nth :clojure.core/rest :clojure.core/next], :line 3174, :examples ["(nthrest (range 10) 5)\n;;=> (5 6 7 8 9)\n\n;; in many cases gives the same result as nthnext\n(nthnext (range 10) 5)\n;;=> (5 6 7 8 9)\n\n;; here is a case where the results differ\n(nthrest [] 3) ;;=> []\n(nthnext [] 3) ;;=> nil\n\n(nthrest [1 2 3 4 5 6 7] 4)\n;;=> (5 6 7)" ";; drop is also similar, but lazy \n(nthrest (range 10) 5) ;;=> (5 6 7 8 9)\n(drop 5 (range 10)) ;;=> (5 6 7 8 9)\n\n;; here is a case where the results differ\n(nthrest [] 3) ;;=> []\n(drop 3 []) ;;=> () ; returning a lazy sequence" ";; nthrest eagerly evaluates the dropped items:\n\n(def a (nthrest (map #(do (print \".\") %) (iterate inc 0)) 10))\n;; ..........#'user/a (note: processing already started)\n\n(def b (drop 10 (map #(do (print \".\") %) (iterate inc 0))))\n;; #'user/b (note: no evaluation)\n\n;; Possible use: always produce side effects (if any) independently \n;; from evaluation of kept items." ";; nthrest returns a suffix of the given sequence"], :notes ["This differs from clojure.core/drop in that it immediately drops the head of the seq, instead of doing so on the first call to first or seq."], :arglists ["coll n"], :doc "Returns the nth rest of coll, coll when n is 0.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/nthrest"}, :clojure.core.logic.fd/*c {:ns "clojure.core.logic.fd", :name "*c", :file "clojure/core/logic/fd.clj", :type "function", :column 1, :see-alsos nil, :line 913, :examples nil, :notes nil, :arglists ["u v w"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/*c"}, :clojure.core.async/alts! {:ns "clojure.core.async", :name "alts!", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos [:clojure.core.async/alt! :clojure.core.async/alts!! :clojure.core.async/alt!!], :line 276, :examples ["user> (let [chans (partition-all 2\n (interleave\n [\"Bob\"\n \"Jane\"\n \"GuyGirl22\"]\n (repeatedly 3 chan)))]\n (go\n (let [[owner port] (rand-nth chans)\n chans-only (mapv second chans)]\n\n (go\n (! port\n (str owner \": First!!!\")))\n\n (let [[v p] (alts! chans-only)]\n (println \"Message: \" v \"\\nFrom Object: \" p)))))\n\n;; Returns => #\n\n;; 1.5 seconds later =>\n;; Message: Bob: First!!! \n;; From Object: #\n" ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;\n;;\n;; THIS example shows `:default`s and `:priority`s\n\n(let [f (fn [x ch] (go (Thread/sleep (rand 100))\n (>! ch x)))\n a (chan)\n b (chan)\n c (chan)]\n (println \"----------\")\n (f 1 a)\n (f 2 b)\n (f 3 c)\n (Thread/sleep 200) ; if this is commented out, it returns the\n ; `:default` every time. If the thread *does*\n ; sleep, then it returns the `a` channel's `1`\n ; every time\n (let [[n ch2] (alts!! [a b c]\n :default 42\n :priority true\n )]\n (println \"received: \" n)))"], :notes nil, :arglists ["ports & {:as opts}"], :doc "Completes at most one of several channel operations. Must be called\n inside a (go ...) block. ports is a vector of channel endpoints,\n which can be either a channel to take from or a vector of\n [channel-to-put-to val-to-put], in any combination. Takes will be\n made as if by !. Unless\n the :priority option is true, if more than one port operation is\n ready a non-deterministic choice will be made. If no operation is\n ready and a :default value is supplied, [default-val :default] will\n be returned, otherwise alts! will park until the first operation to\n become ready completes. Returns [val port] of the completed\n operation, where val is the value taken for takes, and a\n boolean (true unless already closed, as per put!) for puts.\n\n opts are passed as :key val ... Supported options:\n\n :default val - the value to use if none of the operations are immediately ready\n :priority true - (default nil) when true, the operations will be tried in order.\n\n Note: there is no guarantee that the port exps or val exprs will be\n used, nor in what order should they be, so they should not be\n depended upon for side effects.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/alts!"}, :clojure.core.logic/waiting-stream? {:ns "clojure.core.logic", :name "waiting-stream?", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1860, :examples nil, :notes nil, :arglists ["x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/waiting-stream_q"}, :clojure.spec.alpha/and {:ns "clojure.spec.alpha", :name "and", :file "clojure/spec/alpha.clj", :type "macro", :column 1, :see-alsos [:clojure.spec.alpha/or], :line 488, :examples ["(require '[clojure.spec.alpha :as s])\n\n(s/conform (s/and int? pos?) 3) ;=> 3"], :macro true, :notes nil, :arglists ["& pred-forms"], :doc "Takes predicate/spec-forms, e.g.\n\n (s/and even? #(< % 42))\n\n Returns a spec that returns the conformed value. Successive\n conformed values propagate through rest of predicates.", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/and"}, :clojure.core.logic/get-dom-fd {:ns "clojure.core.logic", :name "get-dom-fd", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2205, :examples nil, :notes nil, :arglists ["a x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/get-dom-fd"}, :clojure.core/identity {:added "1.0", :ns "clojure.core", :name "identity", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/nil? :clojure.core/some? :clojure.core/constantly], :line 1451, :examples ["user=> (identity 4)\n4" "user=> (filter identity [1 2 3 nil 4 false true 1234])\n(1 2 3 4 true 1234)" "user=> (map #(%1 %2) (cycle [inc identity]) [1 2 3 4 5 6 7 8 9 10])\n(2 2 4 4 6 6 8 8 10 10)\n" "user=> (partition-by identity (sort \"abcdaabccc\"))\n((\\a \\a \\a) (\\b \\b) (\\c \\c \\c \\c) (\\d))\n" "user=> (map first (partition-by identity [1 1 2 3 3 1 1 5 5]))\n(1 2 3 1 5)" "user=> (group-by identity \"abracadabra\")\n{\\a [\\a \\a \\a \\a \\a], \\b [\\b \\b], \\r [\\r \\r], \\c [\\c], \\d [\\d]}" "user=> (map #(identity %) [1 2 3 4]) ; ~ (map (fn [x] x) [1 2 3 4])\n(1 2 3 4)" "; `identity` can serve in workarounds, because you can't pass a macro\n; to a function. For example, you can't pass `and` as a parameter to `apply`:\n(apply and '(true 1 \"yes\"))\n; \\=> CompilerException... Can't take value of a macro...\n\n; Instead:\n(every? identity '(true 1 \"yes\"))\n"], :notes ["I don't quite see the usefulness of this :P" "It's useful for example with -> macro when we eventually want to return its argument (in this case: state)\r\n\r\n\r\n\r\n(defn example[state]\r\n (-> state\r\n update-function-1\r\n update-function-2\r\n identity))" "Here is another good example:\r\n
(some identity ((juxt :foo :bar) {:bar :b}))
\r\nequivalent to \r\n
(let [map {:bar b}] (or (:foo map) (:bar map)))" "user=> (mapcat identity [[[0 1] [1 2]] [[11 12]]])\n([0 1] [1 2] [11 12])\n"], :arglists ["x"], :doc "Returns its argument.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/identity"}, :clojure.core.server/repl-init {:ns "clojure.core.server", :name "repl-init", :file "clojure/core/server.clj", :type "function", :column 1, :see-alsos nil, :line 163, :examples nil, :notes nil, :arglists [""], :doc "Initialize repl in user namespace and make standard repl requires.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.server/repl-init"}, :clojure.core.logic.fd/-member? {:ns "clojure.core.logic.fd", :name "-member?", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["this n"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/-member_q"}, :clojure.core/send-off {:added "1.0", :ns "clojure.core", :name "send-off", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/send :clojure.core/agent :clojure.core/shutdown-agents :clojure.core/send-via], :line 2122, :examples ["user=> (def my-agent (agent \"\"))\n#'user/my-agent\nuser=> @my-agent\n\"\"\n\n;; Note the following happens asynchronously in a thread\n;; pool\nuser=> (send-off my-agent #(slurp %2) \"file.txt\")\n#\n\n;; while the slurp is in-progress, @my-agent will return \"\".\n\n;; Once the request has completed, the value will\n;; be updated when we look at it.\nuser=> @my-agent\n\"file contents\"\n" ";; send should be used for actions that are CPU limited,\n;; while send-off is appropriate for actions that may block on IO.\n\n;; send is like async/go, send-off is like async/thread\n;; so send use limited pool by CPU for agents to not overload CPU,\n;; while send-off use independent threads without limitations."], :notes ["The example uses \"send\", this is supposed to be an example for \"send-off\"." "\"send\" and \"send-off\" are identical in syntax and semantics. The only difference is the thread pool used to dispatch the agent. \"send\" uses a fixed-sized thread pool initialized at startup to contain a few more threads than the number of cores on the host computer. Since \"send\"s thread pool is fixed size, using it to dispatch blocking code can result in all the pool's threads being blocked, and other \"send\"s queued waiting for a thread to finish its work. This can produce artificially low performance, and in rare conditions, can deadlock (if a queued thread is needed to unblock the blocked pool threads).\n\n\"send-off\" uses a separate thread pool which can grow as-needed. I.e. a \"send-off\" request will never be queued waiting for a thread; if the existing pool is empty, a new thread is created. However, if many long-running CPU-bound (not blocking) requests are being submitted, \"send-off\" can be counter-productive; having more CPU-bound threads than cores results in unnecessary scheduling overhead as the threads are timeshared across the cores. \"send\"s limited thread pool produces higher throughput for CPU-bound requests."], :arglists ["a f & args"], :doc "Dispatch a potentially blocking action to an agent. Returns the\n agent immediately. Subsequently, in a separate thread, the state of\n the agent will be set to the value of:\n\n (apply action-fn state-of-agent args)", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/send-off"}, :clojure.spec.alpha/merge-spec-impl {:ns "clojure.spec.alpha", :name "merge-spec-impl", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 1190, :examples nil, :notes nil, :arglists ["forms preds gfn"], :doc "Do not call this directly, use 'merge'", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/merge-spec-impl"}, :clojure.test.junit/finish-element {:ns "clojure.test.junit", :name "finish-element", :file "clojure/test/junit.clj", :type "function", :column 1, :see-alsos nil, :line 70, :examples nil, :notes nil, :arglists ["tag pretty"], :library-url "https://github.com/clojure/clojure", :href "/clojure.test.junit/finish-element"}, :clojure.core/proxy-name {:ns "clojure.core", :name "proxy-name", :file "clojure/core_proxy.clj", :type "function", :column 1, :see-alsos nil, :line 37, :examples nil, :notes nil, :tag "java.lang.String", :arglists ["super interfaces"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/proxy-name"}, :clojure.core.logic/distribute {:ns "clojure.core.logic", :name "distribute", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2283, :examples nil, :notes nil, :arglists ["v* strategy"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/distribute"}, :clojure.core.logic/lvar {:ns "clojure.core.logic", :name "lvar", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 706, :examples ["(let [x (lvar 'x)]\n (run 10 [q]\n (membero x [1 2 3])\n (== q x)))"], :notes nil, :arglists ["" "name" "name unique"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/lvar"}, :clojure.stacktrace/root-cause {:added "1.1", :ns "clojure.stacktrace", :name "root-cause", :file "clojure/stacktrace.clj", :type "function", :column 1, :see-alsos nil, :line 18, :examples [";; make an exception\n(def anex (try (/ 1 0) (catch Exception ex ex)))\n\n;; get the root cause\n(clojure.stacktrace/root-cause anex)\n;;=> #error {\n;; :cause \"Divide by zero\"\n;; :via\n;; [{:type java.lang.ArithmeticException\n;; :message \"Divide by zero\"\n;; :at [clojure.lang.Numbers divide \"Numbers.java\" 163]}]\n;; :trace\n;; [[clojure.lang.Numbers divide \"Numbers.java\" 163]\n;; [clojure.lang.Numbers divide \"Numbers.java\" 3833]\n;; ...\n;; [java.lang.Thread run \"Thread.java\" 748]]}\n"], :notes nil, :arglists ["tr"], :doc "Returns the last 'cause' Throwable in a chain of Throwables.", :library-url "https://github.com/clojure/clojure", :href "/clojure.stacktrace/root-cause"}, :clojure.test.junit/message-el {:ns "clojure.test.junit", :name "message-el", :file "clojure/test/junit.clj", :type "function", :column 1, :see-alsos nil, :line 113, :examples nil, :notes nil, :arglists ["tag message expected-str actual-str"], :library-url "https://github.com/clojure/clojure", :href "/clojure.test.junit/message-el"}, :clojure.core/compare-and-set! {:added "1.0", :ns "clojure.core", :name "compare-and-set!", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/atom :clojure.core/reset! :clojure.core/swap! :clojure.core/swap-vals!], :line 2368, :examples [";; first we make a demonstration atom\n(def a (atom 0))\n;; #'user/a \n\n;; failing to set the demonstration atom because the old-value does not match. \n(compare-and-set! a 10 20)\n;;=> false\n\n;; as you can see there was no change to the atom\n@a\n;;=> 0\n\n;; but when the old-value matches the atom is set to the new-value.\n(compare-and-set! a 0 10)\n;;=> true\n\n@a\n;;=> 10\n" ";; Use compare-and-set! to implement a version of swap!\n;; that stops retrying after some number of attempts, for example\n;; because of a slow update fn and high concurrency on the atom:\n\n(defn swap-or-bail! [a f & [attempts]]\n (loop [i (or attempts 3)]\n (if (zero? i)\n (println \"Could not update. Bailing out.\")\n (let [old (deref a)\n success? (compare-and-set! a old (f old))]\n (when-not success?)\n (println \"Update failed. Retry\" i)\n (recur (dec i)))))))\n\n(defn slow-inc [x]\n (Thread/sleep 5000) \n (inc x))\n\n(def a (atom 0))\n(def f (future (swap-or-bail! a slow-inc)))\n(reset! a 1)\n;; \"Update failed. Retry 3\"\n(reset! a 2)\n;; \"Update failed. Retry 2\"\n(reset! a 3)\n;; Could not update. Bailing out."], :notes ["`compare-and-set!` actually runs an equality comparison, not an identity comparison. The documentation should read:\n\n> Atomically sets the value of atom to newval if and only if the current value of the atom is identical equal to oldval.\n\n (def my-sym (atom 'a))\n (identical? @my-sym 'a)\n ;;=> false\n (= @my-sym 'a)\n ;;=> true\n (compare-and-set! my-sym 'a 'z)\n ;;=> true\n @my-sym\n ;;=> z" "The note that `compare-and-set!` uses equality comparison is wrong, `compare-and-set!` really _does_ use *identity comparison* (Java `==`). Internally, Clojure uses the `AtomicReference.compareAndSet(old, new)` method.\n\nThe reason his example works is due to interning of the `a` symbol: in his example, each `a` is the same (identical) object.\n\nBut as you can see from the example below, even numeric autoboxing can lead to surprising results:\n\n (def a (atom 0))\n ;=> #'user/a\n (compare-and-set! a 0 100)\n ;=> true\n ;(compare-and-set! a 100 200)\n ;=> true\n ;; Fails?! (on Oracle JVM 8 with default settings)\n (compare-and-set! a 200 300)\n ;=> false\n @a\n ;=> 200 ; WAT?\n\nClojure almost always uses boxed numbers (via Java autoboxing) unless you take special steps to avoid it. compare-and-set! only accepts Objects, so numbers are autoboxed to Longs.\n\nJava JVMs will usually intern small integers; by default Oracle/OpenJDK will intern -127 to 128 (the `byte` range) so that all such boxed numbers are identical. This can be altered with the `-XX:AutoBoxCacheMax=` command line flag. This may vary by JVM implementation, too.\n\n(In fact, on ClojureCLR, `compare-and-set!` of longs always fails because the CLR does not intern small numbers, see [this bug report](https://dev.clojure.org/jira/browse/CLJCLR-28).)\n\nSo in the example above, `compare-and-set!` on 0 and 100 work fine due to this auto-interning, but the compare with 200 fails because: `(identical? 200 200)` is false due to autoboxing: two distinct invisible `Long` objects are created for each \"200\" value.\n\nYou don't have to worry about this with `swap!` because the \"old\" value it compares against for the compare-and-set operation is always from the atom itself, so identity comparison works as long as no one else put a different object in the atom in the meantime. However, it is easy to imagine a pathological case with a highly-contented atom where everyone keeps putting the same \"equal\" value into it over and over, and yet swappers have to retry over and over."], :arglists ["atom oldval newval"], :doc "Atomically sets the value of atom to newval if and only if the\n current value of the atom is identical to oldval. Returns true if\n set happened, else false", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/compare-and-set!"}, :clojure.test/use-fixtures {:added "1.1", :ns "clojure.test", :name "use-fixtures", :file "clojure/test.clj", :type "var", :column 1, :see-alsos [:clojure.test/join-fixtures :clojure.test/compose-fixtures], :line 670, :examples ["; See https://clojure.github.io/clojure/clojure.test-api.html for details\n\n; my-test-fixture will be passed a fn that will call all your tests \n; (e.g. test-using-db). Here you perform any required setup \n; (e.g. create-db), then call the passed function f, then perform \n; any required teardown (e.g. destroy-db).\n(defn my-test-fixture [f]\n (create-db)\n (f)\n (destroy-db))\n\n; Here we register my-test-fixture to be called once, wrapping ALL tests \n; in the namespace\n(use-fixtures :once my-test-fixture)\n \n; This is a regular test function, which is to be wrapped using my-test-fixture\n(deftest test-using-db\n (is ... \n))" "; This fixture is intended to perform setup/teardown for each individual test in the namespace. Note that it assumes the :once fixture will handle creating/destroying the DB, while we only create/drop tables within the DB.\n(defn another-fixture [f]\n (create-db-table)\n (f)\n (drop-db-table))\n\n; Here we register another-fixture to wrap each test in the namespace\n(use-fixtures :each another-fixture)" ";; `use-fixtures` supports multiples arguments. \n;; They wrap the tests in order (left-to-right).\n\n;; We define some fixtures that are to be run in order\n(defn with-db [f] \n (start-db)\n (f)\n (stop-db))\n\n(defn with-data [f] \n (fill-db)\n (f)\n (empty-db))\n\n;; Here we register them\n(use-fixtures :once with-db with-data)"], :notes nil, :arglists [], :doc "Wrap test runs in a fixture function to perform setup and\n teardown. Using a fixture-type of :each wraps every test\n individually, while :once wraps the whole run in a single function.", :library-url "https://github.com/clojure/clojure", :href "/clojure.test/use-fixtures"}, :clojure.test.junit/*depth* {:ns "clojure.test.junit", :name "*depth*", :file "clojure/test/junit.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 49, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.test.junit/*depth*"}, :clojure.core/float? {:added "1.0", :ns "clojure.core", :name "float?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/double? :clojure.core/bigdec? :clojure.core/decimal?], :line 3604, :examples ["user=> (float? 0)\nfalse\nuser=> (float? 0.0)\ntrue" ";; float? returns true for both float and double.\nuser=> (map (juxt type float?) [(float 1) (double 1)])\n([java.lang.Float true] [java.lang.Double true])\n\n;; Call instance? to check if the value is specifically float or double.\nuser=> (map (juxt type #(instance? Float %)) [(float 1) (double 1)])\n([java.lang.Float true] [java.lang.Double false])" ";; BigDecimal is not float\nuser=> (float? 0.0M)\nfalse"], :notes nil, :arglists ["n"], :doc "Returns true if n is a floating point number", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/float_q"}, :clojure.core.logic/trace-lvars {:ns "clojure.core.logic", :name "trace-lvars", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1305, :examples ["(run* [q]\n (fresh [v]\n (conde\n [(trace-lvars \"1:A clause\" q v)\n (== q 1)\n (== v 23)\n (trace-lvars \"1:B clause\" q v)]\n [(== q 2)\n (trace-lvars \"2:A clause\" q v)\n (== q v)\n (trace-lvars \"2:B clause\" q v)])))\n\n\n;; => (1 _0)\n\n1:A clause\n q = _0\n v = _0\n1:B clause\n q = 1\n v = 23\n2:A clause\n q = 2\n v = _0\n2:B clause\n q = 2\n v = 2"], :macro true, :notes nil, :arglists ["title & lvars"], :doc "Goal for tracing the values of logic variables.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/trace-lvars"}, :clojure.core/inc' {:added "1.0", :ns "clojure.core", :name "inc'", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/inc :clojure.core/dec'], :line 915, :examples ["> (inc' 1)\n2\n\n> (inc' 3.14)\n4.140000000000001\n\n> (inc' 4/5)\n9/5\n\n> (inc' -1)\n0\n\n> (inc' -3/2)\n-1/2\n\n> (inc' -0.2)\n0.8" ";;;; (inc') auto-promotes on integer overflow:\n\n(inc' (Long/MAX_VALUE))\n;;=> 9223372036854775808N\n\n;;;; Unlike (inc) which does not:\n\n(inc (Long/MAX_VALUE))\n;;=> ArithmeticException integer overflow"], :notes nil, :arglists ["x"], :doc "Returns a number one greater than num. Supports arbitrary precision.\n See also: inc", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/inc'"}, :clojure.core.reducers/coll-fold {:ns "clojure.core.reducers", :name "coll-fold", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["coll n combinef reducef"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.reducers/coll-fold"}, :clojure.core/booleans {:added "1.1", :ns "clojure.core", :name "booleans", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/boolean-array], :line 5348, :examples [";; for fast interop\nuser=> (set! *warn-on-reflection* true)\ntrue\nuser=> (defn get-a-bool [bs] (aget bs 1))\nReflection warning, NO_SOURCE_PATH:1 - call to aget can't be resolved.\n#'user/get-a-bool\nuser=> (defn get-a-bool [bs] (let [bs (booleans bs)] (aget bs 1)))\n#'user/get-a-bool\n" ";; can also be used as type hint to avoid reflection:\nuser=> (set! *warn-on-reflection* true)\ntrue\nuser=> (defn get-a-bool [^booleans bs] (aget bs 1))\n#'user/get-a-bool"], :notes nil, :arglists ["xs"], :doc "Casts to boolean[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/booleans"}, :clojure.core/binding {:added "1.0", :ns "clojure.core", :name "binding", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/with-redefs :clojure.core/with-bindings :clojure.core/with-local-vars :clojure.core/def], :line 1947, :examples [";; Here are the definitions.\n(defn mymax [x y]\n (min x y))\n\n(defn find-max [x y]\n (max x y))\n\nuser=> (let [max mymax]\n (find-max 10 20))\n\n20 ;let is ineffective outside current lexical scope\n\n\nuser=> (binding [max mymax]\n (find-max 10 20))\n\n10 ;because max is now acting as min" ";; As of Clojure 1.3, vars need to be explicitly marked as ^:dynamic in order for\n;; them to be dynamically rebindable:\n\nuser=> (def ^:dynamic x 1)\nuser=> (def ^:dynamic y 1)\nuser=> (+ x y)\n2\n\n;; Within the scope of the binding, x = 2 and y = 3\n\nuser=> (binding [x 2 \n y 3]\n (+ x y))\n5\n\n;; But once you leave the binding's scope, x and y maintain their original\n;; bindings:\n\nuser=> (+ x y)\n2" ";;Use t like a \"template\"\n\n(declare ^:dynamic t)\n\n(defn addt [] \n (+ t 10))\n\n(binding [t 1]\n (addt))\n=> 11" "; You can set! bindings. Useful in a stateful programming.\nuser=> (def ^:dynamic d)\n#'user/d\nuser=> d\n#\nuser=> (binding [d 0] (prn d) (set! d 1) (prn d))\n0\n1\nnil\nuser=> d\n#\n\n; Note that you can't use set! outside of binding [] \"stack\":\n(set! d 1) ; => ...Can't change/establish root binding...\n; You can use set! anywhere under binding [] \"stack\", including from lazy sequences:\n(defn set-d [v] (set! d v))\n(binding [d 0] (set-d 1) (prn d)) ;=> 1\n(first (binding [d 0] (set-d 1) (repeat d)) ) ;=> 1\n; But NOT from delay/force:\n(force (binding [d 0] (set-d 1) (delay d)) ) ;=> ...clojure.lang.Var$Unbound..." "; Speed test. recur is the preferred way.\nuser=> (def a (atom 0))\n#'user/a\nuser=> (def ^:dynamic b)\n#'user/b\nuser=> (def d)\n#'user/d\nuser=> (time (loop [r 0] (when (< r 10000000) (recur (inc r)))))\n\"Elapsed time: 8.062612 msecs\"\nnil\nuser=> (time (dotimes [_ 10000000] (reset! a 1)))\n\"Elapsed time: 93.428704 msecs\"\nnil\nuser=> (time (binding [b 0] (dotimes [_ 10000000] (set! b 1))))\n\"Elapsed time: 484.331821 msecs\"\nnil\nuser=> (time (with-local-vars [w 0] (dotimes [_ 10000000] (var-set w 1))))\n\"Elapsed time: 490.598696 msecs\"\nnil\nuser=> (time (dotimes [_ 10000000] (def d 1)))\n\"Elapsed time: 2154.646688 msecs\"\nnil\n" ";; You can modify the variable inside a binding, \n;; inside a let, you can't.\n\n(def ^:dynamic z)\n\n(binding [z nil]\n (doseq [x (range 4) y (range 4)]\n (set! z [x y]))\n z)\n\n; => [3 3]\n\n;; You can modify the variable inside a for, with dorun.\n\n(binding [z nil]\n (dorun\n (for [x (range 4) y (range 4)]\n (set! z [x y])))\n z)\n\n; => [3 3]" ";; from stackoverflow http://stackoverflow.com/questions/1523240/let-vs-binding-in-clojure\n;; let creates a lexically scoped immutable alias for some value. \n;; binding creates a dynamically scoped binding for some Var.\n\n;; Dynamic binding means that the code inside your binding form and any code \n;; which that code calls (even if not in the local lexical scope) will see the new binding.\n\nuser> (def ^:dynamic x 0)\n#'user/x\n\n;; Lexical vs. dynamic binding:\n\nuser> (defn foo [] (println x))\n#'user/foo\nuser> (binding [x 1] (foo))\n1\nnil\nuser> (let [x 1] (foo))\n0\nnil" ";; Beware usage in ClojureScript around asynchronous calls, as the bound\n;; var's original value will be re-established before the async code executes:\n\n(def ^:dynamic *foo* nil)\n\n(binding [*foo* :bar]\n (js/setTimeout\n (fn []\n *foo* ;;=> nil\n ))\n\n;; Also beware *synchronous* usage inside `cljs.test/async`, as the bound\n;; var's original value will not be re-established:\n\n(ns my-ns\n (:require [cljs.test :refer-macros [async deftest is]]))\n\n(def ^:dynamic *foo* nil)\n\n(deftest my-test\n (async done\n (binding [*foo* :bar]\n (done))))\n\n(deftest another-test\n (async done\n (is (nil? *foo*))))\n\n;; FAIL in (another-test)\n;; expected: (nil? *foo*)\n;; actual: (not (nil? :bar))\n\n;; At time of writing, the stable ClojureScript version is 1.9.89." ";; Re-bind `*in*` so that `read-line` reads from a file instead of stdin.\n;; Taken from here: https://stackoverflow.com/a/24826485/1019491\n\n(with-open [is (clojure.java.io/reader \"/tmp/foo.txt\")]\n (binding [*in* is]\n (println (read-line))))\n\n" ";; Seed the random number generator so every invocation comes out the same.\n\n(require '[clojure.data.generators :as gen])\n\n(defn not-random-at-all []\n (let [wordlist '[one two three four five]]\n (binding [gen/*rnd* (java.util.Random. 42)]\n (gen/shuffle wordlist))))\n\n(not-random-at-all)\n;; => [two five one three four]\n(not-random-at-all)\n;; => [two five one three four]\n(not-random-at-all)\n;; => [two five one three four]\n" ";; Beware of lazyness\n(def ^:dynamic *foo* :FOO)\n(defn foo [x] [*foo* x])\n\n;; realized when bindings are reset\n(binding [*foo* :BAR]\n (map foo [1 2 3]))\n=> ([:FOO 1] [:FOO 2] [:FOO 3])\n\n;; force realization while bindings active\n(binding [*foo* :BAR]\n (doall (map foo [1 2 3])))\n=> ([:BAR 1] [:BAR 2] [:BAR 3]) \n\n;; closure `bound-foo` with bindings\n(binding [*foo* :BAR]\n (let [bound-foo (bound-fn [x] (foo x))]\n (map bound-foo [1 2 3])))\n=> ([:BAR 1] [:BAR 2] [:BAR 3]) \n\n;; more convenient closuring\n(binding [*foo* :BAR]\n (let [bound-foo (bound-fn* foo)]\n (map bound-foo [1 2 3])))\n=> ([:BAR 1] [:BAR 2] [:BAR 3]) \n"], :macro true, :notes ["The first example (binding mymax to max) appears to be broken. The last line generates the error:\r\n
\r\n\r\nI tried inserting (.setDynamic #'max) at the top, and it got rid of the error, but the binding didn't seem to actually happen. I.e. the last line prints 20.\r\n\r\n The only way I could get it to work is by redefining max from scratch as dynamic:\r\n\r\n
\r\n(defn ^:dynamic max\r\n ([x] x)\r\n ([x y] (. clojure.lang.Numbers (max x y)))\r\n ([x y & more]\r\n (reduce max (max x y) more)))\r\n
\r\n\r\nAfter THIS the first example succeeds.\r\n\r\n The moral of the story - I guess you can't easily bind built-in functions. You need to write your functions with the intention of them being bindable. And I guess the first example should simply be removed?" "So about first example --\n
\nLong story short: var needs to be defined `^:dynamic` before you create your function with var being bound here, or else no dynamic building occur (which is intended behavior, I guess)." "There's a great blog post from Chas Emerick about `binding`, [Be Mindful of Clojure's `binding`](https://cemerick.com/blog/2009/11/03/be-mindful-of-clojures-binding.html), that discusses two common pitfalls that one can fall into when using `binding`."], :arglists ["bindings & body"], :doc "binding => var-symbol init-expr\n\n Creates new bindings for the (already-existing) vars, with the\n supplied initial values, executes the exprs in an implicit do, then\n re-establishes the bindings that existed before. The new bindings\n are made in parallel (unlike let); all init-exprs are evaluated\n before the vars are bound to their new values.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/binding"}, :clojure.core/*read-eval* {:added "1.0", :ns "clojure.core", :name "*read-eval*", :type "var", :see-alsos [:clojure.core/read :clojure.core/read-string :clojure.core/load], :examples [";;just from the doc\n\n(binding [*read-eval* false] (read-string \"#=(eval (def x 3))\"))\n=> EvalReader not allowed when *read-eval* is false.\n [Thrown class java.lang.RuntimeException]\n\n;;remove the anonymous function:\n\n(binding [*read-eval* false] (read-string \"(def x 3)\"))\n=> (def x 3)\n\n;;which is evaluable\n\n(eval (binding [*read-eval* false] (read-string \"(def x 3)\")))\n=> #'user/x\n\nx\n=>3"], :notes ["This dynamic Var defines if `read` and `read-string` will be allowed to evaluate code using the eval reader `#=`. That said, the way that the eval reader will evaluate things within the context of reading is very strange, here are the rules (credit to p-himik from Slack):\n\nEvaluation done by `read` and `read-string` using the eval reader is very limited and supports only the following cases:\n\n1. The form is a symbol naming a Java class, `(read-string \"#=java.lang.String\")`\n2. The form is a list and the first symbol is a symbol\n 2. that is var and the next one is a fully qualified symbol, `(def x) (read-string \"#=(var user/x)\")`\n 2. that denotes a constructor calling, `(read-string \"#=(java.lang.String. \\\"x\\\")\")`\n 2. that denotes a static member calling, `(read-string \"#=(java.lang.Integer/parseInt \\\"1\\\")\")`\n 2. that names something in the current NS, and the rest are quoted entities, `(read-string \"#=(inc 1)\")`\n\nAs you can see, everything after the first symbol is left untouched. This makes the eval reader extremely limited by itself in comparison to normal eval, but you can use eval there to circumvent that: `(def x 1) (read-string \"#=(eval x)\")`\n\nTo be more clear, in the given example:\n\n```\n(read-string \"#=(+ 1 (+ 2 3))\")\n```\n\nEverything after the first `+` are read as if quoted, so the above is equivalent to:\n\n```\n(+ '1 '(+ 2 3))\n```\n\nWhich will throw an exception:\n\n> PersistentList cannot be cast to class java.lang.Number\n\nThat's why the trick if you want to use the eval reader to evaluate arbitrary code is to use `eval` inside it like so:\n\n```\n(read-string \"#=(eval (+ 1 (+ 2 3)))\")\n```\n\nWhich will even let you reference a value in the current context:\n\n```\n(def x 1)\n#=(eval (+ 1 x))\n;;=> 2\n```"], :arglists [], :doc "Defaults to true (or value specified by system property, see below)\n ***This setting implies that the full power of the reader is in play,\n including syntax that can cause code to execute. It should never be\n used with untrusted sources. See also: clojure.edn/read.***\n\n When set to logical false in the thread-local binding,\n the eval reader (#=) and record/type literal syntax are disabled in read/load.\n Example (will fail): (binding [*read-eval* false] (read-string \"#=(* 2 21)\"))\n\n The default binding can be controlled by the system property\n 'clojure.read.eval' System properties can be set on the command line\n like this:\n\n java -Dclojure.read.eval=false ...\n\n The system property can also be set to 'unknown' via\n -Dclojure.read.eval=unknown, in which case the default binding\n is :unknown and all reads will fail in contexts where *read-eval*\n has not been explicitly bound to either true or false. This setting\n can be a useful diagnostic tool to ensure that all of your reads\n occur in considered contexts. You can also accomplish this in a\n particular scope by binding *read-eval* to :unknown\n ", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*read-eval*"}, :clojure.main/renumbering-read {:added "1.10", :ns "clojure.main", :name "renumbering-read", :file "clojure/main.clj", :type "function", :column 1, :see-alsos nil, :line 140, :examples nil, :notes nil, :arglists ["opts reader line-number"], :doc "Reads from reader, which must be a LineNumberingPushbackReader, while capturing\n the read string. If the read is successful, reset the line number and re-read.\n The line number on re-read is the passed line-number unless :line or\n :clojure.core/eval-file meta are explicitly set on the read value.", :library-url "https://github.com/clojure/clojure", :href "/clojure.main/renumbering-read"}, :clojure.core/transduce {:added "1.7", :ns "clojure.core", :name "transduce", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/completing], :line 6870, :examples [";; First, define a transducer for producing the first ten odd numbers:\n(def xf (comp (filter odd?) (take 10)))\n\n;; We can then apply this transducer in different ways using transduce.\n\n;; Get the numbers as a sequence:\n\n(transduce xf conj (range))\n;;=> [1 3 5 7 9 11 13 15 17 19]\n\n;; Or sum them:\n\n(transduce xf + (range))\n;; => 100\n\n;; ... with an initializer:\n\n(transduce xf + 17 (range))\n;; => 117\n\n;; Or concatenate them to a string:\n\n(transduce xf str (range))\n;; => \"135791113151719\"\n\n;; .. with an initializer:\n\n(transduce xf str \"...\" (range))\n;; => \"...135791113151719\"\n" ";; When studying Korean, I had notes with mixture of Korean and\n;; English and I wanted to filter out any English. \n\n(def example (str \"I will write an autobiography(자서전) later\\n\"\n \"(저는) 나중에 자서전을 쓸 거에요\"))\n\n;; Here's a transducer to filter out english characters\n\n(defn filter-out-english \n \"filter out english characters in a string\"\n []\n (filter (fn [c] \n (let [i (int c)] \n (not (or (and (>= i 65) (<= i 90)) \n (and (>= i 97) (<= i 122))))))))\n\n;; Here's a transducer to help deal with extra spaces and newlines.\n;; Notice the mapcat ensures that the output will always be the same\n;; shape as the input\n\n(defn trim-chars [c n]\n \"Ensure exactly n characters c in a row. For example, squash\n multiple spaces into single space or expand newlines into 2\n newlines\"\n (comp (partition-by #{c})\n (mapcat #(if (= c (first %)) (repeat n c) %))))\n\n\n;; put it all together, we filter out english characters, replace\n;; multiple spaces with single space, and ensure each line is double\n;; spaced (two line breaks between each line)\n(def xf (comp (filter-out-english) \n (trim-chars \\space 1)\n (trim-chars \\newline 2)))\n\n(apply str (transduce xf conj example))\n;; => \" (자서전) \\n\\n(저는) 나중에 자서전을 쓸 거에요\"\n" ";; transduce with the identity transform is equivalent to reduce,\n;; in the following way:\n(transduce identity f sample)\n(f (reduce f (f) sample))\n\n;; For example, we can define a reducing function and then use it:\n(defn conj-second\n ([]\n [])\n ([result]\n result)\n ([result [x y]]\n (conj result y)))\n\n(def sample [[1 :a] [2 :b] [3 :c]])\n\n(transduce identity conj-second sample)\n;;=>[:a :b :c]\n(conj-second (reduce conj-second (conj-second) sample))\n;;=>[:a :b :c]\n\n;; Let's prove the point with printing:\n(defn conj-second\n ([]\n (println \"0\") [])\n ([result]\n (println \"1\") result)\n ([result [x y]]\n (println \"2\") (conj result y)))\n\n;; Then the following both print 0 2 2 2 1\n(transduce identity conj-second sample)\n(conj-second (reduce conj-second (conj-second) sample))\n" ";;; BUILD A STATEFULL TRANSDUCER\n\n;; Make a transducer that accumulates a sequence when pred is truthy and\n;; returns individual values when pred is falsy.\n;;\n;; For example when pred is odd?, partition\n;;\n;; [1 1 1 2 2 3 3 3]\n;; \n;; into\n;; \n;; [[1 1 1] [2] [2] [3 3 3]]\n;;\n\n(defn accumulate-when [pred]\n ;; A transducer takes a reducer function and returns a reducer function.\n (fn [rf]\n ;; State (an accumulator) which is closed over by the reducer function.\n (let [acc (java.util.ArrayList.)]\n (fn\n ;; Arity 0 (state initializer). In this step we can initialize `acc`\n ;; based on the returned valued of (rf), but here, as it is usually the\n ;; case, this is not needed.\n ([] (rf))\n \n ;; Arity 1 (completer). Called after the reducing process has ended (if\n ;; ever). In this step local state must be cleaned and residual reducing\n ;; step may be performed. `result` is an unreduced value (see reduced\n ;; and unreduced).\n ([result]\n (let [result (if (.isEmpty acc)\n ;; No residual state. Simply return the result.\n result\n ;; Need to clear the residual state and perform one last\n ;; reducing step on the so far accumulated values.\n (let [v (vec (.toArray acc))]\n (.clear acc)\n ;; This step might return a completed value (i.g. on\n ;; which reduced? gives true). We need to deref it\n ;; with `unreduced` in order to supply it to rf.\n (unreduced (rf result v))))]\n ;; Nested rf call. Must happen once!\n (rf result)))\n \n ;; Arity 2 (reducer). This is where the main work happens.\n ([result input]\n (if (pred input)\n ;; When pred is truthy, accumulate and don't call the nested reducer.\n (do\n (.add acc input)\n result)\n ;; When pred is falsy, call nested reducer (possibly twice).\n (if (.isEmpty acc)\n ;; When accumulator is empty, reduce with a singleton.\n (rf result [input])\n (let [v (vec (.toArray acc))]\n (.clear acc)\n ;; First reduce on the accumulated sequence.\n (let [ret (rf result v)]\n (if (reduced? ret)\n ;; If sequence is completed, no more reductions\n ret\n ;; else, reduce once more with the current (falsy) input.\n (rf ret [input])))))))))))\n\n(def x [1 1 1 2 2 3 3 3])\n\n;; Step through with the debugger in order to gain a better understanding of the\n;; involved steps.\n\n(transduce (accumulate-when odd?) conj x)\n;; user> [[1 1 1] [2] [2] [3 3 3]]\n\n(transduce (comp (take 4) (accumulate-when odd?)) conj x)\n;; user> [[1 1 1] [2]]\n\n(transduce (comp (accumulate-when odd?) (take 3)) conj x)\n;; user> [[1 1 1] [2] [2]]\n\n(transduce (comp (accumulate-when odd?) (take 4)) conj x)\n;; user> [[1 1 1] [2] [2] [3 3 3]]\n\n;; Clojure core statefull transducers are partition-by, partition-all, take,\n;; drop, drop-while, take-nth, distinct, interpose, map-indexed and\n;; keep-indexed.\n" "(transduce\n (partition-by identity)\n (fn\n ;; init - returns initial value for accumulator, called when no init is given to transduce\n ([] [])\n ;; completion - returns the final result, take the final accumulated value, called once there are no more elements to process\n ([acc] acc)\n ;; step - do whatever you want on each element, returns accumulated state and takes accumulated state from before and new element\n ([acc e] (conj acc e)))\n '()\n [1 1 1 2 2 3 3 4 4 5 6 7 7])\n\n;; => ([7 7] [6] [5] [4 4] [3 3] [2 2] [1 1 1])" ";; These two forms are equivalent:\n\n(reduce ((map inc) conj) [] '(1 2 3 4 5))\n;; => [2 3 4 5 6]\n\n(transduce (map inc) conj [] '(1 2 3 4 5))\n;; => [2 3 4 5 6]\n\n;; Which shows how transduce works: it applies the transducer to the reducing\n;; function, and reduces the collection with that\n\n;; But n.b. this example masks the fact that transduce does call f an extra\n;; time for \"completion\", because arity-1 conj = identity."], :notes ["Usually you use existing functions to create the transformation, using map, filter, paritition-all, etc. But you can also define your own transformations. A transformation (or transducer) is a function that takes a reducing function and returns a reducing function. See the source for [take](https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L2752) and [filter](https://github.com/clojure/clojure/blob/clojure-1.8.0/src/clj/clojure/core.clj#L2684) for examples."], :arglists ["xform f coll" "xform f init coll"], :doc "reduce with a transformation of f (xf). If init is not\n supplied, (f) will be called to produce it. f should be a reducing\n step function that accepts both 1 and 2 arguments, if it accepts\n only 2 you can add the arity-1 with 'completing'. Returns the result\n of applying (the transformed) xf to init and the first item in coll,\n then applying xf to that result and the 2nd item, etc. If coll\n contains no items, returns init and f is not called. Note that\n certain transforms may inject or skip items.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/transduce"}, :clojure.core.logic.fd/binops->fd {:ns "clojure.core.logic.fd", :name "binops->fd", :file "clojure/core/logic/fd.clj", :type "var", :column 1, :see-alsos nil, :line 1099, :examples nil, :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.fd/binops->fd"}, :clojure.core.logic/reify-constraints {:ns "clojure.core.logic", :name "reify-constraints", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 2164, :examples nil, :notes nil, :arglists ["v r a"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/reify-constraints"}, :clojure.core/-> {:added "1.0", :ns "clojure.core", :name "->", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/->> :clojure.core/as-> :clojure.core/get-in :clojure.core/some-> :clojure.core/doto :clojure.core/..], :line 1677, :examples [";; Use of `->` (the \"thread-first\" macro) can help make code\n;; more readable by removing nesting. It can be especially\n;; useful when using host methods:\n\n;; Arguably a bit cumbersome to read:\nuser=> (first (.split (.replace (.toUpperCase \"a b c d\") \"A\" \"X\") \" \"))\n\"X\"\n\n;; Perhaps easier to read:\nuser=> (-> \"a b c d\" \n .toUpperCase \n (.replace \"A\" \"X\") \n (.split \" \") \n first)\n\"X\"\n\n;; It can also be useful for pulling values out of deeply-nested\n;; data structures:\nuser=> (def person \n {:name \"Mark Volkmann\"\n :address {:street \"644 Glen Summit\"\n :city \"St. Charles\"\n :state \"Missouri\"\n :zip 63304}\n :employer {:name \"Object Computing, Inc.\"\n :address {:street \"12140 Woodcrest Dr.\"\n :city \"Creve Coeur\"\n :state \"Missouri\"\n :zip 63141}}})\n \nuser=> (-> person :employer :address :city)\n\"Creve Coeur\"\n\n;; same as above, but with more nesting\nuser=> (:city (:address (:employer person)))\n\"Creve Coeur\"\n\n;; Note that this operator (along with ->>) has at times been\n;; referred to as a 'thrush' operator.\n\n;; http://blog.fogus.me/2010/09/28/thrush-in-clojure-redux/\n" ";; Your own REPL! (Read Eval Print Loop)\n\n;; We would need a little helper macro for that\n;; It does what its name says - loops forever\nuser=> (defmacro loop-forever [& body] `(loop [] ~@body (recur)))\n\n;; Your own REPL\nuser=> (loop-forever (println (eval (read)))) \n(+ 1 2)\n3\n\n;; If you read the above code left to right (outside in) it reads LPER.\n;; Inside out it reads REPL alright.\n\n;; Sometimes it might be easier to read code outside in, just like a sequence of steps:\n;; 1. Read, 2. Eval, 3. Print, 4. Loop\n;; Here's how -> helps you:\n\nuser=> (-> (read) (eval) (println) (loop-forever)) \n(+ 1 2)\n3\n\n;; Does that read easier for you? If it does, -> is your friend!\n\n;; To see what Clojure did behind the scenes with your -> expression:\nuser=> (require 'clojure.walk)\nnil\nuser=> (clojure.walk/macroexpand-all '(-> (read) (eval) (println) (loop-forever)))\n(loop* [] (println (eval (read))) (recur))\n\n;; You can even use ->'s cousin ->> to setup your own REPL:\nuser=> (->> (read) (eval) (println) (while true))\n(+ 1 2)\n3\n\n;; Can you see why we can't use -> to write the above?\n\n" "user=> (def c 5)\nuser=> (-> c (+ 3) (/ 2) (- 1)) \n3\n\n;; and if you are curious why\nuser=> (use 'clojure.walk)\nuser=> (macroexpand-all '(-> c (+ 3) (/ 2) (- 1)))\n(- (/ (+ c 3) 2) 1)\n" ";; simplest usage example, fill as second item in the first and second form\n\nuser=> (-> \"foo\"\n (str \"bar\")\n (str \"zoo\"))\n\"foobarzoo\"\nuser=> (str \"foo\" \"bar\")\n\"foobar\"\nuser=> (str (str \"foo\" \"bar\") \"zoo\")\n\"foobarzoo\"" "(-> 3 (- 2)) ; It means (- 3 2)\n=> 1\n\n(->> 3 (- 2)) ; It means (- 2 3)\n=> -1\n\n(doto 3 (- 2)) ; It means (- 3 2) but return the first object 3\n=> 3" ";; Be cautious with anonymous functions; they must be wrapped in an outer\n;; pair of parens.\n(-> 10\n #(/ % 2))\n;; will throw an exception, but\n(-> 10\n (#(/ % 2)))\n;; will work fine. Similarly,\n(-> 10\n (fn [n] (/ n 2)))\n;; will throw an exception, but\n(-> 10\n ((fn [n] (/ n 2))))\n;; works as intended.\n" ";; How to thread functions that expect more than one argument\n\n;; Say you want to thread this.\nuser=> (inc (/ 10 2))\n=> 6\n\n;; This obviously won't work\nuser=> (-> 2 10 / inc)\n=> ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn\n\n;; Since Clojure is expecting a function instead of `10` in `(10 2)`\nuser=> (clojure.walk/macroexpand-all '(-> 2 10 + inc))\n=> (inc (+ (10 2)))\n\n;; Instead you have two options, either just\nuser=> (-> (/ 10 2) inc)\n=> 6\n\n;; or\nuser=> (-> 10 (/ 2) inc)\n=> 6" ";; For large threads you can use commas (interpreted as whitespaces) \n;; to visualize where the items are going to be inserted.\n\nuser=> (-> + (reduce 10 [6 4]) (* 5) (/ 100))\n=> 1\n\n;; with two commas (you can use one if you prefer)\nuser=> (-> + (reduce ,, 10 [6 4]) (* ,, 5) (/ ,, 100))\n=> 1\n\n;; For instance:\n;; (reduce ,, 10 [6 4])\n;; means\n;; (reduce + 10 [6 4])" ";; 4Clojure Question 38\n\n(= (#(-> %& \n sort \n reverse \n first) 1 8 3 4) 8)"], :macro true, :notes ["See also ->> which is similar but threads the first expr as the last argument of the forms." "I have a [short blog](http://wangjinquan.me/show/Clojure%20线性(ç®å¤´ï¼‰æ“�作符) on this, in case you are still confused on it and understand Chinese." "Can be used as an alternative to get-in."], :arglists ["x & forms"], :doc "Threads the expr through the forms. Inserts x as the\n second item in the first form, making a list of it if it is not a\n list already. If there are more forms, inserts the first form as the\n second item in second form, etc.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/->"}, :clojure.java.io/IOFactory {:added "1.2", :ns "clojure.java.io", :name "IOFactory", :file "clojure/java/io.clj", :type "var", :column 1, :see-alsos [:clojure.java.io/reader :clojure.java.io/writer :clojure.java.io/input-stream :clojure.java.io/output-stream], :line 69, :examples nil, :notes nil, :arglists [], :doc "Factory functions that create ready-to-use, buffered versions of\n the various Java I/O stream types, on top of anything that can\n be unequivocally converted to the requested kind of stream.\n\n Common options include\n \n :append true to open stream in append mode\n :encoding string name of encoding to use, e.g. \"UTF-8\".\n\n Callers should generally prefer the higher level API provided by\n reader, writer, input-stream, and output-stream.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/IOFactory"}, :clojure.core.logic/or* {:ns "clojure.core.logic", :name "or*", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1185, :examples nil, :notes nil, :arglists ["goals"], :doc "A function version of conde, which takes a list of goals and tries them as if via conde.\n Note that or* only does disjunction, ie (or* [a b c]) is the same as (conde [a] [b] [c]).\n If you need something like (conde [a b] [c]), you can use and*, or all:\n (or* [(and* a b) c]).", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/or*"}, :clojure.java.javadoc/add-local-javadoc {:added "1.2", :ns "clojure.java.javadoc", :name "add-local-javadoc", :file "clojure/java/javadoc.clj", :type "function", :column 1, :see-alsos [:clojure.java.javadoc/javadoc :clojure.java.javadoc/*local-javadocs*], :line 43, :examples ["(require '[clojure.java.javadoc :as javadoc])\n\n;; After extracting JDK 11 Javadocs into ~/javadocs/jdk11\n(javadoc/add-local-javadoc \n (str (System/getProperty \"user.home\")\n \"/javadocs/jdk11/api/java.base\"))\n\n;; Open default browser showing java.io.PrintStream\n(javadoc/javadoc System/out)\n"], :notes nil, :arglists ["path"], :doc "Adds to the list of local Javadoc paths.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.javadoc/add-local-javadoc"}, :clojure.core/repeatedly {:added "1.0", :ns "clojure.core", :name "repeatedly", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/repeat :clojure.core/iterate :clojure.core/lazy-seq :clojure.core/dotimes :clojure.core/doall :clojure.core/rand-int :clojure.core/constantly :clojure.core/while], :line 5143, :examples [";; these two functions are equivalent \n\n(take 5 (repeatedly #(rand-int 11)))\n;;=> (6 6 3 9 8)\n\n;; this version only returns the first five elements\n(repeatedly 5 #(rand-int 11))\n;;=> (1 8 6 9 6)\n\n;; compare with repeat, which\n;; only calls the 'rand-int' function once,\n;; repeating the value five times.\n(repeat 5 (rand-int 100))\n(94 94 94 94 94)" "(defn counter [] \n (let [tick (atom 0)]\n #(swap! tick inc)))\n\n(def tick (counter))\n\n(take 10 (repeatedly tick))\n;;=> (1 2 3 4 5 6 7 8 9 10)\n\n;; or equivalently\n(repeatedly 10 (counter))\n;;=> (1 2 3 4 5 6 7 8 9 10)" ";;;; If you want random values for each element in repeatedly\n;; don't call rand as an argument in partial\n(= true\n (every? true?\n [(apply = (flatten\n (repeatedly 2 (partial vector (rand)))))\n (apply = (flatten\n (repeatedly 2 (partial (partial vector (rand))))))]))\n\n;; but do call it within a #(...) or (fn [] ...)\n(= true\n (every? false?\n [(apply = (repeatedly 2 rand)) \n (apply = (repeatedly 2 #(rand))) \n (apply = (repeatedly 2 (partial rand))) ; passing the rand function works\n (apply = (flatten\n (repeatedly 2 (fn [] (vector (rand))))))\n (apply = (flatten\n (repeatedly 2 #((partial vector (rand))))))\n (apply = (flatten\n (repeatedly 2 #(vector (rand)))))]))" ";; \"repeatedly\" used to build a infinite sequence of side-effecting futures.\n;; Futures are taken in batch of \"parallel\" concurrent threads. The queue\n;; can be fed while the loop is running. \"done?\" determines the exit condition.\n\n(import '[java.util.concurrent ConcurrentLinkedQueue])\n(def q (ConcurrentLinkedQueue. (range 100)))\n\n(let [parallel 5\n done? #(> (reduce + (remove nil? %)) 30)\n task #(do (println \"start\" %) (Thread/sleep 1000) (inc %))]\n (loop [workers (repeatedly\n #(let [out *out*]\n (future\n (binding [*out* out]\n (when-let [item (.poll q)]\n (task item))))))]\n (println \"-> starting\" parallel \"new workers\")\n (let [futures (doall (take parallel workers))\n results (mapv deref futures)]\n (cond\n (done? results) results\n (.isEmpty q) (println \"Empty.\")\n :else (recur (drop parallel workers))))))\n\n;; -> starting 5 new workers\n;; startstart 03\n;;\n;; startstart 1\n;; 2start 4\n;;\n;; -> starting 5 new workers\n;; start 5start\n;; start start7start\n;; 6\n;; 8\n;; 9\n[6 7 8 9 10]\n" ";; CLI app to return the type of a line\n\n(doseq [val (repeatedly read-line)]\n (prn\n (type\n (clojure.edn/read-string val))))\n\n;; $\nHello\nclojure.lang.Symbol\n15\njava.lang.Long\n:keyword\nclojure.lang.Keyword\n{}\nclojure.lang.PersistentArrayMap"], :notes ["if the function you want to repeat doesn't have side effects and has an argument, 'iterate' may be what you are looking for."], :arglists ["f" "n f"], :doc "Takes a function of no args, presumably with side effects, and\n returns an infinite (or length n if supplied) lazy sequence of calls\n to it", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/repeatedly"}, :clojure.string/trimr {:added "1.2", :ns "clojure.string", :name "trimr", :file "clojure/string.clj", :type "function", :column 1, :see-alsos [:clojure.string/trim :clojure.string/triml], :line 263, :examples ["(use 'clojure.string)\n(trimr \" my string \")\n=> \" my string\"" ";; Note: see an example at trim for the differences between\n;; \"whitespace\" for trim/trimr/triml and \n;; \"whitespace\" for regex (\\s)"], :notes nil, :tag "java.lang.String", :arglists ["s"], :doc "Removes whitespace from the right side of string.", :library-url "https://github.com/clojure/clojure", :href "/clojure.string/trimr"}, :clojure.core.logic/fail {:ns "clojure.core.logic", :name "fail", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos nil, :line 1144, :examples nil, :notes nil, :arglists ["a"], :doc "A goal that always fails.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/fail"}, :clojure.core/reversible? {:added "1.0", :ns "clojure.core", :name "reversible?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 6268, :examples ["user=> (reversible? [])\ntrue\nuser=> (reversible? (sorted-map))\ntrue\nuser=> (reversible? (sorted-set))\ntrue\nuser=> (reversible? '())\nfalse\nuser=> (reversible? {})\nfalse\nuser=> (reversible? #{})\nfalse"], :notes nil, :arglists ["coll"], :doc "Returns true if coll implements Reversible", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reversible_q"}, :clojure.core/unchecked-inc-int {:added "1.0", :ns "clojure.core", :name "unchecked-inc-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/unchecked-dec-int], :line 1149, :examples ["(unchecked-inc-int 42);; => 43\n(unchecked-inc-int 42.8);; => 43\n(unchecked-inc-int Integer/MAX_VALUE);; => -2147483648"], :notes nil, :arglists ["x"], :doc "Returns a number one greater than x, an int.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-inc-int"}, :clojure.core.async/map< {:ns "clojure.core.async", :name "map<", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 999, :examples nil, :deprecated "0.1.319.0-6b1aca-alpha", :notes ["Can anyone show, using an example, how to use a transducer instead of this function?"], :arglists ["f ch"], :doc "Deprecated - this function will be removed. Use transducer instead", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/map<"}, :clojure.core/empty? {:added "1.0", :ns "clojure.core", :name "empty?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/seq :clojure.core/empty :clojure.core/not-empty], :line 6206, :examples ["user=> (empty? ())\ntrue\nuser=> (empty? '(1))\nfalse" "user=> (every? empty? [\"\" [] () '() {} #{} nil])\ntrue\n\n;example of recommended idiom for testing if not empty\nuser=> (every? seq [\"1\" [1] '(1) {:1 1} #{1}])\ntrue" "user=> (drop-while empty? [\"\" [] \"foobar\"])\n(\"foobar\")" "user=> (empty? nil)\ntrue" ";; A collection with a \"nothing\" in it is not empty.\n(= true\n (every? false? [(empty? [nil])\n (empty? #{nil})\n (empty? '(nil))]))\n\n;; But a collection of nothing is empty.\n(= true\n (every? true? [(empty? [])\n (empty? #{})\n (empty? '())]))"], :notes ["Some explanation of why (seq x) is preferable over (not (empty? x)) would be good. Because it's far less readable. When I come across (not (empty? x)) in some code, I immediately understand the author's intention. Not so much with (seq x)." "I think this is an efficiency thing. If you expand the source you can see that empty? is equivalent to (not (seq coll)) so (not (empty? coll)) would macroexpand to (not (not (seq coll)) " "Avoiding `(not (empty? s))` because it macroexpands into `(not (not ...))`, on the grounds of efficiency, is ridiculous. \n\nI'm a fan of:\n\n```clojure\n(when (not-empty s)\n ...)\n```" "If I just want to return false when empty, true when not empty, then what can I use if I am going to avoid (not (empty? ...))?" "Just note `(not (empty? x))` is not perfectly equivalent to `seq`:\n\n~~~\nuser=> (seq '(1 2))\n(1 2)\nuser=> (not (empty? '(1 2)))\ntrue\n~~~" "```\nuser> (let [r (and (not (empty? [])))] r)\n;; => false\nuser> (let [r (and (seq []))] r)\n;; => nil\n```\n" "`(seq x)` is considered idiomatic, so in theory it should be understood by experienced Clojurians. `(not (empty? x))` might be better when you expect your code to be read by those who don't fit that description. (However, there are a number of Clojure idioms that could be confusing to those without much experience; avoiding them all might not be desirable.)"], :arglists ["coll"], :doc "Returns true if coll has no items - same as (not (seq coll)).\n Please use the idiom (seq x) rather than (not (empty? x))", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/empty_q"}, :clojure.core.async/tap* {:ns "clojure.core.async", :name "tap*", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["m ch close?"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/tap*"}, :clojure.core/== {:added "1.0", :ns "clojure.core", :name "==", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/= :clojure.core/identical? :clojure.core/compare], :line 1100, :examples [";; true:\n(== 1)\n(== 1 1) \n(== 1/1, 2/2, 3/3, 4/4) \n(== 1, 1.0, 1/1)\n(== :foo)\n\n\n;; false:\n(== 1 2)\n\n;; ClassCastException\n(== 1 \\1)\n(== 1 \"1\")" "user=> (= 0.0 0)\nfalse\nuser=> (== 0.0 0)\ntrue" ";; Just what you would expect\n(== 2.0 1.9999999)\n;;=> false\n\n;; a suprising result\n(== 2.0 2 6/3 1.9999999999999999)\n;;=> true ??!?\n;; Yes, there is some rounding off going on.\n;; if you take off just one of the repeating 9 (on my machine) these compare.\n" "\n;; When floating point numbers are far enough from each other\n(== 2.0 1.9999999)\n;;=> false\n(- 100.0 100.00000000000001) ;13(Thirteen) 0s after floating point in the last number\n;;=> -1.4210854715202004E-14\n\n;; When two floating point numbers are too close some basic algebraic properties don't strictly hold.\n(== 2.0 1.9999999999999999)\n;;=> true\n\n(* 100 (- 1.0 1.0000000000000001)) ;15(fifteen) 0s after floating point in the last number\n;;=> 0.0\n\n;; They are still different types\n(= 2 1.9999999999999999)\n;;=> false\n\n;; see more from https://en.wikibooks.org/wiki/Floating_Point/Epsilon\n;; I found above example was distracting by putting 6/3 and 2 in the equality check that is why I decided to write up a similar but new example." ";; See the Clojure Equality guide for more details:\n;; https://clojure.org/guides/equality\n\n;; == returns false whenever comparing the special \"not a number\" value to any\n;; number, including itself.\n\nuser=> (== 1 ##NaN)\nfalse ;; this result you probably expect\n\nuser=> (== ##NaN ##NaN)\nfalse ;; this one may surprise you\n" "user => (= 1/2 0.5)\n;; => false\n\nuser => (== 1/2 0.5)\n;; => true"], :notes ["There is a difference between \"=\" and \"==\". For primitives you definitely want to use \"==\" as \"=\" will result in a cast to the wrapped types for it's arguments.\r\n\r\nThis may not be the case come Clojure 1.3 (see [1])\r\n\r\n[1] http://github.com/clojure/clojure/commit/df8c65a286e90e93972bb69392bc106128427dde" "So what is difference with =? " "'== is defined only for numbers, where '= is general equality. The example showing (== :foo) as true is a bit misleading because (== :foo :foo) produces an exception. Unary == always returns true as an optimization."], :arglists ["x" "x y" "x y & more"], :doc "Returns non-nil if nums all have the equivalent\n value (type-independent), otherwise false", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/=="}, :clojure.core.async/filter> {:ns "clojure.core.async", :name "filter>", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 1047, :examples nil, :deprecated "0.1.319.0-6b1aca-alpha", :notes nil, :arglists ["p ch"], :doc "Deprecated - this function will be removed. Use transducer instead", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/filter>"}, :clojure.core/comp {:added "1.0", :ns "clojure.core", :name "comp", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/partial :clojure.core/juxt :clojure.core/every-pred], :line 2557, :examples ["(def negative-quotient (comp - /))\n;; #'user/negative-quotient\n\n(negative-quotient 8 3) ;;=> -8/3\n\n(def concat-and-reverse (comp (partial apply str) reverse str)) \n;; #'user/concat-and-reverse\n\n(concat-and-reverse \"hello\" \"clojuredocs\")\n;;=> \"scoderujolcolleh\"\n" "((comp str +) 8 8 8) \n;;=> \"24\"\n" "(map\n (comp - (partial + 3) (partial * 2))\n [1 2 3 4])\n;;=> (-5 -7 -9 -11)" "(filter (comp not zero?) [0 1 0 2 0 3 0 4])\n;;=> (1 2 3 4)" ";; make a struct 'goods'. it assumes that every goods has\n;; its id number and price.\n(defstruct goods :id :price)\n\n;; generate data.\n(def data (map #(struct goods %1 %2)\n\t (shuffle (range 0 10)) \n (shuffle\n\t (into (range 100 500 100)\n\t\t\t(range 100 500 100)))))\n\n(defn comp-goods-price\n \"a compare function by :price of the struct 'goods.' the sort order \n is that the lower price is superior to the higher one and if the \n price is same, the lower id is superior to the higher one.\"\n [el1 el2]\n (if (or (< (:price el1) (:price el2))\n (and (= (:price el1) (:price el2)) (< (:id el1) (:id el2))))\n true\n false))\n\n;; The shuffle will cause your results to differ.\ndata \n;;=> ({:id 1, :price 300} {:id 6, :price 100} \n;; {:id 3, :price 100} {:id 4, :price 400}\n;; {:id 0, :price 300} {:id 2, :price 200} \n;; {:id 5, :price 200} {:id 8, :price 400})\n\n(sort (comp comp-goods-price) data)\n;;=> ({:id 3, :price 100} {:id 6, :price 100} \n;; {:id 2, :price 200} {:id 5, :price 200} \n;; {:id 0, :price 300} {:id 1, :price 300}\n;; {:id 4, :price 400} {:id 8, :price 400})\n\n(sort-by :price < data) ; compare this with the above.\n;;=> ({:id 6, :price 100} {:id 3, :price 100} \n;; {:id 2, :price 200} {:id 5, :price 200} \n;; {:id 1, :price 300} {:id 0, :price 300} \n;; {:id 4, :price 400} {:id 8, :price 400})\n\n;; Yet another example of 'comp' by PriorityBlockingQueue.\n\n(import [java.util.concurrent PriorityBlockingQueue])\n;; java.util.concurrent.PriorityBlockingQueue\n\n(def pqdata (new PriorityBlockingQueue 8\n\t\t (comp comp-goods-price)))\n;; #'user/pqdata\n\n(doseq [x data] (.add pqdata x))\n;;=> nil\n\n(dotimes [_ 8] (println (.poll pqdata)))\n;; {:id 3, :price 100}\n;; {:id 6, :price 100}\n;; {:id 2, :price 200}\n;; {:id 5, :price 200}\n;; {:id 0, :price 300}\n;; {:id 1, :price 300}\n;; {:id 4, :price 400}\n;; {:id 8, :price 400}\n;;=> nil\n" "(def countif (comp count filter))\n#'user/countif\n\n(countif even? [2 3 1 5 4])\n;;=> 2" "; Get 2nd to last element from a list\n( (comp second reverse) '(\"a\" 2 7 \"b\")) \n;;=> 7" "; We need an example that composes more than just two functions.\n; The following example is an overly complicated reimplementation of 'nth'\n; but it does show the composition of an arbitrary number of functions (rest).\n( #((apply comp first (repeat %2 rest)) %1) [1 2 3 4 5 6] 3 ) \n;;=> 4" "; `comp`-ing maps, filters with a little help from our friend `partial`\n; the following function filters numbers in a `coll` if it is divisible by 3\n; then on that filtered `coll`, multiplies all by 2\n\n; a little helper to find if a number is div by 3 \n; also comp-ed\n\n(def mod3nz? (comp not zero? #(mod % 3)))\n\n; now for that elusive function that muls by 2 after filter those not div by 3\n(def mul-2-nd-3\n \"Takes a seq of numbers, filters those not divisible by 3 and muls them by 2\"\n (comp (partial map #(* % 2))\n (partial filter mod3nz?)))\n\n(mul-2-nd-3 [16 15 30 43]) ;; => (32 86)\n" "; Split a number into sequence of it's digits\n((comp (partial map (comp read-string str)) str) 33)\n;;=> (3 3)" ";; Keywords are used as functions to access data in maps.\n\n(:foo {:foo \"bar\"})\n;;=> \"bar\"\n\n;; With a nested data structure, it is common to use\n;; several keywords in sequence to navigate the hierarchy.\n\n(def my-data {:this {:that {:the-other \"val\"}}})\n;;=> #'user/my-data\n\n(-> my-data :this :that :the-other)\n;;=> \"val\"\n\n;; Since keywords are functions,\n;; they can be 'comp'ed just like any other function.\n\n(def those (comp :the-other :that :this)) ; Note: reverse order\n;;=> #'user/those\n\n(those my-data)\n;;=> \"val\"\n\n;; The composed keyword-sequence can be used with other keywords: -\n\n(def my-data-2\n {:this {:that {:the-other {:a \"apple\" :b \"banana\"}}}})\n;;=> #'user/my-data-2\n\n(let [a (-> my-data-2 those :a)\n b (-> my-data-2 those :b)]\n (str \"These: \" a \", \" b))\n;;=> \"These: apple, banana\"" ";; ((comp func1 func2) data) mean ...\n;; (-> data func2 func1)\n;; so,\n((comp (partial * 3) inc) 1)\n;; means\n(* 3 (inc 1))\n\n;; advanced ...\n\n((comp seq re-seq) #\"(\\w+)=(\\S+)\" \"foo=bar\")\n;; ([\"foo=bar\" \"foo\" \"bar\"])\n(seq (re-seq #\"(\\w+)=(\\S+)\" \"foo=bar\"))\n\n;; * \"#(\\w+)...\" and \"foo=...\" are arguments for #re-seq" ";; comp is the transducer equivalent to thrush \n\n;; An example of using the \"thread-last\" macro to get\n;; the sum of the first 10 even squares.\n(->> (range)\n (map #(* % %))\n (filter even?)\n (take 10)\n (reduce +))\n;;=> 1140\n\n;; Many the seq functions now produce transducers.\n;; `reduce` does not but has been replaced with `transduce`.\n(transduce \n (comp\n (map #(* % %))\n (filter even?)\n (take 10))\n + 0 (range) )\n;;=> 1140" ";;trim will remove the white spaces and return a new string which will be passed ;;to the second function capitalize which will return a new string\n\n((comp clojure.string/capitalize clojure.string/trim) \" london \")\n;;\"London\"\n" "(def my-car\n {:name \"audi\"\n :data {:cc 2990\n :bhp 350}})\n\n((comp :bhp :data) my-car)\n;;350\n\n;;which is the equivalent of\n\n(:bhp (:data my-car))\n;;350" "(require '[reagent.core :as r])\n\n(def float-parsable? (comp not js/isNaN js/parseFloat))\n(def find-parsable-or-nil \n (comp first \n (partial re-find \n #\"(\\-?\\d+\\.)?\\d+([eE][-+]?\\d+)?\")))\n\n(defn number-input\n \"HTML input element for number only input\"\n [value]\n [:input\n {:value @value\n :type \"text\"\n :on-change (comp\n #(when-let [new-value %]\n (reset! value new-value))\n (fn [new-value]\n (cond\n (empty? new-value) \"\"\n (float-parsable? new-value) new-value\n :otherwise (find-parsable-or-nil new-value)))\n (fn [target]\n (.-value target))\n (fn [event]\n (.-target event)))}])\n\n(def value (r/atom \"\"))\n\n(defn demo []\n [:div\n ; Displays NaN when value is \"\", displays a number otherwise.\n (-> @value js/parseFloat str) [:br]\n [number-input value]])" "; Demonstrating the order of parameters vs. normal function application.\n\n(def x {:bar {:foo 42}})\n\n(:foo (:bar x))\n;;=> 42\n\n((comp :foo :bar) x)\n;;=> 42" "; Without arguments returns identity function\n\n(identical? (comp) identity)\n;;=> true\n\n((comp) :arg)\n;;=> :arg"], :notes nil, :arglists ["" "f" "f g" "f g & fs"], :doc "Takes a set of functions and returns a fn that is the composition\n of those fns. The returned fn takes a variable number of args,\n applies the rightmost of fns to the args, the next\n fn (right-to-left) to the result, etc.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/comp"}, :clojure.core/byte {:added "1.0", :ns "clojure.core", :name "byte", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/byte-array :clojure.core/bytes :clojure.core/short :clojure.core/unchecked-byte], :line 3504, :examples ["user=> (def x (byte-array [(byte 0x43) \n (byte 0x6c)\n (byte 0x6f)\n (byte 0x6a)\n (byte 0x75)\n (byte 0x72)\n (byte 0x65)\n (byte 0x21)]))\n#'user/x\n\nuser=> (String. x)\n\"Clojure!\"\n" ";; Casting a string does not work\n(byte \"123\")\n;;=> Execution error (ClassCastException) at user/eval157 (REPL:1).\n;;java.lang.String cannot be cast to java.lang.Number\n\n;; Use Java interop instead\n(Byte/parseByte \"123\")\n;;=> 123\n\n;; Content originally posted by u/didibus on https://clojuredocs.org/clojure.core/num"], :notes nil, :arglists ["x"], :doc "Coerce to byte", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/byte"}, :clojure.core.logic/fne {:ns "clojure.core.logic", :name "fne", :file "clojure/core/logic.clj", :type "macro", :column 1, :see-alsos nil, :line 1693, :examples ["(run 10 [q]\n ((fne [x y]\n ([[h . t] t]))\n [1 2 3] q)) ; => ((2 3))\n\n(run 10 [q]\n ((fne [x y]\n ([[o? 2 _ 4 5]] (== y o?))\n ([[1 2 _ . o?]] (== y o?)))\n [1 2 3 4 5] q))"], :macro true, :notes nil, :arglists ["& rest"], :doc "Define an anonymous goal fn. Supports pattern matching. All\n patterns will be tried. See conde.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/fne"}, :clojure.core.logic/lcons {:ns "clojure.core.logic", :name "lcons", :file "clojure/core/logic.clj", :type "function", :column 1, :see-alsos [:clojure.core.logic/llist], :line 868, :examples ["(run* [q]\n (fresh [a d]\n (== [1 2 3 4] (lcons a d))\n (== q d))) ;; ((2 3 4))" "(run* [t] (== [1 2 3] (lcons 1 t)))\n;;=> ((2 3))"], :notes nil, :arglists ["a d"], :doc "Constructs a sequence a with an improper tail d if d is a logic variable.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic/lcons"}, :clojure.instant/read-instant-calendar {:ns "clojure.instant", :name "read-instant-calendar", :file "clojure/instant.clj", :type "function", :column 1, :see-alsos nil, :line 281, :examples nil, :notes nil, :arglists ["cs"], :doc "To read an instant as a java.util.Calendar, bind *data-readers* to a map with\nthis var as the value for the 'inst key. Calendar preserves the timezone\noffset.", :library-url "https://github.com/clojure/clojure", :href "/clojure.instant/read-instant-calendar"}, :clojure.java.io/as-relative-path {:added "1.2", :ns "clojure.java.io", :name "as-relative-path", :file "clojure/java/io.clj", :type "function", :column 1, :see-alsos nil, :line 408, :examples ["(require '[clojure.java.io :as io])\n\n; on windows\nuser> (io/as-relative-path \"this/is\")\n\"this\\\\is\n\nuser> (io/as-relative-path \"c:/code\")\nIllegalArgumentException c:\\code is not a relative path clojure.java.io/as-relative-path (io.clj:405)"], :notes nil, :tag "java.lang.String", :arglists ["x"], :doc "Take an as-file-able thing and return a string if it is\n a relative path, else IllegalArgumentException.", :library-url "https://github.com/clojure/clojure", :href "/clojure.java.io/as-relative-path"}, :clojure.core.async/unmix-all* {:ns "clojure.core.async", :name "unmix-all*", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["m"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/unmix-all*"}, :clojure.data/diff {:added "1.3", :ns "clojure.data", :name "diff", :file "clojure/data.clj", :type "function", :column 1, :see-alsos nil, :line 120, :examples ["(use 'clojure.data)\n(def uno {:same \"same\", :different \"one\"})\n(def dos {:same \"same\", :different \"two\", :onlyhere \"whatever\"})\n(diff uno dos)\n=> ({:different \"one\"} {:onlyhere \"whatever\", :different \"two\"} {:same \"same\"})\n;; {different in uno} { different or unique in dos } {same in both}\n(diff {:a 1} {:a 1 :b 2})\n=> (nil {:b 2} {:a 1})\n;; the first contains nothing unique, but only the second contains :b\n;; and both contain :a" "(diff [1 2 3] [5 9 3 2 3 7]) ;;=> [[1 2] [5 9 nil 2 3 7] [nil nil 3]]\n(diff (set [1 2 3]) (set [5 9 3 2 3 7])) ;;=> [#{1} #{7 9 5} #{3 2}]" ";; To invert a diff you can re-apply diff to its output and then merge this back with the prior state \n;; This works in almost all cases (with the exception of preserving empty maps) \n\n(defn- seqzip\n \"returns a sequence of [[ value-left] [value-right]....] padding with nulls for shorter sequences \"\n [left right]\n (loop [list [] a left b right]\n (if (or (seq a) (seq b))\n (recur (conj list [(first a) (first b)] ) (rest a) (rest b))\n list)))\n\n(defn- recursive-diff-merge\n \" Merge two structures recusively , taking non-nil values from sequences and maps and merging sets\" \n [part-state original-state]\n (cond\n (sequential? part-state) (map (fn [[l r]] (recursive-diff-merge l r)) (seqzip part-state original-state))\n (map? part-state) (merge-with recursive-diff-merge part-state original-state)\n (set? part-state) (set/union part-state original-state)\n (nil? part-state ) original-state\n :default part-state))\n\n(defn undiff\n \"returns the state of x after reversing the changes described by a diff against\n an earlier state (where before and after are the first two elements of the diff)\"\n [x before after]\n (let [[a _ _] (clojure.data/diff x after)]\n (recursive-diff-merge a before)))\n\n;; examples: \n\n;; Simple data types\n(clojure.data/diff :before :after )\n=> [:before :after nil]\n\n(undiff :after :before :after)\n=> :before\n\n;; Lists \n(clojure.data/diff [1 2 3 4] [1 2 3 5] )\n=> [[nil nil nil 4] [nil nil nil 5] [1 2 3]]\n(undiff [1 2 3 5] [nil nil nil 4] [nil nil nil 5] )\n=> (1 2 3 4)\n\n;; Nested complex data structures; \n(clojure.data/diff {:a 1 :b [1 2 3] :c {:d 4}}\n {:a 2 :b [1 2 3 4] :c {:d 3 :e 10}})\n=> ({:c {:d 4}, :a 1} {:c {:d 3, :e 10}, :b [nil nil nil 4], :a 2} {:b [1 2 3]})\n\n(undiff {:a 2 :b [1 2 3 4] :c {:d 3 :e 10}} ; State after diff \n {:c {:d 4}, :a 1} ; first element of diff against previous state\n {:c {:d 3, :e 10}, :b [nil nil nil 4], :a 2}) ; second element of diff \n ; against previous state \n=> {:b [1 2 3], :c {:d 4}, :a 1}\n" ";; Beware that empty maps get turned into nil\n(clojure.data/diff {:a {:b 1} :c 2} {:a {} :c 2})\n=> ({:a {:b 1}} {:a nil} {:c 2})" ";; The diff also applies for nested structures\n\n;; Example creating a function that evaluates if a given value is subset of a map\n(defn map-subset? [map subset]\n (let [[_ subset_diff _] (clojure.data/diff map subset)]\n (nil? subset_diff)))\n\n(def a {\"KEY\" {\n :kv1 {:nested \"X\"}\n :kv2 \"Y\"\n }} )\n(def b {\"KEY\" {\n :kv1 {:nested \"X\"}\n }})\n(map-subset? a b)\n\n=> true"], :notes ["See also https://github.com/lambdaisland/deep-diff2 \"Deep diff Clojure data structures and pretty print the result\"" "See https://github.com/juji-io/editscript \"Editscript is a library designed to extract the differences between two Clojure/Clojurescript data structures as an 'editscript', which represents the minimal modification necessary to transform one to another\""], :arglists ["a b"], :doc "Recursively compares a and b, returning a tuple of\n [things-only-in-a things-only-in-b things-in-both].\n Comparison rules:\n\n * For equal a and b, return [nil nil a].\n * Maps are subdiffed where keys match and values differ.\n * Sets are never subdiffed.\n * All sequential things are treated as associative collections\n by their indexes, with results returned as vectors.\n * Everything else (including strings!) is treated as\n an atom and compared for equality.", :library-url "https://github.com/clojure/clojure", :href "/clojure.data/diff"}, :clojure.core.async/fn-handler {:ns "clojure.core.async", :name "fn-handler", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos nil, :line 34, :examples nil, :notes nil, :arglists ["f" "f blockable"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.async/fn-handler"}, :clojure.main/skip-if-eol {:ns "clojure.main", :name "skip-if-eol", :file "clojure/main.clj", :type "function", :column 1, :see-alsos nil, :line 108, :examples nil, :notes nil, :arglists ["s"], :doc "If the next character on stream s is a newline, skips it, otherwise\n leaves the stream untouched. Returns :line-start, :stream-end, or :body\n to indicate the relative location of the next character on s. The stream\n must either be an instance of LineNumberingPushbackReader or duplicate\n its behavior of both supporting .unread and collapsing all of CR, LF, and\n CRLF to a single \\newline.", :library-url "https://github.com/clojure/clojure", :href "/clojure.main/skip-if-eol"}, :clojure.core/with-precision {:added "1.0", :ns "clojure.core", :name "with-precision", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [:clojure.core/*math-context*], :line 5086, :examples [";; The \"M\" suffix denotes a BigDecimal instance\n;; http://download.oracle.com/javase/6/docs/api/java/math/BigDecimal.html\n\nuser=> (with-precision 10 (/ 1M 6))\n0.1666666667M\n\nuser=> (.floatValue 0.1666666667M)\n0.16666667\n" ";; This may come in handy for example when you use JDBC to grab data\n;; from a database, and numbers comes in as BigDecimal. Notice the\n;; following ArithmeticException, and solution:\n\n(/ 2M 3M) ; => ArithmeticException\n(with-precision 2 (/ 2M 3M)) ; => 0.67M\n\n;; To make this error more searchable, here's what it is, exactly:\n;;\n;; Non-terminating decimal expansion; no exact representable decimal result. \n;; java.lang.ArithmeticException: Non-terminating decimal expansion; no exact\n;; representable decimal result.\n"], :macro true, :notes nil, :arglists ["precision & exprs"], :doc "Sets the precision and rounding mode to be used for BigDecimal operations.\n\n Usage: (with-precision 10 (/ 1M 3))\n or: (with-precision 10 :rounding HALF_DOWN (/ 1M 3))\n\n The rounding mode is one of CEILING, FLOOR, HALF_UP, HALF_DOWN,\n HALF_EVEN, UP, DOWN and UNNECESSARY; it defaults to HALF_UP.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/with-precision"}, :clojure.core/unchecked-long {:added "1.3", :ns "clojure.core", :name "unchecked-long", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/long], :line 3540, :examples ["(unchecked-long 1)\n;;=> 1\n(unchecked-long 1N)\n;;=> 1\n(unchecked-long 1.1)\n;;=> 1\n(unchecked-long 1.9)\n;;=> 1\n(unchecked-long 5/3)\n;;=> 1\n\n(unchecked-long -1)\n;;=> -1\n(unchecked-long -1N)\n;;=> -1\n(unchecked-long -1.1)\n;;=> -1\n(unchecked-long -1.9)\n;;=> -1\n(unchecked-long -5/3)\n;;=> -1\n\n;;;; Note that (unchecked-long) does not range check its argument\n;;;; so integer overflow or rounding may occur. \n;;;; Use (long) if you want to throw an exception in such cases.\n\n(unchecked-long 9223372036854775808N)\n;;=> -9223372036854775808\n(unchecked-long -9223372036854775809N)\n;;=> 9223372036854775807\n\n(long 9223372036854775808N)\n;;=> IllegalArgumentException Value out of range for long: 922337203685477580\n(long -9223372036854775809N)\n;;=> IllegalArgumentException Value out of range for long: -9223372036854775809\n\n(unchecked-long 1.0E18)\n;;=> 1000000000000000000\n(unchecked-long 1.0E19)\n;;=> 9223372036854775807\n(unchecked-long 1.0E20)\n;;=> 9223372036854775807\n\n(long 1.0E18)\n;;=> 1000000000000000000\n(long 1.0E19)\n;;=> IllegalArgumentException Value out of range for long: 1.0E19\n(long 1.0E20)\n;;=> IllegalArgumentException Value out of range for long: 1.0E20"], :notes nil, :arglists ["x"], :doc "Coerce to long. Subject to rounding or truncation.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-long"}, :clojure.spec.alpha/* {:ns "clojure.spec.alpha", :name "*", :file "clojure/spec/alpha.clj", :type "macro", :column 1, :see-alsos [:clojure.spec.alpha/+ :clojure.spec.alpha/?], :line 602, :examples nil, :macro true, :notes nil, :arglists ["pred-form"], :doc "Returns a regex op that matches zero or more values matching\n pred. Produces a vector of matches iff there is at least one match", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/*"}, :clojure.core/mapcat {:added "1.0", :ns "clojure.core", :name "mapcat", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/map :clojure.core/concat :clojure.core/flatten], :line 2783, :examples ["user=> (mapcat reverse [[3 2 1 0] [6 5 4] [9 8 7]])\n(0 1 2 3 4 5 6 7 8 9)\n" "user=> (mapcat (fn [[k v]] \n (for [[k2 v2] v] \n (concat [k k2] v2)))\n '{:a {:x (1 2) :y (3 4)}\n :b {:x (1 2) :z (5 6)}})\n\n((:a :x 1 2) (:a :y 3 4) (:b :x 1 2) (:b :z 5 6))" "user=> (require '[clojure.string :as cs])\nnil\n\n;; Suppose you have a fn in a `map` that itself returns\n;; multiple values.\nuser=> (map #(cs/split % #\"\\d\") [\"aa1bb\" \"cc2dd\" \"ee3ff\"])\n([\"aa\" \"bb\"] [\"cc\" \"dd\"] [\"ee\" \"ff\"])\n\n;; Now, if you want to concat them all together, you *could*\n;; do this:\nuser=> (apply concat (map #(cs/split % #\"\\d\") [\"aa1bb\" \"cc2dd\" \"ee3ff\"]))\n(\"aa\" \"bb\" \"cc\" \"dd\" \"ee\" \"ff\")\n\n;; But `mapcat` can save you a step:\nuser=> (mapcat #(cs/split % #\"\\d\") [\"aa1bb\" \"cc2dd\" \"ee3ff\"])\n(\"aa\" \"bb\" \"cc\" \"dd\" \"ee\" \"ff\")\n" ";; Suppose you've got a function that takes a value\n;; and returns a list of things from it, for example:\n(defn f1\n [n]\n [(- n 1) n (+ n 1)])\n\n(f1 1)\n;=> [0 1 2]\n\n;; Perhaps you'd like to map it onto each item in a collection:\n(map f1 [1 2 3])\n;=> ([0 1 2] [1 2 3] [2 3 4])\n\n;; But suppose you wanted them all concatenated? You could do this:\n(apply concat (map f1 [1 2 3]))\n;=> (0 1 2 1 2 3 2 3 4)\n\n;; Or you could get the same thing with `mapcat`:\n(mapcat f1 [1 2 3])\n;=> (0 1 2 1 2 3 2 3 4)\n" "; Flatten a map, consing keys on to each nested vector \n(mapcat (fn [[k vs]] (map (partial cons k) vs)) {:foo [[1 2] [3 2]] :bar [[3 1]]})\n;=> ((:foo 1 2) (:foo 3 2) (:bar 3 1))\n" ";; A very useful feature of mapcat is that it allows function f to produce no result\n;; by returning nil or an empty collection:\n(mapcat #(remove even? %) [[1 2] [2 2] [2 3]])\n;; => (1 3)\n\n;; note that applying (remove even?) to [2 2] produced () which was \"eaten\"\n;; and ignored by mapcat." ";; map vs. mapcat -\n;; For duplicating each item in a sequence\n\n;; Using map:\n(map #(repeat 2 %) [1 2])\n;; => ((1 1) (2 2))\n\n;; Using mapcat:\n(mapcat #(repeat 2 %) [1 2])\n;; => (1 1 2 2)\n" ";; I think it is cool to use juxt together with mapcat\n;; mapcat requires element to be collection and the result of juxt will be collection. \n\n(mapcat (juxt inc dec) [1 2 3 4])\n;; => (2 0 3 1 4 2 5 3)" ";;(mapcat f & colls)\n(mapcat list [:a :b :c] [1 2 3])\n;;=> (:a 1 :b 2 :c 3)"], :notes ["
\n;; mapcat always evaluates the first 4 arguments.\n(def a (mapcat range (map #(do (print \".\") %) (into () (range 10)))))\n;; ....\n\n;; it can be solved avoiding 'apply' to handle varargs\n(defn mapcat* [f & colls]\n (letfn [(step [colls]\n (lazy-seq\n (when-first [c colls]\n (concat c (step (rest colls))))))]\n (step (apply map f colls))))\n\n(def a (mapcat* range (map #(do (print \".\") %) (into () (range 10)))))\n;; nothing prints\n
"], :arglists ["f" "f & colls"], :doc "Returns the result of applying concat to the result of applying map\n to f and colls. Thus function f should return a collection. Returns\n a transducer when no collections are provided", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/mapcat"}, :clojure.core/set-agent-send-executor! {:added "1.5", :ns "clojure.core", :name "set-agent-send-executor!", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/set-agent-send-off-executor! :clojure.core/send-via :clojure.core/shutdown-agents], :line 2089, :examples [";; This permanently change the thread pool used\n;; by agents receiving tasks with \"send\"\n(import '[java.util.concurrent Executors])\n(def fj-pool (Executors/newWorkStealingPool 20))\n(set-agent-send-executor! fj-pool)"], :notes nil, :arglists ["executor"], :doc "Sets the ExecutorService to be used by send", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/set-agent-send-executor!"}, :clojure.core/to-array {:added "1.0", :ns "clojure.core", :name "to-array", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/alength :clojure.core/char-array :clojure.core/int-array :clojure.core/long-array :clojure.core/into-array :clojure.core/make-array :clojure.core/to-array-2d], :line 338, :examples ["user=> (to-array [1 2 3])\n#
\r\n"], :arglists ["" "& keyvals"], :doc "Constructs an array-map. If any keys are equal, they are handled as\n if by repeated uses of assoc.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/array-map"}, :clojure.spec.alpha/nilable-impl {:ns "clojure.spec.alpha", :name "nilable-impl", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos nil, :line 1829, :examples nil, :notes nil, :arglists ["form pred gfn"], :doc "Do not call this directly, use 'nilable'", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/nilable-impl"}, :clojure.core/partial {:added "1.0", :ns "clojure.core", :name "partial", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/comp :clojure.core/juxt :clojure.core/apply], :line 2614, :examples ["user=> (def to-english (partial clojure.pprint/cl-format nil \"~@(~@[~R~]~^ ~A.~)\"))\n#'user/to-english\n\nuser=> (to-english 1234567890)\n\"One billion, two hundred thirty-four million, five hundred sixty-seven thousand, eight hundred ninety\"\n" "user=> (def hundred-times (partial * 100))\n#'user/hundred-times\n\nuser=> (hundred-times 5)\n500\n\nuser=> (hundred-times 4 5 6)\n12000\n\nuser=> (def add-hundred (partial + 100))\n#'user/add-hundred\n\nuser=> (add-hundred 5)\n105\n" "(def subtract-from-hundred (partial - 100))\n\nuser=> (subtract-from-hundred 10) ; same as (- 100 10)\n90\n\nuser=> (subtract-from-hundred 10 20) ; same as (- 100 10 20)\n70" "; Maps exponent to coefficient\n; x^3 + 2x + 1\n(def poly (fn [n]\n (cond\n (= 0 n) 1\n (= 1 n) 2\n (= 3 n) 1\n :else 0)))\n\n; Differentiates input by returning a polynomial that is curried\n; 3x^2 + 2\n(defn diff [p]\n (partial (fn [p n] (* (+ 1 n) (p (+ 1 n)))) p))\n\n(poly 3)\n;=> 1\n((diff poly) 3)\n;=> 0\n((diff poly) 2)\n;=> 3\n" "user=> (defn fun-full [x y] (+ x y))\n;=> # (fun-full 2 3)\n;=> 5\n\nuser=> (def fun-half (partial fun-full 2))\n;=> # (fun-half 3)\n;=> 5\n" ";;Takes a function f and the normal full arguments is allowed\n\nuser=> (defn add [x y] (+ x y))\n#'user/add\nuser=> (partial add 1 1 )\n#object[clojure.core$partial$fn__4529 0x5eb8fe04 \"clojure.core$partial$fn__4529@5eb8fe04\"]\nuser=> (apply (partial add 1 1 ) nil)\n2\nuser=> ((partial add 1 1 ))\n2\nuser=> ((partial add 1 1 1))\nArityException Wrong number of args (3) passed to: user/add clojure.lang.AFn.throwArity (AFn.java:429)\n\nuser=>" "user=> (def add1 (partial + 1))\n#'user/add1\nuser=> (add1)\n;=> 1\nuser=> (add1 2)\n;=> 3\nuser=> (add1 2 3 4)\n;=> 10\nuser=> (= (add1 2 3 4) (+ 1 2 3 4))\n;=> true" "(def times (partial *))\n\n(times 1) ; -> 1\n\n(times 1 2 3) ; -> 6\n\n(* 1 2 3) ; -> 6\n\n\n(def add-hundred (partial + 100))\n\n(add-hundred 1) ; -> 101\n\n(add-hundred 1 2 3) ; -> 106\n\n(+ 100 1 2 3) ; -> 106" ";; Check if a character is vowel\n\n(def vowel? #(some (partial = %) \"aiueo\"))\n\n(vowel? \\e)\n;;=> true\n\n(vowel? \\c)\n;;=> nil" ";; apply feeds sequence items as variable args to the conj function\n;; variable args gets converted to list in the function arg and hence conj \n;; adds them as a list\n(apply #(conj [0 1] %&) [2 3 4 5])\n;;=> [0 1 (2 3 4 5)]\n\n;; Partial offers are mechanism to feed the variable args as is to the conj \n;; function effectively like (conj [] 2 3 4 5)\n(apply (partial conj [0 1]) [2 3 4 5])\n;;=> [0 1 2 3 4 5]" ";;practical example\n\n(def add-domain\n (partial (str \"@clojure.com\")))\n\n(str \"info\" add-domain )\n;;\"info@clojure.com\"" "(defn email-struct\n [username domain]\n (str username \"@\" domain))\n\n(def build-email\n #(partial email-struct %))\n\n((build-email \"info\") \"example.com\")\n;;\"info@example.com\"" ";; partial does not gel well with pure java methods\n\n;; Wrap Java method in Clojure fn\n(defn letter? [ch]\n (Character/isLetter ch))\n\n;; Idiomatic\n(filter letter? \"hello, world!\")\n;; => (\\h \\e \\l \\l \\o \\w \\o \\r \\l \\d)\n\n;; This works\n(filter (partial letter?) \"hello, world!\")\n;; => (\\h \\e \\l \\l \\o \\w \\o \\r \\l \\d)\n\n;; This also works\n(filter #(Character/isLetter %) \"hello, world!\")\n;; => (\\h \\e \\l \\l \\o \\w \\o \\r \\l \\d)\n\n;; This doesn't\n(filter (partial Character/isLetter) \"hello, world!\")\n;; => Unable to find static field: isLetter in class java.lang.Character" ";; Beware that partial \"bakes in\" the original function and does not look it up\n;; again at call time, which can be confusing when mocking.\n\n(defn foo [] \"hit foo\")\n;; => #'user/foo\n(defn mock [] \"hit the mock\")\n;; => #'user/mock\n(def par (partial foo))\n;; => #'user/par\n(with-redefs-fn {#'foo mock} #(foo))\n;; => \"hit the mock\"\n(with-redefs-fn {#'foo mock} #(par))\n;; => \"hit foo\"" ";; Partial application by calling partial significantly differs from partial\n;; application by wrapping a function call in an anonymous function.\n\n;; The code representing the to-be-applied function and to-be-applied-to arguments\n;; - with the 'call to partial' approach\n;; - is evaluated exactly once, when the call to partial is evaluated.\n;; - is not evaluated when a call to the resulting function is evaluated.\n;; - with the 'wrapped in an anonymous function' approach\n;; - is not evaluated when the anonymous function is evaluated.\n;; - is evaluated anew each time a call to the anonymous function is evaluated.\n\n;; If there are side effects involved in obtaining the to-be-applied function or\n;; to-be-applied-to arguments (because of with-redefs, this includes referring to a\n;; var by providing a symbol), carefully consider which approach to take.\n\n(defn fetch-processing-fn! [] (prn \"fetching...\") (fn [entity] entity))\n\n(defn load-entity! [id] (prn \"loading...\") :entity)\n\n\n(def top-level-fn-1 (partial (fetch-processing-fn!) (load-entity! 123)))\n;; \"fetching...\" is printed.\n;; \"loading...\" is printed.\n\n(top-level-fn-1)\n;; Nothing is printed.\n\n(top-level-fn-1)\n;; Nothing is printed.\n\n\n(def top-level-fn-2 #((fetch-processing-fn!) (load-entity! 123)))\n;; Nothing is printed.\n\n(top-level-fn-2)\n;; \"fetching...\" is printed.\n;; \"loading...\" is printed.\n\n(top-level-fn-2)\n;; \"fetching...\" is printed.\n;; \"loading...\" is printed."], :notes ["This function implements the concept of “[currying](http://en.wikipedia.org/wiki/Currying)�."], :arglists ["f" "f arg1" "f arg1 arg2" "f arg1 arg2 arg3" "f arg1 arg2 arg3 & more"], :doc "Takes a function f and fewer than the normal arguments to f, and\n returns a fn that takes a variable number of additional args. When\n called, the returned function calls f with args + additional args.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/partial"}, :clojure.core/chunk-rest {:ns "clojure.core", :name "chunk-rest", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/chunk-first :clojure.core/chunk-next], :line 704, :examples ["(let [chunked-cons (seq (range 1 42))\n rest-chunk (chunk-rest chunked-cons)]\n\n (class rest-chunk)\n ;; => clojure.lang.LazySeq\n\n (first rest-chunk)\n ;; => 33\n\n (last rest-chunk)\n ;; => 41\n)"], :notes nil, :tag "clojure.lang.ISeq", :arglists ["s"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/chunk-rest"}, :clojure.spec.alpha/Spec {:ns "clojure.spec.alpha", :name "Spec", :file "clojure/spec/alpha.clj", :type "var", :column 1, :see-alsos nil, :line 37, :examples nil, :notes nil, :arglists [], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/Spec"}, :clojure.spec.alpha/unform {:ns "clojure.spec.alpha", :name "unform", :file "clojure/spec/alpha.clj", :type "function", :column 1, :see-alsos [:clojure.spec.alpha/conform :clojure.spec.alpha/conformer], :line 166, :examples ["(require '[clojure.spec.alpha :as s])\n\n;; define spec as a sequential concatenation of two more specs:\n;; pos? and one of possible units (:meters :miles)\n;; :amount and :unit are the names we are giving to each position\n(s/def ::distance (s/cat :amount (s/and number? pos?)\n :unit #{:meters :miles}))\n\n(s/conform ::distance [3 :meters])\n;; => {:amount 3, :unit :meters}\n\n(s/unform ::distance {:amount 3, :unit :meters})\n;; => (3 :meters)\n\n(s/unform ::distance {:amount 3, :unit :foo})\n;; => (3 :foo)\n\n(s/unform ::distance {:amount 3, :foo :miles})\n;; => (3)\n\n(s/unform ::distance {:bar 3, :foo :miles})\n;; => ()\n"], :notes nil, :arglists ["spec x"], :doc "Given a spec and a value created by or compliant with a call to\n 'conform' with the same spec, returns a value with all conform\n destructuring undone.", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/unform"}, :clojure.core.server/stop-servers {:ns "clojure.core.server", :name "stop-servers", :file "clojure/core/server.clj", :type "function", :column 1, :see-alsos nil, :line 139, :examples nil, :notes nil, :arglists [""], :doc "Stop all servers ignores all errors, and returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.server/stop-servers"}, :clojure.core.logic.pldb/with-dbs {:ns "clojure.core.logic.pldb", :name "with-dbs", :file "clojure/core/logic/pldb.clj", :type "macro", :column 1, :see-alsos nil, :line 8, :examples nil, :macro true, :notes nil, :arglists ["dbs & body"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core.logic.pldb/with-dbs"}, :clojure.core/ex-message {:added "1.10", :ns "clojure.core", :name "ex-message", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [:clojure.core/ex-data :clojure.core/ex-info], :line 4800, :examples ["(try\n (let [error-message \"Something went wrong!\"\n error-data {:error 404}]\n (throw (ex-info error-message error-data)))\n (catch Exception e\n (prn (str \"Oops! \" (ex-message e)))\n (prn (str \"Because! \" (ex-data e)))))\n\n;; => \"Oops! Something went wrong!\"\n;; \"Because! {:error 404}\""], :notes nil, :arglists ["ex"], :doc "Returns the message attached to ex if ex is a Throwable.\n Otherwise returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ex-message"}, :clojure.core/create-ns {:added "1.0", :ns "clojure.core", :name "create-ns", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/remove-ns :clojure.core/find-ns :clojure.core/intern], :line 4132, :examples [";; This won't work because the symbol my-new-namespace isn't defined yet\nuser=> (create-ns my-new-namespace)\njava.lang.Exception: Unable to resolve symbol: my-new-namespace in this context (NO_SOURCE_FILE:2)\n\n\n;; This won't work because create-ns expects a symbol, not a string \nuser=> (create-ns \"my-new-namespace\")\njava.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.Symbol (NO_SOURCE_FILE:0)\n\n\n;; Here my-new-namespace is quoted and passed literally to create-ns\n;; without being looked up. It works as documented.\nuser=> (create-ns 'my-new-namespace)\n#\n" ";; Let's create a namespace and check for our result\n;; the new namespace will be \"my-new-namespace\"\n\n;; it does not exist yet, so looking for it, finds nothing\nuser=> (find-ns 'my-new-namespace) \nnil\n\n;; let's create it\nuser=> (create-ns 'my-new-namespace)\n#\n\n;; now searching for it again will have a result\nuser=> (find-ns 'my-new-namespace)\n#\n" ";; You can create a namespace, not switch to it and still work in, by storing it\n\n;; create the namespace\nuser=> (def for-later-use (create-ns 'my-namespace))\n#'user/for-later-use\n\n;; assign a value for a variable\nuser=> (intern for-later-use 'my-var \"some value\")\n#'my-namespace/my-var\n;; notice how the \"for-later-use\" symbol has been evaluated to the namespace it represents\n\n;; check the new variable\nuser=> my-namespace/my-var\n\"some value\"\n\n;; you can also work on a namespace by using the its name\n;; (but quoting it) instead of the return of \"create-ns\"\nuser=> (intern 'my-namespace 'my-var \"some other value\")\n#'my-namespace/my-var\n\n;; check the new assignment and see what's changed\nuser=> my-namespace/my-var\n\"some other value\"\n"], :notes nil, :arglists ["sym"], :doc "Create a new namespace named by the symbol if one doesn't already\n exist, returns it or the already-existing namespace of the same\n name.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/create-ns"}, :clojure.core.async/tap {:ns "clojure.core.async", :name "tap", :file "clojure/core/async.clj", :type "function", :column 1, :see-alsos [:clojure.core.async/mult :clojure.core.async/untap], :line 712, :examples ["user=> (def sz 20)\n#'user/sz\n\nuser=> (def c (chan sz))\n#'user/c\n\nuser=> (def mult-c (mult c))\n#'user/mult-c\n\nuser=> (def cx (chan sz))\n#'user/cx\n\nuser=> (def cy (chan sz))\n#'user/cy\n\nuser=> (def cz (chan sz))\n#'user/cz\n\nuser=> (tap mult-c cx)\n#\n\nuser=> (tap mult-c cy)\n#\n\nuser=> (tap mult-c cz)\n#\n\nuser=> (put! c \"sent to all\")\ntrue\n\nuser=> ( ( ( (prompt \"How old are you?\")\nHow old are you?\n34 ; <== This is what you enter\n\"34\" ; <== This is returned by the function\n\n;; You can now simulate entering your age at the prompt by using with-in-str\n\nuser=> (with-in-str \"34\" (prompt \"How old are you?\"))\nHow old are you?\n\"34\" ; <== The function now returns immediately \n"], :macro true, :notes nil, :arglists ["s & body"], :doc "Evaluates body in a context in which *in* is bound to a fresh\n StringReader initialized with the string s.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/with-in-str"}, :clojure.core.reducers/take {:added "1.5", :ns "clojure.core.reducers", :name "take", :file "clojure/core/reducers.clj", :type "function", :column 1, :see-alsos nil, :line 201, :examples nil, :notes nil, :arglists ["n" "n coll"], :doc "Ends the reduction of coll after consuming n values.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core.reducers/take"}, :clojure.spec.alpha/*coll-error-limit* {:ns "clojure.spec.alpha", :name "*coll-error-limit*", :file "clojure/spec/alpha.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 33, :examples nil, :notes nil, :arglists [], :doc "The number of errors reported by explain in a collection spec'ed with 'every'", :library-url "https://github.com/clojure/clojure", :href "/clojure.spec.alpha/*coll-error-limit*"}, :clojure.core/into-array {:added "1.0", :ns "clojure.core", :name "into-array", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [:clojure.core/to-array :clojure.core/make-array], :line 3443, :examples [";; Array's component type is set to (class 2), cannot add Strings.\n;; This will result in an IllegalArgumentException\nuser=> (into-array [2 \"4\" \"8\" 5])\n;; Evaluation aborted.\n\n;; However, if the common type is specified, aforementioned values can be put into an array\nuser=> (into-array Object [2 \"4\" \"8\" 5])\n#