diff --git a/exports/export.edn b/exports/export.edn
index dde40f3..563d8ab 100644
--- a/exports/export.edn
+++ b/exports/export.edn
@@ -1 +1 @@
-{:created-at 1692091858189, :description "ClojureDocs Data Export", :vars [{:ns "clojure.core", :name "def", :type "var", :see-alsos [{:created-at 1289040035000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defn", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b15"} {:created-at 1289040039000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "fn", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b16"} {:created-at 1289040051000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defmacro", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b17"} {:created-at 1289040055000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defmulti", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b18"} {:created-at 1421928720188, :author {:login "Gitward", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8510849?v=3"}, :to-var {:ns "clojure.core", :name "defonce", :library-url "https://github.com/clojure/clojure"}, :_id "54c0e910e4b0e2ac61831cce"} {:created-at 1426949770053, :author {:login "ryoakg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/23413?v=3"}, :to-var {:ns "clojure.core", :name "ns-unmap", :library-url "https://github.com/clojure/clojure"}, :_id "550d868ae4b056ca16cfecf8"}], :examples [{:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (def my-val 5)\n#'user/my-val\n\nuser=> my-val\n5", :created-at 1289040027000, :updated-at 1411962925119, :_id "542692cfc026201cdc326e95"} {:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [], :body "user=> (def my-function (fn [x] (* x x x)))\n#'user/my-function\nuser=> (my-function 4)\n64", :created-at 1289040110000, :updated-at 1289040110000, :_id "542692cfc026201cdc326e96"} {:author {:login "puredanger", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/89c8afd032c7b3473f67c9b00d3acd5a?r=PG&default=identicon"}, :editors [{:login "puredanger", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/89c8afd032c7b3473f67c9b00d3acd5a?r=PG&default=identicon"} {:login "pjlegato", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4ce55cfd8b3ae2f63f5ecbc8fc1c05d4?r=PG&default=identicon"} {:login "pjlegato", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4ce55cfd8b3ae2f63f5ecbc8fc1c05d4?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; This is an example of setting a docstring during a def.\n;; (Note that the clojure.repl namespace which contains the\n;; doc function is not loaded by default in Emacs' SLIME mode.)\n\nuser> (def ted-nugent \"The nuge rocks\" 123)\n#'user/ted-nugent\nuser> (doc ted-nugent)\n-------------------------\nuser/ted-nugent\n The nuge rocks\nuser> ted-nugent\n123\n", :created-at 1300830366000, :updated-at 1411962895678, :_id "542692cfc026201cdc326e97"} {:author {:login "jamesqiu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc1268deaa7f2e78fe2b5ea76e6481d8?r=PG&default=identicon"}, :editors [{:login "jamesqiu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc1268deaa7f2e78fe2b5ea76e6481d8?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; give function another name\nuser=> (def sys-map map)\n\n;; give macro another name\nuser=> (def #^{:macro true} sys-loop #'loop)", :created-at 1313515810000, :updated-at 1411962917894, :_id "542692cfc026201cdc326e9b"} {:updated-at 1518778836326, :created-at 1518778836326, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;Assign a Function to a Variable\n\n(def say-hello\n (fn [name]\n (str \"Hello \" name)))\n\n(say-hello \"World\")\n;;\"Hello World\"\n\n\n;;the same but using an anonymous function\n(def say-hello\n #(str \"Hello \" %))\n\n(say-hello \"World\")\n;;\"Hello World\"\n\n\n;;anonymous function using two arguments\n(def hello-doc #(str \"Hello \" %1 %2))\n\n(hello-doc \"Dr.\" \"House\")\n;;\"Hello Dr.House\"\n\n", :_id "5a86b9d4e4b0316c0f44f8c6"} {:updated-at 1640101185494, :created-at 1640101185494, :author {:login "deadghost", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1156996?v=4"}, :body ";; Private var\n(def ^:private foobar\n \"I am the docstring.\"\n \"I am the value.\")\n", :_id "61c1f541e4b0b1e3652d758c"} {:updated-at 1654772119878, :created-at 1654772119878, :author {:login "clojer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/107184681?v=4"}, :body "\n;; function checks: variable = 9 or not\nuser=> (def ?9 #(= % 9))\n#'user/?9\nuser=> (?9 9)\ntrue\nuser=> (?9 5)\nfalse", :_id "62a1d197e4b0b1e3652d75fa"}], :notes nil, :arglists [], :doc "Creates and interns or locates a global var with the name of symbol and a\nnamespace of the value of the current namespace (*ns*). See\nhttp://clojure.org/special_forms for more information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/def"} {:ns "clojure.core", :name "if", :type "var", :see-alsos [{:created-at 1302510837000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "cond", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e12"} {:created-at 1311797747000, :author {:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e13"} {:created-at 1334293230000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "if-let", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e14"} {:created-at 1340541172000, :author {:login "jhulten", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b15299ac3f0bf5347d14a1232338b1cd?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "if-not", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e15"} {:created-at 1545243343724, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "when-let", :ns "clojure.core"}, :_id "5c1a8acfe4b0ca44402ef5ed"}], :examples [{:author {:login "Victor", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc41ebab54cc0e0fbe99d753876d45ce?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "(defn is-small? [number]\n (if (< number 100) \"yes\" \"no\"))\n\nuser=> (is-small? 50)\n\"yes\"\n\nuser=> (is-small? 500)\n\"no\"", :created-at 1288222254000, :updated-at 1288871229000, :_id "542692cfc026201cdc326e9d"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; Be aware that the only two values considered \"logical false\" in Clojure\n;; are nil and false, where Clojure's \"false\" is the Java value Boolean/FALSE\n;; under the hood. Everything else is \"logical true\". Particularly surprising\n;; may be that the Java Object with class Boolean and value (Boolean. false) is\n;; considered logical true.\n\n;; This notion of logical true and logical false holds for at least the following\n;; conditional statements in Clojure: if, cond, when, if-let, when-let.\n;; It also applies to functions like filter, remove, and others that use\n;; these conditional statements in their implementation.\n\n;; nil and false are logical false\nuser=> (if nil \"logical true\" \"logical false\")\n\"logical false\"\nuser=> (if false \"logical true\" \"logical false\")\n\"logical false\"\n;; Boolean/FALSE is how Clojure's \"false\" is represented internally.\nuser=> (if Boolean/FALSE \"logical true\" \"logical false\")\n\"logical false\"\n\n;; Everything else that is the value of the condition, including numbers (even 0),\n;; characters, strings (even the empty string), vectors, maps, _and_ a freshly\n;; constructed Boolean class object (Boolean. false), is logical true.\n\nuser=> (if 0 \"logical true\" \"logical false\")\n\"logical true\"\n;; A vector containing nil is not the same as nil.\nuser=> (if [nil] \"logical true\" \"logical false\")\n\"logical true\"\nuser=> (if (first [nil]) \"logical true\" \"logical false\")\n\"logical false\"\n\n;; Bad idea even in Java. See below for more details.\nuser=> (if (Boolean. false) \"logical true\" \"logical false\")\n\"logical true\"\n\n;; Java documentation itself warns:\n;; Note: It is rarely appropriate to use this constructor. Unless a new instance\n;; is required, the static factory valueOf(boolean) is generally a better choice.\n;; It is likely to yield significantly better space and time performance.\n\n;; (boolean x) converts a value to a primitive boolean. It converts nil, false,\n;; and (Boolean. false) to primitive false.\nuser=> (if (boolean (Boolean. false)) \"logical true\" \"logical false\")\n\"logical false\"\n\n;; (Boolean/valueOf ) is similar:\nuser=> (if (Boolean/valueOf (Boolean. false)) \"logical true\" \"logical false\")\n\"logical false\"\n", :created-at 1334293223000, :updated-at 1422027142917, :_id "542692d6c026201cdc3270cc"} {:updated-at 1603184553184, :created-at 1603184553184, :author {:login "agodde", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/18694682?v=4"}, :body ";; if vs. when\n\n;; An if without an else branch...\nuser=> (if true \"then branch\")\n\"then branch\"\nuser=> (if false \"then branch\")\nnil\n\n;; ...is the same as when.\nuser=> (when true \"then branch\")\n\"then branch\"\nuser=> (when false \"then branch\")\nnil\n\n;; Use of when instead of if is recommended in cases where you do not need the else branch.", :_id "5f8ea7a9e4b0b1e3652d73e6"}], :notes [{:author {:login "kimtg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7685905?v=3"}, :updated-at 1441174250945, :created-at 1441174250945, :body "```\nuser=> (doc if)\n-------------------------\nif\n (if test then else?)\nSpecial Form\n Evaluates test. If not the singular values nil or false,\n evaluates and yields then, otherwise, evaluates and yields else. If\n else is not supplied it defaults to nil.\n\n Please see http://clojure.org/special_forms#if\n```\nhttp://clojure.org/special_forms#if", :_id "55e692eae4b0efbd681fbb92"}], :arglists [], :doc "Evaluates test.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/if"} {:ns "clojure.core", :name "do", :type "var", :see-alsos nil, :examples [{:author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; do is used to evaluate multiple expressions in order, usually for the\n;; purpose of evaluating exprs that have side-effects (such as printing\n;; or I/O). do returns the value of its last expression.\n;;\n;; do w/o args returns nil.\n\n=> (do\n (println \"LOG: Computing...\")\n (+ 1 1))\nLOG: Computing...\n2\n\n=> (do)\nnil\n", :created-at 1287999552000, :updated-at 1287999682000, :_id "542692cfc026201cdc326e9f"} {:body ";; `fn` (`defn` by extension) and `let` have an implicit `do`\n\n=> ((fn []\n (println \"Something\") ; printed in stdout\n (str \"Return this\")))\n\"Return this\"\n\n=> (defn do-example []\n (println \"Something\") ; printed in stdout\n (str \"Return this\")))\n=> (do-example)\n\"Return this\"\n\n=> (let [name \"John\"]\n (println \"Something\") ; printed in stdout\n (str \"Hello \" name))\n\"Hello John\"", :author {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"}, :created-at 1432926921112, :updated-at 1432927054881, :editors [{:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"}], :_id "5568bac9e4b03e2132e7d180"} {:updated-at 1456676930045, :created-at 1456676817498, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}, :body "user=> (if (> 2 1)\n (do\n (print \"2 greater than 1\") ; with 'do' you can extend if block\n true))\n\n;;=>\"2 greater than 1\"\n;;=>true", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3", :account-source "github", :login "ertugrulcetin"}], :_id "56d31fd1e4b0b41f39d96cd6"} {:updated-at 1500223229802, :created-at 1500223229802, :author {:login "joncorr", :account-source "github", :avatar-url "https://avatars6.githubusercontent.com/u/908484?v=4"}, :body ";; Print the result of time without the output of (range 1000)\n\n=> (do (time (range 1000)) nil)", :_id "596b96fde4b0d19c2ce9d6fe"}], :notes nil, :arglists [], :doc "Evaluates the expressions in order and returns the value of the last. If no\nexpressions are supplied, returns nil. See http://clojure.org/special_forms\nfor more information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/do"} {:ns "clojure.core", :name "quote", :type "var", :see-alsos [{:created-at 1537911884113, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unquote", :ns "clojure.core"}, :_id "5baaac4ce4b00ac801ed9ea7"}], :examples [{:updated-at 1650678469915, :created-at 1293674217000, :body ";; ' is the shortcut for quote\nuser> (= 'a (quote a))\ntrue\n\n;; quoting keeps something from being evaluated\nuser> (quote (println \"foo\"))\n(println \"foo\")\n\n=> *clojure-version*\n{:major 1, :minor 5, :incremental 0, :qualifier \"RC17\"}\n=> (quote)\nnil\n=> (quote 1)\n1\n=> (quote 1 2 3 4 5) ; this worked in Clojure 1.0 through 1.7 but stopped working in 1.8\n1\n=> quote\nCompilerException java.lang.RuntimeException: Unable to resolve symbol: quote in this context, compiling:(NO_SOURCE_PATH:1:42)\n", :editors [{:avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon", :account-source "clojuredocs", :login "AtKaaZ"} {:avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon", :account-source "clojuredocs", :login "AtKaaZ"} {:login "seancorfield", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/43875?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon", :account-source "clojuredocs", :login "dakrone"}, :_id "542692d0c026201cdc326ea2"} {:body ";; Proof that ' is just a syntactic sugar for quote:\nuser=> (macroexpand ''(1 2 3))\n(quote (1 2 3))\n\n;; Two ' must be used because reader processes and removes the first one", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423019653856, :updated-at 1423019653856, :_id "54d18e85e4b081e022073c54"} {:updated-at 1549280175530, :created-at 1549280175530, :author {:login "Bost", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1174677?v=4"}, :body ";; Quote returns the argument you pass it, without evaluation. So:\n;; In the expression `(quote 42)` the argument is the number 42 and...\nuser> (= (quote 42) 42)\ntrue ;; ... it is returned without any evaluation and...\nuser> (= (type (quote 42)) (type 42) java.lang.Long)\ntrue ;; ... as expected, without changing it's type.\n\n;; In the expression `(quote (quote 42))` the argument is the list of two\n;; elements `(quote 42)` ...\nuser> (= (quote (quote 42)) (list (read-string \"quote\") (read-string \"42\")))\ntrue ;; ... and it is returned without any evaluation and...\nuser> (= (type (quote (quote 42))) (type (list \"1st-elem\" \"2nd-elem\"))\n clojure.lang.PersistentList)\ntrue ;; ... again, without changing it's type.", :_id "5c5823afe4b0ca44402ef662"} {:editors [{:login "soulawaker", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/5372217?v=4"}], :body ";; Since clojure 1.9, if all keys in a map have the same namespace qualifier\n;; then the common namespace become the prefix of the map.\nuser> 'org.clojure/clojure\norg.clojure/clojure\n\nuser> '{org.clojure/clojure 3}\n#:org.clojure{clojure 3} ;; expecting {org.clojure/clojure 3} but not\n\nuser> '{org.clojure/clojure 3 :k 8}\n{org.clojure/clojure 3, :k 8} ;; Because of the keys' different namespaces \n\n;; If you want to avoid second case then flip *print-namespace-maps* temporally.\nuser> (binding [*print-namespace-maps* false]\n (pprint '{org.clojure/clojure 3}))\n{org.clojure/clojure 3}\nnil\n\n;; 'This is not a thing about quote. It is about map with key of namespaced keyword.'\n;; (@ShiTianshu's reply is quoted from below link)\n;; To know the detail reason, go to the below link and see the reply of @didibus.\n;; https://clojureverse.org/t/the-quote-special-form-behaves-strangely-on-maps/4879#post_2", :author {:avatar-url "https://avatars2.githubusercontent.com/u/5372217?v=4", :account-source "github", :login "soulawaker"}, :created-at 1569190020566, :updated-at 1569354172296, :_id "5d87f084e4b0ca44402ef7ba"}], :notes [{:updated-at 1289668928000, :body "Quote gives you the unevaluated form. That is:\r\n\r\n
user=> '(foo bar baz)
\r\n\r\nWill not attempt to evaluate foo as a function but rather just return the data structure as is (with the three symbols unevaluated).", :created-at 1289662273000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fa3"} {:updated-at 1371659988000, :body "I found this blog post interesting: http://blog.8thlight.com/colin-jones/2012/05/22/quoting-without-confusion.html\r\n\r\nCheers", :created-at 1371659988000, :author {:login "santeron", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/27a696b2606968635d5f4a5c6e2c7871?r=PG&default=identicon"}, :_id "542692edf6e94c6970522006"}], :arglists [], :doc "Yields the unevaluated form. See http://clojure.org/special_forms for more\ninformation.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/quote"} {:ns "clojure.core", :name "var", :type "var", :see-alsos [{:created-at 1289212861000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "meta", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c12"} {:created-at 1289212876000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "symbol", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c13"} {:created-at 1289212908000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "symbol?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c14"} {:created-at 1289212912000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "var?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c15"} {:created-at 1349393081000, :author {:login "eric", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2b0c9ae6f1da9716451e7c86bc87230b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "binding", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c17"} {:created-at 1349393092000, :author {:login "eric", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2b0c9ae6f1da9716451e7c86bc87230b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-redefs", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c18"} {:created-at 1349393097000, :author {:login "eric", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2b0c9ae6f1da9716451e7c86bc87230b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-redefs-fn", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c19"} {:created-at 1349393197000, :author {:login "eric", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2b0c9ae6f1da9716451e7c86bc87230b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "set!", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c1a"} {:created-at 1362015211000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "var-set", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c1b"} {:created-at 1362015214000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "var-get", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c1c"} {:created-at 1362015219000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-local-vars", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c1d"}], :examples [{:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body ";;getting meta-data for a defined symbol (as opposed to what it's pointing to.\n\nuser=> meta\n#\n\nuser=> (var meta)\n#'clojure.core/meta\n\n;; Reader shortcut for var is #'\nuser=> #'meta\n#'clojure.core/meta\n\nuser=> (meta (var meta))\n{:ns #, :name meta, :file \"clojure/core.clj\", :line 178, :arglists ([obj]), :doc \"Returns the metadata of obj, returns nil if there is no metadata.\", :added \"1.0\"}\n", :created-at 1289212848000, :updated-at 1423522981079, :_id "542692d0c026201cdc326ea5"} {:author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :editors [{:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}], :body "=> *clojure-version*\n{:major 1, :minor 5, :incremental 0, :qualifier \"RC17\"}\n=> var\n;CompilerException java.lang.RuntimeException: Unable to resolve symbol: var in this context, compiling:(NO_SOURCE_PATH:1:42) \n=> (var)\n;CompilerException java.lang.NullPointerException, compiling:(NO_SOURCE_PATH:1:1) \n=> (var 1)\n;CompilerException java.lang.ClassCastException: java.lang.Long cannot be cast to clojure.lang.Symbol, compiling:(NO_SOURCE_PATH:1:1) \n=> (var defn)\n#'clojure.core/defn\n=> (var defn 1 2 3 4)\n#'clojure.core/defn\n", :created-at 1362014971000, :updated-at 1362015006000, :_id "542692d6c026201cdc3270d0"} {:editors [{:login "beoliver", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1413969?v=4"}], :body "user> (def a 1)\n#'user/a\n\nuser> (def b (var a))\n#'user/b\n\nuser> (alter-var-root (var a) inc)\n2\n\nuser> (alter-var-root b inc)\n3\n\nuser> (deref b)\n3\n", :author {:avatar-url "https://avatars2.githubusercontent.com/u/1413969?v=4", :account-source "github", :login "beoliver"}, :created-at 1509263736051, :updated-at 1509263779264, :_id "59f58978e4b0a08026c48c80"}], :notes nil, :arglists [], :doc "The symbol must resolve to a var, and the Var object itself (not its value)\nis returned. The reader macro #'x expands to (var x). See\nhttp://clojure.org/special_forms for more information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/var"} {:ns "clojure.core", :name "recur", :type "var", :see-alsos [{:created-at 1289618026000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "loop", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e3a"} {:created-at 1289618032000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "trampoline", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e3b"}], :examples [{:updated-at 1524485644327, :created-at 1290256018000, :body "(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))))", :editors [{:avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon", :account-source "clojuredocs", :login "john.r.woodward"} {:login "allentiak", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1922297?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/a06d0fc5d5b9a1d254e566c1d0e449a8?r=PG&default=identicon", :account-source "clojuredocs", :login "ique"}, :_id "542692d0c026201cdc326ea6"} {:author {:login "ique", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a06d0fc5d5b9a1d254e566c1d0e449a8?r=PG&default=identicon"}, :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/1922297?v=4", :account-source "github", :login "allentiak"}], :body "; 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))))", :created-at 1290256169000, :updated-at 1524485722720, :_id "542692d0c026201cdc326ea8"} {:author {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"}, :editors [], :body "(loop [i 0] \n (when (< i 5) \n (println i) \n (recur (inc i)); loop i will take this value\n))", :created-at 1342658004000, :updated-at 1342658004000, :_id "542692d6c026201cdc3270d2"} {:author {:login "azkesz", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/467196a4f2498080c9740a81fcbde855?r=PG&default=identicon"}, :editors [{:login "azkesz", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/467196a4f2498080c9740a81fcbde855?r=PG&default=identicon"}], :body "(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)))", :created-at 1345941881000, :updated-at 1345942092000, :_id "542692d6c026201cdc3270d3"} {:editors [{:login "jdwaterson", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2714395?v=3"}], :body "; 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.", :author {:avatar-url "https://avatars.githubusercontent.com/u/2714395?v=3", :account-source "github", :login "jdwaterson"}, :created-at 1442790612342, :updated-at 1442872934681, :_id "55ff3cd4e4b08e404b6c1c7f"} {:updated-at 1443215990041, :created-at 1443215347637, :author {:login "teymuri", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/13352033?v=3"}, :body ";;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))))))))", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/13352033?v=3", :account-source "github", :login "teymuri"}], :_id "5605b7f3e4b08e404b6c1c82"} {:editors [{:login "clojurianix", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19415437?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/19415437?v=3", :account-source "github", :login "clojurianix"}, :created-at 1463825907835, :updated-at 1463826090672, :_id "574035f3e4b0a1a06bdee495"} {:updated-at 1608716871582, :created-at 1608716871582, :author {:login "caumond", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11491686?v=4"}, :body ";; 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))))", :_id "5fe31247e4b0b1e3652d7420"}], :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"} {:ns "clojure.core", :name "throw", :type "var", :see-alsos [{:created-at 1341631202000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "try", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f2e"} {:created-at 1341631204000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "catch", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f2f"} {:created-at 1341631207000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "finally", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f30"} {:created-at 1430235342019, :author {:login "ljosa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/197881?v=3"}, :to-var {:ns "clojure.core", :name "ex-info", :library-url "https://github.com/clojure/clojure"}, :_id "553fa8cee4b06eaacc9cda7f"} {:created-at 1460277375628, :author {:login "ryoakg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/23413?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-data", :ns "clojure.core"}, :_id "570a107fe4b075f5b2c864df"}], :examples [{:author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :editors [], :body "=> (throw (Exception. \"my exception message\"))\njava.lang.Exception: my exception message (NO_SOURCE_FILE:0)\n", :created-at 1288000015000, :updated-at 1288000015000, :_id "542692d0c026201cdc326ea9"} {:editors [{:login "green-coder", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4"}], :body ";; Different types of exception can be thrown\n=> (throw (AssertionError. \"Wrong input.\"))\njava.lang.AssertionError: Wrong input.", :author {:avatar-url "https://avatars3.githubusercontent.com/u/10631263?v=4", :account-source "github", :login "asiegfried"}, :created-at 1501935005004, :updated-at 1533054136477, :_id "5985b59de4b0d19c2ce9d70b"} {:updated-at 1603831007076, :created-at 1603831007076, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/8271291?v=4"}, :body ";; ClojureScript usage\n=> (throw (js/Error. \"something went wrong...\"))", :_id "5f9884dfe4b0b1e3652d73f6"}], :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"} {:ns "clojure.core", :name "try", :type "var", :see-alsos [{:created-at 1287995793000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "catch", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f49"} {:created-at 1341631154000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "finally", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f4a"} {:created-at 1341631196000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "throw", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f4b"} {:created-at 1517506079914, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-info", :ns "clojure.core"}, :_id "5a734e1fe4b076dac5a728af"} {:created-at 1517506631341, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-data", :ns "clojure.core"}, :_id "5a735047e4b076dac5a728b0"}], :examples [{:author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :editors [], :body "=> (try\n (/ 1 0)\n (catch Exception e (str \"caught exception: \" (.getMessage e))))\n\n\"caught exception: Divide by zero\"", :created-at 1287995834000, :updated-at 1287995834000, :_id "542692d0c026201cdc326eaa"} {:author {:login "acagle", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7df8ebcd99fdbdd4a2f7682513897692?r=PG&default=identicon"}, :editors [], :body ";; for Clojurescript use js/Object as type\n(try\n (/ 1 0)\n (catch js/Object e\n (.log js/console e)))", :created-at 1344400343000, :updated-at 1344400343000, :_id "542692d6c026201cdc3270d5"} {:editors [{:login "masmatsum", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8317204?v=4"}], :body ";; Example with multiple catch clauses and a finally clause.\n(try (f)\n (catch SQLException se (prn (.getNextException e)))\n (catch Exception2 e (prn \"Handle generic exception\"))\n (finally (prn \"Release some resource\")))", :author {:avatar-url "https://avatars.githubusercontent.com/u/632775?v=3", :account-source "github", :login "Rovanion"}, :created-at 1463816138311, :updated-at 1633612258613, :_id "57400fcae4b00a9b70be566b"} {:editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}], :body ";; The catch/finally clause is an implicit do.\n(try\n (/ 1 0)\n (catch Exception ex \n (.printStackTrace ex)\n (str \"caught exception: \" (.getMessage ex))))\n;; java.lang.ArithmeticException: Divide by zero\n;;\tat clojure.lang.Numbers.divide(Numbers.java:163)\n;;\tat clojure.lang.Numbers.divide(Numbers.java:3833)\n;; ...\n;; at main.java:37)\n;;=> \"caught exception: Divide by zero\"\n", :author {:avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4", :account-source "github", :login "phreed"}, :created-at 1513121596628, :updated-at 1513202809575, :_id "5a30673ce4b0a08026c48cd4"} {:updated-at 1554055517810, :created-at 1554055517810, :author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4"}, :body ";; try multiple expressions\n(try (println \"expression 1\")\n (println \"expression 2\")\n (/ 1 0)\n (println \"expression 4\")\n (catch Exception e (println \"expression 3 throws\")))\n;;=> expression 1\n;;=> expression 2\n;;=> expression 3 throws", :_id "5ca1015de4b0ca44402ef6f4"} {:updated-at 1661740260118, :created-at 1661740260118, :author {:login "Obscerno", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33399601?v=4"}, :body ";; The last value in the body of try will be returned.\n(try \"I will not be returned.\"\n \"I will be returned\"\n (catch Exception e (.getMessage e))\n (finally \"I will also not be returned.\"))\n;; => \"I will be returned\"\n\n;; If there's an exception the last value in the body of catch will be returned.\n(try (throw (RuntimeException.))\n \"I will not be returned\"\n (catch Exception e \"I will be returned\")\n (finally \"I will also not be returned.\"))\n;; => \"I will be returned\"", :_id "630c24e4e4b0b1e3652d765d"}], :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/try"} {:ns "clojure.core", :name "catch", :type "var", :see-alsos [{:created-at 1287995785000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "try", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ad9"} {:created-at 1288000232000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "finally", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ada"} {:created-at 1517620569282, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "throw", :ns "clojure.core"}, :_id "5a750d59e4b0e2d9c35f740b"} {:created-at 1517620590089, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-data", :ns "clojure.core"}, :_id "5a750d6ee4b0e2d9c35f740c"} {:created-at 1517620611031, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-info", :ns "clojure.core"}, :_id "5a750d83e4b0e2d9c35f740d"} {:created-at 1518042276700, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "print-stack-trace", :ns "clojure.stacktrace"}, :_id "5a7b7ca4e4b0316c0f44f8a7"}], :examples [{:author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :editors [], :body "=> (try\n (/ 1 0)\n (catch Exception e (str \"caught exception: \" (.getMessage e))))\n\n\"caught exception: Divide by zero\"", :created-at 1287995772000, :updated-at 1287995772000, :_id "542692d0c026201cdc326eae"} {:updated-at 1474647298976, :created-at 1474647298976, :author {:login "JoshAaronJones", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19951591?v=3"}, :body ";; multiple catch clauses which handle different exceptions\n\n=> (let [divisor [2 0 \"clojure\"]]\n (try\n (/ 4 (rand-nth divisor))\n (catch ArithmeticException e\n (println \"Probably trying to divide by zero...\")\n 111)\n (catch ClassCastException e\n (println \"Did you try to do math with a string?\")\n 222)\n (catch Exception e\n (println \"Some other exception, won't be caught in this case...\")\n 333)\n (finally\n (println \"Always executed but won't return a value!\"))))\n\n;; first case\nAlways executed but won't return a value!\n=> 2\n\n;; second case\nProbably trying to divide by zero...\nAlways executed but won't return a value!\n=> 111\n\n;; third case\nDid you try to do math with a string?\nAlways executed but won't return a value!\n=> 222", :_id "57e55502e4b0709b524f050a"} {:updated-at 1482420504337, :created-at 1482420504337, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :body ";; Note that in ClojureScript, one can use (catch :default e ...) to catch any \n;; type of value, roughly equivalent to (catch Exception e ...) in JVM Clojure.\n\n(try\n (/ 2 (rand-nth [0 \"oops\"]))\n (catch :default e ; Note: ClojureScript only!\n (println \"Error!\" e)))\n\n;; This is not currently possible in JVM Clojure, though the ticket CLJ-1293 \n;; proposes adding the same behavior there and has some background info.", :_id "585bf118e4b0123d4c9dfa35"}], :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/catch"} {:ns "clojure.core", :name "finally", :type "var", :see-alsos [{:created-at 1288000213000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "try", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e23"} {:created-at 1288000217000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "catch", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e24"} {:created-at 1517617085736, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-data", :ns "clojure.core"}, :_id "5a74ffbde4b0e2d9c35f7406"} {:created-at 1517620981684, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "throw", :ns "clojure.core"}, :_id "5a750ef5e4b0e2d9c35f7410"}], :examples [{:updated-at 1317221828000, :created-at 1288260604000, :body "(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\"", :editors [{:avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon", :account-source "clojuredocs", :login "philos99"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d0c026201cdc326eaf"} {:editors [{:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4", :account-source "github", :login "huahaiy"}, :created-at 1592604689313, :updated-at 1663143524487, :_id "5eed3811e4b0b1e3652d7309"}], :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"} {:ns "clojure.core", :name ".", :type "var", :see-alsos [{:created-at 1461732266533, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "..", :ns "clojure.core"}, :_id "572043aae4b0fc95a97eab5c"}], :examples [{:updated-at 1514391136118, :created-at 1461732237604, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10404?v=3"}, :body "(def date (java.util.Date.))\n;; => #'date\n(. date getMonth)\n;; => 11 ; 0-based, so this indicates \"December\"", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/430319?v=4", :account-source "github", :login "jcburley"}], :_id "5720438de4b0fc95a97eab5a"} {:updated-at 1471001203866, :created-at 1471001203866, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}, :body "user=> (. \"abc\" (toUpperCase)) \n;;=> \"ABC\"\n\nuser=> (. \"abc\" toUpperCase) \n;;=> \"ABC\"\n;;if function has one arg you can use non-parenthesis form\n\n", :_id "57adb273e4b0bafd3e2a04f0"} {:updated-at 1555179101611, :created-at 1555175138250, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; '.' For static access\n(. Thread sleep 1000) ; static method of 1 arg.\n(. Math random) ; static field access first, static method of no args next.\n(. Math (random)) ; static method of no args (unambiguously).\n(. Math -PI) ; static field access (unambiguously).\n(. Thread$State NEW) ; inner class static method.\n\n;; Corresponding slashed forms are converted internally to dotted:\n(Thread/sleep 1000) ; static method of 1 arg.\n(Math/random) ; static field access first, static method of no args next.\n(Math/-PI) ; static field access (unambiguously).\n\n;; For instance access \n(import 'java.awt.Point)\n(. (Point. 1 2) x) ; instance field first, method of no args next\n(.x (Point. 1 2)) ; same as above\n(. (Point. 1 2) (getX)) ; instance method (unambiguously)\n(.-x (Point. 1 2)) ; instance field (unambiguously)\n\n;; Showing how to compose names dynamically\n(eval `(. (Point. 1 2) ~(symbol (str \"get\" \"X\"))))\n;; 1.0", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :_id "5cb216e2e4b0ca44402ef708"}], :notes nil, :arglists [], :doc "The '.' special form is the basis for access to Java. It can be considered\na member-access operator, and/or read as 'in the scope of'. See\nhttp://clojure.org/special_forms for more information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/_."} {:ns "clojure.core", :name "set!", :type "var", :see-alsos [{:created-at 1361164008000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "reset!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dc5"} {:created-at 1361164022000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "binding", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dc6"} {:created-at 1361164032000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "alter-var-root", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dc7"} {:created-at 1546021427673, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "atom", :ns "clojure.core"}, :_id "5c266a33e4b0ca44402ef603"}], :examples [{:author {:login "ninjudd", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7ced25585a7556e9b9b975c1f9e136e3?r=PG&default=identicon"}, :editors [], :body "(set! var-symbol expr)", :created-at 1307137727000, :updated-at 1307137727000, :_id "542692d0c026201cdc326ead"} {:author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :editors [], :body "(set! *warn-on-reflection* true)", :created-at 1361163932000, :updated-at 1361163932000, :_id "542692d6c026201cdc3270d6"} {:updated-at 1552509115019, :created-at 1552509115019, :author {:login "nhlx2", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4058121?v=4"}, :body "user=> (let [object (java.awt.Point. 1 2)]\n (set! (. object -y) 8)\n (bean object)\n )\n{:class java.awt.Point, :location #object[java.awt.Point 0x383fc59b \"java.awt.Point[x=1,y=8]\"], :x 1.0, :y 8.0}\n", :_id "5c8968bbe4b0ca44402ef6b4"} {:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}], :body ";; A mutable (and thread unsafe) Counter class.\n;; set! is used to mutate the internal cnt attribute.\n\n(deftype Counter [^:unsynchronized-mutable cnt]\n clojure.lang.IFn\n (invoke [this] (set! cnt (inc cnt))))\n\n(def counter (->Counter 0))\n(counter) ;; 1\n(counter) ;; 2", :author {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1554278192236, :updated-at 1554278208406, :_id "5ca46730e4b0ca44402ef6fb"}], :notes [{:updated-at 1298369674000, :body "As of Clojure 1.2, the basic info for set! has moved to http://clojure.org/vars.", :created-at 1298369674000, :author {:login "gregg-williams", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/58610a64fc8638eec8d2239d80d4046f?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fb3"}], :arglists [], :doc "Assignment special form. When the first operand is a field member access\nform, the assignment is to the corresponding field. If it is an instance\nfield, the instance expr will be evaluated, then the expr. In all cases\nthe value of expr is returned. Note - you cannot assign to function params\nor local bindings. Only Java fields, Vars, Refs and Agents are mutable in\nClojure. See http://clojure.org/special_forms for more information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/set!"} {:ns "clojure.core", :name "monitor-enter", :type "var", :see-alsos nil, :examples nil, :notes [{:body "\"should be avoided\". OK. But why is it available? How might it be used?\n\nhttp://stackoverflow.com/questions/36485155/use-locking-macro-or-monitor-enter-and-monitor-exit-in-java-from-clojure/36485607", :created-at 1461052938480, :updated-at 1461053268343, :author {:avatar-url "https://avatars.githubusercontent.com/u/11754710?v=3", :account-source "github", :login "terjedahl"}, :_id "5715e60ae4b0fc95a97eab4e"}], :arglists [], :doc "A synchronization primitive that should be avoided in user code. Use the\nlocking macro. See http://clojure.org/special_forms for more information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/monitor-enter"} {:ns "clojure.core", :name "monitor-exit", :type "var", :see-alsos nil, :examples nil, :notes nil, :arglists [], :doc "A synchronization primitive that should be avoided in user code. Use the\nlocking macro. See http://clojure.org/special_forms for more information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/monitor-exit"} {:ns "clojure.core", :name "new", :type "var", :see-alsos [{:created-at 1352083329000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name ".", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bf1"}], :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; Create a Java ArrayList using the 0 argument constructor\nuser=> (def a (new java.util.ArrayList))\n#'user/a\nuser=> (.add a \"aaa\")\ntrue\nuser=> (.add a \"bbb\")\ntrue\nuser=> a\n#\n", :created-at 1313491605000, :updated-at 1313491605000, :_id "542692d0c026201cdc326eab"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; Create another ArrayList and add integers using the doto macro\nuser=> (def ai (doto (new java.util.ArrayList) (.add 1) (.add 2) (.add 0)))\n#'user/ai\nuser=> ai\n#", :created-at 1313491629000, :updated-at 1313491629000, :_id "542692d0c026201cdc326eac"}], :notes nil, :arglists [], :doc "Instantiate a class. See http://clojure.org/java_interop#new for\nmore information.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/new"} {:ns "clojure.core", :name "primitives-classnames", :file "clojure/core_print.clj", :type "var", :column 1, :see-alsos nil, :line 372, :examples [{:body "user=> (use 'clojure.pprint)\nuser=> (pprint primitives-classnames)\n{float \"Float/TYPE\",\n int \"Integer/TYPE\",\n long \"Long/TYPE\",\n boolean \"Boolean/TYPE\",\n char \"Character/TYPE\",\n double \"Double/TYPE\",\n byte \"Byte/TYPE\",\n short \"Short/TYPE\"}", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423019236792, :updated-at 1423019236792, :_id "54d18ce4e4b081e022073c53"}], :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/primitives-classnames"} {:added "1.0", :ns "clojure.core", :name "+'", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1412881252224, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "+", :library-url "https://github.com/clojure/clojure"}, :_id "5436db64e4b06dbffbbb00c0"} {:created-at 1423526974611, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "unchecked-add", :library-url "https://github.com/clojure/clojure"}, :_id "54d94c3ee4b081e022073c83"}], :line 972, :examples [{:body "(+')\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", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1412881234729, :updated-at 1412881548215, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}], :_id "5436db52e4b0ae7956031576"} {:body "(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", :author {:login "yangwansu", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/89217?v=3"}, :created-at 1422876391721, :updated-at 1422876391721, :_id "54cf5ee7e4b081e022073c3e"}], :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/+'"} {:added "1.0", :ns "clojure.core", :name "decimal?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1496006134313, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bigdec?", :ns "clojure.core"}, :_id "592b3df6e4b093ada4d4d78b"} {:created-at 1496006153201, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "double?", :ns "clojure.core"}, :_id "592b3e09e4b093ada4d4d78c"} {:created-at 1496006158570, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "float?", :ns "clojure.core"}, :_id "592b3e0ee4b093ada4d4d78d"}], :line 3598, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [], :body "user=> (decimal? 1)\nfalse\n\nuser=> (decimal? 1.0)\nfalse\n\nuser=> (decimal? 1M)\ntrue\n\nuser=> (decimal? 99999999999999999999999999999999999)\nfalse\n\nuser=> (decimal? 1.0M)\ntrue", :created-at 1286508904000, :updated-at 1286508904000, :_id "542692cbc026201cdc326bd0"}], :notes nil, :arglists ["n"], :doc "Returns true if n is a BigDecimal", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/decimal_q"} {:added "1.2", :ns "clojure.core", :name "restart-agent", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1326769275000, :author {:login "Mark", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4d7c9ac1dd03a71c7d6b548e80c9d4f9?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "agent-error", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b32"} {:created-at 1326769279000, :author {:login "Mark", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4d7c9ac1dd03a71c7d6b548e80c9d4f9?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "agent", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b33"}], :line 2177, :examples [{:updated-at 1497900418842, :created-at 1497900418842, :author {:login "cloojure", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/7083783?v=3"}, :body "(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", :_id "59482582e4b06e730307db3b"}], :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"} {:added "1.0", :ns "clojure.core", :name "sort-by", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1302917800000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "sort", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ca1"} {:created-at 1361334368000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "compare", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ca2"}], :line 3119, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "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])", :created-at 1281552743000, :updated-at 1423276838828, :_id "542692cbc026201cdc326c28"} {:author {:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (sort-by :rank [{:rank 2} {:rank 3} {:rank 1}])\n({:rank 1} {:rank 2} {:rank 3})", :created-at 1281554134000, :updated-at 1332949762000, :_id "542692cbc026201cdc326c2a"} {:updated-at 1465979342950, :created-at 1305342274000, :body "(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})", :editors [{:avatar-url "https://www.gravatar.com/avatar/d1906fc5df2c8ce5b2d58cc6ea855aab?r=PG&default=identicon", :account-source "clojuredocs", :login "shuaybi"} {:avatar-url "https://www.gravatar.com/avatar/47018db2b156f6c7f606950e19cf6134?r=PG&default=identicon", :account-source "clojuredocs", :login "ordnungswidrig"} {:login "bfontaine", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1334295?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/d1906fc5df2c8ce5b2d58cc6ea855aab?r=PG&default=identicon", :account-source "clojuredocs", :login "shuaybi"}, :_id "542692cbc026201cdc326c2c"} {:author {:login "jamesqiu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc1268deaa7f2e78fe2b5ea76e6481d8?r=PG&default=identicon"}, :editors [], :body "(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})", :created-at 1313489274000, :updated-at 1313489274000, :_id "542692cbc026201cdc326c2f"} {:author {:login "Yogthos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a2640fb40f901598b3789ac2f5c5b701?r=PG&default=identicon"}, :editors [{:login "Yogthos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a2640fb40f901598b3789ac2f5c5b701?r=PG&default=identicon"}], :body ";sort entries in a map by value\nuser=> (sort-by val > {:foo 7, :bar 3, :baz 5})\n([:foo 7] [:baz 5] [:bar 3])", :created-at 1327752237000, :updated-at 1327752286000, :_id "542692d5c026201cdc327090"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; 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", :created-at 1331771914000, :updated-at 1332833698000, :_id "542692d5c026201cdc327092"} {:body ";;; 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})", :author {:login "foxlog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/150418?v=3"}, :created-at 1429710293523, :updated-at 1429710293523, :_id "5537a5d5e4b033f34014b770"} {:updated-at 1551027269645, :created-at 1471045254496, :author {:login "egracer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4086884?v=3"}, :body ";; 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\"})", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/4086884?v=3", :account-source "github", :login "egracer"} {:login "gautamr", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/70894?v=4"}], :_id "57ae5e86e4b0bafd3e2a04f1"} {:editors [{:login "overset", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/34342?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/34342?v=3", :account-source "github", :login "overset"}, :created-at 1488583557264, :updated-at 1488842435985, :_id "58b9fb85e4b01f4add58fe69"} {:updated-at 1557361208644, :created-at 1557361208644, :author {:login "fdhenard", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/884972?v=4"}, :body ";; 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})", :_id "5cd37238e4b0ca44402ef71d"} {:editors [{:login "cgaustin", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/16307176?v=4"}], :body ";; 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)...", :author {:avatar-url "https://avatars2.githubusercontent.com/u/16307176?v=4", :account-source "github", :login "cgaustin"}, :created-at 1602184227139, :updated-at 1602184337489, :_id "5f7f6423e4b0b1e3652d73cf"} {:editors [{:login "naxels", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/3195443?v=4"}], :body ";; 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})", :author {:avatar-url "https://avatars.githubusercontent.com/u/3195443?v=4", :account-source "github", :login "naxels"}, :created-at 1622382371391, :updated-at 1622382870076, :_id "60b39723e4b0b1e3652d7504"}], :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"} {:added "1.0", :ns "clojure.core", :name "macroexpand", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1284957731000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "macroexpand-1", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d2e"} {:created-at 1304099187000, :author {:login "pauldoo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5cb916d3c8abc9f45a093209e72489fb?r=PG&default=identicon"}, :to-var {:ns "clojure.walk", :name "macroexpand-all", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d2f"}], :line 4026, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [], :body ";; It is useful to combine macroexpand with pprint as the\n;; default output can be hard to read.\nuser=> (clojure.pprint/pprint (macroexpand '(time (print \"timing\"))))\n(let*\n [start__3917__auto__\n (. java.lang.System (clojure.core/nanoTime))\n ret__3918__auto__\n (print \"timing\")]\n (clojure.core/prn\n (clojure.core/str\n \"Elapsed time: \"\n (clojure.core//\n (clojure.core/double\n (clojure.core/-\n (. java.lang.System (clojure.core/nanoTime))\n start__3917__auto__))\n 1000000.0)\n \" msecs\"))\n ret__3918__auto__)\n\n;; Even after pretty printing you may benefit from some\n;; manual cleanup.\n\n;; Also worth noting that most of the time macroexpand-1 is\n;; a better alternative to avoid over expanding down too \n;; many levels.", :created-at 1286272649000, :updated-at 1286272649000, :_id "542692ccc026201cdc326c5e"} {:author {:login "BertrandDechoux", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/528360?v=3"}, :editors [{:login "raxod502", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6559064?v=3"}], :body "user=> (macroexpand '(-> c (+ 3) (* 2))) \n(* (+ c 3) 2)\n", :created-at 1339248908000, :updated-at 1457991523840, :_id "542692d4c026201cdc326ff9"}], :notes nil, :arglists ["form"], :doc "Repeatedly calls macroexpand-1 on form until it no longer\n represents a macro form, then returns it. Note neither\n macroexpand-1 nor macroexpand expand macros in subforms.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/macroexpand"} {:added "1.0", :ns "clojure.core", :name "ensure", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1299215930000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "commute", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bfa"} {:created-at 1299215941000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref-set", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bfb"} {:created-at 1364879934000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bfc"} {:created-at 1371688442000, :author {:login "juan.facorro", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d6f59d93cc17c698f16e550034a2d1ad?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "alter", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bfd"}], :line 2488, :examples [{:updated-at 1553541533678, :created-at 1553536468220, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; 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}", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :_id "5c9915d4e4b0ca44402ef6c2"}], :notes [{:updated-at 1299280980000, :body "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.", :created-at 1299215917000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fb6"} {:author {:login "glts", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1483271?v=4"}, :updated-at 1574323395658, :created-at 1574323395658, :body "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", :_id "5dd644c3e4b0ca44402ef7e1"}], :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"} {:ns "clojure.core", :name "chunk-first", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1443934291486, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk-next", :ns "clojure.core"}, :_id "5610b053e4b08e404b6c1c93"} {:created-at 1443934297249, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk-rest", :ns "clojure.core"}, :_id "5610b059e4b0686557fcbd44"}], :line 701, :examples [{:updated-at 1443934874463, :created-at 1443934874463, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :body "(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)", :_id "5610b29ae4b08e404b6c1c94"}], :notes nil, :tag "clojure.lang.IChunk", :arglists ["s"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/chunk-first"} {:added "1.7", :ns "clojure.core", :name "eduction", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1496674622028, :author {:login "vspinu", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1363467?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "transduce", :ns "clojure.core"}, :_id "5935713ee4b06e730307db2a"} {:created-at 1496674683706, :author {:login "vspinu", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1363467?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "reduce", :ns "clojure.core"}, :_id "5935717be4b06e730307db2b"} {:created-at 1496674762346, :author {:login "vspinu", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1363467?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "reductions", :ns "clojure.core"}, :_id "593571cae4b06e730307db2c"} {:created-at 1520634073209, :author {:login "glts", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1483271?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "sequence", :ns "clojure.core"}, :_id "5aa308d9e4b0316c0f44f918"}], :line 7694, :examples [{:editors [{:login "freckletonj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8399149?v=3"} {:login "JoshAaronJones", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19951591?v=3"} {:avatar-url "https://avatars0.githubusercontent.com/u/1363467?v=3", :account-source "github", :login "vspinu"} {:login "Bost", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1174677?v=4"}], :body ";; `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)", :author {:avatar-url "https://avatars.githubusercontent.com/u/17842?v=3", :account-source "github", :login "ghiden"}, :created-at 1452742324167, :updated-at 1608819387090, :_id "569716b4e4b060004fc217ad"} {:editors [{:login "freckletonj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8399149?v=3"} {:login "JoshAaronJones", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19951591?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/8399149?v=3", :account-source "github", :login "freckletonj"}, :created-at 1480456257096, :updated-at 1485277360753, :_id "583df841e4b0782b632278cd"} {:updated-at 1483046915116, :created-at 1483046915116, :author {:login "jvanderhyde", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6516608?v=3"}, :body ";; 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", :_id "58658003e4b0fd5fb1cc964c"} {:editors [{:login "vspinu", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1363467?v=3"} {:avatar-url "https://avatars0.githubusercontent.com/u/1174677?v=4", :account-source "github", :login "Bost"} {:login "jngbng", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/552977?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars0.githubusercontent.com/u/1363467?v=3", :account-source "github", :login "vspinu"}, :created-at 1496674440865, :updated-at 1633576431878, :_id "59357088e4b06e730307db26"}], :notes [{:author {:login "glts", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1483271?v=4"}, :updated-at 1520634037505, :created-at 1520634037505, :body "`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
", :created-at 1279552212000, :author {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"}, :_id "542692ebf6e94c6970521f82"} {:updated-at 1354058595000, :body "As Rich points out on the ML: \r\n\r\n`contains?` tells you whether or not `get` will succeed. It is not a \"rummager\".\r\n\r\n`contains?` and `get` abstract over fast lookup.\r\n", :created-at 1354058595000, :author {:login "uvtc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/34f159f89cbd1d9beac0276f5a7af552?r=PG&default=identicon"}, :_id "542692edf6e94c6970521ff5"} {:updated-at 1388617095000, :body "If you have a vector or list and want to check whether a *value* is contained in it, you will find that `contains?` does not work.\r\n\r\n
; does not work as you might expect\r\n(contains? [:a :b :c] :b) ; = false
\r\n\r\nThere are four things you can try in this case:\r\n\r\n1. Consider whether you really need a vector or list. If you use a set instead, `contains?` will work.\r\n
(contains? #{:a :b :c} :b) ; = true
\r\n2. Use [`some`](http://clojuredocs.org/clojure_core/clojure.core/some) instead, wrapping the target in a set, as follows:\r\n
(some #{:b} [:a :b :c]) ; = :b, which is truthy
\r\n3. The set-as-function shortcut will not work if you might be searching for a falsy value (`false` or `nil`).\r\n
; will not work\r\n(some #{false} [true false true]) ; = nil
\r\n In that case, you will have to write the predicate function the long way:\r\n
(some #(= false %) [true false true]) ; = true
\r\n4. If you will need to do this kind of search a lot, write a function for it:\r\n
", :created-at 1385323398000, :author {:login "roryokane", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5b2b185c814bb25f2f95a1152e58f033?r=PG&default=identicon"}, :_id "542692edf6e94c697052200f"} {:author {:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=3"}, :updated-at 1462902144512, :created-at 1462902144512, :body "In order to determine if an element is contained in the collection, it may be easiest to use the `Vector.indexOf()` function from java:\n\n (.indexOf (range 10) 5)\n ;=> 5\n (.indexOf [:a :b :c] :b)\n ;=> 1\n\n[Java API Docs are here](http://docs.oracle.com/javase/7/docs/api/java/util/Vector.html#indexOf%28java.lang.Object%29)", :_id "57321d80e4b012fa59bdb2f1"} {:body "You may wonder why this statement evaluates to true: \n\n(contains? [1 1 1 1 1] 4) \n;=> true\n\n\nLet's do some investigation to find the answer. First we start by finding out the type of [1 1 1 1 1]:\n\n(class [1 1 1 1 1]) \n;=> clojure.lang.PersistentVector\n\n\nSo when the statement (contains? [1 1 1 1 1] 4) is evaluated, the function contains? in core.clj is called.\n\nThis function delegates to the static Java function contains(Object coll, Object key) in clojure.lang.RT, which discovers that the incoming vector is an instance of Associative (PersistentVector > APersistentVector > IPersistentVector > Associative) and exits with: \n\nreturn ((Associative) coll).containsKey(key)\n\n\nThis means that these two statements are equivalent, based on the current implementation of PersistentVector: \n\n(contains? [1 1 1 1 1] 4) ; true \n(.containsKey [1 1 1 1 1 1] 4) ; true\n\n\nThe method containsKey of APersistentVector is finally called. It checks if the vector has at least four elements (size >= 4) which it has (5) and that's why it returns true. Mystery solved!\n", :created-at 1469650697268, :updated-at 1469653287748, :author {:avatar-url "https://avatars.githubusercontent.com/u/631272?v=3", :account-source "github", :login "tengstrand"}, :_id "57991709e4b0bafd3e2a04c1"} {:author {:login "coutego", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/86327033?v=4"}, :updated-at 1670094879509, :created-at 1670094709380, :body "This `in?` function could be a convenient one line replacement for `contains?` implementing the expected semantics for containers:\n \n
\n(defn in? [xs el] (some #(= % el) xs))\n
", :_id "638b9f75e4b0b1e3652d7693"}], :arglists ["coll key"], :doc "Returns true if key is present in the given collection, otherwise\n returns false. Note that for numerically indexed collections like\n vectors and Java arrays, this tests if the numeric key is within the\n range of indexes. 'contains?' operates constant or logarithmic time;\n it will not perform a linear search for a value. See also 'some'.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/contains_q"} {:added "1.0", :ns "clojure.core", :name "every?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1302013840000, :author {:login "pauldoo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5cb916d3c8abc9f45a093209e72489fb?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "some", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d9e"} {:created-at 1315793054000, :author {:login "wdkrnls", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/6d08a2f792f289b95fe1d982d4133d71?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "not-any?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d9f"} {:created-at 1422932256217, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "not-every?", :library-url "https://github.com/clojure/clojure"}, :_id "54d03920e4b081e022073c43"}], :line 2672, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (every? even? '(2 4 6))\ntrue\nuser=> (every? even? '(1 2 3))\nfalse", :created-at 1279073869000, :updated-at 1332951153000, :_id "542692cfc026201cdc326e56"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "Rich_Morin", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d4d28bd014f9e7324bad99dcc3b0d390?r=PG&default=identicon"}], :body ";; 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", :created-at 1310851356000, :updated-at 1358775095000, :_id "542692cfc026201cdc326e58"} {:author {:login "dkvasnicka", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/55c9f4624d94a0c87c4f4fcb7f152393?r=PG&default=identicon"}, :editors [{:login "dkvasnicka", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/55c9f4624d94a0c87c4f4fcb7f152393?r=PG&default=identicon"} {:avatar-url "https://avatars3.githubusercontent.com/u/1195619?v=3", :account-source "github", :login "jeffi"} {:login "beoliver", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1413969?v=4"} {:avatar-url "https://avatars2.githubusercontent.com/u/22192927?v=4", :account-source "github", :login "elenacanovi"} {:login "PEZ", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/30010?v=4"}], :body ";; 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", :created-at 1356575084000, :updated-at 1670431457567, :_id "542692d3c026201cdc326fa1"} {:updated-at 1512078155897, :created-at 1512078155897, :author {:login "chbrown", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/360279?v=4"}, :body ";; 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", :_id "5a207b4be4b0a08026c48cca"}], :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"} {:added "1.0", :ns "clojure.core", :name "proxy-mappings", :file "clojure/core_proxy.clj", :type "function", :column 1, :see-alsos nil, :line 323, :examples [{:updated-at 1683032923886, :created-at 1683032784200, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body "(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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4", :account-source "github", :login "tomdl89"}], :_id "64510ad0e4b08cf8563f4ba9"}], :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"} {:added "1.2", :ns "clojure.core", :name "keep-indexed", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1324314274000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "map-indexed", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b55"} {:created-at 1337189104000, :author {:login "SoniaH", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56a007a4b2c47b141bd39790278f88a7?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "keep", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b56"}], :line 7346, :examples [{:author {:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "SoniaH", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56a007a4b2c47b141bd39790278f88a7?r=PG&default=identicon"}], :body "user=> (keep-indexed #(if (odd? %1) %2) [:a :b :c :d :e])\n(:b :d)", :created-at 1282318865000, :updated-at 1337189353000, :_id "542692c9c026201cdc326a84"} {:author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :editors [], :body "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)", :created-at 1292177237000, :updated-at 1292177237000, :_id "542692c9c026201cdc326a87"} {:author {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}, :editors [{:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"} {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"} {:login "clojureking", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/92625b8a6be91bb8c688d0d07b4e2a32?r=PG&default=identicon"} {:login "clojureking", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/92625b8a6be91bb8c688d0d07b4e2a32?r=PG&default=identicon"}], :body "(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", :created-at 1306319468000, :updated-at 1409547666000, :_id "542692c9c026201cdc326a88"} {:updated-at 1444409466360, :created-at 1444409466360, :author {:login "PetrGlad", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/124476?v=3"}, :body ";; 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)))", :_id "5617f07ae4b084e61c76ecbf"} {:updated-at 1528067828447, :created-at 1528067828447, :author {:login "statcompute", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/4590938?v=4"}, :body "(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 |", :_id "5b1476f4e4b00ac801ed9e0a"} {:updated-at 1545622986549, :created-at 1542944952784, :author {:login "gluer", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/22495106?v=4"}, :body ";; 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\")", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/22495106?v=4", :account-source "github", :login "gluer"}], :_id "5bf778b8e4b0ca44402ef5c8"} {:editors [{:login "kevinmungai", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/23656776?v=4"}], :body ";; 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]", :author {:avatar-url "https://avatars3.githubusercontent.com/u/23656776?v=4", :account-source "github", :login "kevinmungai"}, :created-at 1594505780319, :updated-at 1594505852298, :_id "5f0a3a34e4b0b1e3652d731f"}], :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"} {:added "1.5", :ns "clojure.core", :name "cond->>", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1432152383427, :author {:login "x", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/693546?v=3"}, :to-var {:ns "clojure.core", :name "cond->", :library-url "https://github.com/clojure/clojure"}, :_id "555ce93fe4b01ad59b65f4d4"} {:created-at 1432152404184, :author {:login "x", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/693546?v=3"}, :to-var {:ns "clojure.core", :name "as->", :library-url "https://github.com/clojure/clojure"}, :_id "555ce954e4b03e2132e7d165"} {:created-at 1432152431951, :author {:login "x", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/693546?v=3"}, :to-var {:ns "clojure.core", :name "->", :library-url "https://github.com/clojure/clojure"}, :_id "555ce96fe4b01ad59b65f4d6"} {:created-at 1432152437689, :author {:login "x", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/693546?v=3"}, :to-var {:ns "clojure.core", :name "->>", :library-url "https://github.com/clojure/clojure"}, :_id "555ce975e4b03e2132e7d167"} {:created-at 1537310356172, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "cond", :ns "clojure.core"}, :_id "5ba17e94e4b00ac801ed9ea0"} {:created-at 1537310390943, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "case", :ns "clojure.core"}, :_id "5ba17eb6e4b00ac801ed9ea1"}], :line 7555, :examples [{:editors [{:login "x", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/693546?v=3"}], :updated-at 1458757086103, :created-at 1432152126897, :author {:avatar-url "https://avatars.githubusercontent.com/u/693546?v=3", :account-source "github", :login "x"}, :body ";; useful for when you want to control doing a bunch of things to a lazy sequence \n;; based on some conditions or, commonly, keyword arguments to a function.\n\n(defn do-stuff\n [coll {:keys [map-fn max-num-things batch-size]}]\n (cond->> coll\n map-fn (map map-fn)\n max-num-things (take max-num-things)\n batch-size (partition batch-size)))\n\nuser=> (do-stuff [1 2 3 4] {})\n[1 2 3 4]\nuser=> (do-stuff [1 2 3 4] {:map-fn str})\n(\"1\" \"2\" \"3\" \"4\")\nuser=> (do-stuff [1 2 3 4] {:map-fn str :batch-size 2})\n((\"1\" \"2\") (\"3\" \"4\"))\nuser=> (do-stuff [1 2 3 4] {:map-fn str :max-num-things 3})\n(\"1\" \"2\" \"3\")", :_id "555ce83ee4b01ad59b65f4d2"}], :macro true, :notes nil, :arglists ["expr & clauses"], :doc "Takes an expression and a set of test/form pairs. Threads expr (via ->>)\n through each form for which the corresponding test expression\n is true. Note that, unlike cond branching, cond->> threading does not short circuit\n after the first true test expression.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/cond->>"} {:added "1.0", :ns "clojure.core", :name "subs", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1318625011000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.string", :name "replace", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f3a"} {:created-at 1318625250000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.string", :name "split", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f3b"} {:created-at 1379039766000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.string", :name "replace-first", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f3c"} {:created-at 1379039915000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "re-find", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f3d"} {:created-at 1379039920000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "re-seq", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f3e"} {:created-at 1379039970000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "re-matches", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f3f"}], :line 4981, :examples [{:author {:login "citizen428", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3881a28fe402dd2d1de44717486cae8?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "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", :created-at 1280470619000, :updated-at 1285496389000, :_id "542692ccc026201cdc326cab"} {:updated-at 1513303984796, :created-at 1379039736000, :body ";; 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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"}, :_id "542692d5c026201cdc32709d"} {:updated-at 1517506971847, :created-at 1517506971847, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}, :body ";; 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;=> \"\"", :_id "5a73519be4b0c974fee49d19"}], :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"} {:added "1.1", :ns "clojure.core", :name "ref-min-history", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1364770283000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c63"} {:created-at 1364770288000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref-max-history", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c64"} {:created-at 1364770294000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref-history-count", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c65"}], :line 2470, :examples [{:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}], :body "(def r (ref 0))\n(ref-min-history r)\n;; 0\n\n(ref-min-history r 1) ; setter\n;; #object[clojure.lang.Ref 0x1f3f02ee {:status :ready, :val 0}]\n\n(ref-min-history r) ; getter\n;; 1\n", :author {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1550443391880, :updated-at 1553683971669, :_id "5c69e37fe4b0ca44402ef68d"} {:updated-at 1550443972155, :created-at 1550443972155, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; Setting the min history > 0 \n;; prevents read faults and related TX restart.\n;; Here T2 changes r after T1 started but haven't deref r yet.\n\n(def r (ref 0)) ; min-history is zero\n\n(future\n (dosync\n (println \"-Tx starting-\")\n (Thread/sleep 10000)\n (println \"T1:\" @r)))\n;; -Tx starting-\n\n(future\n (dosync\n (println \"T2:\" (alter r inc))))\n;; T2: 1\n;; -Tx starting-\n;; T1: 1\n\n;; Here T1 has one ref history value available and\n;; does not restart.\n(def r (ref 0))\n(ref-min-history r 1)\n\n(future\n (dosync\n (println \"-Tx starting-\")\n (Thread/sleep 10000)\n (println \"T1:\" @r)))\n;; -Tx starting-\n\n(future\n (dosync\n (println \"T2:\" (alter r inc))))\n;; T2: 1\n;; T1: 0", :_id "5c69e5c4e4b0ca44402ef68e"}], :notes nil, :arglists ["ref" "ref n"], :doc "Gets the min-history of a ref, or sets it and returns the ref", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ref-min-history"} {:added "1.0", :ns "clojure.core", :name "set", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289811222000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "hash-set", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f12"} {:created-at 1289811227000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "sorted-set", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f13"} {:created-at 1289811237000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "conj", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f14"} {:created-at 1313621942000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "join", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f15"} {:created-at 1313621949000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "select", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f16"} {:created-at 1313621954000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "difference", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f17"} {:created-at 1313621961000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "intersection", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f18"} {:created-at 1313621965000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "union", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f19"} {:created-at 1313621977000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "index", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f1a"} {:created-at 1313621988000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "project", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f1b"} {:created-at 1313621999000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "rename", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f1c"} {:created-at 1313622003000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "rename-keys", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f1d"} {:created-at 1313622018000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "map-invert", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f1e"} {:created-at 1313622048000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "disj", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f1f"} {:created-at 1315819885000, :author {:login "wdkrnls", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/6d08a2f792f289b95fe1d982d4133d71?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "distinct", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f20"}], :line 4105, :examples [{:author {:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"}, :editors [{:login "seancorfield", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9354eec0679e2d3b36b77ff62165f717?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body ";; returns distinct elements\nuser=> (set '(1 1 2 3 2 4 5 5))\n#{1 2 3 4 5}\n\n;; returns distinct elements (different nomenclature)\nuser=> (set [1 1 2 3 2 4 5 5])\n#{1 2 3 4 5}\n\nuser=> (set [1 2 3 4 5]) \n#{1 2 3 4 5}\n\nuser=> (set \"abcd\")\n#{\\a \\b \\c \\d}\n\nuser=> (set '(\"a\" \"b\" \"c\" \"d\"))\n#{\"a\" \"b\" \"c\" \"d\"}\n\nuser=> (set {:one 1 :two 2 :three 3})\n#{[:two 2] [:three 3] [:one 1]}\n\nuser=> (set nil)\n#{}", :created-at 1279417897000, :updated-at 1423275927213, :_id "542692cbc026201cdc326bfb"} {:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [{:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}], :body "(set [1 2 3 2 1 2 3])\n-> #{1 2 3}\n\n#{:a :b :c :d}\n-> #{:d :a :b :c}\n\n(hash-set :a :b :c :d)\n-> #{:d :a :b :c}\n \n(sorted-set :a :b :c :d)\n-> #{:a :b :c :d}\n\n;------------------------------------------------\n\n(def s #{:a :b :c :d})\n(conj s :e)\n-> #{:d :a :b :e :c}\n \n(count s)\n-> 4\n \n(seq s)\n-> (:d :a :b :c)\n \n(= (conj s :e) #{:a :b :c :d :e})\n-> true\n\n(s :b)\n-> :b\n \n(s :k)\n-> nil", :created-at 1289811205000, :updated-at 1289811299000, :_id "542692cbc026201cdc326bff"}], :notes [{:updated-at 1316747546000, :body "The documentation doesn't mention the order, is it undefined?\r\n\r\n#{:a :b :c :d}\r\n-> #{:d :a :b :c}\r\n", :created-at 1316747546000, :author {:login "icefox", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/dc848256f8954abd612cbe7e81859f91?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fce"} {:author {:login "venantius", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1824859?v=3"}, :updated-at 1476386802865, :created-at 1476386802865, :body "Sets are a core data structure that by definition do not store elements in a sorted order. The actual order will ultimately be determined by the specific hashing function underpinning the data structure. ", :_id "57ffdff2e4b001179b66bdcc"} {:author {:login "dhbarnett", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1676252?v=4"}, :updated-at 1568233525282, :created-at 1568233525282, :body "Is the order guaranteed to be consistent if so is it not ordered (just not asc/desc)? ", :_id "5d795835e4b0ca44402ef7b2"} {:author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :updated-at 1573849219982, :created-at 1573849219982, :body "Sets are not ordered, so there’s not guarantee on their “order”.", :_id "5dcf0883e4b0ca44402ef7e0"}], :arglists ["coll"], :doc "Returns a set of the distinct elements of coll.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/set"} {:added "1.1", :ns "clojure.core", :name "take-last", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1306817623000, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "last", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d0d"} {:created-at 1306817710000, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "butlast", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d0e"} {:created-at 1306817740000, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "drop-last", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d0f"} {:created-at 1473271791957, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "subvec", :ns "clojure.core"}, :_id "57d057efe4b0709b524f04ea"}], :line 2941, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "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", :created-at 1280323099000, :updated-at 1423278794590, :_id "542692cec026201cdc326de0"}], :notes [{:author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :updated-at 1521555189789, :created-at 1521555189789, :body "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
", :_id "5ab116f5e4b045c27b7fac1a"}], :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"} {:added "1.0", :ns "clojure.core", :name "bit-set", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1461359248259, :author {:login "fasiha", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/37649?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bit-test", :ns "clojure.core"}, :_id "571a9290e4b0e6b5e3f27e5c"} {:created-at 1527805055459, :author {:login "NealEhardt", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1338977?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bit-clear", :ns "clojure.core"}, :_id "5b10747fe4b045c27b7fac8a"}], :line 1337, :examples [{:updated-at 1461359232399, :created-at 1280337241000, :body "user=> (bit-set 2r1011 2) ; index is 0-based\n15 \n;; 15 = 2r1111\n\n;; the same in decimal\nuser=> (bit-set 11 2) \n15", :editors [{:avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon", :account-source "clojuredocs", :login "zmila"} {:avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon", :account-source "clojuredocs", :login "zmila"} {:login "fasiha", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/37649?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon", :account-source "clojuredocs", :login "zmila"}, :_id "542692c7c026201cdc32696f"} {:editors [{:login "fasiha", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/37649?v=3"}], :body ";; Returns a long, like all Clojure bit operations\nuser=> (bit-set 0 63)\n-9223372036854775808\n; A signed 64-bit number with only the sign bit (most significant bit) on.\n; This is the most negative number representable by signed 64 bits: -(2**63).\n; Same as:\nuser=> (bit-shift-left 1 63)\n-9223372036854775808\n\n;; And in case you forget your common powers to two, here's a reference ^^\nuser=> (bit-set 0 32)\n4294967296\nuser=> (bit-set 0 16)\n65536\nuser=> (bit-set 0 8)\n256\nuser=> (bit-set 0 4)\n16", :author {:avatar-url "https://avatars.githubusercontent.com/u/37649?v=3", :account-source "github", :login "fasiha"}, :created-at 1461359743597, :updated-at 1461359793455, :_id "571a947fe4b0e6b5e3f27e5d"}], :notes nil, :arglists ["x n"], :doc "Set bit at index n", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-set"} {:added "1.7", :ns "clojure.core", :name "reader-conditional", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1495962203638, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "reader-conditional?", :ns "clojure.core"}, :_id "592a925be4b093ada4d4d776"} {:created-at 1495962209101, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "read", :ns "clojure.core"}, :_id "592a9261e4b093ada4d4d777"} {:created-at 1495962222485, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "read-string", :ns "clojure.core"}, :_id "592a926ee4b093ada4d4d778"}], :line 7738, :examples [{:updated-at 1495962191755, :created-at 1495962191755, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body ";;;; The data representation for reader conditionals is used by Clojure\n;;;; when reading a string/file into Clojure data structures but choosing \n;;;; to preserve the conditionals themselves (instead of replacing them with\n;;;; the appropriate platform-specific code)\n\n;;;; Create a data representation for a NON-SPLICING reader conditional\n\n(def r-cond (reader-conditional '(:clj (Math/random)) false))\n;;=> #'user/r-cond\nr-cond\n;;=> #?(:clj (Math/random))\n(:form r-cond)\n;;=> (:clj (Math/random))\n(:splicing? r-cond)\n;;=> false\n\n;;;; Data representation is same as the one produced by (read-string)\n;;;; and (read) when provided with the option to preserve data conditionals\n\n(= r-cond (read-string {:read-cond :preserve} \"#?(:clj (Math/random))\"))\n;;=> true\n\n;;;; Create a data representation for a SPLICING reader conditional\n\n(def r-cond (reader-conditional '(:clj [Math/PI Math/E]) true))\n;;=> #'user/r-cond\n(:clj [Math/PI Math/E])\n;;=> #?@(:clj [Math/PI Math/E])\n(:form r-cond)\n;;=> (:clj [Math/PI Math/E])\n(:splicing? r-cond)\n;;=> true\n\n;;;; Data representation is same as the one produced by (read-string)\n;;;; and (read) when provided with the option to preserve data conditionals\n\n(= r-cond (read-string {:read-cond :preserve} \"#?@(:clj [Math/PI Math/E])\"))\n;;=> true", :_id "592a924fe4b093ada4d4d775"}], :notes nil, :arglists ["form splicing?"], :doc "Construct a data representation of a reader conditional.\n If true, splicing? indicates read-cond-splicing.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reader-conditional"} {:added "1.0", :ns "clojure.core", :name "gen-class", :file "clojure/genclass.clj", :type "macro", :column 1, :see-alsos [{:created-at 1360270663000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "proxy", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bd7"} {:created-at 1360270670000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "gen-interface", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bd8"}], :line 507, :examples [{:author {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"}, :editors [{:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"} {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "(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)))", :created-at 1279770352000, :updated-at 1332952789000, :_id "542692cec026201cdc326dab"} {:author {:login "daviddurand", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1316941?v=2"}, :editors [], :body ";; 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", :created-at 1325884685000, :updated-at 1325884685000, :_id "542692d3c026201cdc326fbb"} {:editors [{:login "mars0i", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1836941?v=4"}], :body ";; 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\".", :author {:avatar-url "https://avatars0.githubusercontent.com/u/1836941?v=4", :account-source "github", :login "mars0i"}, :created-at 1554533983608, :updated-at 1554575687135, :_id "5ca84e5fe4b0ca44402ef6fe"} {:updated-at 1558971581245, :created-at 1558971581245, :author {:login "holyjak", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/624958?v=4"}, :body ";; 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", :_id "5cec04bde4b0ca44402ef72b"} {:updated-at 1625726462164, :created-at 1625726462164, :author {:login "mattiuusitalo", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/47240847?v=4"}, :body ";; 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", :_id "60e69dfee4b0b1e3652d7513"}], :macro true, :notes [{:updated-at 1280115806000, :body "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
", :created-at 1280115806000, :author {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f8a"} {:updated-at 1311325790000, :body "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", :created-at 1306791528000, :author {:login "ckirkendall", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c29cd3a5f182e6de85cbd172fb9b5ab8?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fbf"} {:body "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.) ;;=> #", :created-at 1418209544515, :updated-at 1418209661100, :author {:login "alilee", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/16739?v=3"}, :_id "54882908e4b04e93c519ffa1"} {:author {:login "staypufd", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/10730?v=4"}, :updated-at 1518392816391, :created-at 1518392816391, :body "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. ", :_id "5a80d5f0e4b0316c0f44f8b8"} {:author {:login "mars0i", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1836941?v=4"}, :updated-at 1554575508996, :created-at 1554575508996, :body "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", :_id "5ca8f094e4b0ca44402ef705"}], :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"} {:added "1.9", :ns "clojure.core", :name "qualified-keyword?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1495715351421, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "keyword?", :ns "clojure.core"}, :_id "5926ce17e4b093ada4d4d766"} {:created-at 1495715368644, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "simple-keyword?", :ns "clojure.core"}, :_id "5926ce28e4b093ada4d4d767"}], :line 1642, :examples [{:editors [{:login "troglotit", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/10955264?v=4"}], :body "(qualified-keyword? :user/:keyword)\n;;=> true\n(qualified-keyword? ::keyword)\n;;=> true\n\n(qualified-keyword? :keyword)\n;;=> false\n\n(qualified-keyword? \"string\")\n;;=> false\n(qualified-keyword? 42)\n;;=> false\n(qualified-keyword? nil)\n;;=> false", :author {:avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3", :account-source "github", :login "svenschoenung"}, :created-at 1495722029967, :updated-at 1525876162343, :_id "5926e82de4b093ada4d4d768"}], :notes nil, :arglists ["x"], :doc "Return true if x is a keyword with a namespace", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/qualified-keyword_q"} {:added "1.0", :ns "clojure.core", :name "while", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1360216659000, :author {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "loop", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e4c"} {:created-at 1423524433851, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "dotimes", :library-url "https://github.com/clojure/clojure"}, :_id "54d94251e4b081e022073c7c"} {:created-at 1502829799304, :author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "repeatedly", :ns "clojure.core"}, :_id "59935ce7e4b0d19c2ce9d718"} {:created-at 1608681273224, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "swap!", :ns "clojure.core"}, :_id "5fe28739e4b0b1e3652d741d"} {:created-at 1608681301934, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "atom", :ns "clojure.core"}, :_id "5fe28755e4b0b1e3652d741e"}], :line 6333, :examples [{:updated-at 1608681521678, :created-at 1280547677000, :body ";; 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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon", :account-source "clojuredocs", :login "dakrone"}, :_id "542692ccc026201cdc326c69"} {:editors [{:login "slipset", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5894926?v=3"} {:avatar-url "https://avatars2.githubusercontent.com/u/87162?v=4", :account-source "github", :login "rafaelrinaldi"} {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}], :body ";; 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\"", :author {:avatar-url "https://avatars.githubusercontent.com/u/20086?v=3", :account-source "github", :login "reborg"}, :created-at 1469865962017, :updated-at 1518975645400, :_id "579c5feae4b0bafd3e2a04c3"}], :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"} {:ns "clojure.core", :name "->Eduction", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 7682, :examples nil, :notes nil, :arglists ["xform coll"], :doc "Positional factory function for class clojure.core.Eduction.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/->Eduction"} {:added "1.0", :ns "clojure.core", :name "butlast", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289038922000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "first", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c0b"} {:created-at 1289038928000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rest", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c0c"} {:created-at 1289038933000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "last", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c0d"} {:created-at 1289038937000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "next", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c0e"} {:created-at 1322055950000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "drop-last", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c0f"} {:created-at 1360842503000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "take-last", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c10"} {:created-at 1442106939048, :author {:login "miner", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/25400?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "pop", :ns "clojure.core"}, :_id "55f4ce3be4b06a9ffaad4fbd"}], :line 272, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}], :body "user=> (butlast [1 2 3])\n(1 2)\nuser=> (butlast (butlast [1 2 3]))\n(1)\nuser=> (butlast (butlast (butlast [1 2 3])))\nnil", :created-at 1279073589000, :updated-at 1289038906000, :_id "542692c8c026201cdc326a4c"} {:updated-at 1438337824330, :created-at 1289038828000, :body ";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)))))", :editors [{:login "danneu", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/529580?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon", :account-source "clojuredocs", :login "boxie"}, :_id "542692c8c026201cdc326a4e"} {:updated-at 1521202617879, :created-at 1521202617879, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; 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]", :_id "5aabb5b9e4b0316c0f44f926"} {:updated-at 1615302673505, :created-at 1615235547686, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :body ";; `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\"", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4", :account-source "github", :login "Crowbrammer"}], :_id "604689dbe4b0b1e3652d7477"}], :notes [{:author {:login "miner", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/25400?v=3"}, :updated-at 1442107338476, :created-at 1442107338476, :body "When using a vector, `pop` is faster than `butlast`.", :_id "55f4cfcae4b05246bdf20a8c"} {:author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4"}, :updated-at 1524422433918, :created-at 1524422433918, :body "`pop` will throw exception if the vector is empty, whereas `butlast` will return `nil`", :_id "5adcd721e4b045c27b7fac4c"} {:author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :updated-at 1615236256681, :created-at 1615235954399, :body "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. ", :_id "60468b72e4b0b1e3652d747b"}], :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"} {:added "1.2", :ns "clojure.core", :name "satisfies?", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos [{:created-at 1326611358000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "extend", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b64"} {:created-at 1345918796000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defprotocol", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b65"} {:created-at 1432578777116, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "instance?", :library-url "https://github.com/clojure/clojure"}, :_id "55636ad9e4b03e2132e7d16e"} {:created-at 1501651305911, :author {:login "chbrown", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/360279?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "extends?", :ns "clojure.core"}, :_id "59816169e4b0d19c2ce9d706"} {:created-at 1542365684479, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "extenders", :ns "clojure.core"}, :_id "5beea1f4e4b00ac801ed9efe"}], :line 569, :examples [{:author {:login "Jeff Rose", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/567898c496278341be69087507d5ed24?r=PG&default=identicon"}, :editors [], :body "(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", :created-at 1294900425000, :updated-at 1294900425000, :_id "542692cfc026201cdc326e5a"} {:updated-at 1557925978004, :created-at 1557925978004, :author {:login "thenonameguy", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/2217181?v=4"}, :body ";; 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", :_id "5cdc105ae4b0ca44402ef725"}], :notes [{:author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4"}, :updated-at 1593310454862, :created-at 1593310294294, :body "Unless this issue is resolved, do not use this function in a hot path, for it is extremely slow. See also this post ", :_id "5ef7fc56e4b0b1e3652d7313"}], :arglists ["protocol x"], :doc "Returns true if x satisfies the protocol", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/satisfies_q"} {:added "1.0", :ns "clojure.core", :name "line-seq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1420222290902, :author {:login "kappa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/47310?v=3"}, :to-var {:ns "clojure.core", :name "read-line", :library-url "https://github.com/clojure/clojure"}, :_id "54a6df52e4b09260f767ca82"}], :line 3085, :examples [{:author {:login "juergenhoetzel", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2736dfffc803c704dcf25b45ff63cede?r=PG&default=identicon"}, :editors [{:login "juergenhoetzel", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2736dfffc803c704dcf25b45ff63cede?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; Count lines of a file (loses head):\nuser=> (with-open [rdr (clojure.java.io/reader \"/etc/passwd\")]\n (count (line-seq rdr)))\n\n", :created-at 1279948343000, :updated-at 1285497370000, :_id "542692cec026201cdc326de3"} {:author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :editors [], :body "(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", :created-at 1301874056000, :updated-at 1301874056000, :_id "542692cec026201cdc326de7"} {:body ";; read from standard input\nuser=> (nth (line-seq (java.io.BufferedReader. *in*)) 2)\n #_=> 0\n #_=> 1\n #_=> 2\n\"2\"\n", :author {:login "kappa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/47310?v=3"}, :created-at 1420222563716, :updated-at 1420222563716, :_id "54a6e063e4b04e93c519ffb0"}], :notes [{:body "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\"`", :created-at 1620895381108, :updated-at 1620896615263, :author {:avatar-url "https://avatars.githubusercontent.com/u/28925709?v=4", :account-source "github", :login "nxtk"}, :_id "609ce695e4b0b1e3652d74fa"}], :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"} {:added "1.0", :ns "clojure.core", :name "unchecked-subtract-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1488034774618, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unchecked-add-int", :ns "clojure.core"}, :_id "58b19bd6e4b01f4add58fe65"}], :line 1205, :examples [{:updated-at 1488034725028, :created-at 1488034725028, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :body ";; Subtracting two int-range Longs works\n(unchecked-subtract-int 1 1)\n;;=> 0\n\n;; Subtracting two int-range BigInts works\n(unchecked-subtract-int 1N 1N)\n;;=> 0\n\n;; Doubles are truncated\n(unchecked-subtract-int 1 1.9)\n;;=> 0\n\n;; BigDecimals are truncated\n(unchecked-subtract-int 1 1.9M)\n;;=> 0\n\n;; Uncaught integer overflow\n(unchecked-subtract-int Integer/MAX_VALUE -1)\n;;=> -2147483648\n\n;; Uncaught integer underflow\n(unchecked-subtract-int Integer/MIN_VALUE 1)\n;;=> 2147483647\n\n;; Fails for Longs outside of int range\n(unchecked-subtract-int 2147483648 0)\n;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)\n\n;; Fails for BigInts outside of int range\n(unchecked-subtract-int 2147483648N 0)\n;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)\n\n;; Fails for Doubles outside of int range\n(unchecked-subtract-int 2147483648.0 0)\n;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)\n\n;; Fails for BigDecimals outside of int range\n(unchecked-subtract-int 2147483648.0M 0)\n;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)", :_id "58b19ba5e4b01f4add58fe64"}], :notes nil, :arglists ["x y"], :doc "Returns the difference of x and y, both int.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-subtract-int"} {: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 [{:updated-at 1540400673371, :created-at 1540400673371, :author {:login "mainej", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/6774?v=4"}, :body ";; 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", :_id "5bd0a621e4b00ac801ed9ee9"}], :notes [{:author {:login "katox", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/287639?v=4"}, :updated-at 1588435708523, :created-at 1588435708523, :body "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```", :_id "5ead9afce4b087629b5a18fc"}], :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*"} {:added "1.0", :ns "clojure.core", :name "take-nth", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1421519147165, :author {:login "kappa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/47310?v=3"}, :to-var {:ns "clojure.core", :name "partition", :library-url "https://github.com/clojure/clojure"}, :_id "54baa92be4b0e2ac61831cbb"} {:created-at 1544035011111, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "nth", :ns "clojure.core"}, :_id "5c081ac3e4b0ca44402ef5db"} {:created-at 1544035026986, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "rand-nth", :ns "clojure.core"}, :_id "5c081ad2e4b0ca44402ef5dc"}], :line 4288, :examples [{:updated-at 1285495759000, :created-at 1280776443000, :body "user=> (take-nth 2 (range 10))\n(0 2 4 6 8)\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692cec026201cdc326dd9"} {:body ";; N <= 0 is a special case\n(take 3 (take-nth 0 (range 2)))\n;;=> (0 0 0)\n\n(take 3 (take-nth -10 (range 2)))\n;;=> (0 0 0)", :author {:login "miner", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/25400?v=3"}, :created-at 1432222807506, :updated-at 1432222807506, :_id "555dfc57e4b03e2132e7d169"}], :notes [{:body "`(take-nth 0 (range 10))` will loop forever.", :created-at 1423278929350, :updated-at 1423278929350, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :_id "54d58351e4b081e022073c6c"} {:body "(take-nth 0 coll) will return an infinite sequence repeating for first item from coll. A negative N is treated the same as 0.", :created-at 1432222489733, :updated-at 1432222489733, :author {:login "miner", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/25400?v=3"}, :_id "555dfb19e4b03e2132e7d168"} {:author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :updated-at 1522313231902, :created-at 1522253561476, :body "
\n;; In case you are searching for it, drop-nth is not in core.\n\n(defn drop-nth [n coll]\n (lazy-seq\n (when-let [s (seq coll)]\n (concat (take (dec n) (rest s))\n (drop-nth n (drop n s))))))\n\n(drop-nth 3 (range 10))\n;; (1 2 4 5 7 8)\n\n;; or alternatively: (keep-indexed #(when-not (zero? (rem %1 n)) %2) coll)\n
", :_id "5abbbef9e4b045c27b7fac29"}], :arglists ["n" "n coll"], :doc "Returns a lazy seq of every nth item in coll. Returns a stateful\n transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/take-nth"} {:added "1.0", :ns "clojure.core", :name "first", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289038142000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rest", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f64"} {:created-at 1289038147000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "next", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f65"} {:created-at 1303125616000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "nth", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f66"} {:created-at 1303125622000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "second", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f67"} {:created-at 1328341708000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "take", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f68"} {:created-at 1348637402000, :author {:login "dansalmo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ffirst", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f69"} {:created-at 1493777583103, :author {:login "Juve-yescas", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/26342224?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "butlast", :ns "clojure.core"}, :_id "59093cafe4b01f4add58fea4"}], :line 49, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(first '(:alpha :bravo :charlie))\n;;=> :alpha", :created-at 1279071245000, :updated-at 1420735684016, :_id "542692ccc026201cdc326c6c"} {:updated-at 1545256959607, :created-at 1303680354000, :body ";; 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", :editors [{:avatar-url "https://www.gravatar.com/avatar/69ad2af1f028b1b7e76c14f83bdf26cb?r=PG&default=identicon", :account-source "clojuredocs", :login "jszakmeister"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "vaer-k", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4069456?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon", :account-source "clojuredocs", :login "belun"}, :_id "542692ccc026201cdc326c6e"} {:updated-at 1493775730548, :created-at 1493775730548, :author {:login "Juve-yescas", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/26342224?v=3"}, :body "=> (first [1 2])\n1\n\n=> (first [ [1 2] [3 4] ])\n[1 2]", :_id "59093572e4b01f4add58fea3"} {:updated-at 1661100444310, :created-at 1661100444310, :author {:login "zuzhi", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11850845?v=4"}, :body "=> (first \"j\")\n\\j\n\n=> (int (first \"j\"))\n106", :_id "6302619ce4b0b1e3652d7647"}], :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"} {:added "1.0", :ns "clojure.core", :name "re-groups", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1282039215000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "re-find", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e6a"} {:created-at 1444479086186, :author {:login "muhuk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/40178?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "re-matcher", :ns "clojure.core"}, :_id "5619006ee4b084e61c76ecc1"}], :line 4858, :examples [{:author {:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"}, :editors [], :body "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)", :created-at 1312374649000, :updated-at 1312374649000, :_id "542692c9c026201cdc326a7f"} {:editors [{:login "jgrodziski", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/408494?v=4"}], :body ";;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...", :author {:avatar-url "https://avatars3.githubusercontent.com/u/408494?v=4", :account-source "github", :login "jgrodziski"}, :created-at 1504879066415, :updated-at 1504880637927, :_id "59b2a1dae4b09f63b945ac64"} {:editors [{:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=4"}], :body ";\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", :author {:avatar-url "https://avatars.githubusercontent.com/u/7083783?v=4", :account-source "github", :login "cloojure"}, :created-at 1622895257068, :updated-at 1622895336509, :_id "60bb6a99e4b0b1e3652d7506"}], :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"} {:added "1.0", :ns "clojure.core", :name "seq?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1286870491000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "seq", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bc7"} {:created-at 1304804140000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "sequential?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bc8"} {:created-at 1304804146000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vector?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bc9"} {:created-at 1304804161000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "coll?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bca"} {:created-at 1304804189000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "list?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bcb"} {:created-at 1304804202000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "map?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bcc"} {:created-at 1304804206000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "set?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bcd"} {:created-at 1495638773577, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "seqable?", :ns "clojure.core"}, :_id "5925a2f5e4b093ada4d4d728"}], :line 146, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [], :body "user> (seq? 1)\nfalse\nuser> (seq? [1])\nfalse\nuser> (seq? (seq [1]))\ntrue", :created-at 1286870431000, :updated-at 1286870431000, :_id "542692c8c026201cdc326a5e"} {:updated-at 1604526011911, :created-at 1334018590000, :body ";; 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> ", :editors [{:login "allentiak", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1922297?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/bad5f5cb177b0968d4288596691ec3cd?r=PG&default=identicon", :account-source "clojuredocs", :login "gregginca"}, :_id "542692d5c026201cdc32707c"} {:updated-at 1485952236986, :created-at 1485952236986, :author {:login "yochannah", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/9271438?v=3"}, :body ";; 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\"", :_id "5891d4ece4b01f4add58fe35"}], :notes nil, :arglists ["x"], :doc "Return true if x implements ISeq", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/seq_q"} {:added "1.0", :ns "clojure.core", :name "dec'", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1415177726472, :author {:login "rvlieshout", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/139665?v=2"}, :to-var {:ns "clojure.core", :name "dec", :library-url "https://github.com/clojure/clojure"}, :_id "5459e5fee4b0dc573b892fb9"} {:created-at 1495706257856, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "inc'", :ns "clojure.core"}, :_id "5926aa91e4b093ada4d4d753"}], :line 1135, :examples [{:author {:login "szemek", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/78b14dbb96afe3befc04757dc5e06225?r=PG&default=identicon"}, :editors [], :body "user=> (dec' 0.1)\n-0.9\n\nuser=> (dec' 1)\n0\n\nuser=> (dec' 1.0)\n0.0", :created-at 1335130392000, :updated-at 1335130392000, :_id "542692d2c026201cdc326f77"} {:updated-at 1495706067200, :created-at 1495706067200, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body ";;;; (dec') auto-promotes on integer overflow:\n\n(dec' (Long/MIN_VALUE))\n;;=> -9223372036854775809N\n\n;;;; Unlike (dec) which does not:\n\n(dec (Long/MIN_VALUE))\n;;=> ArithmeticException integer overflow", :_id "5926a9d3e4b093ada4d4d751"}], :notes nil, :arglists ["x"], :doc "Returns a number one less than num. Supports arbitrary precision.\n See also: dec", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/dec'"} {:added "1.0", :ns "clojure.core", :name "ns-unmap", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1288683645000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "remove-ns", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d33"} {:created-at 1341280172000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ns-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d34"} {:created-at 1426949911751, :author {:login "ryoakg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/23413?v=3"}, :to-var {:ns "clojure.core", :name "def", :library-url "https://github.com/clojure/clojure"}, :_id "550d8717e4b056ca16cfecf9"} {:created-at 1484215112470, :author {:login "rauhs", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11081351?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "intern", :ns "clojure.core"}, :_id "58775348e4b09108c8545a57"} {:created-at 1512578699260, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ns-unalias", :ns "clojure.core"}, :_id "5a281e8be4b0a08026c48cd1"}], :line 4178, :examples [{:author {:login "james", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4b163432c99a124feee4be046a3f9d66?r=PG&default=identicon"}, :editors [{:login "MicahElliott", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/159047?v=3"}], :body "user=> (def foo 1)\n#'user/foo\n\nuser=> foo\n1\n\nuser=> (ns-unmap 'user 'foo) ; explicit\nnil\n\nuser=> (ns-unmap *ns* 'foo) ; convenient\nnil\n\nuser=> foo\n\"Unable to resolve symbol: foo in this context\"\n", :created-at 1290213451000, :updated-at 1335243941000, :_id "542692c7c026201cdc3269a3"}], :notes [{:author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :updated-at 1512036603446, :created-at 1512036603446, :body "Note this function doesn’t work for namespaces aliases; you need to use `ns-unalias` if you want to remove one.", :_id "5a1fd8fbe4b0a08026c48cc8"}], :arglists ["ns sym"], :doc "Removes the mappings for the symbol from the namespace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ns-unmap"} {:added "1.0", :ns "clojure.core", :name "println-str", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1318573842000, :author {:login "haplo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/890d46f8c0e24dd6fb8546095b1144e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "println", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e07"} {:created-at 1374264235000, :author {:login "lbeschastny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/416170465e4045f810f09a9300dda4dd?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "print-str", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e08"} {:created-at 1592850187673, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "str", :ns "clojure.core"}, :_id "5ef0f70be4b0b1e3652d730d"}], :line 4763, :examples [{:author {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"} {:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"} {:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"} {:login "matthewg", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b29dd31d183124d9e87d8037bb30e326?r=PG&default=identicon"}], :body ";; Create a newline-terminated string from the items and store it in x.\nuser=> (def x (println-str 1 \"foo\" \\b \\a \\r {:a 2}))\n#'user/x\n\n;; It's a string.\nuser=> (string? x)\ntrue\n\n;; Notice that the items are separated by a space. Also, the newline string is\n;; platform-specific. See clojure.core/newline.\nuser=> x\n\"1 foo b a r {:a 2}\\r\\n\"\n", :created-at 1284257337000, :updated-at 1323234147000, :_id "542692cfc026201cdc326e4c"}], :notes nil, :tag "java.lang.String", :arglists ["& xs"], :doc "println to a string, returning it", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/println-str"} {:added "1.1", :ns "clojure.core", :name "with-bindings*", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1374313837000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-bindings", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bb4"}], :line 1973, :examples [{:updated-at 1335591761000, :created-at 1335591761000, :body "user=> (let [f (fn [] *warn-on-reflection*)]\n (with-bindings* {#'*warn-on-reflection* true} f))\ntrue", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d6c026201cdc3270b8"}], :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*"} {:added "1.9", :ns "clojure.core", :name "inst-ms", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1495635499100, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "inst?", :ns "clojure.core"}, :_id "5925962be4b093ada4d4d721"}], :line 6787, :examples [{:updated-at 1495636375815, :created-at 1495636375815, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body "(inst-ms (java.util.Date.))\n;;=> 1495636054438\n(inst-ms (java.time.Instant/now))\n;;=> 1495636054438\n\n(inst-ms (java.sql.Date. 1495636054438))\n;;=> 1495636054438\n(inst-ms (java.sql.Timestamp. 1495636054438))\n;;=> 1495636054438", :_id "59259997e4b093ada4d4d723"}], :notes nil, :arglists ["inst"], :doc "Return the number of milliseconds since January 1, 1970, 00:00:00 GMT", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/inst-ms"} {:added "1.0", :ns "clojure.core", :name "iterator-seq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1398980083000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "seq", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e96"}], :line 5721, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; 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", :created-at 1284711960000, :updated-at 1287995124000, :_id "542692cdc026201cdc326d15"} {:updated-at 1519828356542, :created-at 1519828356542, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; 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\")", :_id "5a96bd84e4b0316c0f44f903"}], :notes [{:updated-at 1287834466000, :body "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.", :created-at 1287834466000, :author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f9d"}], :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"} {:added "1.0", :ns "clojure.core", :name "iterate", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1291953286000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "cycle", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b0d"} {:created-at 1335482527000, :author {:login "metajack", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/194d8437f5baed192c90be27369c4922?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "repeatedly", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b0e"} {:created-at 1343152603000, :author {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "repeat", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b0f"} {:created-at 1455301227264, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "take", :ns "clojure.core"}, :_id "56be226be4b060004fc217c1"} {:created-at 1455301237712, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "nth", :ns "clojure.core"}, :_id "56be2275e4b060004fc217c2"}], :line 3013, :examples [{:author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :editors [{:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/2746668?v=4", :account-source "github", :login "victoraldecoa"} {:login "stoat1", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2543524?v=4"}], :body ";; iterate Ad Infinitum starting at 5 using the inc (increment) function\nuser=> (iterate inc 5)\n(5 6 7 8 9 10 11 12 13 14 15 ... n ...\n\n;; limit results\nuser=> (take 3 (iterate inc 5))\n(5 6 7)\n\nuser=> (take 10 (iterate (partial + 2) 0))\n(0 2 4 6 8 10 12 14 16 18)\n\nuser=> (take 20 (iterate (partial + 2) 0))\n(0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38)\n\n", :created-at 1279048785000, :updated-at 1615738001527, :_id "542692cac026201cdc326b22"} {:author {:login "citizen428", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3881a28fe402dd2d1de44717486cae8?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (def powers-of-two (iterate (partial * 2) 1))\n#'user/powers-of-two\n\nuser=> (nth powers-of-two 10)\n1024\nuser=> (take 10 powers-of-two)\n(1 2 4 8 16 32 64 128 256 512)\n", :created-at 1280707793000, :updated-at 1285496060000, :_id "542692cac026201cdc326b29"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"} {:login "Bobby", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c0541baac8a638e07f5895c7224f8b7e?r=PG&default=identicon"} {:login "Bobby", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c0541baac8a638e07f5895c7224f8b7e?r=PG&default=identicon"} {:login "maacl", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8ff89765136c38707e0f57cf48679a13?r=PG&default=identicon"}], :body ";; demonstrating the power of iterate\n;; to generate the Fibonacci sequence\n;; uses +' to promote to BigInt\nuser=> (def fib (map first (iterate (fn [[a b]] [b (+' a b)]) [0 1])))\n#'user/fib\n\nuser=> (take 10 fib)\n(0 1 1 2 3 5 8 13 21 34)", :created-at 1310850870000, :updated-at 1388690059000, :_id "542692cac026201cdc326b2b"} {:updated-at 1520938144240, :created-at 1520938144240, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; iterate (also range, repeat and cycle) have a reduce\n;; fast path. Use with reduce, transduce, eduction etc.\n\n(defn pi\n \"Approximate Pi to the 1/n decimal with Leibniz formula\"\n [n]\n (transduce\n (comp (map #(/ 4 %)) (take n))\n +\n (iterate #(* ((if (pos? %) + -) % 2) -1) 1.0)))\n\n(time (pi 1e8))\n\"Elapsed time: 9776.924934 msecs\"\n;; 3.141592643589326", :_id "5aa7aca0e4b0316c0f44f923"}], :notes nil, :arglists ["f x"], :doc "Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/iterate"} {:added "1.0", :ns "clojure.core", :name "slurp", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1330170507000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.java.io", :name "reader", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521efd"} {:created-at 1314301885000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "spit", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f54"} {:created-at 1529010527201, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "resource", :ns "clojure.java.io"}, :_id "5b22d95fe4b00ac801ed9e16"}], :line 6942, :examples [{:author {:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (spit \"blubber.txt\" \"test\")\nnil\nuser=> (slurp \"blubber.txt\")\n\"test\"", :created-at 1280458838000, :updated-at 1332952657000, :_id "542692cac026201cdc326b32"} {:updated-at 1603841965576, :created-at 1314221982000, :body ";; To access web page. Note the use of https://\n;; prefix\n\nuser=> (slurp \"https://clojuredocs.org\")\n; This will return the html content of clojuredocs.org", :editors [{:login "fhightower", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/3599813?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon", :account-source "clojuredocs", :login "OnesimusUnbound"}, :_id "542692cac026201cdc326b34"} {:author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :editors [], :body ";; Access absolute location on Windows\n\nuser=> (slurp \"C:\\\\tasklists.xml\")\n", :created-at 1314301837000, :updated-at 1314301837000, :_id "542692cac026201cdc326b35"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; On Linux, some JVMs have a bug where they cannot read a file in the /proc\n;; filesystem as a buffered stream or reader. A workaround to this JVM issue\n;; is to open such a file as unbuffered:\n(slurp (java.io.FileReader. \"/proc/cpuinfo\"))", :created-at 1330170476000, :updated-at 1330170476000, :_id "542692d5c026201cdc327086"} {:author {:login "nils.grunwald", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/6c7661b3ea6397abbf5a2048ee07d995?r=PG&default=identicon"}, :editors [{:login "nils.grunwald", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/6c7661b3ea6397abbf5a2048ee07d995?r=PG&default=identicon"} {:login "nils.grunwald", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/6c7661b3ea6397abbf5a2048ee07d995?r=PG&default=identicon"}], :body ";; You can specify what encoding to use by giving a :encoding param, and an encoding string recognized by your JVM\n\nuser=> (slurp \"/path/to/file\" :encoding \"ISO-8859-1\")", :created-at 1342145976000, :updated-at 1342146268000, :_id "542692d5c026201cdc327087"} {:updated-at 1464367678770, :created-at 1464367678770, :author {:login "freckletonj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8399149?v=3"}, :body ";; you can fetch URLs\n\n(slurp \"http://www.example.com\")", :_id "57487a3ee4b0bafd3e2a0467"} {:updated-at 1485689448487, :created-at 1485689448487, :author {:login "mhmdsalem1993", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10787314?v=3"}, :body ";; you can read bytes also\n\n(def arr-bytes (into-array Byte/TYPE (range 128)))\n(slurp arr-bytes)", :_id "588dd268e4b01f4add58fe33"}], :notes [{:updated-at 1309555971000, :body "Use slurp also to read an input stream into a string.", :created-at 1309555971000, :author {:login "mjg123", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2d7180cd610e068c47d3ba7337f1425c?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fc3"} {:updated-at 1387184994000, :body "With link: “See [`clojure.java.io/reader`](http://clojuredocs.org/clojure_core/clojure.java.io/reader) for a complete list of supported arguments.â€�\r\n\r\nAccording to those docs, here are the supported types for `f`, the object to read:\r\n\r\n* [`Reader`](http://docs.oracle.com/javase/7/docs/api/java/io/Reader.html)\r\n* [`BufferedReader`](http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html)\r\n* [`InputStream`](http://docs.oracle.com/javase/7/docs/api/java/io/InputStream.html)\r\n* [`File`](http://docs.oracle.com/javase/7/docs/api/java/io/File.html)\r\n* [`URI`](http://docs.oracle.com/javase/7/docs/api/java/net/URI.html)\r\n* [`URL`](http://docs.oracle.com/javase/7/docs/api/java/net/URL.html)\r\n* [`Socket`](http://docs.oracle.com/javase/7/docs/api/java/net/Socket.html)\r\n* byte arrays (`byte[]`)\r\n* character arrays (`char[]`)\r\n* [`String`](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html)\r\n\r\n`slurp` can read objects of any of these types into a string.", :created-at 1387183993000, :author {:login "roryokane", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5b2b185c814bb25f2f95a1152e58f033?r=PG&default=identicon"}, :_id "542692edf6e94c6970522015"} {:body "
\n(defn slurp-bytes\n \"Slurp the bytes from a slurpable thing\"\n [x]\n (with-open [out (java.io.ByteArrayOutputStream.)]\n (clojure.java.io/copy (clojure.java.io/input-stream x) out)\n (.toByteArray out)))\n
", :created-at 1522121921297, :updated-at 1522121998843, :author {:avatar-url "https://avatars0.githubusercontent.com/u/13529973?v=4", :account-source "github", :login "nevesjorgelucio"}, :_id "5ab9bcc1e4b045c27b7fac27"} {:author {:login "didibus", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/601540?v=4"}, :updated-at 1585180980301, :created-at 1585180980301, :body "Valid options include:\n\n :encoding string name of encoding to use, e.g. \\\"UTF-8\\\".", :_id "5e7bf134e4b087629b5a18c3"}], :tag "java.lang.String", :arglists ["f & opts"], :doc "Opens a reader on f and reads all its contents, returning a string.\n See clojure.java.io/reader for a complete list of supported arguments.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/slurp"} {:added "1.0", :ns "clojure.core", :name "newline", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 3697, :examples [{:author {:login "jjcomer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ef581bba2f97adb539c67a35465b3e1b?r=PG&default=identicon"}, :editors [{:login "cloojure", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon"}], :body ";; 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=>", :created-at 1330655016000, :updated-at 1402384428000, :_id "542692d4c026201cdc327012"}], :notes nil, :arglists [""], :doc "Writes a platform-specific newline to *out*", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/newline"} {:added "1.1", :ns "clojure.core", :name "short-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "shorts", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917718000, :_id "542692eaf6e94c6970521ad6"}], :line 5309, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}], :body ";; create an array of shorts using short-array\n;; and demonstrate how it can be used with the java Arrays functions\n;; (note the needed coercions)\n\nuser=> (def ss (short-array (map short (range 3 10))))\n#'user/ss\nuser=> (type ss)\n[S\nuser=> (vec ss)\n[3 4 5 6 7 8 9]\nuser=> (java.util.Arrays/binarySearch ss (short 6))\n3\nuser=> (java.util.Arrays/fill ss (short 99))\nnil\nuser=> (vec ss)\n[99 99 99 99 99 99 99]\nuser=>", :created-at 1313908642000, :updated-at 1313962982000, :_id "542692c7c026201cdc326987"}], :notes nil, :arglists ["size-or-seq" "size init-val-or-seq"], :doc "Creates an array of shorts", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/short-array"} {:added "1.0", :ns "clojure.core", :name "fn?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1321052077000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ifn?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b3c"}], :line 6237, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "replore", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e7869fe1a48cb1814c657eaca6bea3eb?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (fn? 5)\nfalse\nuser=> (fn? inc)\ntrue\nuser=> (fn? (fn []))\ntrue\nuser=> (fn? #(5))\ntrue", :created-at 1279073964000, :updated-at 1332952252000, :_id "542692c6c026201cdc3268f8"} {:author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; Even though maps, sets, vectors and keywords behave as functions:\nuser=> ({:a 1} :a)\n1\n\n;; fn? still returns false for them because they are not created using fn:\nuser=> (fn? {:a 1})\nfalse\n", :created-at 1279155323000, :updated-at 1285500252000, :_id "542692c6c026201cdc3268fc"}], :notes [{:author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :updated-at 1504887813989, :created-at 1504887813989, :body "Note `fn?` only tests if something was created using `fn`, *not* if it’s a function. Use [`ifn?`](https://clojuredocs.org/clojure.core/ifn_q) for that. Some things are functions even though they weren’t created with `fn`, such as maps, vectors and keywords.", :_id "59b2c405e4b09f63b945ac66"}], :arglists ["x"], :doc "Returns true if x implements Fn, i.e. is an object created via fn.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/fn_q"} {:added "1.0", :ns "clojure.core", :name "doall", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289672752000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "dorun", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a8b"} {:created-at 1289672768000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "doseq", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a8c"} {:created-at 1659463132215, :author {:login "puredanger", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/171129?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "run!", :ns "clojure.core"}, :_id "62e965dce4b0b1e3652d7636"}], :line 3148, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"} {:login "orivej", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cab90c7de5efde92a29f1eacb603ba9a?r=PG&default=identicon"}], :body ";; 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)", :created-at 1280548280000, :updated-at 1362554691000, :_id "542692cbc026201cdc326ba2"} {:updated-at 1436248770172, :created-at 1436248770172, :author {:login "gdeer81", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1340575?v=3"}, :body ";;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", :_id "559b6ac2e4b020189d740548"} {:updated-at 1493187295161, :created-at 1493187295161, :author {:login "chbrown", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/360279?v=3"}, :body ";; 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", :_id "59003adfe4b01f4add58fe9c"} {:updated-at 1510465598561, :created-at 1510464241601, :author {:login "elect000", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/18697629?v=4"}, :body ";; #'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;", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/18697629?v=4", :account-source "github", :login "elect000"}], :_id "5a07daf1e4b0a08026c48cb1"}], :notes [{:updated-at 1341951212000, :body "Shouldn't we use seq instead of coll in the function signature since we should really pass a sequence?", :created-at 1341951200000, :author {:login "johnnyluu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ba99f2dc1064733c7badbb16db9254a?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fe5"} {:updated-at 1390120527000, :body "'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)", :created-at 1390120527000, :author {:login "zephjc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/47639b1aa7a7ccb90000a3ea12b84d7e?r=PG&default=identicon"}, :_id "542692edf6e94c697052201a"}], :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"} {:added "1.0", :ns "clojure.core", :name "prefers", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1337584993000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "prefer-method", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b6f"} {:created-at 1337585000000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "methods", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b70"} {:created-at 1337585004000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "get-method", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b71"}], :line 1824, :examples [{:updated-at 1475527508775, :created-at 1475527508775, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}, :body "(def m {:os ::osx})\n\n(defmulti ex :os)\n\n(defmethod ex ::unix\n [_]\n \"unix\")\n\n(derive ::osx ::unix)\n\n(defmethod ex ::bsd\n [_]\n \"bsd\")\n\n(derive ::osx ::bsd)\n\n(prefer-method ex ::unix ::bsd)\n\n(prefers ex)\n;;=> {:user/unix #{:user/bsd}}", :_id "57f2c354e4b0709b524f051d"}], :notes nil, :arglists ["multifn"], :doc "Given a multimethod, returns a map of preferred value -> set of other values", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/prefers"} {: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 [{:author {:login "leifp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d2f37720f063404ef83b987d2824353d?r=PG&default=identicon"}, :editors [], :body "user=> (enumeration-seq (java.util.StringTokenizer. \"exciting example\"))\n(\"exciting\" \"example\")\n", :created-at 1342527173000, :updated-at 1342527173000, :_id "542692d2c026201cdc326f9d"} {:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}], :body ";; 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)", :author {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1519838098877, :updated-at 1519838192224, :_id "5a96e392e4b0316c0f44f904"}], :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"} {:added "1.7", :ns "clojure.core", :name "dedupe", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1440188329568, :author {:login "blx", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/887504?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "distinct", :ns "clojure.core"}, :_id "55d787a9e4b072d7f27980ea"}], :line 7655, :examples [{:editors [{:login "blx", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/887504?v=3"}], :body "user=> (dedupe [1 2 3 3 3 1 1 6])\n(1 2 3 1 6)", :author {:avatar-url "https://avatars.githubusercontent.com/u/887504?v=3", :account-source "github", :login "blx"}, :created-at 1440188225498, :updated-at 1440188473719, :_id "55d78741e4b0831e02cddf18"} {:updated-at 1558989991424, :created-at 1558989991424, :author {:login "AMacGregor27", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/46518023?v=4"}, :body ";; This is taken from a problem on 4Clojure (30. Compress a sequence).\nuser=> (dedupe \"Leeeeroy\")\n(\\L \\e \\r \\o \\y)\n\nuser=> (dedupe [[1 2] [1 2] [3 4] [1 2]])\n([1 2] [3 4] [1 2])\n\nuser=> (dedupe [[1 [1 2]] [1 [2 3]] [1 [1 2]] [1 [1 2]]])\n([1 [1 2]] [1 [2 3]] [1 [1 2]])\n\n;; This does not remove all duplicates from a collection, only consecutive ones.\nuser=> (dedupe [1 2 2 1 1 1 2 1 2 2])\n(1 2 1 2 1 2)\n\n;; To remove all duplicates, use distinct.\nuser=> (distinct [1 2 2 1 1 1 2 1 2 2])\n(1 2)", :_id "5cec4ca7e4b0ca44402ef72f"} {:updated-at 1607179810709, :created-at 1607179810709, :author {:login "siddharthjain-in", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/6537820?v=4"}, :body "user=> (dedupe [1/2 2/4])\n(1/2)\n\nuser=>(dedupe [1/2 2/6])\n(1/2 1/3)\n\nuser=>(dedupe [1/2 0.5 2/4])\n(1/2 0.5 1/2)", :_id "5fcb9e22e4b0b1e3652d7416"} {:editors [{:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=4"}], :body ";; parentheses can be omitted in thread macro \nuser> (->> [1 1 2 2] (map inc) dedupe)\n(2 3)\n;; transducer version that does not work, parentheses cannot be omitted\nuser> (sequence (comp (map inc) dedupe) [1 1 2 2])\nExecution error (IllegalArgumentException) at user/eval15380 (form-init7517833771916228311.clj:104).\nDon't know how to create ISeq from: clojure.lang.TransformerIterator$1\n;; transducer that works\nuser> (sequence (comp (map inc) (dedupe)) [1 1 2 2])\n(2 3)", :author {:avatar-url "https://avatars.githubusercontent.com/u/889685?v=4", :account-source "github", :login "huahaiy"}, :created-at 1639422117065, :updated-at 1639422160521, :_id "61b798a5e4b0b1e3652d7589"}], :notes nil, :arglists ["" "coll"], :doc "Returns a lazy sequence removing consecutive duplicates in coll.\n Returns a transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/dedupe"} {:added "1.0", :ns "clojure.core", :name "dissoc", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1293866784000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "assoc", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c5a"} {:created-at 1351064004000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "disj", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c5c"} {:created-at 1367625873000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "select-keys", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c5d"}], :line 1504, :examples [{:updated-at 1565336715281, :created-at 1280340610000, :body "(dissoc {:a 1 :b 2 :c 3}) ; dissoc nothing \n;;=> {:a 1, :b 2, :c 3} \n\n(dissoc {:a 1 :b 2 :c 3} :b) ; dissoc key :b\n;;=> {:a 1, :c 3} \n\n(dissoc {:a 1 :b 2 :c 3} :d) ; dissoc not existing key\n;;=> {:a 1, :b 2, :c 3} \n\n(dissoc {:a 1 :b 2 :c 3} :c :b) ; several keys at once\n;;=> {:a 1} \n", :editors [{:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/201852?v=3", :account-source "github", :login "michaelcameron"} {:login "dominem", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11671382?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon", :account-source "clojuredocs", :login "zmila"}, :_id "542692cfc026201cdc326e63"} {:updated-at 1442111008755, :created-at 1442111008755, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :body ";; There is no (dissoc-in) analogous to (get-in) or (assoc-in), but \n;; you can achieve a similar effect using (update-in):\n\n(update-in {:a {:b {:x 3} :c 1}} [:a :b] dissoc :x)\n;;=> {:a {:b {}, :c 1}}", :_id "55f4de20e4b05246bdf20a8e"} {:updated-at 1492776031769, :created-at 1492776031769, :author {:login "skuro", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/186085?v=3"}, :body ";; When applied to a record and one of its base fields, \n;; dissoc produces a plain map instead of a record\n\n(defrecord Widget [id])\n(def w (->Widget \"id\"))\n\n(class w)\n;; user.Widget\n\n(class (dissoc w :id))\n;; clojure.lang.PersistentArrayMap", :_id "58f9f45fe4b01f4add58fe99"} {:updated-at 1516223401897, :created-at 1516223370479, :author {:login "RobinNagpal", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/745748?v=4"}, :body ";; Removing multiple from nested map\n(update-in {:a {:b {:x 3 :y 5} :c 1}} [:a :b] \n (fn [nested] (apply dissoc nested [:x :y] )) )\n=> {:a {:b {}, :c 1}} ", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/745748?v=4", :account-source "github", :login "RobinNagpal"}], :_id "5a5fbb8ae4b0a08026c48cfc"} {:updated-at 1608027071533, :created-at 1608027071533, :author {:login "Em-AK", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1518393?v=4"}, :body ";; dissoc keys in a coll\nuser=> (apply (partial dissoc {:a 1 :b 2 :c 3}) #{:b :c})\n{:a 1}", :_id "5fd88bbfe4b0b1e3652d7418"}], :notes [{:author {:login "u473t8", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/17592435?v=4"}, :updated-at 1629458054605, :created-at 1629458054605, :body "`(update {} :a dissoc :b) => {:a nil}`", :_id "611f8e86e4b0b1e3652d7533"}], :arglists ["map" "map key" "map key & ks"], :doc "dissoc[iate]. Returns a new map of the same (hashed/sorted) type,\n that does not contain a mapping for key(s).", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/dissoc"} {:added "1.0", :ns "clojure.core", :name "atom", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1281849237000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "reset!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eeb"} {:created-at 1281849248000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "swap!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eec"} {:created-at 1341623864000, :author {:login "johnnyluu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ba99f2dc1064733c7badbb16db9254a?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "compare-and-set!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eed"} {:created-at 1349392634000, :author {:login "eric", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2b0c9ae6f1da9716451e7c86bc87230b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "add-watch", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eee"} {:created-at 1349392638000, :author {:login "eric", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2b0c9ae6f1da9716451e7c86bc87230b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "remove-watch", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eef"} {:created-at 1364873735000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "set-validator!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ef0"} {:created-at 1527705006799, :author {:login "agarman", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/138454?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "swap-vals!", :ns "clojure.core"}, :_id "5b0eedaee4b045c27b7fac7d"} {:created-at 1527705359815, :author {:login "agarman", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/138454?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "reset-vals!", :ns "clojure.core"}, :_id "5b0eef0fe4b045c27b7fac84"}], :line 2327, :examples [{:author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}], :body "user=> (def my-atom (atom 0))\n#'user/my-atom\n\nuser=> @my-atom\n0\n\nuser=> (swap! my-atom inc)\n1\n\nuser=> @my-atom\n1\n\nuser=> (swap! my-atom (fn [n] (* (+ n n) 2)))\n4\n\nuser=> (reset! my-atom 0)\n0\n\nuser=> @my-atom\n0", :created-at 1281460949000, :updated-at 1476155071423, :_id "542692cec026201cdc326db7"} {:body "user=> (def a (atom #{}))\n#'user/a\n\nuser=>(swap! a conj :tag)\n#{:tag}\n\nuser=> @a\n#{:tag}", :author {:login "mzenzie", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1862891?v=3"}, :created-at 1433438207582, :updated-at 1433438207582, :_id "557087ffe4b01ad59b65f4ee"} {:updated-at 1450892672375, :created-at 1450892672375, :author {:login "bostonaholic", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/362146?v=3"}, :body "user=> (def my-atom (atom 0 :validator even?))\n#'user/my-atom\n\nuser=> @my-atom\n0\n\nuser=> (swap! my-atom inc)\nIllegalStateException Invalid reference state clojure.lang.ARef.validate (ARef.java:33)\n\nuser=> (swap! my-atom (partial + 2))\n2\n\nuser=> @my-atom\n2", :_id "567add80e4b01f598e267e8f"} {:updated-at 1518532012281, :created-at 1518532012281, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body "(def car\n (atom {:make \"Audi\"\n :model \"Q3\"}))\n\n@car\n;;{:make \"Audi\", :model \"Q3\"}\n\n(swap!\n car\n assoc :model \"Q5\")\n;;{:make \"Audi\", :model \"Q5\"}\n\n(reset! car {:make \"\" :model \"\"})\n;;{:make \"\", :model \"\"}", :_id "5a82f5ace4b0316c0f44f8bc"} {:editors [{:login "djblue", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1986211?v=4"}], :body "(defn atom? [v]\n #?(:clj (instance? clojure.lang.Atom v)\n :cljs (satisfies? cljs.core/IAtom v)))\n\n(atom? (atom nil)) ;; => true", :author {:avatar-url "https://avatars.githubusercontent.com/u/1986211?v=4", :account-source "github", :login "djblue"}, :created-at 1661551176193, :updated-at 1661551230443, :_id "63094248e4b0b1e3652d7658"}], :notes nil, :arglists ["x" "x & options"], :doc "Creates and returns an Atom with an initial value of x and zero or\n more options (in any order):\n\n :meta metadata-map\n\n :validator validate-fn\n\n If metadata-map is supplied, it will become the metadata on the\n atom. validate-fn must be nil or a side-effect-free fn of one\n argument, which will be passed the intended new state on any state\n change. If the new state is unacceptable, the validate-fn should\n return false or throw an exception.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/atom"} {:added "1.0", :ns "clojure.core", :name "import", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1291627622000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "require", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ace"} {:created-at 1291628363000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "use", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521acf"} {:created-at 1291628388000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ns", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ad0"}], :line 3425, :examples [{:author {:login "nipra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/142529?v=3"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "YizhePKU", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/42838469?v=4"}], :body "user=> (import java.util.Date)\njava.util.Date\n\nuser=> (def now (Date.))\n#'user/now\n\nuser=> (str now)\n\"Tue Jul 13 17:53:54 IST 2010\"\n", :created-at 1279049126000, :updated-at 1588421112835, :_id "542692c8c026201cdc326a01"} {:author {:login "dale", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a7a1eca257c6cea943fea41e5cc3e9a3?r=PG&default=identicon"}, :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/169654?v=4", :account-source "github", :login "noisesmith"} {:login "YizhePKU", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/42838469?v=4"}], :body ";; You can import multiple classes at once.\n(import (java.util Date Calendar)\n (java.net URI ServerSocket)\n java.sql.DriverManager)", :created-at 1294019024000, :updated-at 1588421172276, :_id "542692c8c026201cdc326a03"} {:author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :editors [], :body ";; importing multiple classes in a namespace\n(ns foo.bar\n (:import (java.util Date\n Calendar)\n (java.util.logging Logger\n Level)))", :created-at 1320992711000, :updated-at 1320992711000, :_id "542692d3c026201cdc326fce"} {:editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"} {:login "Rooke", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1158538?v=4"} {:avatar-url "https://avatars1.githubusercontent.com/u/42838469?v=4", :account-source "github", :login "YizhePKU"}], :body ";; For cases when 'import' does not do it for you, i.e. \"live-coding\"\n;; You can use the DynamicClassLoader, ClassReader and the Resolver.\n\n(def dcl (clojure.lang.DynamicClassLoader.))\n\n(defn dynamically-load-class! \n [class-loader class-name]\n (let [class-reader (clojure.asm.ClassReader. class-name)]\n (when class-reader\n (let [bytes (.-b class-reader)]\n (.defineClass class-loader \n class-name \n bytes\n \"\")))))\n\n(dynamically-load-class! dcl \"java.lang.Long\")\n(dynamically-load-class! dcl 'org.joda.time.DateTime)\n\n;; From that point the dynamically loaded class can be\n;; used by the Reflector to invoke constructors, methods and to get fields. ", :author {:avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4", :account-source "github", :login "phreed"}, :created-at 1508173740564, :updated-at 1588421462200, :_id "59e4e7ace4b03026fe14ea8d"} {:editors [{:login "ooooak", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1457253?v=4"}], :body "(import [org.apache.commons.codec.digest DigestUtils])\n\n(defn md5-hash [input] \n (DigestUtils/md5Hex input))\n\n(md5-hash \"hello world!\") \n;; fc3ff98e8c6a0d3087d515c0473f8677", :author {:avatar-url "https://avatars1.githubusercontent.com/u/1457253?v=4", :account-source "github", :login "ooooak"}, :created-at 1580227890599, :updated-at 1580227900588, :_id "5e305d32e4b0ca44402ef824"}], :macro true, :notes [{:updated-at 1291628547000, :body "Good description of use/require/import here:\r\n\r\nhttp://blog.8thlight.com/articles/2010/12/6/clojure-libs-and-namespaces-require-use-import-and-ns", :created-at 1291628547000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fa9"} {:updated-at 1403035286000, :body "`import` will also accept vectors instead of lists, but I would discourage folks from doing so:\r\n\r\n* It's undocumented.\r\n* Lists and vectors have different meanings for `require`, so there's precedent for making a distinction.\r\n* Lists have a distinguished first element, and so they indent more meaningfully here. :-P", :created-at 1403035286000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :_id "542692edf6e94c697052202a"} {:author {:login "YizhePKU", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/42838469?v=4"}, :updated-at 1588421551270, :created-at 1588421551270, :body "You don't need to use `import` if you fully qualify the class name, e.g. `(java.util.Date.)`.", :_id "5ead63afe4b087629b5a18fb"}], :arglists ["& import-symbols-or-lists"], :doc "import-list => (package-symbol class-name-symbols*)\n\n For each name in class-name-symbols, adds a mapping from name to the\n class named by package.name to the current namespace. Use :import in the ns\n macro in preference to calling this directly.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/import"} {:added "1.0", :ns "clojure.core", :name "bit-shift-right", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1405719667000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bit-shift-left", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aaf"} {:created-at 1405719682000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bit-xor", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ab0"} {:created-at 1405719694000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bit-or", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ab1"} {:created-at 1405719700000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bit-and", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ab2"} {:created-at 1405719706000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bit-set", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ab3"} {:created-at 1405719712000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bit-test", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ab4"} {:created-at 1405719724000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bit-flip", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ab5"} {:created-at 1405719732000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bit-and-not", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ab6"} {:created-at 1405719739000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bit-clear", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ab7"} {:created-at 1412094678691, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=2"}, :to-var {:ns "clojure.core", :name "unsigned-bit-shift-right", :library-url "https://github.com/clojure/clojure"}, :_id "542adad6e4b0df9bb778a5a4"}], :line 1362, :examples [{:author {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; 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", :created-at 1280029081000, :updated-at 1421878196402, :_id "542692cec026201cdc326dbb"} {:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "replore", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e7869fe1a48cb1814c657eaca6bea3eb?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(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", :created-at 1280339098000, :updated-at 1421877723171, :_id "542692cec026201cdc326dbe"} {:editors [{:login "fasiha", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/37649?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/37649?v=3", :account-source "github", :login "fasiha"}, :created-at 1460044794475, :updated-at 1460044978009, :_id "570683fae4b0fc95a97eab30"} {:editors [{:login "Sophia-Gold", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19278114?v=3"}], :body ";; 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)))))", :author {:avatar-url "https://avatars.githubusercontent.com/u/19278114?v=3", :account-source "github", :login "Sophia-Gold"}, :created-at 1483958434391, :updated-at 1484376283481, :_id "587368a2e4b09108c8545a53"}], :notes [{:updated-at 1326789497000, :body "From the IRC channel, a way to get zero-fill bit-shift-right:\r\n\r\n
\n", :created-at 1422938659514, :updated-at 1422939155762, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :_id "54d05223e4b0e2ac61831cfa"} {:author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :updated-at 1530020021260, :created-at 1530020021260, :body "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```", :_id "5b3240b5e4b00ac801ed9e20"} {:author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :updated-at 1582729216279, :created-at 1582729216279, :body "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.", :_id "5e568800e4b087629b5a18a9"}], :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"} {:added "1.1", :ns "clojure.core", :name "char", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1321310785000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "char?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b80"} {:created-at 1333595214000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "int", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b81"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "chars", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917303000, :_id "542692eaf6e94c6970521b82"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "char-array", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917307000, :_id "542692eaf6e94c6970521b83"}], :line 3510, :examples [{:author {:login "mattdw", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ee24aacb65359196b0a1bad050f9a62f?r=PG&default=identicon"}, :editors [{:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"}], :body ";; 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)", :created-at 1280322589000, :updated-at 1317219055000, :_id "542692cdc026201cdc326d01"} {:updated-at 1444162460695, :created-at 1444162460695, :author {:login "teymuri", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/13352033?v=3"}, :body "(->> [67 108 111 106 117 114 101]\n (map char)\n (apply str))\n\n\"Clojure\"", :_id "56142b9ce4b084e61c76ecbd"} {:updated-at 1562515072023, :created-at 1562515072023, :author {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/24317401?v=4"}, :body ";; 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\\\\", :_id "5d221680e4b0ca44402ef77e"} {:updated-at 1575989957857, :created-at 1575989957857, :author {:login "vladkotu", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/389119?v=4"}, :body ";; 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", :_id "5defb2c5e4b0ca44402ef7f5"} {:updated-at 1674282378834, :created-at 1674282378834, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4"}, :body "(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))", :_id "63cb858ae4b08cf8563f4b68"}], :notes nil, :arglists ["x"], :doc "Coerce to char", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/char"} {:added "1.0", :ns "clojure.core", :name "mapcat", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1294988622000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cb4"} {:created-at 1294988628000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "concat", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cb5"} {:created-at 1580338264619, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "flatten", :ns "clojure.core"}, :_id "5e320c58e4b0ca44402ef827"}], :line 2783, :examples [{:updated-at 1285501773000, :created-at 1279063141000, :body "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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :_id "542692cac026201cdc326b36"} {:updated-at 1337333286000, :created-at 1337333286000, :body "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))", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d4c026201cdc327006"} {:author {:login "uvtc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/34f159f89cbd1d9beac0276f5a7af552?r=PG&default=identicon"}, :editors [{:login "uvtc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/34f159f89cbd1d9beac0276f5a7af552?r=PG&default=identicon"}], :body "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", :created-at 1340097786000, :updated-at 1340099694000, :_id "542692d4c026201cdc327007"} {:author {:login "uvtc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/34f159f89cbd1d9beac0276f5a7af552?r=PG&default=identicon"}, :editors [], :body ";; 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", :created-at 1343650918000, :updated-at 1343650918000, :_id "542692d4c026201cdc327009"} {:author {:login "devth", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/70c7535cbb9fea0353250a4edda155be?r=PG&default=identicon"}, :editors [], :body "; 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", :created-at 1357801138000, :updated-at 1357801138000, :_id "542692d4c026201cdc32700a"} {:body ";; 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.", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423014103873, :updated-at 1423014118164, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :_id "54d178d7e4b081e022073c4d"} {:updated-at 1505377247866, :created-at 1505377247866, :author {:login "buzzdan", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/18007791?v=4"}, :body ";; 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", :_id "59ba3bdfe4b09f63b945ac75"} {:updated-at 1557893179267, :created-at 1557893179267, :author {:login "humorless", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/3061798?v=4"}, :body ";; 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)", :_id "5cdb903be4b0ca44402ef724"} {:updated-at 1559995255249, :created-at 1559995255249, :author {:login "sodesu99", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/31072774?v=4"}, :body ";;(mapcat f & colls)\n(mapcat list [:a :b :c] [1 2 3])\n;;=> (:a 1 :b 2 :c 3)", :_id "5cfba377e4b0ca44402ef750"}], :notes [{:body "
\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
", :created-at 1521801795650, :updated-at 1521801813945, :author {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :_id "5ab4da43e4b045c27b7fac1f"}], :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"} {:added "1.3", :ns "clojure.core", :name "unchecked-long", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1496088171964, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "long", :ns "clojure.core"}, :_id "592c7e6be4b093ada4d4d79b"}], :line 3540, :examples [{:updated-at 1496088165852, :created-at 1496088165852, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body "(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", :_id "592c7e65e4b093ada4d4d79a"}], :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"} {:added "1.0", :ns "clojure.core", :name "aset-long", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 3951, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; create an array of 10 longs and set one of the values to 31415\n\nuser=> (def ls (long-array 10))\n#'user/ls\nuser=> (vec ls)\n[0 0 0 0 0 0 0 0 0 0]\nuser=> (aset-long ls 3 31415)\n31415\nuser=> (vec ls)\n[0 0 0 31415 0 0 0 0 0 0]\nuser=>", :created-at 1313915173000, :updated-at 1313915173000, :_id "542692cec026201cdc326d8a"}], :notes [{:body "See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax.", :created-at 1432829151791, :updated-at 1432829151791, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :_id "55673cdfe4b01ad59b65f4df"}], :arglists ["array idx val" "array idx idx2 & idxv"], :doc "Sets the value at the index/indices. Works on arrays of long. Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aset-long"} {:added "1.6", :ns "clojure.core", :name "some?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1431460708707, :author {:login "mmavko", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1064539?v=3"}, :to-var {:ns "clojure.core", :name "nil?", :library-url "https://github.com/clojure/clojure"}, :_id "55525b64e4b03e2132e7d160"} {:created-at 1434787747213, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:ns "clojure.core", :name "some", :library-url "https://github.com/clojure/clojure"}, :_id "55851fa3e4b05f167dcf233f"}], :line 531, :examples [{:editors [{:login "klimenko-serj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2082879?v=3"}], :body "user> (some? nil)\n;; => false\n\nuser> (some? 42)\n;; => true\nuser> (some? false)\n;; => true\nuser> (some? [])\n;; => true\nuser> (some? {})\n;; => true\nuser> (some? '())\n;; => true", :author {:avatar-url "https://avatars.githubusercontent.com/u/2082879?v=3", :account-source "github", :login "klimenko-serj"}, :created-at 1438944110688, :updated-at 1438944205513, :_id "55c48b6ee4b0080a1b79cdb7"} {:updated-at 1514328933133, :created-at 1514328933133, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}, :body ";; equivalent to implementing not-nil?\n(some? :kw)\n;; => true\n(not (nil? :kw))\n;; => true\n\n(some? nil)\n;; => false\n(not (nil? nil))\n;; => false", :_id "5a42d365e4b0a08026c48cda"}], :notes nil, :tag "java.lang.Boolean", :arglists ["x"], :doc "Returns true if x is not nil, false otherwise.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/some_q"} {:added "1.0", :ns "clojure.core", :name "unchecked-negate", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1289217312000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-add", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c21"} {:created-at 1289217314000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-dec", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c22"} {:created-at 1289217316000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-inc", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c23"} {:created-at 1289217318000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-negate", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c24"} {:created-at 1289217321000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-divide", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c25"} {:created-at 1289217324000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-subtract", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c26"} {:created-at 1289217326000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-multiply", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c27"} {:created-at 1289217329000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-remainder", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c28"} {:created-at 1423522476536, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "-", :library-url "https://github.com/clojure/clojure"}, :_id "54d93aace4b0e2ac61831d32"}], :line 1184, :examples [{:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=3"}], :body ";; *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", :author {:avatar-url "https://avatars.githubusercontent.com/u/20086?v=3", :account-source "github", :login "reborg"}, :created-at 1458063308020, :updated-at 1458063919478, :_id "56e847cce4b0b41f39d96ce4"}], :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"} {:added "1.10", :ns "clojure.core", :name "remove-tap", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1590688377580, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "tap>", :ns "clojure.core"}, :_id "5ecffa79e4b087629b5a191a"} {:created-at 1590688383018, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "add-tap", :ns "clojure.core"}, :_id "5ecffa7fe4b087629b5a191b"}], :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"} {:added "1.0", :ns "clojure.core", :name "gen-interface", :file "clojure/genclass.clj", :type "macro", :column 1, :see-alsos [{:created-at 1360270679000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "proxy", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dbf"} {:created-at 1360270682000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "gen-class", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dc0"}], :line 688, :examples [{:updated-at 1542284408999, :created-at 1542284408999, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; gen-interface defines the class in memory, but does not spit it to disk\n;; (unless AOT-ing). Note: this is different from gen-class (that actually does\n;; nothing unless it's AOT compiling).\n\n(gen-interface :name \"user.IFoo\" :extends [clojure.lang.IPersistentMap])\n;; user.IFoo\n\n(reify user.IFoo (seq [_]) (empty [_]))\n;; {}", :_id "5bed6478e4b00ac801ed9efa"}], :macro true, :notes nil, :arglists ["& options"], :doc "When compiling, generates compiled bytecode for an interface with\n the 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 nothing.\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\n optional:\n\n :name aname\n\n The package-qualified name of the class to be generated\n\n :extends [interface ...]\n\n One or more interfaces, which will be extended by this interface.\n\n :methods [ [name [param-types] return-type], ...]\n\n This parameter is used to specify the signatures of the methods of\n the generated interface. Do not repeat superinterface signatures\n here.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/gen-interface"} {:added "1.0", :ns "clojure.core", :name "*command-line-args*", :type "var", :see-alsos nil, :examples [{:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; If you save this program as showargs.clj on a Unix-like system, then the\n;; following command will produce the output shown.\n\n;; % java -classpath clojure-1.2.0.jar clojure.main showargs.clj arg1 2 \"whitespace in most command shells if you quote\"\n;; arg='arg1'\n;; arg='2'\n;; arg='whitespace in most command shells if you quote'\n;; \n;; \n;; Second arg is string 2, not number 2.\n\n(ns com.demo.showargs)\n\n(doseq [arg *command-line-args*]\n (printf \"arg='%s'\\n\" arg))\n\n(if (= \"2\" (second *command-line-args*))\n (println \"\\n\\nSecond arg is string 2, not number 2.\"))\n", :created-at 1298557801000, :updated-at 1298557801000, :_id "542692c8c026201cdc326a6a"}], :notes [{:body "To see which JVM command line parameters were used to start Clojure, execute:\n```\n(into [] (.getInputArguments\n (java.lang.management.ManagementFactory/getRuntimeMXBean)))\n```", :created-at 1647721826905, :updated-at 1647721856269, :author {:avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4", :account-source "github", :login "mars0i"}, :_id "62363d62e4b0b1e3652d75c0"}], :arglists [], :doc "A sequence of the supplied command line arguments, or nil if\n none were supplied", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*command-line-args*"} {:added "1.0", :ns "clojure.core", :name "reverse", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1293103264000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rseq", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521de3"}], :line 947, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (reverse '(1 2 3))\n(3 2 1)\n", :created-at 1280321963000, :updated-at 1285496763000, :_id "542692cbc026201cdc326bf7"} {:updated-at 1568496474720, :created-at 1568496474720, :author {:login "rosineygp", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/5224519?v=4"}, :body "(reverse \"clojure\")\n; (\\e \\r \\u \\j \\o \\l \\c)\n\n(apply str (reverse \"clojure\"))\n; \"erujolc\"", :_id "5d7d5b5ae4b0ca44402ef7b4"} {:updated-at 1613699240347, :created-at 1613699240347, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :body ";; 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\"", :_id "602f18a8e4b0b1e3652d745b"}], :notes [{:updated-at 1293103337000, :body "If you've got a vector rseq is a good option instead of reverse.", :created-at 1293103337000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fb0"} {:body "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. ", :created-at 1613699495793, :updated-at 1613699637662, :author {:avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4", :account-source "github", :login "Crowbrammer"}, :_id "602f19a7e4b0b1e3652d745d"}], :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"} {:added "1.9", :ns "clojure.core", :name "inst?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1495635485203, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "inst-ms", :ns "clojure.core"}, :_id "5925961de4b093ada4d4d720"}], :line 6793, :examples [{:updated-at 1495635467250, :created-at 1495635467250, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body "(inst? (java.util.Date.))\n;;=> true\n(inst? (java.util.Calendar/getInstance))\n;;=> false\n\n(inst? (java.sql.Timestamp. 0))\n;;=> true\n(inst? (java.sql.Date. 0))\n;;=> true\n\n(inst? (java.time.Instant/now))\n;;=> true\n(inst? (java.time.LocalDateTime/now))\n;;=> false", :_id "5925960be4b093ada4d4d71f"}], :notes nil, :arglists ["x"], :doc "Return true if x satisfies Inst", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/inst_q"} {:added "1.0", :ns "clojure.core", :name "range", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1611082428123, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "take", :ns "clojure.core"}, :_id "60072abce4b0b1e3652d743a"} {:created-at 1611082519863, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "iterate", :ns "clojure.core"}, :_id "60072b17e4b0b1e3652d743b"}], :line 3019, :examples [{:author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"} {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:avatar-url "https://avatars1.githubusercontent.com/u/22159831?v=4", :account-source "github", :login "yuxuan813"}], :body ";; 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", :created-at 1279160563000, :updated-at 1523435961458, :_id "542692ccc026201cdc326c77"} {:author {:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; Since clojure 1.2:\n\nuser=> (take 10 (range))\n(0 1 2 3 4 5 6 7 8 9)\n", :created-at 1282319317000, :updated-at 1285494502000, :_id "542692ccc026201cdc326c80"} {:author {:login "rebcabin", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/880b0bb3a4be9237326dd69565444dee?r=PG&default=identicon"}, :editors [], :body ";; 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", :created-at 1374181746000, :updated-at 1374181746000, :_id "542692d4c026201cdc327048"} {:editors [{:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3", :account-source "github", :login "mars0i"}, :created-at 1438100731938, :updated-at 1438101658841, :_id "55b7acfbe4b0080a1b79cdaf"} {:updated-at 1494572384501, :created-at 1494572384501, :author {:login "st-keller", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/476463?v=3"}, :body "user=> (range 0 0)\n()\n\nuser=> (range 0 1)\n(0)", :_id "59155d60e4b01920063ee059"}], :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"} {:added "1.0", :ns "clojure.core", :name "sort", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1285265346000, :author {:login "morphling", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/90ffa70a579c3e0c398b7523ecdc6a87?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "sort-by", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e7c"} {:created-at 1548624421040, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "compare", :ns "clojure.core"}, :_id "5c4e2225e4b0ca44402ef654"}], :line 3102, :examples [{:updated-at 1624481253798, :created-at 1281550866000, :body "user=> (sort [3 1 2 4])\n(1 2 3 4)\n\nuser=> (sort > (vals {:foo 5, :bar 2, :baz 10}))\n(10 5 2)\n\n;; do not do this, use sort-by instead because it handles calling the fn (e.g last) and compare for you.\nuser=> (sort #(compare (last %1) (last %2)) {:b 1 :c 3 :a 2})\n([:b 1] [:a 2] [:c 3])\n\n;; like this:\nuser=> (sort-by last {:b 1 :c 3 :a 2})\n([:b 1] [:a 2] [:c 3])", :editors [{:avatar-url "https://www.gravatar.com/avatar/90ffa70a579c3e0c398b7523ecdc6a87?r=PG&default=identicon", :account-source "clojuredocs", :login "morphling"} {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:login "drewverlee", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1130688?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon", :account-source "clojuredocs", :login "zmila"}, :_id "542692cfc026201cdc326e5b"} {:updated-at 1602514013062, :created-at 1306322169000, :body ";; 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)) (shuffle\n\t\t\t\t (into (range 100 500 100)\n\t\t\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 superior to the lower price and if the price is same, it is \n superior to the lower id.\"\n [el1 el2]\n (or (< (:price el1) (:price el2))\n (and (= (:price el1) (:price el2))(< (:id el1) (:id el2)))))\n\nuser=> data\n({:id 1, :price 300} {:id 6, :price 100} {:id 3, :price 100} {:id 4, :price 400} {:id 0, :price 300} {:id 2, :price 200} {:id 5, :price 200} {:id 8, :price 400})\nuser=> (sort comp-goods-price data)\n({:id 3, :price 100} {:id 6, :price 100} {:id 2, :price 200} {:id 5, :price 200} {:id 0, :price 300} {:id 1, :price 300} {:id 4, :price 400} {:id 8, :price 400})\nuser=> (sort-by :price < data) ; compare this with the above.\n({:id 6, :price 100} {:id 3, :price 100} {:id 2, :price 200} {:id 5, :price 200} {:id 1, :price 300} {:id 0, :price 300} {:id 4, :price 400} {:id 8, :price 400})\n\n\n", :editors [{:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"} {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"} {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"} {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"} {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"}, :_id "542692cfc026201cdc326e5e"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; 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 11]))\n#'user/x\n\nuser=> (seq x)\n(32 11)\n\nuser=> (def y (sort x))\n#'user/y\n\n;; Return sorted sequence\nuser=> y\n(11 32)\n\nuser=> (class y)\nclojure.lang.ArraySeq\n\n;; but also modifies x, because it used the array to do the sorting.\nuser=> (seq x)\n(11 32)\n\n;; One way to avoid this is copying the array before sorting:\nuser=> (def y (sort (aclone x)))\n#'user/y", :created-at 1331771749000, :updated-at 1332833601000, :_id "542692d5c026201cdc32708e"} {:editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}], :body ";; Sorting with > only works for numbers, whereas sort\n;; also works for other types such as vectors.\n;; To sort any data in reverse (descending) order,\n;; use a negated comparator:\n\nuser=> (sort (comp - compare) [[1 0] [0 0] [0 3] [2 1]])\n([2 1] [1 0] [0 3] [0 0])\n\n;; There are subtle cases where negating a comparator can give the wrong sort order.\n;; See this article for details, and a more robust suggestion of reversing the\n;; order of arguments given to the comparator:\n;; https://clojure.org/guides/comparators\n\nuser=> (sort #(compare %2 %1) [[1 0] [0 0] [0 3] [2 1]])\n([2 1] [1 0] [0 3] [0 0])", :author {:avatar-url "https://avatars.githubusercontent.com/u/23474334?v=3", :account-source "github", :login "ferdinand-beyer"}, :created-at 1479202684434, :updated-at 1548624336544, :_id "582ad77ce4b0782b632278c1"} {:updated-at 1483387364837, :created-at 1483387364837, :author {:login "Invertisment", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1641263?v=3"}, :body ";; Reverse the collection\n\nuser=> (sort #(compare %2 %1) '(:a :b :c :d))\n(:d :c :b :a)", :_id "586ab1e4e4b0fd5fb1cc9651"} {:editors [{:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/8271291?v=3"}], :body "(def data [{:v 12, :a 10} {:v 21, :a 113} {:v 1, :a 2} {:v 12, :a 223} {:v 100, :a 23} {:v 1, :a 113}])\n\n(defn multi-comp\n ([fns a b]\n (multi-comp fns < a b))\n ([[f & others :as fns] order a b]\n (if (seq fns)\n (let [result (compare (f a) (f b))\n f-result (if (= order >) (* -1 result) result)]\n (if (= 0 f-result)\n (recur others order a b)\n f-result))\n 0)))\n\n(sort #(multi-comp [:a :v] > %1 %2) data)\n;;=> ({:v 12, :a 223} {:v 21, :a 113} {:v 1, :a 113} {:v 100, :a 23} {:v 12, :a 10} {:v 1, :a 2}) \n\n(sort #(multi-comp [:a :v] < %1 %2) data)\n;;=> ({:v 1, :a 2} {:v 12, :a 10} {:v 100, :a 23} {:v 1, :a 113} {:v 21, :a 113} {:v 12, :a 223})", :author {:avatar-url "https://avatars2.githubusercontent.com/u/8271291?v=3", :account-source "github", :login "ertugrulcetin"}, :created-at 1491607217680, :updated-at 1491607544907, :_id "58e81eb1e4b01f4add58fe88"} {:editors [{:login "malloryerik", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10395849?v=4"}], :body ";; Sort strings into ordered character lists\n\nuser=> (sort \"alphabet!321\") \n(\\! \\1 \\2 \\3 \\a \\a \\b \\e \\h \\l \\p \\t)\n\nuser=> (sort \"안녕하세요\") \n(\\녕 \\세 \\안 \\요 \\하)\n\nuser=> (sort \"花间一壶酒,独酌无相亲。\") \n(\\。 \\一 \\亲 \\壶 \\无 \\独 \\相 \\花 \\酌 \\酒 \\间 \\,)", :author {:avatar-url "https://avatars3.githubusercontent.com/u/10395849?v=4", :account-source "github", :login "malloryerik"}, :created-at 1566135485015, :updated-at 1566176013086, :_id "5d5954bde4b0ca44402ef7a4"}], :notes nil, :arglists ["coll" "comp coll"], :doc "Returns a sorted sequence of the items in coll. 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"} {: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"} {:added "1.0", :ns "clojure.core", :name "unchecked-inc-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1678034683900, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unchecked-dec-int", :ns "clojure.core"}, :_id "6404c6fbe4b08cf8563f4b79"}], :line 1149, :examples [{:updated-at 1658482040938, :created-at 1658482040938, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body "(unchecked-inc-int 42);; => 43\n(unchecked-inc-int 42.8);; => 43\n(unchecked-inc-int Integer/MAX_VALUE);; => -2147483648", :_id "62da6d78e4b0b1e3652d762d"}], :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"} {:added "1.2", :ns "clojure.core", :name "map-indexed", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1290495691000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e3e"} {:created-at 1324314182000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "keep-indexed", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e3f"}], :line 7283, :examples [{:updated-at 1596522358724, :created-at 1280778877000, :body "user=> (map-indexed (fn [idx itm] [idx itm]) \"foobar\")\n([0 \\f] [1 \\o] [2 \\o] [3 \\b] [4 \\a] [5 \\r])\n", :editors [{:avatar-url "https://www.gravatar.com/avatar/4c1869a83a1bf9c5090b07b0db6fb450?r=PG&default=identicon", :account-source "clojuredocs", :login "kredaxx"} {:avatar-url "https://www.gravatar.com/avatar/4c1869a83a1bf9c5090b07b0db6fb450?r=PG&default=identicon", :account-source "clojuredocs", :login "kredaxx"} {:avatar-url "https://www.gravatar.com/avatar/4c1869a83a1bf9c5090b07b0db6fb450?r=PG&default=identicon", :account-source "clojuredocs", :login "kredaxx"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:login "zackteo", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/7510179?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/4c1869a83a1bf9c5090b07b0db6fb450?r=PG&default=identicon", :account-source "clojuredocs", :login "kredaxx"}, :_id "542692cdc026201cdc326d25"} {:author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :editors [], :body ";; or simply\nuser=> (map-indexed vector \"foobar\")\n([0 \\f] [1 \\o] [2 \\o] [3 \\b] [4 \\a] [5 \\r])", :created-at 1324306400000, :updated-at 1324306400000, :_id "542692d4c026201cdc327005"} {:editors [{:login "zackteo", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/7510179?v=4"}], :body "(map-indexed hash-map \"foobar\")\n;;=> ({0 \\f} {1 \\o} {2 \\o} {3 \\b} {4 \\a} {5 \\r})", :author {:avatar-url "https://avatars2.githubusercontent.com/u/2665931?v=4", :account-source "github", :login "freetonik"}, :created-at 1540845475652, :updated-at 1596521745408, :_id "5bd76fa3e4b00ac801ed9eea"} {:editors [{:login "gluer", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/22495106?v=4"}], :body ";; 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\")", :author {:avatar-url "https://avatars3.githubusercontent.com/u/22495106?v=4", :account-source "github", :login "gluer"}, :created-at 1542944994140, :updated-at 1545622964814, :_id "5bf778e2e4b0ca44402ef5ca"} {:updated-at 1596521989649, :created-at 1596521989649, :author {:login "zackteo", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/7510179?v=4"}, :body ";; Join the index and elements with list\n(map-indexed list [:a :b :c])\n;;=> ((0 :a) (1 :b) (2 :c))", :_id "5f28fe05e4b0b1e3652d734c"} {:updated-at 1616528771927, :created-at 1616528756028, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :body "(= (map-indexed #(when (= 2 %2) [%1 \"Hi\"]) [1 1 2 2]) \n '(nil nil [2 \"Hi\"] [3 \"Hi\"])) ;;=>true", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4", :account-source "github", :login "Crowbrammer"}], :_id "605a4574e4b0b1e3652d74a8"}], :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"} {:added "1.1", :ns "clojure.core", :name "with-bindings", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1365637665000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-bindings*", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ade"} {:created-at 1374310477000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-local-vars", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521adf"} {:created-at 1374313569000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "binding", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ae0"} {:created-at 1375792510000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-redefs", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ae1"}], :line 1986, :examples [{:body "(def ^:dynamic x 1)\n;;=> #'user/x\n\nx\n;;=> 1\n\n(with-bindings {#'x 2}\n x)\n;;=> 2", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423525132511, :updated-at 1423525132511, :_id "54d9450ce4b0e2ac61831d40"}], :macro true, :notes nil, :arglists ["binding-map & body"], :doc "Takes a map of Var/value pairs. Installs for the given Vars the associated\n values as thread-local bindings. Then executes body. Pops the installed\n bindings after body was evaluated. Returns the value of body.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/with-bindings"} {:added "1.2", :ns "clojure.core", :name "rand-nth", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1292321208000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rand", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f63"} {:created-at 1434034859003, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:ns "clojure.core", :name "shuffle", :library-url "https://github.com/clojure/clojure"}, :_id "5579a2abe4b01ad59b65f4f1"} {:created-at 1586185491703, :author {:login "green-coder", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "nth", :ns "clojure.core"}, :_id "5e8b4513e4b087629b5a18cc"}], :line 7231, :examples [{:author {:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "XPherior", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/656a48d6bef2a9f034af0e8b2b4d588d?r=PG&default=identicon"}], :body "user=> (def food [:ice-cream :steak :apple])\n#'user/food\n\nuser=> (rand-nth food)\n:apple\nuser=> (rand-nth food)\n:ice-cream\n", :created-at 1282319178000, :updated-at 1352188362000, :_id "542692cec026201cdc326dfe"} {:updated-at 1507688537707, :created-at 1507688537707, :author {:login "parkeristyping", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/9487556?v=4"}, :body "user=> (def food [:ice-cream :steak :apple])\n#'user/food\n\nuser=> (rand-nth food)\n:ice-cream\nuser=> (rand-nth food)\n:ice-cream", :_id "59dd8059e4b03026fe14ea5f"} {:editors [{:login "jnriver", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/2074698?v=4"}], :body "user=> (rand-nth [])\nIndexOutOfBoundsException clojure.lang.PersistentVector.arrayFor (PersistentVector.java:158)\n\nuser=>\n(let [xs []]\n (when (not (empty? xs))\n (rand-nth xs)))\nnil\n", :author {:avatar-url "https://avatars2.githubusercontent.com/u/2074698?v=4", :account-source "github", :login "jnriver"}, :created-at 1527215870505, :updated-at 1527216042499, :_id "5b0776fee4b045c27b7fac79"}], :notes nil, :arglists ["coll"], :doc "Return a random element of the (sequential) collection. Will have\n the same performance characteristics as nth for the given\n collection.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/rand-nth"} {:added "1.0", :ns "clojure.core", :name "comp", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1358904701000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "partial", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ec3"} {:created-at 1358904763000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "juxt", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ec4"} {:created-at 1427713283146, :author {:login "peter-courcoux", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1872022?v=3"}, :to-var {:ns "clojure.core", :name "every-pred", :library-url "https://github.com/clojure/clojure"}, :_id "55192d03e4b056ca16cfecfc"}], :line 2557, :examples [{:author {:login "citizen428", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3881a28fe402dd2d1de44717486cae8?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(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", :created-at 1280554862000, :updated-at 1420648866563, :_id "542692cbc026201cdc326c04"} {:updated-at 1486787503828, :created-at 1292499977000, :body "((comp str +) 8 8 8) \n;;=> \"24\"\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "bsifou", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8908139?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/e8a89e26df41f3dd921ff1de2afa4db7?r=PG&default=identicon", :account-source "clojuredocs", :login "zpinter"}, :_id "542692cbc026201cdc326c06"} {:author {:login "semperos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/edeae8e7534b3d554e4ec2c35ffc68d?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(map\n (comp - (partial + 3) (partial * 2))\n [1 2 3 4])\n;;=> (-5 -7 -9 -11)", :created-at 1296193214000, :updated-at 1420649045506, :_id "542692cbc026201cdc326c07"} {:updated-at 1420649083250, :created-at 1305843170000, :body "(filter (comp not zero?) [0 1 0 2 0 3 0 4])\n;;=> (1 2 3 4)", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"}], :author {:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"}, :_id "542692cbc026201cdc326c08"} {:author {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}, :editors [{:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"} {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"} {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"} {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"} {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; 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", :created-at 1306322829000, :updated-at 1420650298514, :_id "542692cbc026201cdc326c09"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(def countif (comp count filter))\n#'user/countif\n\n(countif even? [2 3 1 5 4])\n;;=> 2", :created-at 1313975540000, :updated-at 1420649227225, :_id "542692cbc026201cdc326c0f"} {:author {:login "Will", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a449004e52cfddd142e63a1d317b191d?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "; Get 2nd to last element from a list\n( (comp second reverse) '(\"a\" 2 7 \"b\")) \n;;=> 7", :created-at 1344506218000, :updated-at 1420649237526, :_id "542692d2c026201cdc326f64"} {:updated-at 1449761968315, :created-at 1449761968315, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :body "; 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", :_id "56699cb0e4b09a2675a0ba72"} {:updated-at 1536867551060, :created-at 1486454398076, :author {:login "purukaushik", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5105099?v=3"}, :body "; `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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/5105099?v=3", :account-source "github", :login "purukaushik"} {:login "Jjunior130", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/7597818?v=4"}], :_id "58997e7ee4b01f4add58fe3d"} {:updated-at 1486787324018, :created-at 1486787324018, :author {:login "bsifou", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8908139?v=3"}, :body "; Split a number into sequence of it's digits\n((comp (partial map (comp read-string str)) str) 33)\n;;=> (3 3)", :_id "589e92fce4b01f4add58fe46"} {:updated-at 1497863678341, :created-at 1497863678341, :author {:login "merliecat", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/27359194?v=3"}, :body ";; 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\"", :_id "594795fee4b06e730307db3a"} {:updated-at 1508821937862, :created-at 1508821937862, :author {:login "elect000", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/18697629?v=4"}, :body ";; ((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", :_id "59eecbb1e4b0a08026c48c73"} {:updated-at 1510097526774, :created-at 1510097526774, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}, :body ";; 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", :_id "5a024276e4b0a08026c48c9b"} {:updated-at 1517927616519, :created-at 1517927616519, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;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", :_id "5a79bcc0e4b0e2d9c35f7419"} {:updated-at 1517928532967, :created-at 1517928532967, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body "(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", :_id "5a79c054e4b0e2d9c35f741a"} {:editors [{:login "Jjunior130", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/7597818?v=4"}], :body "(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]])", :author {:avatar-url "https://avatars1.githubusercontent.com/u/7597818?v=4", :account-source "github", :login "Jjunior130"}, :created-at 1536856092993, :updated-at 1536879826363, :_id "5b9a901ce4b00ac801ed9e9c"} {:editors [{:login "luontola", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/42678?v=4"}], :body "; 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", :author {:avatar-url "https://avatars0.githubusercontent.com/u/42678?v=4", :account-source "github", :login "luontola"}, :created-at 1552650253291, :updated-at 1552650469262, :_id "5c8b900de4b0ca44402ef6b6"} {:updated-at 1615715410336, :created-at 1615715410336, :author {:login "nbardiuk", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/381992?v=4"}, :body "; Without arguments returns identity function\n\n(identical? (comp) identity)\n;;=> true\n\n((comp) :arg)\n;;=> :arg", :_id "604ddc52e4b0b1e3652d748f"}], :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"} {:added "1.0", :ns "clojure.core", :name "await", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1298860359000, :author {:login "ninjudd", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7ced25585a7556e9b9b975c1f9e136e3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "await-for", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a8a"}], :line 3274, :examples [{:updated-at 1435096085344, :created-at 1283693589000, :body ";; 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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/1453?v=4", :account-source "github", :login "ghoseb"}, :_id "542692cdc026201cdc326cdb"} {:body "(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", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :created-at 1435098875036, :updated-at 1435102514521, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :_id "5589defbe4b05f167dcf2341"}], :notes [{:author {:login "andrewni420", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/77020120?v=4"}, :updated-at 1690255271897, :created-at 1690255271897, :body " ;;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 ", :_id "64bf3fa7e4b08cf8563f4bd6"}], :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"} {:added "1.2", :ns "clojure.core", :name "spit", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1330170569000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "slurp", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e97"} {:created-at 1330170573000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.java.io", :name "writer", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e98"} {:created-at 1350073135000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "load-file", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e99"} {:created-at 1515622120441, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "make-parents", :ns "clojure.java.io"}, :_id "5a568ee8e4b0a08026c48cec"}], :line 6954, :examples [{:author {:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}], :body "user=> (spit \"flubber.txt\" \"test\")\nnil\nuser=> (slurp \"flubber.txt\")\n\"test\"", :created-at 1280458792000, :updated-at 1366325983000, :_id "542692c7c026201cdc326972"} {:author {:login "megapatch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9a9b25017146e62801acc97861d74c4e?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "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", :created-at 1283972766000, :updated-at 1285487376000, :_id "542692c7c026201cdc326975"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "Juxtaspiral", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1b0546af898df8046160d0ed80e13165?r=PG&default=identicon"}], :body "(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))", :created-at 1334796093000, :updated-at 1348351258000, :_id "542692d5c026201cdc32709b"} {:updated-at 1510413046445, :created-at 1510413046445, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;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\"))", :_id "5a0712f6e4b0a08026c48cb0"} {:updated-at 1543709529631, :created-at 1543709529631, :author {:login "messinm", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1719572?v=4"}, :body "; ClojureCLR doesn't use :append, use this instead\n(spit \"hi.txt\" \"Test 1\\n\" :file-mode System.IO.FileMode/Append)\n", :_id "5c032359e4b0ca44402ef5d5"}], :notes [{:author {:login "flyboarder", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147004?v=3"}, :updated-at 1469398101037, :created-at 1469398101037, :body "The only valid options for `spit` are `:append` and `:encoding`.", :_id "57953c55e4b0bafd3e2a04b6"} {:author {:login "didibus", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/601540?v=4"}, :updated-at 1585180895729, :created-at 1585180895729, :body "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\\\".", :_id "5e7bf0dfe4b087629b5a18c2"}], :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"} {:added "1.1", :ns "clojure.core", :name "future-done?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1297120552000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "future", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521df0"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "future-cancel", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1339251476000, :_id "542692ebf6e94c6970521df1"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "future?", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1339252213000, :_id "542692ebf6e94c6970521df2"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "future-cancelled?", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1339252225000, :_id "542692ebf6e94c6970521df3"}], :line 6536, :examples [{:updated-at 1339251719000, :created-at 1339251719000, :body "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", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :_id "542692d3c026201cdc326fb7"} {:updated-at 1339252193000, :created-at 1339252193000, :body ";; 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)", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :_id "542692d3c026201cdc326fb8"} {:updated-at 1669054840067, :created-at 1668769697257, :author {:login "sundaramss", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1131710?v=4"}, :body ";; removed unhelpful example", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/1131710?v=4", :account-source "github", :login "sundaramss"} {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :_id "637767a1e4b0b1e3652d7686"}], :notes [{:updated-at 1300164452000, :body "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()", :created-at 1300164452000, :author {:login "pauldoo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5cb916d3c8abc9f45a093209e72489fb?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fb8"}], :arglists ["f"], :doc "Returns true if future f is done", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/future-done_q"} {:added "1.0", :ns "clojure.core", :name "*read-eval*", :type "var", :see-alsos [{:created-at 1352963695000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "read", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d50"} {:created-at 1352963701000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "read-string", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d51"} {:created-at 1352963704000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "load", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d52"}], :examples [{:author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :editors [{:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}], :body ";;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", :created-at 1327090750000, :updated-at 1327090760000, :_id "542692d1c026201cdc326f3a"}], :notes [{:body "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```", :created-at 1627197824169, :updated-at 1627198605717, :author {:avatar-url "https://avatars.githubusercontent.com/u/601540?v=4", :account-source "github", :login "didibus"}, :_id "60fd1180e4b0b1e3652d751d"}], :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*"} {:added "1.0", :ns "clojure.core", :name "dorun", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1296708499000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "doall", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d8c"} {:created-at 1520117044268, :author {:login "finalfantasia", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/2316604?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "doseq", :ns "clojure.core"}, :_id "5a9b2534e4b0316c0f44f908"} {:created-at 1520117066852, :author {:login "finalfantasia", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/2316604?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "run!", :ns "clojure.core"}, :_id "5a9b254ae4b0316c0f44f909"}], :line 3133, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "fyquah95", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6006469?v=3"}], :body "user=> (dorun 5 (repeatedly #(println \"hi\")))\nhi\nhi\nhi\nhi\nhi\nhi\nnil", :created-at 1281092803000, :updated-at 1434450783133, :_id "542692c6c026201cdc326907"} {:updated-at 1335431834000, :created-at 1335431834000, :body "user=> (let [x (atom 0)]\n (dorun (take 10 (repeatedly #(swap! x inc))))\n @x)\n10", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d2c026201cdc326f8e"} {:author {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"}, :editors [{:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"} {:login "orivej", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cab90c7de5efde92a29f1eacb603ba9a?r=PG&default=identicon"} {:login "orivej", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cab90c7de5efde92a29f1eacb603ba9a?r=PG&default=identicon"}], :body "user=> (dorun (map #(println \"hi\" %) [\"mum\" \"dad\" \"sister\"]))\nhi mum\nhi dad\nhi sister\nnil", :created-at 1343166324000, :updated-at 1362554649000, :_id "542692d2c026201cdc326f8f"} {:updated-at 1436247797064, :created-at 1436247797064, :author {:login "gdeer81", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1340575?v=3"}, :body ";;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", :_id "559b66f5e4b00f9508fd66f6"}], :notes [{:author {:login "finalfantasia", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/2316604?v=4"}, :updated-at 1520197531487, :created-at 1520115866563, :body "`clojure.core/run!` can take the place of `(dorun (map ...))`.", :_id "5a9b209ae4b0316c0f44f907"}], :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"} {:added "1.9", :ns "clojure.core", :name "simple-symbol?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1495715090890, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "symbol?", :ns "clojure.core"}, :_id "5926cd12e4b093ada4d4d75d"} {:created-at 1495715101981, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "qualified-symbol?", :ns "clojure.core"}, :_id "5926cd1de4b093ada4d4d75e"}], :line 1627, :examples [{:updated-at 1495723255240, :created-at 1495723255240, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body "(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", :_id "5926ecf7e4b093ada4d4d76a"}], :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"} {:added "1.0", :ns "clojure.core", :name "disj", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1351063996000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "dissoc", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e31"} {:created-at 1351064021000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "disj!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e32"} {:created-at 1405367718000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.set", :name "difference", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e33"} {:created-at 1561679596230, :author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "conj", :ns "clojure.core"}, :_id "5d1556ece4b0ca44402ef777"}], :line 1518, :examples [{:updated-at 1462050216483, :created-at 1280340321000, :body "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}", :editors [{:avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon", :account-source "clojuredocs", :login "zmila"} {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon", :account-source "clojuredocs", :login "zmila"}, :_id "542692cec026201cdc326dc6"} {:editors [{:login "Hamido-san", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/27916344?v=4"}], :body "user=> (apply disj #{1 2 3} [1 3]) ; disjoin keys in a coll\n#{2}", :author {:avatar-url "https://avatars2.githubusercontent.com/u/5283430?v=4", :account-source "github", :login "randomizedthinking"}, :created-at 1602141980639, :updated-at 1620639101734, :_id "5f7ebf1ce4b0b1e3652d73ce"}], :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"} {:added "1.0", :ns "clojure.core", :name "*2", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [{:created-at 1303109714000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "*1", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ad4"} {:created-at 1303109726000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "*3", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ad5"}], :dynamic true, :line 6284, :examples [{:updated-at 1285502123000, :created-at 1279048024000, :body "user=> \"Hello!\"\n\"Hello!\"\n\nuser=> \"Hello World!\"\n\"Hello World!\"\n\nuser=> [*1 *2]\n[\"Hello World!\" \"Hello!\"]\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :_id "542692c7c026201cdc326960"}], :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"} {:added "1.0", :ns "clojure.core", :name "eval", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1318930260000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "read-string", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ea3"}], :line 3210, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "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", :created-at 1280547525000, :updated-at 1332949962000, :_id "542692cec026201cdc326daf"} {:author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :editors [], :body "user=> (eval '(let [a 10] (+ 3 4 a)))\n17\n", :created-at 1308973342000, :updated-at 1308973342000, :_id "542692cec026201cdc326db1"} {:updated-at 1458054160560, :created-at 1458054160560, :author {:login "APOS80", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6387252?v=3"}, :body "(def x '(+ 2 3))\n(println x) \n=> (+ 2 3)\n(println (eval x))\n=> 5", :_id "56e82410e4b0507458dcf5a7"}], :notes [{:updated-at 1308973573000, :body "In normal code, `eval` is rarely used.", :created-at 1308973573000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fc2"} {:author {:login "eengebruiker", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/31795546?v=4"}, :updated-at 1521045003085, :created-at 1521045003085, :body "Once you get used to eval you will use it more often. You can make nifty things with it.", :_id "5aa94e0be4b0316c0f44f924"}], :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"} {:added "1.0", :ns "clojure.core", :name "cons", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1297212928000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "conj", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d54"} {:created-at 1617817312569, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "seq", :ns "clojure.core"}, :_id "606deee0e4b0b1e3652d74b4"}], :line 22, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"} {:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; 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)", :created-at 1279071078000, :updated-at 1420651535055, :_id "542692ccc026201cdc326c5b"} {:body ";; 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", :author {:login "phalphalak", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/438136?v=3"}, :created-at 1425547438764, :updated-at 1425547666700, :editors [{:login "phalphalak", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/438136?v=3"}], :_id "54f820aee4b0b716de7a6530"} {:editors [{:login "TheCodingGent", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1191123?v=3"}], :body ";; 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\"})}", :author {:avatar-url "https://avatars.githubusercontent.com/u/782909?v=3", :account-source "github", :login "edcaceres"}, :created-at 1479822182560, :updated-at 1483975426262, :_id "58344b66e4b0782b632278c4"} {:updated-at 1486154226776, :created-at 1486154226776, :author {:login "belun", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/282287?v=3"}, :body "(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", :_id "5894e9f2e4b01f4add58fe3b"} {:editors [{:login "earthfail", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/21296448?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars2.githubusercontent.com/u/3019924?v=4", :account-source "github", :login "didiercrunch"}, :created-at 1527347046020, :updated-at 1621162590490, :_id "5b097766e4b045c27b7fac7b"}], :notes [{:body "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", :created-at 1486153640658, :updated-at 1486153936827, :author {:avatar-url "https://avatars.githubusercontent.com/u/282287?v=3", :account-source "github", :login "belun"}, :_id "5894e7a8e4b01f4add58fe3a"}], :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"} {:added "1.0", :ns "clojure.core", :name "refer", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1327515389000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "refer-clojure", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f2c"} {:created-at 1351990184000, :author {:login "Mark Addleman", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/768de71b6c873394290733acf422b4d5?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ns", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f2d"}], :line 4217, :examples [{:author {:login "teyc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bd6e62afb4881ab0f617611b8b65d003?r=PG&default=identicon"}, :editors [{:login "teyc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bd6e62afb4881ab0f617611b8b65d003?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}], :body "user=> (refer 'clojure.string :only '[capitalize trim])\nnil\n\nuser=> (capitalize (trim \" hOnduRAS \"))\n\"Honduras\"", :created-at 1283925242000, :updated-at 1321967031000, :_id "542692cdc026201cdc326d0b"} {:author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :editors [{:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}], :body "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\"", :created-at 1399370253000, :updated-at 1399636313000, :_id "542692d5c026201cdc32706a"} {:author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :editors [{:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"} {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}], :body ";;; `: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)", :created-at 1399370354000, :updated-at 1399662756000, :_id "542692d5c026201cdc32706c"}], :notes [{:author {:login "KingMob", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/946421?v=4"}, :updated-at 1671686270847, :created-at 1671686270847, :body "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.", :_id "63a3e87ee4b08cf8563f4b54"}], :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"} {:ns "clojure.core", :name "print-dup", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [{:created-at 1300959285000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "print-ctor", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e2a"} {:created-at 1332539534000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "print-method", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e2b"}], :line 3666, :examples [{:author {:login "cdorrat", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5dedcb7069d39421760f6d255def10c3?r=PG&default=identicon"}, :editors [{:login "cdorrat", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5dedcb7069d39421760f6d255def10c3?r=PG&default=identicon"}], :body ";; 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)))", :created-at 1300104716000, :updated-at 1300104999000, :_id "542692cac026201cdc326b8c"} {:author {:login "cdorrat", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5dedcb7069d39421760f6d255def10c3?r=PG&default=identicon"}, :editors [], :body ";; 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)) ", :created-at 1300104973000, :updated-at 1300104973000, :_id "542692cac026201cdc326b8e"}], :notes [{:updated-at 1300480179000, :body "This is a multimethod that can be implemented to define the printing of various values when \\*print-dup\\* is bound to true.", :created-at 1299414938000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fb7"}], :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/print-dup"} {:ns "clojure.core", :name "-reset-methods", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos nil, :line 628, :examples nil, :notes nil, :arglists ["protocol"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/-reset-methods"} {:added "1.0", :ns "clojure.core", :name "floats", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1658139428172, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "float-array", :ns "clojure.core"}, :_id "62d53324e4b0b1e3652d7624"}], :line 5368, :examples [{:updated-at 1658139411698, :created-at 1658139411698, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; 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\"", :_id "62d53313e4b0b1e3652d7623"} {:updated-at 1682271661910, :created-at 1682271661910, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; 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", :_id "64456dade4b08cf8563f4b93"}], :notes nil, :arglists ["xs"], :doc "Casts to float[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/floats"} {:added "1.0", :ns "clojure.core", :name "pos?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1345518606000, :author {:login "cbare", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b394e97f24f3576861239e2b839703a4?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "neg?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e09"} {:created-at 1400618875000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "zero?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e0a"} {:created-at 1587669222475, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "nat-int?", :ns "clojure.core"}, :_id "5ea1e8e6e4b087629b5a18e1"} {:created-at 1609194007084, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "pos-int?", :ns "clojure.core"}, :_id "5fea5a17e4b0b1e3652d7424"}], :line 1247, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/7412474?v=3", :account-source "github", :login "Lacty"}], :body "user=> (pos? 1)\ntrue\nuser=> (pos? 0)\nfalse\nuser=> (pos? -1)\nfalse", :created-at 1279074734000, :updated-at 1471000907146, :_id "542692cdc026201cdc326cff"} {:updated-at 1471000959608, :created-at 1471000959608, :author {:login "Lacty", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7412474?v=3"}, :body "user=> (pos? 0.1)\ntrue\nuser=> (pos? -0.1)\nfalse", :_id "57adb17fe4b0bafd3e2a04ec"} {:updated-at 1598394302046, :created-at 1598394302046, :author {:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}, :body "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", :_id "5f458fbee4b0b1e3652d73ab"}], :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"} {:added "1.2", :ns "clojure.core", :name "fnil", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1548717313952, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "partial", :ns "clojure.core"}, :_id "5c4f8d01e4b0ca44402ef656"} {:created-at 1548717329309, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "comp", :ns "clojure.core"}, :_id "5c4f8d11e4b0ca44402ef657"} {:created-at 1548717337353, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "juxt", :ns "clojure.core"}, :_id "5c4f8d19e4b0ca44402ef658"} {:created-at 1608656139520, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "or", :ns "clojure.core"}, :_id "5fe2250be4b0b1e3652d741a"} {:created-at 1609357960896, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "some-fn", :ns "clojure.core"}, :_id "5fecda88e4b0b1e3652d7426"}], :line 6556, :examples [{:author {:login "looselytyped", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9bfc2e772db334c8b8516c86b9da7a0c?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}], :body ";; a function that expects a non-nil value\n(defn say-hello [name] (str \"Hello \" name))\n;;=> #'user/say-hello\n\n;; fnil lets you create another function with a default\n;; arg in case it is passed a nil\n(def say-hello-with-defaults (fnil say-hello \"World\"))\n;;=> #'user/say-hello-with-defaults\n\n;; the happy path works as you would expect\n(say-hello-with-defaults \"Sir\")\n;;=> \"Hello Sir\"\n\n;; but in the case that the function is passed a nil it will use the \n;; default supplied to fnil\n(say-hello-with-defaults nil)\n;;=> \"Hello World\"\n\n;; this works with different arities too\n(defn say-hello [first other] (str \"Hello \" first \" and \" other))\n;;=> #'user/say-hello\n\n;; lets create it with defaults\n(def say-hello-with-defaults (fnil say-hello \"World\" \"People\"))\n;;=> #'user/say-hello-with-defaults\n\n;; call the function with all nil args - notice it uses the defaults\n;; supplied to fnil\n(say-hello-with-defaults nil nil)\n;;=> \"Hello World and People\"\n\n;; any of the args can be nil - the function will supply \n;; the default supplied with fnil\n(say-hello-with-defaults \"Sir\" nil)\n;;=> \"Hello Sir and People\"\n\n;; and again - notice that \"World\" is the default here\n(say-hello-with-defaults nil \"Ma'am\")\n;;=> \"Hello World and Ma'am\"\n\n;; or pass all args \n(say-hello-with-defaults \"Sir\" \"Ma'am\")\n;;=> \"Hello Sir and Ma'am\"\n", :created-at 1284845008000, :updated-at 1412880276286, :_id "542692cdc026201cdc326ce4"} {:body ";; Treat nil as 0 for the purposes of incrementing\n((fnil inc 0) nil)\n;;=> 1\n;; While the following would not work:\n(inc nil)\n;;=> NullPointerException clojure.lang.Numbers.ops (Numbers.java:961)\n\n;; fnil is very useful for specifying default values when updating maps\n;; For a map containing counters of keys:\n(update-in {:a 1} [:a] inc)\n;;=> {:a 2}\n\n;; Oops, our map does not have a key :b and update-in passes nil to inc\n(update-in {:a 1} [:b] inc)\n;;=> NullPointerException clojure.lang.Numbers.ops (Numbers.java:961)\n\n;; But if we use fnil it works:\n(update-in {:a 1} [:b] (fnil inc 0))\n;;=> {:b 1, :a 1}\n\n;; Another example is when map values are collections and we don't want\n;; default behavior of conj with nil that produces a list\n(conj nil 1)\n;;=> (1)\n;; I.e.\n(update-in {} [:a] conj 1)\n;;=> {:a (1)}\n\n;; But say we want map values to be vectors instead:\n(update-in {} [:a] (fnil conj []) 1)\n;;=> {:a [1]}", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1422935102507, :updated-at 1422935102507, :_id "54d0443ee4b0e2ac61831cf7"} {:editors [{:login "KyleErhabor", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/40676441?v=4"}], :body ";;; Note that `fnil` still requires the appropriate number of arguments for an\n;;; arity (i.e. no \"implicit\" default)\n\n(def tempids {-1 1\n -2 2\n -3 3})\n\n(def id (fnil get nil -1))\n\n;; You may expect `fnil` to implicitly add -1 as the last argument, but that's\n;; not true.\n(id tempids)\n;;=> ArityException: Wrong number of args (1) passed to: clojure.core/fnil/fn--...\n\n;; But it will here, since the argument is there (as `nil`).\n(id tempids nil)\n;;=> 1\n\n;; Of course, you can supply it explicitly.\n(id tempids -1)\n;;=> 1", :author {:avatar-url "https://avatars.githubusercontent.com/u/40676441?v=4", :account-source "github", :login "KyleErhabor"}, :created-at 1642980269186, :updated-at 1642980293301, :_id "61ede3ade4b0b1e3652d75a1"}], :notes nil, :arglists ["f x" "f x y" "f x y z"], :doc "Takes a function f, and returns a function that calls f, replacing\n a nil first argument to f with the supplied value x. Higher arity\n versions can replace arguments in the second and third\n positions (y, z). Note that the function f can take any number of\n arguments, not just the one(s) being nil-patched.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/fnil"} {:added "1.0", :ns "clojure.core", :name "merge-with", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1294676734000, :author {:login "Nebulus", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/61aa4140c24b0cded6b20d88200e7f16?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "merge", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e16"}], :line 3051, :examples [{:author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :editors [{:login "nipra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/142529?v=3"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/39192?v=3", :account-source "github", :login "mlanza"}], :body "(merge-with into\n\t {\"Lisp\" [\"Common Lisp\" \"Clojure\"]\n\t \"ML\" [\"Caml\" \"Objective Caml\"]}\n\t {\"Lisp\" [\"Scheme\"]\n\t \"ML\" [\"Standard ML\"]})\n;;=> {\"Lisp\" [\"Common Lisp\" \"Clojure\" \"Scheme\"], \"ML\" [\"Caml\" \"Objective Caml\" \"Standard ML\"]}", :created-at 1279052705000, :updated-at 1495768299408, :_id "542692cec026201cdc326dce"} {:author {:login "fogus", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5aa24eee4238e1e964210ed447e8dc91?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; merge two maps using the addition function\n\n(merge-with + \n {:a 1 :b 2}\n {:a 9 :b 98 :c 0}) \n;;=> {:c 0, :a 10, :b 100}", :created-at 1279058935000, :updated-at 1422375185880, :_id "542692cec026201cdc326dd1"} {:updated-at 1422375228363, :created-at 1279059124000, :body ";; 'merge-with' works with an arbitrary number of maps:\n\n(merge-with + \n {:a 1 :b 2}\n {:a 9 :b 98 :c 0}\n {:a 10 :b 100 :c 10}\n {:a 5}\n {:c 5 :d 42})\n \n;;=> {:d 42, :c 15, :a 25, :b 200}", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"} {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"} {:avatar-url "https://www.gravatar.com/avatar/5aa24eee4238e1e964210ed447e8dc91?r=PG&default=identicon", :account-source "clojuredocs", :login "fogus"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"}], :author {:avatar-url "https://www.gravatar.com/avatar/5aa24eee4238e1e964210ed447e8dc91?r=PG&default=identicon", :account-source "clojuredocs", :login "fogus"}, :_id "542692cec026201cdc326dd3"} {:author {:login "jaley", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d8dc27aff613e5972bb6af8521a07891?r=PG&default=identicon"}, :editors [{:login "Iceland_jack", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c889e0a95a3bb07f90ab28ad442f1127?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; Use union to merge sets of elements\n(use 'clojure.set)\n(merge-with union\n {:a #{1 2 3}, :b #{4 5 6}}\n {:a #{2 3 7 8}, :c #{1 2 3}})\n\n;;=> {:c #{1 2 3}, :a #{1 2 3 7 8}, :b #{4 5 6}}", :created-at 1325882151000, :updated-at 1422375252797, :_id "542692d4c026201cdc32700f"} {:body ";; Demonstrating difference between merge and merge-with\n\n;; For merge the value from the right-most map wins:\n(merge {:a 1} {:a 2} {:a 3})\n;;=> {:a 3}\n\n;; while for merge-with values are merged (with function + in this example):\n(merge-with + {:a 1} {:a 2} {:a 3})\n;;=> {:a 6}", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1422935798019, :updated-at 1423014440333, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :_id "54d046f6e4b0e2ac61831cf8"} {:body ";; Use merge-with and merge to merge values that are one level deep maps.\n\n(merge-with merge {:x {:y 1}} {:x {:z 2}})\n;;=> {:x {:z 2, :y 1}}\n\n;; Deeper maps are not merged:\n(merge-with merge {:x {:y {:a 1}}} {:x {:y {:b 2}}})\n;;=>{:x {:y {:b 2}}}", :author {:login "dmos62", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2715476?v=3"}, :created-at 1427644396920, :updated-at 1427644529515, :editors [{:login "dmos62", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2715476?v=3"}], :_id "55181fece4b08eb9aa0a8d3c"} {:updated-at 1448314167339, :created-at 1448313757814, :author {:login "mlanza", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/39192?v=3"}, :body ";;Use into to avoid losing the shape (i.e. a vector) of the original data:\n(merge-with into\n\t {\"Lisp\" [\"Common Lisp\" \"Clojure\"]\n\t \"ML\" [\"Caml\" \"Objective Caml\"]}\n\t {\"Lisp\" [\"Scheme\"]\n\t \"ML\" [\"Standard ML\"]})\n;;=> {\"Lisp\" [\"Common Lisp\" \"Clojure\" \"Scheme\"], \"ML\" [\"Caml\" \"Objective Caml\" \"Standard ML\"]}\n\n;;No need to use type-specific verbs such as union:\n(merge-with into\n {:a #{1 2 3}, :b #{4 5 6}}\n {:a #{2 3 7 8}, :c #{1 2 3}})\n;;=> {:c #{1 2 3}, :a #{1 2 3 7 8}, :b #{4 5 6}}", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/39192?v=3", :account-source "github", :login "mlanza"}], :_id "5653839de4b0be225c0c4799"} {:editors [{:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}], :body ";; Note that merge-with is fundamentally additive, which can have unintuitive\n;; consequences if you are using a subtractive operation.\n(require '[clojure.set :as set])\n\n;; Subtract members of one set from another with the same keys:\n\n(merge-with set/difference {:a #{1 2 3}} {:a #{1}})\n;;=> {:a #{3 2}}\n\n(merge-with set/difference {:a #{1 2 3} :b #{2}} {:a #{1} :b #{4}})\n;;=> {:a #{3 2}, :b #{2}}\n\n;; If a key in the second map doesn't occur in the first, (merge-with) will \n;; simply copy it as in (merge), and the passed-in function will not be called:\n\n(merge-with set/difference {:a #{1 2 3}} {:a #{1} :z #{4}})\n;;=> {:a #{3 2}, :z #{4}}\n\n;; The solution in this case is to ensure that both maps have the same keys:\n\n(merge-with set/difference {:a #{1 2 3} :z #{}} {:a #{1} :z #{4}})\n;;=> {:a #{3 2}, :z #{}}", :author {:avatar-url "https://avatars.githubusercontent.com/u/94482?v=3", :account-source "github", :login "timgilbert"}, :created-at 1488321014610, :updated-at 1488321184789, :_id "58b5f9f6e4b01f4add58fe67"} {:updated-at 1535151143457, :created-at 1535149114035, :author {:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4"}, :body "(defn deep-merge-with\n \"Like merge-with, but merges maps recursively, applying the given fn\n only when there's a non-map at a particular level.\n (deep-merge-with + {:a {:b {:c 1 :d {:x 1 :y 2}} :e 3} :f 4}\n {:a {:b {:c 2 :d {:z 9} :z 3} :e 100}})\n -> {:a {:b {:z 3, :c 3, :d {:z 9, :x 1, :y 2}}, :e 103}, :f 4}\"\n [f & maps]\n (apply\n (fn m [& maps]\n (if (every? map? maps)\n (apply merge-with m maps)\n (apply f maps)))\nmaps))\n\n(deep-merge-with + {:a {:b {:c 1 :d {:x 1 :y 2}} :e 3} :f 4}\n {:a {:b {:c 2 :d {:z 9} :z 3} :e 100}})\n;; {:a {:b {:z 3, :c 3, :d {:z 9, :x 1, :y 2}}, :e 103}, :f 4}\n\n(deep-merge-with + {:foo {:bar {:baz 1}}}\n {:foo {:bar {:baz 6 :qux 42}}})\n;; {:foo {:bar {:baz 7, :qux 42}}}\n\n;; Source: https://clojure.github.io/clojure-contrib/map-utils-api.html#clojure.contrib.map-utils/deep-merge-with", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4", :account-source "github", :login "dijonkitchen"}], :_id "5b80843ae4b00ac801ed9e74"} {:updated-at 1590172835865, :created-at 1590172728020, :author {:login "themustafabasit", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/24441401?v=4"}, :body "\n;; I will be explaining it From java perspective\n\n;; merge-with is like conflict resolver function that \n;; we have in java - map.merge(key, val, (v1, v2)-> ...... )\n\n;; resolve conflict by discarding second value\n(defn conflict-resolver\n [v1 v2]\n (println \"conflict is between these values: \" v1 v2 ) \n v1)\n\n(merge-with conflict-resolver\n {:a 2 :b 4 :c 5}\n {:a 1}\n {:a 9 :b 3 :c 10 :d 3})\n;; => conflict is between these values: 2 1 - a,a\n;; conflict is between these values: 2 9 - new a, a\n;; conflict is between these values: 4 3 - b,b\n;; conflict is between these values: 5 10 - c,c\n;; {:a 2, :b 4, :c 5, :d 3}\n\n\n;; example - 2\n\n;; resolve conflict by adding both values\n(defn conflict-resolver\n [v1 v2]\n (println \"conflict is between these values: \" v1 v2)\n (+ v1 v2))\n\n(merge-with conflict-resolver\n {:a 2 :b 4 :c 5}\n {:a 1}\n {:a 9 :b 3 :c 10 :d 3})\n;; => conflict is between these values: 2 1 - a,a\n;; conflict is between these values: 3 9 - new a, a\n;; conflict is between these values: 4 3 - b,b\n;; conflict is between these values: 5 10 - c,c\n;; {:a 12, :b 7, :c 15, :d 3}\n\n", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/24441401?v=4", :account-source "github", :login "themustafabasit"}], :_id "5ec81c38e4b087629b5a1912"} {:updated-at 1637867197307, :created-at 1637867197307, :author {:login "joshuamzm", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10285345?v=4"}, :body ";; deep-merge version of clojure.core/merge\n\n(defn deep-merge [& maps]\n (letfn [(reconcile-keys [val-in-result val-in-latter]\n (if (and (map? val-in-result)\n (map? val-in-latter))\n (merge-with reconcile-keys val-in-result val-in-latter)\n val-in-latter))\n (reconcile-maps [result latter]\n (merge-with reconcile-keys result latter))]\n (reduce reconcile-maps maps)))\n\n(deep-merge\n {:a 1 :b {:c {:g 99} :d 3}}\n {:a 10 :b {:c {:g 98} :e 4}}\n {:a 100 :b {:c {:g 97} :e 40 :f 5}})\n\n;; => {:a 100, :b {:c {:g 97}, :d 3, :e 40, :f 5}}\n\n;; Take into account processing latter maps with non-maps values \"override\"\n;; previously seen map values.\n\n(deep-merge\n {:deep {:deeep {:a 1}}}\n {:deep {:deeep {:b 2}}}\n {:a 34 :deep 8 :v 3})\n\n;; => {:deep 8, :a 34, :v 3}\n\n;; We decided to define reconcile-maps, which is the then-branch expression\n;; of the if within reconcile-keys. This way, using reduce will throw errors\n;; as when using merge-with with non-map arguments.\n\n(deep-merge 1 {:a 1})\n\n;; IllegalArgumentException contains? not supported on type: java.lang.Long ...\n\n(deep-merge {:a 1} 2)\n\n;; IllegalArgumentException Don't know how to create ISeq from: java.lang.Long ...\n\n\n\n;; Reviewed and help received from github.com/datz", :_id "619fdebde4b0b1e3652d757a"}], :notes nil, :arglists ["f & 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(s)\n from the latter (left-to-right) will be combined with the mapping in\n the result by calling (f val-in-result val-in-latter).", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/merge-with"} {:added "1.3", :ns "clojure.core", :name "nthrest", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1356088808000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "drop", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ddb"} {:created-at 1356088885000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "nthnext", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ddc"} {:created-at 1356088888000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "nth", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ddd"} {:created-at 1505013505146, :author {:login "didibus", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/601540?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "rest", :ns "clojure.core"}, :_id "59b4af01e4b09f63b945ac68"} {:created-at 1505013511258, :author {:login "didibus", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/601540?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "next", :ns "clojure.core"}, :_id "59b4af07e4b09f63b945ac69"}], :line 3174, :examples [{:author {:login "jmglov", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/67e9a6f766dc4b30bd5e9ff3e77c1777?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(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)", :created-at 1338817014000, :updated-at 1420737060810, :_id "542692d4c026201cdc327021"} {:body ";; 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", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :created-at 1420737465554, :updated-at 1420737465554, :_id "54aebbb9e4b0e2ac61831c98"} {:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}], :body ";; 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.", :author {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1521467358474, :updated-at 1521467381232, :_id "5aafbfdee4b0316c0f44f92d"} {:updated-at 1661527937101, :created-at 1661527937101, :author {:login "jimka2001", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6414129?v=4"}, :body ";; nthrest returns a suffix of the given sequence", :_id "6308e781e4b0b1e3652d7652"}], :notes [{:updated-at 1356088840000, :body "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.", :created-at 1356088381000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :_id "542692edf6e94c6970521ff9"}], :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"} {:added "1.0", :ns "clojure.core", :name "load", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1286271399000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "load-file", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c29"} {:created-at 1352963712000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "*read-eval*", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c2a"} {:created-at 1519290672082, :author {:login "witek", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/209520?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "load-string", :ns "clojure.core"}, :_id "5a8e8930e4b0316c0f44f8ea"}], :line 6109, :examples [{:updated-at 1546453955894, :created-at 1307936370000, :body ";; 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\")", :editors [{:avatar-url "https://www.gravatar.com/avatar/1c0c20072f52de3a6335cae183b865f6?r=PG&default=identicon", :account-source "clojuredocs", :login "lambder"} {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/1c0c20072f52de3a6335cae183b865f6?r=PG&default=identicon", :account-source "clojuredocs", :login "lambder"}, :_id "542692cbc026201cdc326c1b"} {:updated-at 1546454215490, :created-at 1546454215490, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; 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", :_id "5c2d04c7e4b0ca44402ef60b"}], :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"} {:added "1.0", :ns "clojure.core", :name "if-not", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1334293416000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "if", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e44"} {:created-at 1374149749000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when-not", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e45"}], :line 767, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "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", :created-at 1280505406000, :updated-at 1332951095000, :_id "542692c6c026201cdc32692d"} {:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (if-not (zero? 0) :then :else)\n:else", :created-at 1280506136000, :updated-at 1332951114000, :_id "542692c6c026201cdc32692f"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; See examples for \"if\" explaining Clojure's idea of logical true\n;; and logical false.", :created-at 1334293411000, :updated-at 1334293411000, :_id "542692d3c026201cdc326fcd"}], :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"} {: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*"} {:added "1.0", :ns "clojure.core", :name "sequential?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1304804232000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "seq?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d22"} {:created-at 1304804263000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "coll?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d23"} {:created-at 1521067928760, :author {:login "glts", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1483271?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "seqable?", :ns "clojure.core"}, :_id "5aa9a798e4b0316c0f44f925"}], :line 6250, :examples [{:updated-at 1437503203443, :created-at 1284875508000, :body "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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/138993?v=3", :account-source "github", :login "Dimagog"} {:avatar-url "https://www.gravatar.com/avatar/65f765955a0a25d112d33528ae6f811b?r=PG&default=identicon", :account-source "clojuredocs", :login "pmbauer"} {:login "lijunle", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1296500?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/e2051c4ebaaa8c22fa9c0bb2f32f64fd?r=PG&default=identicon", :account-source "clojuredocs", :login "rustem.suniev"}, :_id "542692c6c026201cdc3268f4"} {:updated-at 1660931114232, :created-at 1660931114232, :author {:login "KGOH", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11963737?v=4"}, :body ";; 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", :_id "62ffcc2ae4b0b1e3652d763f"}], :notes [{:author {:login "zackteo", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/7510179?v=4"}, :updated-at 1603928204513, :created-at 1603927987239, :body "Of the four key collection types, vectors and lists are ordered (aka sequential). Sets and maps are not.", :_id "5f99ffb3e4b0b1e3652d73f9"}], :arglists ["coll"], :doc "Returns true if coll implements Sequential", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/sequential_q"} {: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 [{:body "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 #]]", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423526085099, :updated-at 1423526085099, :_id "54d948c5e4b081e022073c7f"}], :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*"} {:added "1.2", :ns "clojure.core", :name "shuffle", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1434034887985, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:ns "clojure.core", :name "rand-nth", :library-url "https://github.com/clojure/clojure"}, :_id "5579a2c7e4b03e2132e7d18b"} {:created-at 1554235245442, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "random-sample", :ns "clojure.core"}, :_id "5ca3bf6de4b0ca44402ef6fa"}], :line 7274, :examples [{:updated-at 1578337855496, :created-at 1282319846000, :body ";; 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]", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:avatar-url "https://avatars.githubusercontent.com/u/138993?v=3", :account-source "github", :login "Dimagog"} {:login "Hindol", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/705227?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon", :account-source "clojuredocs", :login "pkolloch"}, :_id "542692cac026201cdc326b48"}], :notes nil, :arglists ["coll"], :doc "Return a random permutation of coll", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/shuffle"} {:added "1.1", :ns "clojure.core", :name "boolean-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 5285, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}], :body ";; 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=>", :created-at 1313908154000, :updated-at 1313963403000, :_id "542692c7c026201cdc326947"}], :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"} {:added "1.0", :ns "clojure.core", :name "find", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1360286923000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "get", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e77"} {:created-at 1360286926000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "get-in", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e78"} {:created-at 1527108492940, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "contains?", :ns "clojure.core"}, :_id "5b05d38ce4b045c27b7fac76"} {:created-at 1548452405616, :author {:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "select-keys", :ns "clojure.core"}, :_id "5c4b8235e4b0ca44402ef62d"}], :line 1534, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "alexander-yakushev", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/468477?v=2"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4", :account-source "github", :login "cljlc"}], :body "(find {:a 1 :b 2 :c 3} :a)\n;;=> [:a 1]\n\n(find {:a nil} :a)\n;;=> [:a nil]\n\n(find {:a 1 :b 2 :c 3} :d)\n;;=> nil \n", :created-at 1280345792000, :updated-at 1548452497936, :_id "542692cfc026201cdc326e3e"} {:author {:login "Nevena", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/fa0e495ccb6ed2997e14f687817e9299?r=PG&default=identicon"}, :editors [{:avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4", :account-source "github", :login "cljlc"} {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :body ";; Note for these examples: as the authoritative documentation speaks only about\n;; map (as first parameter), passing anything else (e.g. a vector, like below)\n;; uses an undocumented behavior, which can change anytime and so is unreliable and\n;; should be avoided.\n\nuser=> (find [:a :b :c :d] 2)\n[2 :c]\n\nuser=> (find [:a :b :c :d] 5)\nnil\n\nuser=> (find [1 2 3] 4294967296)\n[4294967296 1]", :created-at 1305594606000, :updated-at 1582483198869, :_id "542692cfc026201cdc326e3f"}], :notes nil, :arglists ["map key"], :doc "Returns the map entry for key, or nil if key not present.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/find"} {:added "1.0", :ns "clojure.core", :name "alength", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1512468544768, :author {:login "tentamen", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/58513?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "into-array", :ns "clojure.core"}, :_id "5a267040e4b0a08026c48ccc"}], :line 3898, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [], :body "user=> (def my-array (into-array Integer/TYPE [1 2 3]))\n#'user/my-array\n\nuser=> (alength my-array)\n3", :created-at 1286508271000, :updated-at 1286508271000, :_id "542692cfc026201cdc326e13"} {:editors [{:login "zezhenyan", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8064559?v=3"}], :body "2D simple array example\nuser=> (def a (to-array-2d [[1 2] [3 4 5] [1]]))\n#'user/a\nuser=> (alength a)\n3\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/8064559?v=3", :account-source "github", :login "zezhenyan"}, :created-at 1486712507911, :updated-at 1486712552508, :_id "589d6ebbe4b01f4add58fe42"}], :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"} {:added "1.0", :ns "clojure.core", :name "bit-xor", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1414514653495, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "bit-and", :library-url "https://github.com/clojure/clojure"}, :_id "544fc7dde4b03d20a1024293"} {:created-at 1414514668964, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "bit-or", :library-url "https://github.com/clojure/clojure"}, :_id "544fc7ece4b03d20a1024294"}], :line 1311, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; set bits to 1 where bits of the arguments are different\nuser=> (bit-xor 2r1100 2r1001) \n5 \n;; 5 = 2r0101\n\n", :created-at 1280338778000, :updated-at 1285496577000, :_id "542692c7c026201cdc3269b3"} {:body ";; here is the truth table for XOR \n(Integer/toBinaryString (bit-xor 2r1100 2r1010) )\n;;=> \"110\"\n;; or 2r0110", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1414514637281, :updated-at 1414514637281, :_id "544fc7cde4b03d20a1024292"}], :notes nil, :arglists ["x y" "x y & more"], :doc "Bitwise exclusive or", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-xor"} {:added "1.1", :ns "clojure.core", :name "deliver", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1324962689000, :author {:login "neotyk", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/366ff985977b3aab09510bc335cd44a4?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "promise", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bba"}], :line 7127, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "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", :created-at 1280748782000, :updated-at 1285495947000, :_id "542692c8c026201cdc326a04"} {:author {:login "neotyk", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/366ff985977b3aab09510bc335cd44a4?r=PG&default=identicon"}, :editors [], :body ";; 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", :created-at 1324962699000, :updated-at 1324962699000, :_id "542692d2c026201cdc326f8c"} {:editors [{:login "JoshAaronJones", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19951591?v=3"}], :body ";; 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]", :author {:avatar-url "https://avatars.githubusercontent.com/u/19951591?v=3", :account-source "github", :login "JoshAaronJones"}, :created-at 1474382307145, :updated-at 1474387055629, :_id "57e149e3e4b0709b524f0503"} {:updated-at 1618026011033, :created-at 1618026011033, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :body ";; `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!\"", :_id "60711e1be4b0b1e3652d74bf"}], :notes [{:updated-at 1385511406000, :body "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).", :created-at 1385511406000, :author {:login "gyim", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/14df9ffd78d1e7062ac317d8bcfcde9f?r=PG&default=identicon"}, :_id "542692edf6e94c6970522012"}], :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"} {:added "1.0", :ns "clojure.core", :name "doseq", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1296708559000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "doall", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d9a"} {:created-at 1296708565000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "dorun", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d9b"} {:created-at 1318959035000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "for", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d9c"} {:created-at 1340037689000, :author {:login "Parijat Mishra", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e3aba44539a78ea92373418456f090e3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "dotimes", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d9d"} {:created-at 1502125400318, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1836941?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "run!", :ns "clojure.core"}, :_id "59889d58e4b0d19c2ce9d70c"}], :line 3216, :examples [{:updated-at 1639218963535, :created-at 1279807621000, :body ";; 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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/164033?v=3", :account-source "github", :login "justgage"} {:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"} {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon", :account-source "clojuredocs", :login "devijvers"}, :_id "542692c6c026201cdc326919"} {:author {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"}, :editors [{:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "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))", :created-at 1279807704000, :updated-at 1285651402000, :_id "542692c6c026201cdc32691b"} {:author {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"}, :editors [{:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "edbond", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/671af8c4a2d223c7d2e2ede3a0154975?r=PG&default=identicon"} {:login "edbond", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/671af8c4a2d223c7d2e2ede3a0154975?r=PG&default=identicon"} {:login "JavierJF", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2714593?v=3"}], :body "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]))", :created-at 1279808561000, :updated-at 1427017735128, :_id "542692c6c026201cdc32691e"} {:author {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"}, :editors [{:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Parijat Mishra", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e3aba44539a78ea92373418456f090e3?r=PG&default=identicon"}], :body "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", :created-at 1279817912000, :updated-at 1340037554000, :_id "542692c6c026201cdc326924"} {:author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :editors [{:login "justgage", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/164033?v=3"}], :body ";; 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", :created-at 1297827822000, :updated-at 1430494032223, :_id "542692c6c026201cdc326928"} {:author {:login "cloojure", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon"}, :editors [{:login "justgage", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/164033?v=3"}], :body ";; 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", :created-at 1403073333000, :updated-at 1430494049365, :_id "542692d2c026201cdc326f93"} {:editors [{:avatar-url "https://avatars.githubusercontent.com/u/164033?v=3", :account-source "github", :login "justgage"} {:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}], :updated-at 1463546941294, :created-at 1427932426392, :author {:avatar-url "https://avatars.githubusercontent.com/u/11763041?v=3", :account-source "github", :login "rezomegrelidze"}, :body ";; 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...", :_id "551c850ae4b08eb9aa0a8d3d"} {:body ";; simplest use\n\nuser=> (doseq [x [1 2 3 4 5]] (prn x))\n1\n2\n3\n4\n5\nnil", :author {:login "justgage", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/164033?v=3"}, :created-at 1430431275365, :updated-at 1430494090363, :editors [{:login "justgage", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/164033?v=3"}], :_id "5542a62be4b01bb732af0a8e"} {:updated-at 1510587865249, :created-at 1510587865249, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;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))))", :_id "5a09bdd9e4b0a08026c48cb6"} {:editors [{:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}], :body ";;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))", :author {:avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4", :account-source "github", :login "ibercode"}, :created-at 1510917150459, :updated-at 1511258586059, :_id "5a0ec41ee4b0a08026c48cbc"} {:editors [{:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=4"}], :body "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", :author {:avatar-url "https://avatars3.githubusercontent.com/u/46395055?v=4", :account-source "github", :login "akhuramazda"}, :created-at 1546681885708, :updated-at 1613255160130, :_id "5c307e1de4b0ca44402ef613"} {:updated-at 1691699072668, :created-at 1691699072668, :author {:login "nimitmaru", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/915615?v=4"}, :body ";; 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", :_id "64d54780e4b08cf8563f4be0"}], :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"} {:added "1.6", :ns "clojure.core", :name "unsigned-bit-shift-right", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1412094407161, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=2"}, :to-var {:ns "clojure.core", :name "bit-shift-right", :library-url "https://github.com/clojure/clojure"}, :_id "542ad9c7e4b0df9bb778a59f"}], :line 1368, :examples [{:body "user=> (format \"%016x\" -1)\n\"ffffffffffffffff\"\n\n;; bit-shift-right sign extends most significant bit while right shifting.\nuser=> (format \"%016x\" (bit-shift-right -1 10))\n\"ffffffffffffffff\"\n\n;; unsigned-bit-shift-right fills most significant bits of result with 0.\n;; No sign extension.\nuser=> (format \"%016x\" (unsigned-bit-shift-right -1 10))\n\"003fffffffffffff\"\n", :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=2"}, :created-at 1412094902885, :updated-at 1412094902885, :_id "542adbb6e4b0df9bb778a5a5"} {:updated-at 1460044954951, :created-at 1460044954951, :author {:login "fasiha", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/37649?v=3"}, :body ";; Warning: unsigned-bit-shift-right, like bit-shift-right, treats inputs as\n;; type Long. Smaller types like byte, short, and int will not behave as such.\n(format \"0x%x\" (byte -128))\n; => \"0x80\"\n(format \"0x%x\" (unsigned-bit-shift-right (byte -128) 1))\n; => \"0x7fffffffffffffc0\"\n(format \"0x%x\" (bit-shift-right (byte -128) 1))\n; => \"0xffffffffffffffc0\"\n\n; If you expected 0x40, you need to upcast your byte yourself, via bit-and,\n; and only then shift:\n(format \"0x%x\" (bit-shift-right (bit-and 0xff (byte -128)) 1))\n; => \"0x40\"", :_id "5706849ae4b0fc95a97eab31"} {:editors [{:login "Sophia-Gold", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19278114?v=3"}], :body ";; Stein's Algorithm (Binary GCD)\n;; https://en.wikipedia.org/wiki/Binary_GCD_algorithm\n\n\n(defn gcd [a b]\n (cond\n (zero? a) b\n (zero? b) a\n (neg? a) (- a)\n (neg? b) (- b)\n (and (even? a) (even? b)) (* 2\n (gcd (unsigned-bit-shift-right a 1)\n (unsigned-bit-shift-right b 1)))\n (and (even? a) (odd? b)) (recur (unsigned-bit-shift-right a 1) b)\n (and (odd? a) (even? b)) (recur a (unsigned-bit-shift-right b 1))\n (and (odd? a) (odd? b)) (recur (unsigned-bit-shift-right\n (Math/abs (long (- a b))) ;; coerce to avoid reflection\n 1) (min a b))))\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/19278114?v=3", :account-source "github", :login "Sophia-Gold"}, :created-at 1482925072354, :updated-at 1505598794504, :_id "5863a410e4b0fd5fb1cc9646"}], :notes nil, :arglists ["x n"], :doc "Bitwise shift right, without sign-extension.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unsigned-bit-shift-right"} {:added "1.0", :ns "clojure.core", :name "neg?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1345518618000, :author {:login "cbare", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b394e97f24f3576861239e2b839703a4?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "pos?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dd6"} {:created-at 1400618884000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "zero?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dd7"}], :line 1254, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "replore", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e7869fe1a48cb1814c657eaca6bea3eb?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/7412474?v=3", :account-source "github", :login "Lacty"}], :body "user=> (neg? -1)\ntrue\nuser=> (neg? 0)\nfalse\nuser=> (neg? 1)\nfalse", :created-at 1279074335000, :updated-at 1471000975948, :_id "542692c9c026201cdc326add"} {:updated-at 1471001005614, :created-at 1471001005614, :author {:login "Lacty", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7412474?v=3"}, :body "user=> (neg? -0.1)\ntrue\nuser=> (neg? 0.1)\nfalse", :_id "57adb1ade4b0bafd3e2a04ee"} {:updated-at 1598394369395, :created-at 1598394369395, :author {:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}, :body "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", :_id "5f459001e4b0b1e3652d73ac"}], :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"} {:added "1.0", :ns "clojure.core", :name "var-set", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1331249164000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "with-local-vars", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521df8"} {:created-at 1550004038668, :author {:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "var-get", :ns "clojure.core"}, :_id "5c632f46e4b0ca44402ef67d"}], :line 4333, :examples [{:editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=4"}], :updated-at 1638151161315, :created-at 1423523544753, :author {:avatar-url "https://avatars.githubusercontent.com/u/138993?v=3", :account-source "github", :login "Dimagog"}, :body "(with-local-vars [x 1]\n (println @x)\n (var-set x 2)\n (println @x))\n;;=> 1\n;;=> 2\n", :_id "54d93ed8e4b0e2ac61831d3b"}], :notes nil, :arglists ["x val"], :doc "Sets the value in the var object to val. The var must be\n thread-locally bound.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/var-set"} {:added "1.3", :ns "clojure.core", :name "unchecked-float", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1496072900762, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "float", :ns "clojure.core"}, :_id "592c42c4e4b093ada4d4d793"}], :line 3546, :examples [{:editors [{:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}], :body "(unchecked-float 1)\n;;=> 1.0\n(unchecked-float 1.11)\n;;=> 1.11\n(unchecked-float 1.111111111111111111111111111M)\n;;=> 1.1111112\n\n;;;; Note that (unchecked-float) doesn't range check its argument.\n;;;; Use (float) instead if you want an exception to be thrown in such a case.\n\n(unchecked-float Double/MAX_VALUE)\n;;=> Infinity\n(float Double/MAX_VALUE)\n;;=> IllegalArgumentException Value out of range for float: 1.7976931348623157E308", :author {:avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3", :account-source "github", :login "svenschoenung"}, :created-at 1496072892226, :updated-at 1496073090370, :_id "592c42bce4b093ada4d4d792"}], :notes nil, :arglists ["x"], :doc "Coerce to float. Subject to rounding.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-float"} {:added "1.0", :ns "clojure.core", :name "pmap", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1281948332000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e0d"} {:created-at 1336536733000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "future", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e0e"} {:created-at 1518042635832, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "pcalls", :ns "clojure.core"}, :_id "5a7b7e0be4b0316c0f44f8a8"} {:created-at 1518042700360, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "pvalues", :ns "clojure.core"}, :_id "5a7b7e4ce4b0316c0f44f8a9"} {:created-at 1518042942025, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "partition", :ns "clojure.core"}, :_id "5a7b7f3ee4b0316c0f44f8af"}], :line 7012, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; This function operates just like map. See\n;; clojure.core/map for more details.\nuser=> (pmap inc [1 2 3 4 5])\n(2 3 4 5 6)", :created-at 1281948454000, :updated-at 1332952345000, :_id "542692cdc026201cdc326cf2"} {:updated-at 1462726187473, :created-at 1313254319000, :body ";; A function that simulates a long-running process by calling Thread/sleep:\n(defn long-running-job [n]\n (Thread/sleep 3000) ; wait for 3 seconds\n (+ n 10))\n\n;; Use `doall` to eagerly evaluate `map`, which evaluates lazily by default.\n\n;; With `map`, the total elapsed time is just under 4 * 3 seconds:\nuser=> (time (doall (map long-running-job (range 4))))\n\"Elapsed time: 11999.235098 msecs\"\n(10 11 12 13)\n\n;; With `pmap`, the total elapsed time is just over 3 seconds:\nuser=> (time (doall (pmap long-running-job (range 4))))\n\"Elapsed time: 3200.001117 msecs\"\n(10 11 12 13)", :editors [{:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon", :account-source "clojuredocs", :login "OnesimusUnbound"}, :_id "542692cdc026201cdc326cf4"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; pmap 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.", :created-at 1336536727000, :updated-at 1336536842000, :_id "542692d4c026201cdc327030"} {:updated-at 1539009726653, :created-at 1538954059979, :author {:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}, :body ";; Parallel application (of 'f') does NOT mean that the result collection would\n;; be sorted according to calculation time. The result collection is sorted\n;; in the same way as for map, i.e. it \"preserves\" the items' order in the 'coll'\n;; (or 'colls') parameter(s) of pmap. In other words: calculation is done parallel,\n;; but the result is delivered in the order the input came (in 'coll'/'colls').\n\n;; So, e.g. if the first item of 'coll' takes 1 hour to be processed (by 'f'), and\n;; the rest requires 1 sec, nothing is delivered by pmap during the 1st hour:\n;; the 1st item \"blocks\" the appearence of the others in the result of pmap,\n;; even if the others are already calculated. E.g. (take 5 (pmap ...) will not \n;; return in 5 secs (but in 1 hour), even if we calculated 5 items in 5 secs\n;; -- we wait for the calculations of the first five in 'coll'.\n\n;; In contrast, side effects of 'f' (if any) are coming in \"random\" order (due to\n;; parallelism): in the example above, we might see the side effects (e.g. swap!-s)\n;; of many appliactions of 'f' to different elements of 'coll', long before we \n;; get the result of (take 1 (pmap ...)).\n\n;; To illustrate the statements above, run this:\n(defn proc\n [i]\n (println \"processing: \" i \"(\" (System/currentTimeMillis) \")\")\n (Thread/sleep\n (if (= i 0)\n 5000\n 10)))\n\n(take 1 (pmap proc (range 5)))\n;; output:\n(processing: processing: processing: processing: processing: 3 42 ( ((1 \n 1539007947561( 1539007947561 ) )1539007947561 0 )\n\n1539007947561( ) 1539007947561 )\n\nnil)\n;; We can see that 5 threads are started at the same time, immediately, in parallel.\n;; 4 of them must be finished in 10 msecs, but we get back the REPL prompt\n;; only after 5 secs, because we wait for the result of the i=0 item.", :editors [{:avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4", :account-source "github", :login "cljlc"}], :_id "5bba934be4b00ac801ed9eb3"} {:updated-at 1539007541878, :created-at 1539007541878, :author {:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}, :body ";; pmap is implemented using Clojure futures. Futures run in threads. \n;; These threads of a pmap's evaluation run independently from each other.\n;; This means that even if one of these threads already determined the result\n;; of the whole pmap*, all the other, already started threads keep running\n;; until they finish their own calculations. (Although these calcualtions might\n;; already be absolutely unnecessary.)\n;; This can be especially important, when these threads have side effects:\n;; these side effects (e.g. swap!-s) might happen later, when they are not\n;; expected anymore.\n;; Moreover, these \"cowboy\" threads keep occuping the resources (CPU, memory...)\n;; they need.\n;; *: this is the case e.g. when one of the threads throws an exception.", :_id "5bbb6435e4b00ac801ed9ec9"}], :notes [{:updated-at 1288191025000, :body "for insight into how pmap does stuff see this presentation: \"From Concurrency to Parallelism\", by David Edgar Liebke @ http://incanter.org/downloads/fjclj.pdf", :created-at 1288191025000, :author {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f9f"} {:author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :updated-at 1553851026351, :created-at 1553789805408, :body "The following can be used to understand how many threads `pmap` runs at once (assuming tasks are roughly the same computational cost). The min level correspond to the situation where the consumer is slower than the producer, while the max level is when the consumer is faster than the producer:\n\n* When the sequence is not chunked (for example subvec) the min parallelism is 1 and the max parallelism is `(+ 2 N-cores)`. Example: with 12 cores, `(doall (pmap #(Thread/sleep %) (subvec (into [] (range 1000)) 0 999)))` keeps 12+2 threads busy.\n* In case of chunked sequences (vast majority are size 32), the min parallelism is `(min chunk-size (+ 2 n-cores))`, while the max amount is equal to `(+ chunk-size 2 N-cores)`. Example: with 12 cores, `(doall (pmap #(Thread/sleep %) (range 1000)))` keeps 12+2+32 threads busy.", :_id "5c9cf36de4b0ca44402ef6ed"}], :arglists ["f coll" "f coll & colls"], :doc "Like map, except f is applied in parallel. Semi-lazy in that the\n parallel computation stays ahead of the consumption, but doesn't\n realize the entire result unless required. Only useful for\n computationally intensive functions where the time of f dominates\n the coordination overhead.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/pmap"} {:added "1.2", :ns "clojure.core", :name "error-mode", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1658139699593, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "set-error-mode!", :ns "clojure.core"}, :_id "62d53433e4b0b1e3652d7625"}], :line 2229, :examples [{:updated-at 1658139926101, :created-at 1658139926101, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body "(def a (agent 42))\n(error-mode a);; => :fail\n\n(set-error-mode! a :continue)\n(error-mode a);; => :continue", :_id "62d53516e4b0b1e3652d7626"}], :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"} {:added "1.0", :ns "clojure.core", :name "num", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "number?", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917500000, :_id "542692ebf6e94c6970521da3"}], :line 3473, :examples [{:author {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}], :body "user=> (num 2048)\n2048\n\n\n;; Calling a Number http://download.oracle.com/javase/6/docs/api/ method:\n\nuser=> (def x (num 2048))\n#'user/x\n\nuser=> (.floatValue x)\n2048.0\n", :created-at 1283819688000, :updated-at 1287791370000, :_id "542692cec026201cdc326dc3"}], :notes [{:author {:login "didibus", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/601540?v=4"}, :updated-at 1560228092431, :created-at 1560228092431, :body "`num` is used to coerce a primitive Java number type such as int, float, long, double, etc., into its boxed version such as Float, Long, Double, etc. If given an existing boxed Number type, as opposed to a primitive number type, it will just return it as is.", :_id "5cff30fce4b0ca44402ef754"} {:body "If you are trying to parse a String into a Number, this is not the function you are looking for. `num` only coerces from other primitive or boxed number types. For coercing from a String, you want to use Java interop such as:\n\n```\n(Long/parseLong \"333\")\n(Float/parseFloat \"333.33\")\n(Double/parseDouble \"333.3333333333332\")\n(Integer/parseInt \"-333\")\n(Integer/parseUnsignedInt \"333\")\n(BigInteger. \"3333333333333333333333333332\")\n(BigDecimal. \"3.3333333333333333333333333332\")\n(Short/parseShort \"400\")\n(Byte/parseByte \"120\")\n```\n\nYou can also alternatively, if you want to parse the String into a Number the same way that the Clojure reader does so, use the edn reader.\n\n```\n(require '[clojure.edn :as edn])\n(edn/read-string \"333\")\n```", :created-at 1560228951511, :updated-at 1560229176287, :author {:avatar-url "https://avatars3.githubusercontent.com/u/601540?v=4", :account-source "github", :login "didibus"}, :_id "5cff3457e4b0ca44402ef756"}], :tag "java.lang.Number", :arglists ["x"], :doc "Coerce to Number", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/num"} {:added "1.5", :ns "clojure.core", :name "reduced?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1416151592590, :author {:login "ljos", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/585174?v=2"}, :to-var {:ns "clojure.core", :name "reduced", :library-url "https://github.com/clojure/clojure"}, :_id "5468c228e4b0dc573b892fd5"} {:created-at 1416151598149, :author {:login "ljos", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/585174?v=2"}, :to-var {:ns "clojure.core", :name "reduce", :library-url "https://github.com/clojure/clojure"}, :_id "5468c22ee4b0dc573b892fd6"} {:created-at 1456683959806, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unreduced", :ns "clojure.core"}, :_id "56d33bb7e4b02a6769b5a4bb"} {:created-at 1464286428199, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ensure-reduced", :ns "clojure.core"}, :_id "57473cdce4b0af2c9436d1f2"}], :line 2842, :examples [{:updated-at 1456683476601, :created-at 1456683476601, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :body "(reduced? :foo)\n;;=> false\n\n(reduced? (reduced :foo))\n;;=> true\n\n(reduced? (clojure.lang.Reduced. :foo))\n;;=> true", :_id "56d339d4e4b0b41f39d96cd7"}], :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"} {:added "1.1", :ns "clojure.core", :name "disj!", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1329970249000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "assoc!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e49"} {:created-at 1329970254000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "dissoc!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e4a"} {:created-at 1533850473558, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "disj", :ns "clojure.core"}, :_id "5b6cb369e4b00ac801ed9e4f"} {:created-at 1577916225137, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "conj!", :ns "clojure.core"}, :_id "5e0d1741e4b0ca44402ef80c"}], :line 3400, :examples [{:updated-at 1577916108217, :created-at 1307739693000, :body ";; Note how we always use the return value of disj! and conj! in these examples\n;; for all future modifications, rather than (incorrectly) ignoring the return\n;; value and continuing to modify the original transient set. See examples for\n;; assoc! and dissoc! for more discussion and examples of this.\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\nuser=> (def foo (transient #{'pore-pore 'slow 'yukkuri}))\n#'user/foo\nuser=> (count foo)\n3\nuser=> (def foo (disj! foo 'yukkuri))\n#'user/foo\nuser=> foo\n#\nuser=> (count foo)\n2\nuser=> (def foo (conj! foo 'yukkuri))\n#'user/foo\nuser=> foo\n#\nuser=> (count foo)\n3\nuser=> (def foo (persistent! foo))\n#'user/foo\nuser=> foo\n#{yukkuri slow pore-pore}\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"}], :author {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"}, :_id "542692cfc026201cdc326e8c"} {:updated-at 1533850455152, :created-at 1533850455152, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; A faster implementation of disj for a large number of keys to disjoin:\n\n(defn disj* [s & ks]\n (persistent!\n (reduce disj! (transient s) ks)))\n\n(let [s (set (range 1000))\n xs (range 400 600)]\n (count (apply disj* s xs)))\n;; 800", :_id "5b6cb357e4b00ac801ed9e4e"}], :notes nil, :arglists ["set" "set key" "set key & ks"], :doc "disj[oin]. Returns a transient 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!"} {:added "1.0", :ns "clojure.core", :name "float?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1496006168817, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "double?", :ns "clojure.core"}, :_id "592b3e18e4b093ada4d4d78e"} {:created-at 1496006177347, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bigdec?", :ns "clojure.core"}, :_id "592b3e21e4b093ada4d4d78f"} {:created-at 1496006182111, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "decimal?", :ns "clojure.core"}, :_id "592b3e26e4b093ada4d4d790"}], :line 3604, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (float? 0)\nfalse\nuser=> (float? 0.0)\ntrue", :created-at 1279073915000, :updated-at 1332951058000, :_id "542692cbc026201cdc326bc6"} {:updated-at 1462076465809, :created-at 1454839923274, :author {:login "guruma", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/534540?v=3"}, :body ";; 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])", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/534540?v=3", :account-source "github", :login "guruma"} {:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}], :_id "56b71873e4b0e8f8f33875d4"} {:updated-at 1592827825230, :created-at 1592827825230, :author {:login "zoren", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/84688?v=4"}, :body ";; BigDecimal is not float\nuser=> (float? 0.0M)\nfalse", :_id "5ef09fb1e4b0b1e3652d730a"}], :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"} {:added "1.0", :ns "clojure.core", :name "aset-float", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1627064336075, :author {:login "rosejn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/36590?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "aget", :ns "clojure.core"}, :_id "60fb0810e4b0b1e3652d751c"}], :line 3961, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; create an array of 10 floats and set one of the values to 3.1415\n\nuser=> (def fs (float-array 10))\n#'user/fs\nuser=> (vec fs)\n[0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]\nuser=> (aset-float fs 3 3.1415)\n3.1415\nuser=> (vec fs)\n[0.0 0.0 0.0 3.1415 0.0 0.0 0.0 0.0 0.0 0.0]\nuser=>", :created-at 1313914809000, :updated-at 1313914809000, :_id "542692c7c026201cdc3269d2"}], :notes [{:body "See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax.", :created-at 1432829158905, :updated-at 1432829158905, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :_id "55673ce6e4b01ad59b65f4e0"}], :arglists ["array idx val" "array idx idx2 & idxv"], :doc "Sets the value at the index/indices. Works on arrays of float. Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aset-float"} {:added "1.2", :ns "clojure.core", :name "deftype", :file "clojure/core_deftype.clj", :type "macro", :column 1, :see-alsos [{:created-at 1361948459000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "definterface", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e0b"} {:created-at 1361948592000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defprotocol", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e0c"} {:created-at 1446587002611, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "defrecord", :ns "clojure.core"}, :_id "56392a7ae4b04b157a6648e2"}], :line 422, :examples [{:author {:login "Kototama", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a54a4dc204925d397ca010b9a332e74d?r=PG&default=identicon"}, :editors [{:login "Kototama", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a54a4dc204925d397ca010b9a332e74d?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "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))", :created-at 1285784862000, :updated-at 1285841395000, :_id "542692ccc026201cdc326cc9"} {:updated-at 1613242656022, :created-at 1462490574656, :author {:login "elsaturnino", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/571496?v=3"}, :body ";; 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)", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/5796449?v=3", :account-source "github", :login "freezhan"} {:login "stoat1", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2543524?v=4"}], :_id "572bd5cee4b050526f331422"} {:updated-at 1462539789757, :created-at 1462539789757, :author {:login "jzwolak", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/285725?v=3"}, :body "(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\")", :_id "572c960de4b050526f331423"} {:updated-at 1539060553178, :created-at 1539060553178, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; 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\"", :_id "5bbc3349e4b00ac801ed9ecb"} {:updated-at 1552943737414, :created-at 1552943737414, :author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4"}, :body ";; 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))", :_id "5c900a79e4b0ca44402ef6b8"} {:editors [{:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/889685?v=4", :account-source "github", :login "huahaiy"}, :created-at 1611856836020, :updated-at 1611856923228, :_id "6012fbc4e4b0b1e3652d743f"} {:updated-at 1658251111297, :created-at 1658251111297, :author {:login "quoll", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/358875?v=4"}, :body ";; 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", :_id "62d6e767e4b0b1e3652d7629"}], :macro true, :notes [{:updated-at 1330691996000, :body "There's also some undocumented support for annotations:\r\n\r\n", :created-at 1330691996000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fda"} {:author {:login "eoliphan", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1065736?v=4"}, :updated-at 1665156668525, :created-at 1665156668525, :body "Annotation docs now available in the reference: https://clojure.org/reference/datatypes#_java_annotation_support", :_id "6340463ce4b0b1e3652d7671"}], :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"} {:added "1.0", :ns "clojure.core", :name "bean", :file "clojure/core_proxy.clj", :type "function", :column 1, :see-alsos nil, :line 398, :examples [{:updated-at 1691941141913, :created-at 1279049231000, :body "user=> (import java.util.Date)\njava.util.Date\n\nuser=> (bean (Date.))\n{:seconds 57, :date 13, :class java.util.Date, :minutes 55, :hours 17, :year 110, :timezoneOffset -330, :month 6, :day 2, :time 1279023957492}\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:login "ode79", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/227520?v=3"} {:login "daemianmack", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24476?v=4"}], :author {:login "nipra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/142529?v=3"}, :_id "542692ccc026201cdc326c70"} {:updated-at 1477395581762, :created-at 1348995044000, :body ";; although not reference-able in Clojuredocs, \n;; org.clojure/java.data provides a useful, alternative 'from-java' function \n;; that works similarly to bean, but more customizable.\n;; See https://github.com/clojure/java.data for more info.", :editors [{:login "G1enY0ung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/15034155?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon", :account-source "clojuredocs", :login "klauern"}, :_id "542692d2c026201cdc326f4e"}], :notes nil, :arglists ["x"], :doc "Takes a Java object and returns a read-only implementation of the\n map abstraction based upon its JavaBean properties.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bean"} {:added "1.1", :ns "clojure.core", :name "booleans", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "boolean-array", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1358052913000, :_id "542692eaf6e94c6970521c0a"}], :line 5348, :examples [{:author {:login "leifp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d2f37720f063404ef83b987d2824353d?r=PG&default=identicon"}, :editors [], :body ";; 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", :created-at 1342528439000, :updated-at 1342528439000, :_id "542692d2c026201cdc326f5b"} {:body ";; 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", :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :created-at 1432832819657, :updated-at 1432832851114, :editors [{:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}], :_id "55674b33e4b01ad59b65f4e2"}], :notes nil, :arglists ["xs"], :doc "Casts to boolean[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/booleans"} {:added "1.0", :ns "clojure.core", :name "ns-unalias", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1390616196000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "alias", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ea7"} {:created-at 1390616206000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "ns-aliases", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ea8"} {:created-at 1512578712943, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ns-unmap", :ns "clojure.core"}, :_id "5a281e98e4b0a08026c48cd2"}], :line 4281, :examples [{:author {:login "daviddurand", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1316941?v=2"}, :editors [], :body ";; 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", :created-at 1326025800000, :updated-at 1326025800000, :_id "542692d4c026201cdc327020"} {:body "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{}", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423017698483, :updated-at 1423017698483, :_id "54d186e2e4b081e022073c52"} {:updated-at 1512578611261, :created-at 1512471675948, :author {:login "ivarref", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/74075?v=4"}, :body ";; To wipe aliases of current namespace:\n*my-ns*=> (map (partial ns-unalias *ns*) (keys (ns-aliases *ns*)))", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/74075?v=4", :account-source "github", :login "ivarref"} {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}], :_id "5a267c7be4b0a08026c48ccd"}], :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"} {:added "1.0", :ns "clojure.core", :name "when-let", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1293436133000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "if-let", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e2c"} {:created-at 1315004448000, :author {:login "srid", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bd3a68d670372cd09876c26270a4299a?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e2d"} {:created-at 1323280128000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when-not", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e2e"} {:created-at 1334293387000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "if", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e2f"} {:created-at 1405367841000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when-first", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e30"} {:created-at 1440455896228, :author {:login "brunchboy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2228869?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "when-some", :ns "clojure.core"}, :_id "55db9cd8e4b072d7f27980f1"} {:created-at 1602614484757, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "let", :ns "clojure.core"}, :_id "5f85f4d4e4b0b1e3652d73df"}], :line 1861, :examples [{:author {:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Confusion", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ca054e9c7aecbfac1d99af1fd0a6d72c?r=PG&default=identicon"}], :body ";; Very useful when working with sequences. Capturing the return value \n;; of `seq` brings a performance gain in subsequent `first`/`rest`/`next`\n;; calls. Also the block is guarded by `nil` punning.\n\n(defn drop-one\n [coll]\n (when-let [s (seq coll)]\n (rest s)))\n\nuser=> (drop-one [1 2 3])\n(2 3)\nuser=> (drop-one [])\nnil\n", :created-at 1281553976000, :updated-at 1342493536000, :_id "542692cbc026201cdc326c01"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; See examples for \"if\" explaining Clojure's idea of logical true\n;; and logical false.", :created-at 1334293395000, :updated-at 1334293395000, :_id "542692d6c026201cdc3270b6"} {:editors [{:login "mkorvas", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2321069?v=3"}], :updated-at 1438294296617, :created-at 1428550770303, :author {:avatar-url "https://avatars.githubusercontent.com/u/367789?v=3", :account-source "github", :login "mattvvhat"}, :body ";; Works well with collections\n\n(def x {:whatever 1})\n\n(when-let [value (:whatever x)]\n (println \"x+1 = \" (inc value)))\n\n;; Prints: \"x+1 = 2\"", :_id "5525f472e4b01bb732af0a7b"} {:updated-at 1469577527836, :created-at 1469577480181, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}, :body ";; when-let multiple bindings version\n\n(defmacro when-let*\n ([bindings & body]\n (if (seq bindings)\n `(when-let [~(first bindings) ~(second bindings)]\n (when-let* ~(drop 2 bindings) ~@body))\n `(do ~@body))))\n\n(when-let* [a 1 \n b 2 \n c (+ a b)]\n (println \"yeah!\")\n c)\n;;=>yeah!\n;;=>3\n\n(when-let* [a 1 \n b nil \n c 3]\n (println \"damn! b is nil\")\n a)\n;;=>nil\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3", :account-source "github", :login "ertugrulcetin"}], :_id "5797f908e4b0bafd3e2a04bb"} {:updated-at 1505500848933, :created-at 1505500848933, :author {:login "bfabry", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/29587?v=4"}, :body ";; test is evaluated before values are bound to binding, so destructuring works\n(when-let [[a] nil] [a])\n=> nil\n(when-let [[a] [:a]] [a])\n=> [:a]\n(when-let [[a] []] [a])\n=> [nil]", :_id "59bc1eb0e4b09f63b945ac76"} {:updated-at 1629082196288, :created-at 1536030316104, :author {:login "arlicle", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/153773?v=4"}, :body ";; when-let multiple bindings version\n;; all bindings are evaluated before checking for falsyness\n\n(defmacro when-let*\n [bindings & body]\n `(let ~bindings\n (if (and ~@(take-nth 2 bindings))\n (do ~@body)\n )))\n\n(when-let* [a 1 \n b 2 \n c (+ a b)]\n (println \"yeah!\")\n c)\n;;yeah!\n;;=> 3\n\n(when-let* [a 1 \n b nil \n c 3]\n (println \"damn! b is nil\")\n a)\n;;=> nil", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/8340498?v=4", :account-source "github", :login "justintaft"}], :_id "5b8df66ce4b00ac801ed9e85"} {:editors [{:login "Jjunior130", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/7597818?v=4"}], :body "(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 [value]\n (cond\n (empty? value) \"\"\n (float-parsable? value) value\n :otherwise (find-parsable-or-nil 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]])", :author {:avatar-url "https://avatars1.githubusercontent.com/u/7597818?v=4", :account-source "github", :login "Jjunior130"}, :created-at 1536532957930, :updated-at 1536815925378, :_id "5b95a1dde4b00ac801ed9e93"}], :macro true, :notes [{:updated-at 1299054268000, :body "The difference between when-let and if-let is that when-let doesn't have an else clause and and also accepts multiple forms so you don't need to use a (do...).", :created-at 1299054268000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fb4"} {:updated-at 1393879475000, :body "The word \"bindings\" seems not to be correct here. In fact `when-let` only accepts **one** binding and not multiple ones.\r\nSo \"bindings\" might be confusing, at least it was for me.", :created-at 1393879360000, :author {:login "n2o", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/73a59429cbc559fd77e9ec50fd99006b?r=PG&default=identicon"}, :_id "542692edf6e94c697052201f"} {:updated-at 1405477326000, :body "Agreed. It ought to be \"binding\" for clarity.", :created-at 1405477326000, :author {:login "Dave Y.", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10d4977e847588cb4b461de4eb9d1646?r=PG&default=identicon"}, :_id "542692edf6e94c697052202c"} {:author {:login "HomoEfficio", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/17228983?v=3"}, :updated-at 1486864109909, :created-at 1486864109909, :body "```clojure\n(when-let [name test]\n (do-something-with-name))\n```\n\nIn the example above, `test` does not have to be a predicate.\n`test` can be any value which is like `(seq coll)` or `3`, `[1 2]`, or so.\n\nIf `test` is neither `false` nor `nil`, `test` is bound to `name`.\n", :_id "589fbeede4b01f4add58fe4c"}], :arglists ["bindings & body"], :doc "bindings => binding-form test\n\n When test is true, evaluates body with binding-form bound to the value of test", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/when-let"} {:added "1.0", :ns "clojure.core", :name "int-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "ints", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917413000, :_id "542692ebf6e94c6970521d57"} {:created-at 1349125778000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "aget", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d58"} {:created-at 1349125782000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "aset", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d59"} {:created-at 1349125888000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "aset-int", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d5a"}], :line 5332, :examples [{:updated-at 1454083049116, :created-at 1284747822000, :body ";; 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", :editors [{:avatar-url "https://www.gravatar.com/avatar/d543a7491b7b47ec7c3e8f259a75d2dd?r=PG&default=identicon", :account-source "clojuredocs", :login "apgwoz"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/d543a7491b7b47ec7c3e8f259a75d2dd?r=PG&default=identicon", :account-source "clojuredocs", :login "apgwoz"}, :_id "542692c9c026201cdc326afa"}], :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"} {:added "1.0", :ns "clojure.core", :name "set?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1293674593000, :author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "set", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d8f"} {:created-at 1414508276593, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "map?", :library-url "https://github.com/clojure/clojure"}, :_id "544faef4e4b0dc573b892faa"} {:created-at 1414508317723, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "vector?", :library-url "https://github.com/clojure/clojure"}, :_id "544faf1de4b03d20a102427f"}], :line 4099, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "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", :created-at 1293674587000, :updated-at 1423276284407, :_id "542692cec026201cdc326dfa"}], :notes nil, :arglists ["x"], :doc "Returns true if x implements IPersistentSet", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/set_q"} {:added "1.0", :ns "clojure.core", :name "inc'", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1444304838174, :author {:login "andreloureiro", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2106717?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "inc", :ns "clojure.core"}, :_id "561657c6e4b0b41dac04c955"} {:created-at 1495706268555, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "dec'", :ns "clojure.core"}, :_id "5926aa9ce4b093ada4d4d754"}], :line 915, :examples [{:updated-at 1444305445453, :created-at 1444305445453, :author {:login "andreloureiro", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2106717?v=3"}, :body "> (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", :_id "56165a25e4b0b41dac04c956"} {:updated-at 1495706130653, :created-at 1495706130653, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body ";;;; (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", :_id "5926aa12e4b093ada4d4d752"}], :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'"} {:added "1.7", :ns "clojure.core", :name "cat", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1462880190642, :author {:login "achesnais", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6626105?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "cat", :ns "clojure.core.reducers"}, :_id "5731c7bee4b012fa59bdb2ef"} {:created-at 1462880208677, :author {:login "achesnais", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6626105?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "foldcat", :ns "clojure.core.reducers"}, :_id "5731c7d0e4b012fa59bdb2f0"} {:created-at 1679512700855, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "into", :ns "clojure.core"}, :_id "641b547ce4b08cf8563f4b84"} {:created-at 1685378198294, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "concat", :ns "clojure.core"}, :_id "6474d496e4b08cf8563f4bc1"}], :line 7619, :examples [{:updated-at 1462880149225, :created-at 1462880149225, :author {:login "achesnais", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6626105?v=3"}, :body ";; cat is handy for untangling nested collections when using transducers\n\n(into [] (comp cat cat (map inc)) [[[1] [2]] [[3] [4]]])\n;; => [2 3 4 5]", :_id "5731c795e4b012fa59bdb2ee"} {:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}], :body ";; Remove the need of (mapcat identity coll) idiom:\n(def rota (sequence cat (repeat [\"tom\" \"nick\" \"jane\"])))\n(nth rota 7) ; who's up next week?\n;; nick", :author {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1510050037744, :updated-at 1510051755220, :_id "5a0188f5e4b0a08026c48c95"} {:editors [{:login "stanislas", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/240862?v=4"}], :body ";; combining map-indexed with cat for a \"mapcat-indexed\"\n(into []\n (comp\n (map-indexed (fn [index val]\n (repeat index val)))\n cat)\n (range 5))\n;; => [1 2 2 3 3 3 4 4 4 4]", :author {:avatar-url "https://avatars.githubusercontent.com/u/240862?v=4", :account-source "github", :login "stanislas"}, :created-at 1629989634908, :updated-at 1629989697016, :_id "6127ab02e4b0b1e3652d7535"} {:updated-at 1659698277633, :created-at 1659698047207, :author {:login "ghoseb", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1453?v=4"}, :body ";;; a concise and performant way to concat into a vector\n\n(into [] cat [[1 2 3] [4] [5 6 7]])\n;; => [1 2 3 4 5 6 7]\n\n(defn concatv\n \"Concatenate `xs` and return the result as a vector.\"\n [& xs]\n (into [] cat xs))\n\n(concatv '(1 2) [3] [4 5])\n;; => [1 2 3 4 5]\n\n;;; this xducer form is equivalent to the `(vec (concat...` pattern\n(let [x [1 2 3]\n y 4\n z [5 6 7]]\n (= \n (into [] cat [x [y] z])\n (vec (concat x [y] z))))\n\n;; => true", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/1453?v=4", :account-source "github", :login "ghoseb"}], :_id "62ecfb7fe4b0b1e3652d7638"}], :notes nil, :arglists ["rf"], :doc "A transducer which concatenates the contents of each input, which must be a\n collection, into the reduction.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/cat"} {:added "1.9", :ns "clojure.core", :name "StackTraceElement->vec", :file "clojure/core_print.clj", :type "function", :column 1, :see-alsos nil, :line 465, :examples [{:editors [{:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}], :body ";;;; StackTraceElements look like vectors when printed, but they\n;;;; are actually a completely different type. \n;;;; (StackTraceElement->vec) turns them into normal Clojure vectors.\n\n(try \n (/ 1 0)\n (catch Exception e \n (let [cause (->> e .getStackTrace seq first)]\n (pprint cause)\n (class cause))))\n;;=> [clojure.lang.Numbers divide \"Numbers.java\" 158]\n;;=> java.lang.StackTraceElement\n\n(try \n (/ 1 0)\n (catch Exception e \n (let [cause (->> e .getStackTrace seq first StackTraceElement->vec)]\n (pprint cause)\n (class cause))))\n;;=> [clojure.lang.Numbers divide \"Numbers.java\" 158]\n;;=> clojure.lang.PersistentVector\n", :author {:avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3", :account-source "github", :login "svenschoenung"}, :created-at 1495970721085, :updated-at 1495970798753, :_id "592ab3a1e4b093ada4d4d77e"}], :notes nil, :arglists ["o"], :doc "Constructs a data representation for a StackTraceElement: [class method file line]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/StackTraceElement->vec"} {:ns "clojure.core", :name "*suppress-read*", :type "var", :see-alsos nil, :examples nil, :notes [{:body "Not meant for public consumption, implementation detail of reader-conditional feature to skip unreadable forms. See https://clojure.atlassian.net/browse/CLJ-1424", :created-at 1618077877511, :updated-at 1618078788123, :author {:avatar-url "https://avatars.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :_id "6071e8b5e4b0b1e3652d74c0"}], :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*suppress-read*"} {:added "1.0", :ns "clojure.core", :name "flush", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 3705, :examples [{:updated-at 1556307726395, :created-at 1556307726395, :author {:login "pauloaug", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/804447?v=4"}, :body ";; iteratively prints the value of x (after a pause of 100ms) \n(doseq [x (range 20)]\n (Thread/sleep 100)\n (pr x)\n (flush))\n\n;; without a `flush` at each iteration,\n;; we'll get all the output stream at once flushed and printed only at the end \n;; of `doseq` evaluation. \n(doseq [x (range 20)]\n (Thread/sleep 100)\n (pr x))", :_id "5cc35f0ee4b0ca44402ef711"}], :notes nil, :arglists [""], :doc "Flushes the output stream that is the current value of\n *out*", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/flush"} {:added "1.0", :ns "clojure.core", :name "take-while", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1301365974000, :author {:login "pauldoo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5cb916d3c8abc9f45a093209e72489fb?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "drop-while", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c3f"} {:created-at 1347077874000, :author {:login "dansalmo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "split-with", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c40"} {:created-at 1473454417291, :author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "some", :ns "clojure.core"}, :_id "57d32151e4b0709b524f04f2"} {:created-at 1538951674784, :author {:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "take", :ns "clojure.core"}, :_id "5bba89fae4b00ac801ed9ead"}], :line 2888, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"} {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Airwoz", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/47391748e84575258520e85e3725d144?r=PG&default=identicon"}], :body ";; Calculate the sum of all numbers under 1000:\nuser=> (reduce + (take-while (partial > 1000) (iterate inc 0)))\n499500", :created-at 1279591693000, :updated-at 1385275768000, :_id "542692cdc026201cdc326d03"} {:author {:login "patazj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d790f5851d80da498e475ece4487e92?r=PG&default=identicon"}, :editors [{:login "patazj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d790f5851d80da498e475ece4487e92?r=PG&default=identicon"} {:login "patazj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d790f5851d80da498e475ece4487e92?r=PG&default=identicon"} {:login "Matt", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/af7cad0e010feb68f651cb61c54424b4?r=PG&default=identicon"} {:login "Kejia", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1039073?v=3"}], :body "user=> (take-while neg? [-2 -1 0 1 2 3])\n(-2 -1)\n\nuser=> (take-while neg? [-2 -1 0 -1 -2 3]) ; note: `take-while' stops traversing the collection when the predicate is false, as is different from `filter'.\n(-2 -1)\n\nuser=> (take-while neg? [ 0 1 2 3])\n()\n\nuser=> (take-while neg? [])\n()\n\nuser=> (take-while neg? nil)\n()", :created-at 1321607184000, :updated-at 1434723642888, :_id "542692d5c026201cdc3270a2"} {:editors [{:login "henghuang", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5959826?v=3"}], :body ";;take the item while it's included in the set \nuser=> (take-while #{[1 2][3 4]} #{[1 2]})\n([1 2])\nuser=> (take-while #{[1 2][3 4]} #{[3 4]})\n([3 4])\nuser=> (take-while #{[1 2][3 4]} #{[4 5]})\n()\nuser=>(take-while #{[1 2][3 4]} #{[5 6] [1 2]}); return nil while any item is not included in the set\n()", :author {:avatar-url "https://avatars.githubusercontent.com/u/5959826?v=3", :account-source "github", :login "henghuang"}, :created-at 1458044677653, :updated-at 1458044982206, :_id "56e7ff05e4b0507458dcf5a6"} {:updated-at 1517038741181, :created-at 1517038741181, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;take-while practical example\n\n(def entries [{:month 1 :val 12}\n {:month 2 :val 3}\n {:month 3 :val 32}\n {:month 4 :val 18}\n {:month 5 :val 32}\n {:month 6 :val 62}\n {:month 7 :val 12}\n {:month 8 :val 142}\n {:month 9 :val 52}\n {:month 10 :val 18}\n {:month 11 :val 23}\n {:month 12 :val 56}])\n\n(defn get-result\n [coll m]\n (take-while\n #(<= (:month %) m) coll))\n\n(get-result entries 3)\n;;({:m 1, :val 12} {:m 2, :val 3} {:m 3, :val 32})\n", :_id "5a6c2c95e4b076dac5a728a7"} {:editors [{:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}], :body ";; Note that usually more items are realized than needed.\n;; In the example below the first 32 items are calculated,\n;; though the first 2 would be enough.\n;; This can be especially important when this extra realization\n;; leads to an exception (see example at 'take') or requires a lot of\n;; resources (CPU, time, memory, etc.) and at the end not needed at all.\n\nuser=> (let [x (map (fn [i]\n (println i)\n (Thread/sleep 100)\n i)\n (range 50))]\n (take-while #(< % 1) x))\n0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n(0)", :author {:avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4", :account-source "github", :login "cljlc"}, :created-at 1538951863286, :updated-at 1538953447395, :_id "5bba8ab7e4b00ac801ed9eae"}], :notes nil, :arglists ["pred" "pred coll"], :doc "Returns a lazy sequence of successive items from coll while\n (pred item) returns logical true. pred must be free of side-effects.\n Returns a transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/take-while"} {:added "1.0", :ns "clojure.core", :name "vary-meta", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1301486152000, :author {:login "ninjudd", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7ced25585a7556e9b9b975c1f9e136e3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-meta", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d19"} {:created-at 1375213046000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "alter-meta!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d1a"}], :line 675, :examples [{:updated-at 1285495771000, :created-at 1280776393000, :body "user=> (meta (vary-meta 'foo assoc :a 1))\n{:a 1}\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692c8c026201cdc326a68"} {:author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :editors [], :body ";; 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", :created-at 1359718168000, :updated-at 1359718168000, :_id "542692d5c026201cdc3270b3"}], :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"} {:added "1.0", :ns "clojure.core", :name "<=", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1451249730987, :author {:login "justCxx", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6506296?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name ">=", :ns "clojure.core"}, :_id "56805042e4b0e0706e05bd90"} {:created-at 1588958577321, :author {:login "alexandreaquiles", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/258331?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "<", :ns "clojure.core"}, :_id "5eb59571e4b087629b5a1907"} {:created-at 1588958583491, :author {:login "alexandreaquiles", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/258331?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "=", :ns "clojure.core"}, :_id "5eb59577e4b087629b5a1908"}], :line 1055, :examples [{:author {:login "mattdw", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ee24aacb65359196b0a1bad050f9a62f?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (<= 1 2)\ntrue\nuser=> (<= 2 2)\ntrue\nuser=> (<= 3 2)\nfalse\nuser=> (<= 2 3 4 5 6)\ntrue", :created-at 1280321906000, :updated-at 1332950755000, :_id "542692cdc026201cdc326cd9"} {:editors [{:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4"}], :body "user=> (<= 1 2 3 2)\nfalse\n\nuser=> (<= 1 2 3 3)\ntrue", :author {:avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4", :account-source "github", :login "dijonkitchen"}, :created-at 1534460808910, :updated-at 1534460833681, :_id "5b760388e4b00ac801ed9e62"} {:editors [{:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}], :body "user=> (<= 1/4 1/3 1/2)\ntrue\n\nuser=> (<= 1/2 1/3 1/4)\nfalse\n\nuser=> (>= 1/2 0.5)\ntrue", :author {:avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4", :account-source "github", :login "berczeck"}, :created-at 1598154740865, :updated-at 1598156861827, :_id "5f41e7f4e4b0b1e3652d738c"}], :notes nil, :arglists ["x" "x y" "x y & more"], :doc "Returns non-nil if nums are in monotonically non-decreasing order,\n otherwise false.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/<="} {:added "1.0", :ns "clojure.core", :name "alter", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1326053288000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cb7"} {:created-at 1350716275000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "commute", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cb8"} {:created-at 1460613552329, :author {:login "fasiha", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/37649?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ref-set", :ns "clojure.core"}, :_id "570f31b0e4b075f5b2c864e8"}], :line 2443, :examples [{:author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; 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]", :created-at 1279456650000, :updated-at 1420669157673, :_id "542692c8c026201cdc326a3c"}], :notes [{:updated-at 1325053153000, :body "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
", :created-at 1325048179000, :author {:login "borg", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/91d340132e883c02020ccd56946b2b91?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fd4"} {:updated-at 1349979324000, :body "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)))
", :created-at 1349979324000, :author {:login "grayzone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/261286ad984a83e1b0c5e0d7695d58fc?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fec"}], :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"} {:added "1.0", :ns "clojure.core", :name "-'", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1412882360420, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "-", :library-url "https://github.com/clojure/clojure"}, :_id "5436dfb8e4b0ae7956031578"} {:created-at 1423527625657, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "unchecked-subtract", :library-url "https://github.com/clojure/clojure"}, :_id "54d94ec9e4b081e022073c86"} {:created-at 1423527647730, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "unchecked-negate", :library-url "https://github.com/clojure/clojure"}, :_id "54d94edfe4b081e022073c87"}], :line 1031, :examples [{:body ";; unlike the * and + functions there is no 0 arity form\n(-')\n;; ArityException: wrong number of args (0)\n\n(-' 1)\n;;=> -1 \n\n(-' 6 3) \n;;=> 3\n\n(-' 10 3 2) \n;;=> 5\n\n(- 0 9000000000000000000 1000000000000000000)\n;; ArithmeticException: integer overflow\n\n(-' 0 9000000000000000000 1000000000000000000)\n;;=> 10000000000000000000N ", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1412882316521, :updated-at 1412882316521, :_id "5436df8ce4b06dbffbbb00c3"}], :notes nil, :arglists ["x" "x y" "x y & more"], :doc "If no ys are supplied, returns the negation of x, else subtracts\n the ys from x and returns the result. Supports arbitrary precision.\n See also: -", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/-'"} {:added "1.6", :ns "clojure.core", :name "if-some", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1417641557196, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:ns "clojure.core", :name "when-some", :library-url "https://github.com/clojure/clojure"}, :_id "547f7e55e4b03d20a10242bd"} {:created-at 1440455816295, :author {:login "brunchboy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2228869?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "if-let", :ns "clojure.core"}, :_id "55db9c88e4b072d7f27980ef"} {:created-at 1528840542254, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "some", :ns "clojure.core"}, :_id "5b20415ee4b00ac801ed9e12"}], :line 1876, :examples [{:body "(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", :author {:login "philoskim", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5637280?v=3"}, :created-at 1420603516061, :updated-at 1420603516061, :_id "54acb07ce4b09260f767ca8e"}], :macro true, :notes [{:body "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", :created-at 1417641857996, :updated-at 1417641857996, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :_id "547f7f81e4b03d20a10242be"} {:author {:login "titogarcia", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/699549?v=4"}, :updated-at 1634126821797, :created-at 1634126821797, :body "> `(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.", :_id "6166cbe5e4b0b1e3652d7559"}], :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"} {:added "1.1", :ns "clojure.core", :name "conj!", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1286870227000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "transient", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d6f"} {:created-at 1329969779000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "assoc!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d70"} {:created-at 1329969851000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "dissoc!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d71"} {:created-at 1473091049902, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "conj", :ns "clojure.core"}, :_id "57cd95e9e4b0709b524f04e3"}], :line 3358, :examples [{:updated-at 1577915992503, :created-at 1286870264000, :body ";; As seen on http://clojure.org/transients\n;; array is initially made transient, modified then\n;; finally made persistent.\n\n;; Note: This example correctly always uses the return value of conj! for\n;; future modifications, not the original value of v. See assoc! examples,\n;; and another example for conj!, for some discussion of why this is important.\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]", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"}], :author {:avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon", :account-source "clojuredocs", :login "gstamp"}, :_id "542692cac026201cdc326b43"} {:updated-at 1577915639084, :created-at 1577915639084, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :body ";; The next function below uses conj! incorrectly, ignoring its return\n;; value.\n\nuser=> (defn into-bad-example-bash-in-place [to-coll from-coll]\n (let [t (transient to-coll)]\n (loop [f (seq from-coll)]\n (if-let [s (seq f)]\n (do\n (conj! t (first s))\n (recur (next s)))\n (persistent! t)))))\n\n;; The first example call below returns the desired value.\n\nuser=> (into-bad-example-bash-in-place {:a 1, :b 2, :c 3} {:d 4, :e 5})\n{:a 1, :b 2, :c 3, :d 4, :e 5}\n\n;; However, it is by accident that it is correct. This effect can be\n;; subtle and surprising to many, because many experiments will return\n;; the desired values, as the example above does.\n\n;; The return value is correct for these inputs because all of these\n;; calls to conj! not only return the mutated object that we should be\n;; using, but they also happen to mutate the object in place that it\n;; is passed. Thus ignoring the return value happens not to lead to\n;; incorrect behavior here.\n\n;; However, conj! _can_ in some cases return a different object than\n;; the one it was passed, and _not_ mutate the object it is passed.\n;; Look at this return value.\n\nuser=> (into-bad-example-bash-in-place\n {:a 1, :b 2, :c 3, :d 4, :e 5, :f 6, :g 7, :h 8}\n {:i 9})\n{:a 1, :b 2, :c 3, :d 4, :e 5, :f 6, :g 7, :h 8}\n\n;; This result is not what we want, because key :i is not present in\n;; the result anywhere. conj! returned a different object than the\n;; one it was given, but the function above does not use the return\n;; value, instead discarding it.\n\n;; The function below uses conj! as it should be, always using its\n;; return value in future calls on the transient collection.\n\nuser=> (defn into-better-use-return-value [to-coll from-coll]\n (loop [t (transient to-coll)\n f (seq from-coll)]\n (if-let [s (seq f)]\n (recur (conj! t (first s))\n (next s))\n (persistent! t))))\n\nuser=> (into-better-use-return-value {:a 1, :b 2, :c 3} {:d 4, :e 5})\n{:a 1, :b 2, :c 3, :d 4, :e 5}\n\nuser=> (into-better-use-return-value\n {:a 1, :b 2, :c 3, :d 4, :e 5, :f 6, :g 7, :h 8}\n {:i 9})\n{:e 5, :g 7, :c 3, :h 8, :b 2, :d 4, :f 6, :i 9, :a 1}\n\n;; The keys are not in the same order, but recall that regular Clojure\n;; maps are not sorted in any predictable way, as opposed to\n;; sorted-map's. However, all 9 of the keys that we expect to be\n;; there, are there.", :_id "5e0d14f7e4b0ca44402ef804"}], :notes nil, :arglists ["" "coll" "coll x"], :doc "Adds x to the transient collection, and return coll. The 'addition'\n may happen at different 'places' depending on the concrete type.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/conj!"} {:added "1.0", :ns "clojure.core", :name "repeatedly", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1286264111000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "repeat", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c8e"} {:created-at 1289359620000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "iterate", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c8f"} {:created-at 1289359625000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "lazy-seq", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c90"} {:created-at 1295239829000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "dotimes", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c91"} {:created-at 1295239907000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "doall", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c92"} {:created-at 1343151093000, :author {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rand-int", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c93"} {:created-at 1345605379000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "constantly", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c94"} {:created-at 1502829747775, :author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "while", :ns "clojure.core"}, :_id "59935cb3e4b0d19c2ce9d717"}], :line 5143, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "citizen428", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3881a28fe402dd2d1de44717486cae8?r=PG&default=identicon"} {:login "citizen428", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3881a28fe402dd2d1de44717486cae8?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"} {:login "nyashh", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2254461eab79d5d84a021414e8e36dba?r=PG&default=identicon"} {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"} {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"} {:login "tomas", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c0c2f195479ae4a71cb6484679f6f49?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; 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)", :created-at 1279093287000, :updated-at 1421872565837, :_id "542692cfc026201cdc326e2f"} {:author {:login "Jeff Rose", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/567898c496278341be69087507d5ed24?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(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)", :created-at 1283550417000, :updated-at 1421872865341, :_id "542692cfc026201cdc326e38"} {:editors [{:login "Jjunior130", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7597818?v=3"}], :body ";;;; 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)))))]))", :author {:avatar-url "https://avatars.githubusercontent.com/u/7597818?v=3", :account-source "github", :login "Jjunior130"}, :created-at 1483821463432, :updated-at 1483821506915, :_id "58715197e4b09108c8545a50"} {:updated-at 1520597247645, :created-at 1520595747920, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; \"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", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :_id "5aa27323e4b0316c0f44f914"} {:updated-at 1576431818434, :created-at 1576431818434, :author {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/24317401?v=4"}, :body ";; 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", :_id "5df670cae4b0ca44402ef7fb"}], :notes [{:updated-at 1289359893000, :body "if the function you want to repeat doesn't have side effects and has an argument, 'iterate' may be what you are looking for.", :created-at 1289359893000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fa1"}], :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"} {:added "1.0", :ns "clojure.core", :name "zipmap", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1325197673000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "interleave", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e62"} {:created-at 1652060861458, :author {:login "KyleErhabor", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/40676441?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "into", :ns "clojure.core"}, :_id "627872bde4b0b1e3652d75ec"}], :line 3071, :examples [{:author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:avatar-url "https://avatars.githubusercontent.com/u/5696817?v=3", :account-source "github", :login "liango2"}], :body "user=> (zipmap [:a :b :c :d :e] [1 2 3 4 5])\n{:a 1, :b 2, :c 3, :d 4, :e 5}\n", :created-at 1279388151000, :updated-at 1451234587672, :_id "542692c7c026201cdc3269a8"} {:author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "liango2", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5696817?v=3"}], :body ";; 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}", :created-at 1335331821000, :updated-at 1451234612952, :_id "542692d6c026201cdc3270cb"} {:editors [{:login "ys-achinta", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/10450478?v=4"}], :body "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}}", :author {:avatar-url "https://avatars.githubusercontent.com/u/4471727?v=3", :account-source "github", :login "edbedbe"}, :created-at 1439315700433, :updated-at 1566311402870, :_id "55ca36f4e4b0080a1b79cdb9"} {:editors [{:login "tecigo", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/13831422?v=3"}], :body ";; 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\"})", :author {:avatar-url "https://avatars.githubusercontent.com/u/13831422?v=3", :account-source "github", :login "tecigo"}, :created-at 1459353469570, :updated-at 1459354350134, :_id "56fbf77de4b069b77203b858"} {:updated-at 1472949315282, :created-at 1472949315282, :author {:login "d-lord", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6218499?v=3"}, :body ";; initialize with 0 for all values\nuser=> (zipmap [:a :b :c] (repeat 0))\n{:a 0, :b 0, :c 0}", :_id "57cb6c43e4b0709b524f04e1"} {:updated-at 1488306683395, :created-at 1488306683395, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :body ";; 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", :_id "58b5c1fbe4b01f4add58fe66"} {:editors [{:login "zyxmn-rvu", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/53867608?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars1.githubusercontent.com/u/53867608?v=4", :account-source "github", :login "zyxmn-rvu"}, :created-at 1574963248718, :updated-at 1574963310117, :_id "5de00830e4b0ca44402ef7ed"} {:updated-at 1649862774454, :created-at 1649862774454, :author {:login "stindrago", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69054881?v=4"}, :body ";; 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", :_id "6256e876e4b0b1e3652d75d3"}], :notes [{:author {:login "seeeturtle", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/22187719?v=4"}, :updated-at 1553308608008, :created-at 1553308608008, :body "`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.", :_id "5c959bc0e4b0ca44402ef6c0"}], :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"} {:added "1.9", :ns "clojure.core", :name "reset-vals!", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 2383, :examples [{:updated-at 1539313237640, :created-at 1539312224752, :author {:login "WinfieldHill", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4356515?v=4"}, :body ";; 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 >>] []]", :editors [{:avatar-url "https://avatars0.githubusercontent.com/u/4356515?v=4", :account-source "github", :login "WinfieldHill"}], :_id "5bc00a60e4b00ac801ed9ed2"}], :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!"} {:added "1.0", :ns "clojure.core", :name "alter-var-root", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1322088086000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-redefs", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f28"} {:created-at 1322088098000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-redefs-fn", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f29"} {:created-at 1360641932000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "intern", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f2a"} {:created-at 1374167327000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "var", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f2b"} {:created-at 1501312693026, :author {:login "didibus", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/601540?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "set!", :ns "clojure.core"}, :_id "597c36b5e4b0d19c2ce9d702"}], :line 5505, :examples [{:updated-at 1607409758219, :created-at 1283913245000, :body "(defn sqr [n] \n \"Squares a number\"\n (* n n))\n\nuser=> (sqr 5)\n25\n\nuser=> (alter-var-root \n (var sqr) ; var to alter\n (fn [f] ; fn to apply to the var's value\n (fn [n] ; returns a new fn wrapping old fn\n (println \"Squaring\" n)\n (f n))))\n\nuser=> (sqr 5)\nSquaring 5\n25\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:login "liuchong", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/236058?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/5aa24eee4238e1e964210ed447e8dc91?r=PG&default=identicon", :account-source "clojuredocs", :login "fogus"}, :_id "542692cfc026201cdc326e70"} {:updated-at 1472301721034, :created-at 1472301721034, :author {:login "manishkumarmdb", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/9373950?v=3"}, :body ";;change the value of a var, instead of (def varName value)\nuser=> (def string \"abcd\")\n#'user/string\n\nuser=> string\n\"abcd\"\n\nuser=> (alter-var-root #'string (constantly \"wxyz\"))\n\"wxyz\"\n\nuser=> string\n\"wxyz\"", :_id "57c18a99e4b0709b524f04d6"} {:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}], :body ";; alter-var-root does not play well with inlined vars\n\n(definline timespi [x] `(* ~x 3.14))\n(alter-var-root #'timespi (fn [_] (constantly 1)))\n(timespi 10)\n;; 31.400000000000002\n\n;; Remove the inlining to pass through the var indirection (credits @bronsa)\n(alter-meta! #'timespi dissoc :inline-arities :inline)\n(timespi 10)\n;; 1", :author {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1546020626144, :updated-at 1546020907201, :_id "5c266712e4b0ca44402ef601"} {:updated-at 1648587095817, :created-at 1648587095817, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/159047?v=4"}, :body "(defn instrument-ns\n \"Add some basic instrumentation to each var in a given namespace `sut`.\n A poor man's profiler, this simply prints out the name of each\n fn (var) when run.\"\n [sut]\n (let [fs (vals (ns-interns sut))]\n (println \"Instrumenting fns to be printed as run for NS:\" sut)\n (doseq [curf fs]\n (when (some? (:arglists (meta curf))) ; ensure a fn\n (alter-var-root\n curf\n (fn [f]\n (fn [& args]\n ;; Just print out the name of the function evaluated\n (println (:name (meta curf)))\n ;; (System/currentTimeMillis) ; could add timing info before/after\n (apply f args))))))))\n", :_id "62437157e4b0b1e3652d75c4"} {:editors [{:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}], :body ";; `alter-var-root` uses the same signature as `swap!` and `update`. \n;; It has uncomfortable, persistent effects if you're not careful. \n\nuser=> (def x \"Hi\")\n#'user/x\nuser=> (alter-var-root #'x #(str % \", world!\"))\n\"Hi, world!\"\nuser=> (alter-var-root #'x #(str % \", world!\"))\n\"Hi, world!, world!\"\nuser=> (alter-var-root #'x #(str % \", world!\"))\n\"Hi, world!, world!, world!\"\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4", :account-source "github", :login "Crowbrammer"}, :created-at 1653498578027, :updated-at 1653498619629, :_id "628e62d2e4b0b1e3652d75f1"}], :notes nil, :arglists ["v f & args"], :doc "Atomically alters the root binding of var v by applying f to its\n current value plus any args", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/alter-var-root"} {:added "1.0", :ns "clojure.core", :name "biginteger", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1509577866305, :author {:login "chrm", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/448995?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bigint", :ns "clojure.core"}, :_id "59fa548ae4b0a08026c48c92"}], :line 3633, :examples [{:author {:login "linxiangyu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2c7492645426ece4ae86fde83d61bd03?r=PG&default=identicon"}, :editors [], :body "user=> (def x (biginteger 19931029))\n#'user/x\nuser=> (class x)\njava.math.BigInteger\n\n\n\n", :created-at 1370558225000, :updated-at 1370558225000, :_id "542692d2c026201cdc326f53"} {:updated-at 1509577857859, :created-at 1509577857859, :author {:login "chrm", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/448995?v=4"}, :body ";; There is a difference between `BigInt` and `BigInteger`. The first is from\n;; Clojure and should be better for performace, because less unboxing is\n;; necessary. The second is from Java and has more functionality.\n;; https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html\n\n(type 123N)\n;; => clojure.lang.BigInt\n\n(type (bigint 123))\n;; => clojure.lang.BigInt\n\n(type (biginteger 123))\n;; => java.math.BigInteger\n\n(.modInverse (bigint 123) (bigint 4))\n;; IllegalArgumentException No matching method found: modInverse for class\n;; clojure.lang.BigInt\n\n(.modInverse (biginteger 123) (biginteger 4))\n;; => 3", :_id "59fa5481e4b0a08026c48c91"} {:editors [{:login "cloojure", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/7083783?v=4"}], :body "; It also works for strings\n(biginteger \"12345\") => 12345 ; java.math.BigInteger\n", :author {:avatar-url "https://avatars0.githubusercontent.com/u/7083783?v=4", :account-source "github", :login "cloojure"}, :created-at 1535909938405, :updated-at 1535910003220, :_id "5b8c2032e4b00ac801ed9e7f"} {:updated-at 1598221345110, :created-at 1598221345110, :author {:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}, :body ";; Take care with ratios the decimal part is removed not rounded\nuser=> (biginteger 5/4) ; 1.25\n;; 1\n\nuser=> (biginteger 5/2) ; 2.5\n;; 2", :_id "5f42ec21e4b0b1e3652d73a8"}], :notes nil, :tag "java.math.BigInteger", :arglists ["x"], :doc "Coerce to BigInteger", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/biginteger"} {:added "1.0", :ns "clojure.core", :name "remove", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1282310768000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "filter", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cee"} {:created-at 1487135935513, :author {:login "chrismurrph", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10278575?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "group-by", :ns "clojure.core"}, :_id "58a3e4bfe4b01f4add58fe55"} {:created-at 1501184742340, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "keep", :ns "clojure.core"}, :_id "597a42e6e4b0d19c2ce9d701"}], :line 2826, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "sir-pinecone", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/40753?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(remove pos? [1 -2 2 -1 3 7 0])\n;;=> (-2 -1 0)\n\n(remove nil? [1 nil 2 nil 3 nil])\n;;=> (1 2 3)\n\n;; remove items that are evenly divisible by 3\n(remove #(zero? (mod % 3)) (range 1 21))\n;;=> (1 2 4 5 7 8 10 11 13 14 16 17 19 20)", :created-at 1281548721000, :updated-at 1420744145542, :_id "542692cfc026201cdc326e3c"} {:body ";; compare to filter\n\n(remove even? (range 10))\n;;=> (1 3 5 7 9)\n\n(remove (fn [x]\n (= (count x) 1))\n [\"a\" \"aa\" \"b\" \"n\" \"f\" \"lisp\" \"clojure\" \"q\" \"\"])\n;;=> (\"aa\" \"lisp\" \"clojure\" \"\")\n\n; When coll is a map, pred is called with key/value pairs.\n(remove #(> (second %) 100)\n {:a 1\n :b 2\n :c 101\n :d 102\n :e -1})\n;;=> ([:a 1] [:b 2] [:e -1])\n", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :created-at 1420744060322, :updated-at 1420744060322, :_id "54aed57ce4b0e2ac61831ca0"} {:updated-at 1453292141320, :created-at 1453292141320, :author {:login "esumitra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/98965?v=3"}, :body ";; remove items from a set/list\n\n(remove #{:a} #{:b :c :d :a :e})\n;;=> (:e :c :b :d)\n\n(remove #{:a} [:b :c :d :a :e :a :f])\n;;=> (:b :c :d :e :f)\n", :_id "569f7a6de4b060004fc217af"} {:updated-at 1516533045589, :created-at 1516533045589, :author {:login "vastus", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/199064?v=4"}, :body ";; use map as a pred\n\n(remove {:a 42 :b 69} #{:a :b :c})\n;;=> (:c)", :_id "5a647535e4b0637c3b2baf4c"} {:updated-at 1594561061837, :created-at 1594561061837, :author {:login "kevinmungai", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/23656776?v=4"}, :body ";; remove all the hyphens in an ISBN Number\n\n(into [] (remove #{\\-}) \"3-598-21508-8\")\n;;=> [\\3 \\5 \\9 \\8 \\2 \\1 \\5 \\0 \\8 \\8]\n\n;; remove is used in the capacity of a transducer", :_id "5f0b1225e4b0b1e3652d7321"} {:updated-at 1601477483307, :created-at 1601477483307, :author {:login "E-A-Griffin", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/53583563?v=4"}, :body ";; remove unique elements from collection\n\n(def nums (concat (range 10) (range 5 15)))\n\n(keys (remove (fn [[k v]] (= v 1))\n (frequencies nums)))\n;;=> (7 6 9 5 8)\n\n;; remove unique elements from collection, preserving order\n(defn keep-duplicates [coll]\n (sort-by #((into {} (map-indexed vector coll)) %) \n (keys (remove (fn [[k v]] (= v 1))\n (frequencies coll)))))\n\n(keep-duplicates nums)\n;; => (5 6 7 8 9)\n\n(def rev-nums (reverse nums))\n\n(keep-duplicates rev-nums)\n;;=> (9 8 7 6 5)", :_id "5f749b6be4b0b1e3652d73c6"}], :notes nil, :arglists ["pred" "pred coll"], :doc "Returns a lazy sequence of the items in coll for which\n (pred item) returns logical false. pred must be free of side-effects.\n Returns a transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/remove"} {:added "1.2", :ns "clojure.core", :name "*", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1323065497000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "*'", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ca8"} {:created-at 1423527840855, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "unchecked-multiply", :library-url "https://github.com/clojure/clojure"}, :_id "54d94fa0e4b081e022073c88"}], :line 1008, :examples [{:author {:login "samaaron", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ee3512261f38df2541b9adca77f025cb?r=PG&default=identicon"}, :editors [{:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jmglov", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/67e9a6f766dc4b30bd5e9ff3e77c1777?r=PG&default=identicon"} {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"} {:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}], :body ";; 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(* 8 1/2)\n;;=> 4N\n\n(* 1234567890 9876543210)\n;; ArithmeticException integer overflow", :created-at 1278738436000, :updated-at 1598154236190, :_id "542692c8c026201cdc326a45"}], :notes nil, :arglists ["" "x" "x y" "x y & more"], :doc "Returns the product of nums. (*) returns 1. Does not auto-promote\n longs, will throw on overflow. See also: *'", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*"} {:added "1.0", :ns "clojure.core", :name "re-pattern", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289146513000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "re-find", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b2f"} {:created-at 1324450178000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.string", :name "replace", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b30"} {:created-at 1324450182000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.string", :name "replace-first", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b31"}], :line 4839, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "NielsK", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/11ab6518d419df03c4883af80b5697ee?r=PG&default=identicon"}], :body "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", :created-at 1280547138000, :updated-at 1365007458000, :_id "542692c6c026201cdc3268c7"}], :notes [{:author {:login "nuggets510", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/5713182?v=4"}, :updated-at 1567898080855, :created-at 1567898080855, :body "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", :_id "5d7439e0e4b0ca44402ef7ae"}], :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"} {:added "1.0", :ns "clojure.core", :name "min", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1371841114000, :author {:login "adereth", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5ad11b4e208a6cdb3bd45fe01dea59b7?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "max", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f10"} {:created-at 1371841126000, :author {:login "adereth", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5ad11b4e208a6cdb3bd45fe01dea59b7?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "min-key", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f11"}], :line 1125, :examples [{:updated-at 1332951489000, :created-at 1279417619000, :body "user=> (min 1 2 3 4 5) \n1\nuser=> (min 5 4 3 2 1)\n1\nuser=> (min 100)\n100", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"}], :author {:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"}, :_id "542692cfc026201cdc326e7a"} {:author {:login "jmglov", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/67e9a6f766dc4b30bd5e9ff3e77c1777?r=PG&default=identicon"}, :editors [], :body ";; If elements are already in a sequence, use apply\nuser=> (apply min [1 2 3 4 3])\n1\nuser=> (apply min '(4 3 5 6 2))\n2", :created-at 1392661837000, :updated-at 1392661837000, :_id "542692d4c026201cdc327011"}], :notes nil, :arglists ["x" "x y" "x y & more"], :doc "Returns the least of the nums.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/min"} {:added "1.1", :ns "clojure.core", :name "pop!", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1329970267000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "assoc!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dcf"} {:created-at 1329970271000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "dissoc!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dd0"} {:created-at 1577916147025, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "conj!", :ns "clojure.core"}, :_id "5e0d16f3e4b0ca44402ef80a"}], :line 3392, :examples [{:updated-at 1577916129615, :created-at 1307739212000, :body ";; Note how we always use the return value of pop! in these examples\n;; for all future modifications, rather than (incorrectly) ignoring the return\n;; value and continuing to modify the original transient set. See examples for\n;; assoc! and dissoc! for more discussion and examples of this.\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\nuser=> (def foo (transient [1 2 3]))\n#'user/foo\nuser=> (count foo)\n3\nuser=> (def foo (pop! foo))\n#'user/foo\nuser=> foo\n#\nuser=> (count foo)\n2\nuser=> (def foo (pop! foo))\n#'user/foo\nuser=> (count foo)\n1\nuser=> (def foo (persistent! foo))\n#'user/foo\nuser=> (count foo)\n1\nuser=> foo\n[1]\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"}], :author {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"}, :_id "542692c7c026201cdc3269ce"}], :notes nil, :arglists ["coll"], :doc "Removes the last item from a transient vector. If\n the collection is empty, throws an exception. Returns coll", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/pop!"} {:ns "clojure.core", :name "chunk-append", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1443937484077, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk-buffer", :ns "clojure.core"}, :_id "5610bccce4b0686557fcbd51"} {:created-at 1443937492439, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk", :ns "clojure.core"}, :_id "5610bcd4e4b08e404b6c1ca4"}], :line 695, :examples [{:updated-at 1443937472462, :created-at 1443937472462, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :body "(let [buf (chunk-buffer 16)]\n ;; Mutably append elements to the ChunkedBuffer\n (dotimes [n 10]\n (chunk-append buf n))\n\n ;; Demonstrate pulling elements out.\n ;; Note that the `capacity` we set above (16) for `buf`.\n (let [ch (chunk buf)]\n (for [n (range 0 17)]\n (try (.nth ch n)\n (catch ArrayIndexOutOfBoundsException e\n \"too far!\")))))\n\n;; => (0 1 2 3 4 5 6 7 8 9 nil nil nil nil nil nil \"too far!\")", :_id "5610bcc0e4b08e404b6c1ca3"}], :notes nil, :arglists ["b x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/chunk-append"} {:added "1.0", :ns "clojure.core", :name "prn-str", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1315392416000, :author {:login "srid", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bd3a68d670372cd09876c26270a4299a?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "prn", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aca"} {:created-at 1412284928324, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.edn", :name "read-string", :library-url "https://github.com/clojure/clojure"}, :_id "542dc200e4b05f4d257a299a"}], :line 4745, :examples [{:updated-at 1495025858123, :created-at 1284257994000, :body "user=> (def x \"Hello!\\nMy name is George.\\n\")\n#'user/x\n\nuser=> (prn-str x)\n=> \"\\\"Hello!\\\\nMy name is George.\\\\n\\\"\\n\"\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://www.gravatar.com/avatar/7c45f63f61e478233f0c2ad3006b178c?r=PG&default=identicon", :account-source "clojuredocs", :login "mdemare"} {:avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon", :account-source "clojuredocs", :login "Miles"} {:avatar-url "https://www.gravatar.com/avatar/890d46f8c0e24dd6fb8546095b1144e?r=PG&default=identicon", :account-source "clojuredocs", :login "haplo"} {:login "flyjwayur", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11784820?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon", :account-source "clojuredocs", :login "Miles"}, :_id "542692cac026201cdc326b1d"} {:updated-at 1522767399827, :created-at 1522767399827, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :body ";; Be aware that prn-str and friends are influenced by a couple global variables\n;; such as *print-length*:\n\n(set! *print-length* 10)\n(prn-str (range 15))\n;=> \"(0 1 2 3 4 5 6 7 8 9 ...)\\n\"\n\n(set! *print-length* -1)\n(prn-str (range 15))\n;=> \"(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14)\\n\"", :_id "5ac39627e4b045c27b7fac33"} {:updated-at 1664293623051, :created-at 1664293623051, :author {:login "jzwolak", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/285725?v=4"}, :body ";; Also, set! cannot change the root binding for *print-length*.\n;; Try the following instead.\n\n(def v [1 2 3 4 5 6 7 8 9 10])\n\n(binding [*print-length* 5] (prn-str v))\n;;=> \"[1 2 3 4 5 ...]\\n\"\n\n(binding [*print-length* -1] (prn-str v))\n;;=> \"[1 2 3 4 5 6 7 8 9 10]\\n\"", :_id "63331af7e4b0b1e3652d766a"}], :notes nil, :tag "java.lang.String", :arglists ["& xs"], :doc "prn to a string, returning it", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/prn-str"} {:added "1.0", :ns "clojure.core", :name "with-precision", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1635281422222, :author {:login "Chouser", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/36110?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "*math-context*", :ns "clojure.core"}, :_id "61786a0ee4b0b1e3652d755b"}], :line 5086, :examples [{:author {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"} {:login "wdkrnls", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/6d08a2f792f289b95fe1d982d4133d71?r=PG&default=identicon"}], :body ";; 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", :created-at 1283812216000, :updated-at 1310865949000, :_id "542692cbc026201cdc326bb1"} {:editors [{:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars1.githubusercontent.com/u/8399149?v=3", :account-source "github", :login "freckletonj"}, :created-at 1490739966308, :updated-at 1524219715125, :_id "58dae2fee4b01f4add58fe7e"}], :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"} {:added "1.0", :ns "clojure.core", :name "format", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1330170781000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "printf", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dbc"} {:created-at 1330170789000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.pprint", :name "cl-format", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dbd"} {:created-at 1330170796000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.pprint", :name "print-table", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dbe"}], :line 5738, :examples [{:author {:login "Jacolyte", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon"}, :editors [{:login "Jacolyte", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"}], :body ";; See http://download.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html\n;; for formatting options.\nuser=> (format \"Hello there, %s\" \"bob\")\n\"Hello there, bob\"\n", :created-at 1279854390000, :updated-at 1317218923000, :_id "542692c6c026201cdc3268ef"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "thethomaseffect", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b4330b8e3ed048b2aa3b50183c42e600?r=PG&default=identicon"}], :body "user=> (format \"%5d\" 3)\n\" 3\"\n\nuser=> (format \"Pad with leading zeros %07d\" 5432)\n\"Pad with leading zeros 0005432\"\n\nuser=> (format \"Left justified :%-7d:\" 5432)\n\"Left justified :5432 :\"\n\nuser=> (format \"Locale-specific group separators %,12d\" 1234567)\n\"Locale-specific group separators 1,234,567\"\n\nuser=> (format \"decimal %d octal %o hex %x upper-case hex %X\" 63 63 63 63)\n\"decimal 63 octal 77 hex 3f upper-case hex 3F\"\n\nuser=> (format \"%2$d %1$s\" \"Positional arguments\" 23)\n\"23 Positional arguments\"\n\n;; ====== Clojure format/printf and large integers =====\n\n;; This big number doesn't fit in a Long. It is a\n;; clojure.lang.BigInt, which format cannot handle directly.\nuser=> (format \"%5d\" 12345678901234567890)\nIllegalFormatConversionException d != clojure.lang.BigInt java.util.Formatter$FormatSpecifier.failConversion (Formatter.java:3999)\n\n;; You can convert it to a java.math.BigInteger, which format does handle.\nuser=> (format \"%5d\" (biginteger 12345678901234567890))\n\"12345678901234567890\"\n\n;; If you do this very often, you might want to use something like\n;; format-plus to avoid sprinkling your code with calls to biginteger.\n(defn coerce-unformattable-types [args]\n (map (fn [x]\n (cond (instance? clojure.lang.BigInt x) (biginteger x)\n (instance? clojure.lang.Ratio x) (double x)\n :else x))\n args))\n\n(defn format-plus [fmt & args]\n (apply format fmt (coerce-unformattable-types args)))\n\n;; Now this works:\nuser=> (format-plus \"%5d\" 12345678901234567890)\n\"12345678901234567890\"", :created-at 1331440228000, :updated-at 1389568458000, :_id "542692d3c026201cdc326fab"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; ==== Clojure format/printf and floating-point formats ====\nuser=> (format \"%.3f\" 2.0)\n\"2.000\"\n\n;; format doesn't handle integers or ratios with %e, %f, %g, or %a\nuser=> (format \"%.3f\" 2)\nIllegalFormatConversionException f != java.lang.Long java.util.Formatter$FormatSpecifier.failConversion (Formatter.java:3999)\n\n;; In general, if you want to use floating-point formats %e, %f, %g,\n;; or %a with format or printf, and you don't know whether the values\n;; you want to format are floats or doubles, you should convert them:\nuser=> (format \"%.3f\" (double 2))\n\"2.000\"\n\nuser=> (format \"%.3f\" (double (/ 5 2)))\n\"2.500\"\n\n;; One could make a function that parses the format string to look for\n;; %f and other floating-point formats and automatically coerces the\n;; corresponding arguments to doubles, but such a function probably\n;; wouldn't fit into a short example. You could also consider using\n;; cl-format which does handle these kinds of things for you. The main\n;; disadvantage to doing so is that you have to learn a different syntax\n;; for format specifiers.", :created-at 1331440712000, :updated-at 1332477536000, :_id "542692d3c026201cdc326fb0"} {:editors [{:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}], :body ";; format doesn't know what nil should look like:\nuser=> (format \"%s\" nil)\n\"null\"\n;; You can use cl-format in this situation:\nuser=> (clojure.pprint/cl-format nil \"~s\" nil)\n\"nil\"\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3", :account-source "github", :login "mars0i"}, :created-at 1437887089127, :updated-at 1437887151600, :_id "55b46a71e4b06a85937088b4"} {:updated-at 1647195081731, :created-at 1647195081731, :author {:login "andreasguther", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/9425214?v=4"}, :body ";; To use the percent sign % you need to escape it with %: %%\nuser=> (format \"%.2f %%\" 2.5)\n\"2.50 %\"", :_id "622e33c9e4b0b1e3652d75ba"} {:updated-at 1663142162249, :created-at 1663142162249, :author {:login "Kynde", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1169360?v=4"}, :body ";; Do notice that it uses the host locale for formatting.\n;; E.g. With Finnish locale it uses comma for separator.\nuser=> (format \"%.2f\" 1.23)\n\"1,23\"\n\n;; You can use the java.lang.String/format to force it.\nuser=> (java.lang.String/format java.util.Locale/US \"%.2f\" (to-array [1.23]))\n\"1.23\"\n\n;; You can override the default, but this affects other things, too.\nuser=> (java.util.Locale/setDefault java.util.Locale/US)\nnil\n\nuser=> (format \"%.2f\" 1.23)\n\"1.23\"\n\n\n", :_id "63218912e4b0b1e3652d7662"}], :notes [{:body "Note that `(format)` is [not currently supported](http://dev.clojure.org/jira/browse/CLJS-324) in ClojureScript, only in Clojure.", :created-at 1438119290177, :updated-at 1438119315501, :author {:avatar-url "https://avatars.githubusercontent.com/u/94482?v=3", :account-source "github", :login "timgilbert"}, :_id "55b7f57ae4b0080a1b79cdb4"} {:author {:login "PEZ", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/30010?v=4"}, :updated-at 1663758017937, :created-at 1663758017937, :body "For ClojureScript there is https://github.com/quoll/clormat. As of this writing it is new and because of that maybe not always fully compliant. Afaiu the goal is to make it fully compliant.", :_id "632aeec1e4b0b1e3652d7664"} {:author {:login "grav", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/119222?v=4"}, :updated-at 1691054508569, :created-at 1691054508569, :body "There's also [Google Closure's format](https://google.github.io/closure-library/api/goog.string.format.html) for ClojureScript. [Example usage](https://tech.toryanderson.com/2020/10/22/zero-padding-and-truncating-with-string-formats-in-clojurescript/).", :_id "64cb71ace4b08cf8563f4bd8"}], :arglists ["fmt & args"], :doc "Formats a string using java.lang.String.format, see java.util.Formatter for format\n string syntax", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/format"} {:added "1.0", :ns "clojure.core", :name "reversible?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 6268, :examples [{:author {:login "replore", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e7869fe1a48cb1814c657eaca6bea3eb?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "user=> (reversible? [])\ntrue\nuser=> (reversible? (sorted-map))\ntrue\nuser=> (reversible? (sorted-set))\ntrue\nuser=> (reversible? '())\nfalse\nuser=> (reversible? {})\nfalse\nuser=> (reversible? #{})\nfalse", :created-at 1321359686000, :updated-at 1423095216846, :_id "542692d5c026201cdc327076"}], :notes nil, :arglists ["coll"], :doc "Returns true if coll implements Reversible", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reversible_q"} {:added "1.0", :ns "clojure.core", :name "shutdown-agents", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1285923562000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "send", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ae5"} {:created-at 1285923568000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "send-off", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ae6"} {:created-at 1285923576000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "agent", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ae7"} {:created-at 1285923589000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "agent-error", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ae8"} {:created-at 1559240451680, :author {:login "pdbrown", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1607096?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "set-agent-send-executor!", :ns "clojure.core"}, :_id "5cf01f03e4b0ca44402ef737"} {:created-at 1559240460246, :author {:login "pdbrown", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1607096?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "set-agent-send-off-executor!", :ns "clojure.core"}, :_id "5cf01f0ce4b0ca44402ef738"}], :line 2254, :examples [{:author {:login "taylor.sando", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c127297f5548f7275ded1428aa5518bb?r=PG&default=identicon"}, :editors [], :body ";; Creating an agent\nuser> (def a (agent 1))\n#'user/a\n\n;; Create a function that can handle an agent\n\nuser> (defn agent-action [a]\n\t33)\n#'user/agent-action\n\n;; The agent will become 33\nuser> (send-off a agent-action)\n#\n\nuser> @a\n33\n;; Create another agent before shutdown\nuser> (def c (agent 3))\n#'user/c\n\n;; Shutdown agents is called\nuser> (shutdown-agents)\nnil\n\n;; Attempt to turn c into 33\nuser> (send c agent-action)\n#\n\n;; The result is that it is still the same value it was initialized with\nuser> @c\n3\n\n;; Agent created after shutdown\nuser> (def d (agent 4))\n#'user/d\n\n;; Try sending it\nuser> (send d agent-action)\n#\n\n;; Same thing, there are no threads to process the agents\nuser> @d\n4", :created-at 1349607696000, :updated-at 1349607696000, :_id "542692d5c026201cdc327084"} {:author {:login "taylor.sando", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c127297f5548f7275ded1428aa5518bb?r=PG&default=identicon"}, :editors [], :body ";; Create the agent that we will be using\nuser=> (def a (agent 0))\n#'user/a\n\n;; Dereference the agent to show the value is 0\nuser=> @a\n0\n\n;; Create a function that can increment the agent\n;; This will continually update the value of the agent\nuser=> (defn agent-inc [a]\n (send-off *agent* agent-inc)\n (inc a))\n#'user/agent-inc\n\n;; Send the agent to the agent-inc function\n;; The value is 188 because by the time the repl has sent off the\n;; agent to the function, the function has already been called recursively\nuser=> (send a agent-inc)\n#\n\n;; Dereference of the value a second or so later\nuser=> @a\n716889\n\n;; Another dereference in another couple of seconds\nuser=> @a\n1455264\n\n;; Shutdown the threads for the agents\nuser=> (shutdown-agents)\nnil\n\n;; Dereference the agent to see what value it is\nuser=> @a\n3522353\n\n;; Dereference the agent again in a few seconds\n;; It's the same value, because the agent pool of threads are no longer\n;; active\nuser=> @a\n3522353\n", :created-at 1349608162000, :updated-at 1349608162000, :_id "542692d5c026201cdc327085"}], :notes nil, :arglists [""], :doc "Initiates a shutdown of the thread pools that back the agent\n system. Running actions will complete, but no new actions will be\n accepted", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/shutdown-agents"} {:added "1.0", :ns "clojure.core", :name "conj", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1297212938000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "cons", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d76"} {:created-at 1398537407000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "into", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d77"} {:created-at 1400493822000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "peek", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d78"} {:created-at 1400493828000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "pop", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d79"} {:created-at 1430745236745, :author {:login "jw-00000", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2936?v=3"}, :to-var {:ns "clojure.core", :name "concat", :library-url "https://github.com/clojure/clojure"}, :_id "55477094e4b01bb732af0a91"} {:created-at 1528231331314, :author {:login "miner", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/25400?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "conj!", :ns "clojure.core"}, :_id "5b16f5a3e4b00ac801ed9e0c"} {:created-at 1544351725441, :author {:login "l3nz", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1101849?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "assoc", :ns "clojure.core"}, :_id "5c0cefede4b0ca44402ef5e8"} {:created-at 1561679674033, :author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "disj", :ns "clojure.core"}, :_id "5d15573ae4b0ca44402ef778"}], :line 75, :examples [{:author {:login "MrHus", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Steve", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/454ce0be068cbbf25ee685af20dc7cd6?r=PG&default=identicon"} {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"} {:login "Wilfred", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1f86c0bc40235a9edf351a16b859aabd?r=PG&default=identicon"} {:login "ElieLabeca", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/724e1112a2be4d5af767c0cf152d087e?r=PG&default=identicon"} {:login "ElieLabeca", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/724e1112a2be4d5af767c0cf152d087e?r=PG&default=identicon"} {:login "s_prakash_joy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7704115a8be45640094d5d9fc6f4e22a?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"} {:login "alidcastano", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/11031952?v=4"}], :body ";; notice that conjoining to a vector is done at the end\n(conj [1 2 3] 4)\n;;=> [1 2 3 4]\n\n;; notice conjoining to a list is done at the beginning\n(conj '(1 2 3) 4)\n;;=> (4 1 2 3)\n\n(conj [\"a\" \"b\" \"c\"] \"d\")\n;;=> [\"a\" \"b\" \"c\" \"d\"]\n\n;; conjoining multiple items is done in order\n(conj [1 2] 3 4) \n;;=> [1 2 3 4]\n\n(conj '(1 2) 3 4) \n;;=> (4 3 1 2)\n\n(conj [[1 2] [3 4]] [5 6]) \n;;=> [[1 2] [3 4] [5 6]]\n\n;; conjoining to maps only take items as vectors of length exactly 2\n(conj {1 2, 3 4} [5 6])\n;;=> {5 6, 1 2, 3 4}\n\n(conj {:firstname \"John\" :lastname \"Doe\"} {:age 25 :nationality \"Chinese\"})\n;;=> {:firstname \"John\", :lastname \"Doe\", :age 25, :nationality \"Chinese\"}\n\n;; conj on a set\n(conj #{1 3 4} 2)\n;;=> #{1 2 3 4}\n\n", :created-at 1279417029000, :updated-at 1582210748471, :_id "542692c9c026201cdc326abc"} {:author {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"}, :editors [{:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"} {:login "Thumbnail", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/db68e51797a2382e185b42ce6534b7a4?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; conjoin shows similar behaviour to cons\n;; The main difference being that conj works on collections\n;; but cons works with seqs. \n(conj [\"a\" \"b\" \"c\"] [\"a\" \"b\" \"c\"] )\n;;=> [\"a\" \"b\" \"c\" [\"a\" \"b\" \"c\"]]", :created-at 1342724544000, :updated-at 1420652159670, :_id "542692d2c026201cdc326f6d"} {:author {:login "jamesqiu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc1268deaa7f2e78fe2b5ea76e6481d8?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; conjoin nil with x or xs\n(conj nil 3)\n;;=> (3)\n\n(conj nil 3 4)\n;;=> (4 3)", :created-at 1349714643000, :updated-at 1420652257330, :_id "542692d2c026201cdc326f70"} {:author {:login "Alan Thompson", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5b677647e3c6fb2bc89fa2f481461b11?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; maps and sets are treated differently\n(conj {1 2} {3 4})\n;;=> {3 4, 1 2} ; the contents of {3 4} are added to {1 2}\n\n(conj #{1 2} #{3})\n;;=> #{1 2 #{3}} ; the whole set #{3} is added to #{1 2}\n\n(clojure.set/union #{1 2} #{3})\n;;=> #{1 2 3} ; must use (clojure.set/union) to merge sets, not conj\n", :created-at 1392346414000, :updated-at 1420652309845, :_id "542692d2c026201cdc326f71"} {:body ";; When conjoining into a map, vector pairs may be provided:\n(conj {:a 1} [:b 2] [:c 3])\n;;=> {:c 3, :b 2, :a 1}\n\n;; Or maps may be provided, with multiple pairings:\n(conj {:a 1} {:b 2 :c 3} {:d 4 :e 5 :f 6})\n;;=> {:f 6, :d 4, :e 5, :b 2, :c 3, :a 1}\n\n;; But multiple pairings cannot appear in vectors:\n(conj {:a 1} [:b 2 :c 3])\n;;=> IllegalArgumentException Vector arg to map conj must be a pair...\n\n;; And pairs may not be provided in lists:\n(conj {:a 1} '(:b 2))\n;;=> ClassCastException ...Keyword cannot be cast to ...Map$Entry...\n", :author {:login "fordsfords", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7671908?v=3"}, :created-at 1417527012413, :updated-at 1417527012413, :_id "547dbee4e4b03d20a10242bb"} {:updated-at 1453750686379, :created-at 1453750686379, :author {:login "bsima", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/200617?v=3"}, :body ";; Useful snippet: \"merge\" two or more vectors with `(comp vec flatten conj)`\n(let [a [{:a \"hi\"} {:b \"hey\"}]\n b [{:c \"yo\"} {:d \"hiya\"}]\n c [{:e \"bonjour\"}]]\n ((comp vec flatten conj) a b c))\n;;=> [{:a \"hi\"} {:b \"hey\"} {:c \"yo\"} {:d \"hiya\"} {:e \"bonjour\"}]", :_id "56a6799ee4b060004fc217b0"} {:updated-at 1456128447651, :created-at 1456128447651, :author {:login "yinwuzhe", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5061317?v=3"}, :body "(conj nil 1)\n;=>(1)\n(conj nil [1 2])\n;=>([1 2])\n", :_id "56cac1bfe4b060004fc217cb"} {:editors [{:login "edcaceres", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/782909?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/1191123?v=3", :account-source "github", :login "TheCodingGent"}], :body ";; Conj new-element into nested structures \"conj-in\"\n\n(def db {:users [{:name \"Eduardo\"}]})\n(def new-element {:name \"Eva\"})\n\n(assoc db :users (conj (:users db) new-element))\n;; => {:users [{:name \"Eduardo\"} {:name \"Eva\"}]}", :author {:avatar-url "https://avatars.githubusercontent.com/u/782909?v=3", :account-source "github", :login "edcaceres"}, :created-at 1479821999279, :updated-at 1483975466743, :_id "58344aafe4b0782b632278c2"} {:editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}], :body ";; implement stack semantics with conj, peek and pop.\n\n;; we start with a list\n(def stack '(2 1 0))\n\n(peek stack)\n;; => 2\n(pop stack)\n;; => (1 0)\n(type (pop stack))\n;; => cljs.core/List\n;; push = conj\n(conj stack 3)\n;; => (3 2 1 0)\n(type (conj stack 3))\n;; => cljs.core/List\n\n;; now let us try a vector\n(def stack [0 1 2])\n\n(peek stack)\n;; => 2\n(pop stack)\n;; => [0 1]\n(type (pop stack))\n;; => clojure.lang.PersistentVector\n;; push = conj\n(conj stack 3)\n;; => [0 1 2 3]\n(type (conj stack 3))\n;; => clojure.lang.PersistentVector\n", :author {:avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4", :account-source "github", :login "phreed"}, :created-at 1510596733632, :updated-at 1510597245457, :_id "5a09e07de4b0a08026c48cb7"} {:editors [{:login "asifm", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/3958387?v=4"}], :body ";; Based on examples from the great book CLOJURE for the BRAVE and TRUE\n;; https://www.braveclojure.com/core-functions-in-depth/\n\n(defn add-first-vec\n\t[target addition]\n\t(apply conj (if (vector? addition) addition [addition]) target))\n\n(add-first-vec [3 4 5 6] 1)\n;; [1 3 4 5 6]\n\n(add-first-vec [3 4 5 6] [1 2])\n;; [1 2 3 4 5 6]", :author {:avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4", :account-source "github", :login "berczeck"}, :created-at 1598229602892, :updated-at 1665916664510, :_id "5f430c62e4b0b1e3652d73aa"} {:updated-at 1678381486402, :created-at 1678381486402, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; conj also has other, undocumented arities:\n\n(conj)\n;; => []\n\n(conj [1 2 3])\n;; => [1 2 3]\n\n;; Which are particularly useful when transducing, as the nullary form can be\n;; used to produce init, and the unary form for completion", :_id "640a11aee4b08cf8563f4b7b"}], :notes [{:author {:login "me7", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10399270?v=3"}, :updated-at 1456199923502, :created-at 1456199923502, :body "list prepend\nvector append", :_id "56cbd8f3e4b02a6769b5a4b1"}], :arglists ["coll x" "coll x & xs"], :doc "conj[oin]. Returns a new collection with the xs\n 'added'. (conj nil item) returns (item). The 'addition' may\n happen at different 'places' depending on the concrete type.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/conj"} {:added "1.2", :ns "clojure.core", :name "bound?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1328397785000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "thread-bound?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521af8"}], :line 5512, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}], :body "user=> (def foobar)\n#'user/foobar\nuser=> (bound? #'foobar)\nfalse\nuser=> (def boing 10)\n#'user/boing\nuser=> (bound? #'boing)\ntrue\nuser=> (defn plus3 [n] (+ 3 n))\n#'user/plus3\nuser=> (bound? #'plus3)\ntrue\n", :created-at 1279073551000, :updated-at 1318467872000, :_id "542692cdc026201cdc326ce1"}], :notes nil, :arglists ["& vars"], :doc "Returns true if all of the vars provided as arguments have any bound value, root or thread-local.\n Implies that deref'ing the provided vars will succeed. Returns true if no vars are provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bound_q"} {:added "1.7", :ns "clojure.core", :name "transduce", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1459164080889, :author {:login "optevo", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1281179?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "completing", :ns "clojure.core"}, :_id "56f913b0e4b09295d75dbf41"}], :line 6870, :examples [{:editors [{:login "bsvingen", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1647562?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/1647562?v=3", :account-source "github", :login "bsvingen"}, :created-at 1435874975857, :updated-at 1435878735757, :_id "5595b69fe4b00f9508fd66f1"} {:updated-at 1473877511741, :created-at 1473871425560, :author {:login "upgradingdave", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/939229?v=3"}, :body ";; 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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/939229?v=3", :account-source "github", :login "upgradingdave"}], :_id "57d97e41e4b0709b524f04f7"} {:updated-at 1483049703082, :created-at 1483049703082, :author {:login "jvanderhyde", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6516608?v=3"}, :body ";; 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", :_id "58658ae7e4b0fd5fb1cc964d"} {:editors [{:login "vspinu", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1363467?v=3"}], :body ";;; 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", :author {:avatar-url "https://avatars0.githubusercontent.com/u/1363467?v=3", :account-source "github", :login "vspinu"}, :created-at 1498561912432, :updated-at 1498561969340, :_id "59523d78e4b06e730307db43"} {:updated-at 1586130966542, :created-at 1586130966542, :author {:login "didibus", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/601540?v=4"}, :body "(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])", :_id "5e8a7016e4b087629b5a18cb"} {:editors [{:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :body ";; 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.", :author {:avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4", :account-source "github", :login "tomdl89"}, :created-at 1678020807238, :updated-at 1678381890546, :_id "640490c7e4b08cf8563f4b78"}], :notes [{:author {:login "jvanderhyde", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6516608?v=3"}, :updated-at 1483050000710, :created-at 1483050000710, :body "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.", :_id "58658c10e4b0fd5fb1cc964e"}], :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"} {:added "1.0", :ns "clojure.core", :name "lazy-seq", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1318395998000, :author {:login "haplo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/890d46f8c0e24dd6fb8546095b1144e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "lazy-cat", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ed7"} {:created-at 1322679999000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "realized?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ed8"} {:created-at 1322680082000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "doall", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ed9"} {:created-at 1370143899000, :author {:login "Mark Addleman", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/768de71b6c873394290733acf422b4d5?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "iterate", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eda"}], :line 683, :examples [{:updated-at 1448773249031, :created-at 1281346189000, :body ";; The following defines a lazy-seq of all positive numbers. Note that \n;; the lazy-seq allows us to make a recursive call in a safe way because\n;; the call does not happen immediately but instead creates a closure.\n\nuser=> (defn positive-numbers \n\t([] (positive-numbers 1))\n\t([n] (lazy-seq (cons n (positive-numbers (inc n))))))\n#'user/positive-numbers\n\nuser=> (take 5 (positive-numbers))\n(1 2 3 4 5)\n\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://www.gravatar.com/avatar/299a3fab7a1a2d6644455dedae9fce0a?r=PG&default=identicon", :account-source "clojuredocs", :login "Stathis Sideris"} {:login "hgijeon", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7885562?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon", :account-source "clojuredocs", :login "gstamp"}, :_id "542692cec026201cdc326ddd"} {:author {:login "jakubholynet", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/32b26dbbf1f84656393a57a292c73728?r=PG&default=identicon"}, :editors [{:login "jakubholynet", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/32b26dbbf1f84656393a57a292c73728?r=PG&default=identicon"} {:login "jakubholynet", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/32b26dbbf1f84656393a57a292c73728?r=PG&default=identicon"} {:login "redraiment", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/33087654dbc710e81f51fda5f8241f28?r=PG&default=identicon"} {:login "Stathis Sideris", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/299a3fab7a1a2d6644455dedae9fce0a?r=PG&default=identicon"} {:avatar-url "https://avatars.githubusercontent.com/u/7885562?v=3", :account-source "github", :login "hgijeon"} {:login "olfal1", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7503672?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/15624487?v=4", :account-source "github", :login "pluieciel"}], :body ";; A lazy-seq of Fibonacci numbers (fn = fn-1 + fn-2)\n;; The producer function takes exactly two parameters\n;; (because we need the last 2 elements to produce a new one)\nuser=> (defn fib \n ([]\n (fib 1 1))\n ([a b]\n (lazy-seq (cons a (fib b (+ a b))))))\n\nuser=> (take 5 (fib))\n(1 1 2 3 5)\n\n;; Another realization\n;; 1 2 3 5 8 ... Fibonacci numbers start from the 2nd position\n;; + 1 1 2 3 5 ... Fibonacci numbers start from the 1st position\n;; = 2 3 5 8 13 ... Fibonacci numbers start from the 3rd position\nuser=> (def fib\n (cons 1\n (lazy-seq (cons 1 (map + (rest fib) fib)))))\n\nuser=> (take 5 fib)\n(1 1 2 3 5)", :created-at 1322121310000, :updated-at 1661333181759, :_id "542692d3c026201cdc326feb"} {:author {:login "jakubholynet", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/32b26dbbf1f84656393a57a292c73728?r=PG&default=identicon"}, :editors [], :body ";; It might be easier to think about the producer function as a function\n;; that, given element n, produces element n+1 via a recursive call to \n;; itself, wrapped with lazy-seq to delay its execution\n;; We might also provide no-argument version of the function that calls \n;; itself for the first element(s) of the sequence being generated.\n;; => variant of fibonaci with a no-arg version and using cons first:\n(defn sum-last-2 \n ([] (sum-last-2 1 2)) \n ([n m] (cons n (lazy-seq (sum-last-2 m (+ n m))))))\n\nuser=> (take 6 (sum-last-2))\n(1 2 3 5 8 13)", :created-at 1330300424000, :updated-at 1330300424000, :_id "542692d3c026201cdc326ff0"} {:updated-at 1436122605747, :created-at 1354916731000, :body ";; An example combining lazy sequences with higher order functions\n;; Generate prime numbers using trial division.\n;; Note that the starting set of sieved numbers should be\n;; the set of integers starting with 2 i.e., (iterate inc 2) \n(defn sieve [s]\n (cons (first s)\n (lazy-seq (sieve (filter #(not= 0 (mod % (first s)))\n (rest s))))))\n\nuser=> (take 20 (sieve (iterate inc 2)))\n(2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71)\n\n\nSadly (nth (sieve (iterate inc 2)) 10000) results in StackOverflowError ;(", :editors [{:avatar-url "https://www.gravatar.com/avatar/b60d7f482b9f88cb3a673f370ea15c9c?r=PG&default=identicon", :account-source "clojuredocs", :login "emdeesee"} {:login "lambder", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/95941?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/d3df4ff6342ed6fba898021bf2d19a6d?r=PG&default=identicon", :account-source "clojuredocs", :login "esumitra"}, :_id "542692d3c026201cdc326ff1"} {:body ";; Other examples on this page are little too eager to produce the head of collection\n;; right away. lazy-seq was introduced to make it possible to postpone any computation\n;; until data is needed.\n;; While it is not relevant for these simple examples, it could be important\n;; for real apps where producing each element is expensive.\n\n;; Here is a demonstration.\n;; Let's define a function that prints mysqr when it's called\n(defn mysqr [n]\n (println \"mysqr\")\n (* n n))\n;; => #'user/mysqr\n\n;; Now function squares that is adopted from positive-numbers example above\n;; Note that lazy-seq is inside of cons\n(defn squares\n ([n] (cons (mysqr n) (lazy-seq (squares (inc n))))))\n;; => #'user/squares\n\n(def sqrs (squares 1))\n;; => mysqr <-- NOTE THAT mysqr WAS CALLED WHEN WE SIMPLY REQUESTED COLLECTION\n;; => #'user/sqrs\n\n(take 1 sqrs)\n;; => (1) <-- HERE WE ARE GETTING FIRST ELEMENT THAT WAS CALCULATED BEFORE\n\n;; Now let's redefine 'squares' by wrapping its entire body in lazy-seq:\n(defn squares\n ([n] (lazy-seq (cons (mysqr n) (squares (inc n))))))\n;; => #'user/squares\n\n;; And when we request the collection:\n(def sqrs (squares 1))\n;; => #'user/sqrs\n;; NOTE THAT mysqr WAS NOT CALLED HERE\n\n(take 1 sqrs)\n;; => mysqr <- AND HERE mysqr IS CALLED WHEN FIRST ELEMENT IS ACTUALLY REQUESTED\n;; => (1)", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423004375232, :updated-at 1423010785906, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :_id "54d152d7e4b0e2ac61831cfc"} {:updated-at 1542427316403, :created-at 1449368696760, :author {:login "esumitra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/98965?v=3"}, :body ";; Compare recursive functions and lazy sequences\n;; generate (some) valid parenthesis combinations.\n;; (Side note: Everything this generates are valid combinations, but this\n;; doesn't generate all possible valid combinations.) \n;; valid paren combinations for 1 paren - ()\n;; valid paren combinations for 2 paren - ()(),(())\n;; valid paren combinations for 3 paren - ()()(),()(()),(())(),(()()),((()))\n\n;; given ith item, generate (i+1)th item\n(defn next-parens\n [xs]\n (set (mapcat (juxt\n #(str \"()\" %)\n #(str % \"()\")\n #(str \"(\" % \")\"))\n xs)))\n\n;; recursive function to get n paren combinations\n;; combinations are recursively calculated on the stack\n(defn parens-nth-item\n [n]\n (if (= 0 n)\n #{\"\"}\n (next-parens (parens-nth-item (dec n)))))\nuser=> (parens-nth-item 3)\n#{\"(()())\" \"((()))\" \"()()()\" \"()(())\" \"(())()\"}\n\n;; lazy function to get sequence of paren combinations\n;; combinations are lazily calculated on the heap\n(defn parens-sequence\n [xs]\n (lazy-seq (cons xs (parens-sequence (next-parens xs)))))\n\nuser=> (take 3 (parens-sequence #{\"\"}))\n(#{\"()\"} #{\"(())\" \"()()\"} #{\"(()())\" \"((()))\" \"()()()\" \"()(())\" \"(())()\"})", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/98965?v=3", :account-source "github", :login "esumitra"} {:login "peter-kehl", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/4270240?v=4"}], :_id "56639c78e4b0f47c7ec61144"} {:updated-at 1464067214072, :created-at 1464067214072, :author {:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=3"}, :body "; Create a finite-length lazy seq\n(defn finite-lazy-builder [values]\n (lazy-seq\n ; We need the when-let so the lazy-seq will terminate\n (when-let [ss (seq values)]\n (cons (first values)\n (finite-lazy-builder (next values))))))\n\n(println (finite-lazy-builder [1 2 3 4 5] ))\n;=> (1 2 3 4 5)\n\n", :_id "5743e48ee4b0a1a06bdee49a"} {:updated-at 1661336397540, :created-at 1518199374837, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;generate a seq by multiplying the first n numbers starting from 1\n;;1*1\n;;1*2\n;;2*3\n;;6*4 .....\n\n(defn multiplen\n ([]\n (multiplen 1 1))\n ([total x]\n (let [new-total (* total x)]\n (lazy-seq\n (cons new-total (multiplen new-total (inc x)))))))\n\n;;take the first 5 elements \n(take 5 (multiplen))\n;;(1 2 6 24 120)\n\n;;Another realization of factorials\n(def factorials\n (lazy-seq\n (cons 1 (map * (iterate inc 2) factorials))))\n\n(take 5 factorials)\n;;(1 2 6 24 120)", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/15624487?v=4", :account-source "github", :login "pluieciel"}], :_id "5a7de24ee4b0316c0f44f8b2"} {:updated-at 1684792382708, :created-at 1684792382708, :author {:login "bdevel", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/65951?v=4"}, :body ";; From the \"Making Clojure Lazier\" docs,\n;; here's an example using a step function.\n\n(defn filter\n \"Returns a lazy sequence of the items in coll for which\n (pred item) returns true. pred must be free of side-effects.\"\n [pred coll]\n (let [step (fn [p c]\n (when-let [s (seq c)]\n (if (p (first s))\n (cons (first s) (filter p (rest s)))\n (recur p (rest s)))))]\n (lazy-seq (step pred coll))))\n", :_id "646be43ee4b08cf8563f4bbd"}], :macro true, :notes [{:body "I think every form of (cons a (lazy-seq (f b))) in examples should be changed to (lazy-seq (cons a (f b))) to be fully lazy. \n\nThink about \n(def one-over ((fn helper [n] (cons (/ 1 n) (lazy-seq (helper (inc n))))) 0)) \nand \n(def one-over ((fn helper [n] (lazy-seq (cons (/ 1 n) (helper (inc n))))) 0)) \n\nFirst one throws an exception right after hitting enter key, while second code postpones the calculation(and that's the point of lazyness!). \nTherefore, cons should be inside of lazy-seq.\n", :created-at 1448772755640, :updated-at 1448772839454, :author {:avatar-url "https://avatars.githubusercontent.com/u/7885562?v=3", :account-source "github", :login "hgijeon"}, :_id "565a8493e4b0be225c0c47a1"}], :arglists ["& body"], :doc "Takes a body of expressions that returns an ISeq or nil, and yields\n a Seqable object that will invoke the body only the first time seq\n is called, and will cache the result and return it on all subsequent\n seq calls. See also - realized?", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/lazy-seq"} {:added "1.0", :ns "clojure.core", :name "*print-length*", :file "clojure/core_print.clj", :type "var", :column 1, :see-alsos nil, :dynamic true, :line 16, :examples [{:author {:login "nipra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/142529?v=3"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/19522656?v=4"}], :body ";; Oops! Don't do this!!!\nuser=> (iterate inc 0)\n;; Frantically doing C-c C-c :-P\n; Evaluation aborted.\n\nuser=> (set! *print-length* 10)\n10\n\n;; Now it's perfectly fine. Yay!\nuser=> (iterate inc 0)\n(0 1 2 3 4 5 6 7 8 9 ...)\n\n", :created-at 1279053974000, :updated-at 1610535308126, :_id "542692cac026201cdc326b12"}], :notes [{:body "```(set! *print-length* nil)``` to revert as it also affects pr-sr which breaks the edn output", :created-at 1641496128326, :updated-at 1641496156661, :author {:avatar-url "https://avatars.githubusercontent.com/u/132936?v=4", :account-source "github", :login "gzmask"}, :_id "61d73e40e4b0b1e3652d759c"}], :arglists [], :doc "*print-length* controls how many items of each collection the\n printer will print. If it is bound to logical false, there is no\n limit. Otherwise, it must be bound to an integer indicating the maximum\n number of items of each collection to print. If a collection contains\n more items, the printer will print items up to the limit followed by\n '...' to represent the remaining items. The root binding is nil\n indicating no limit.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*print-length*"} {:added "1.0", :ns "clojure.core", :name "*file*", :type "var", :see-alsos nil, :examples [{:updated-at 1615735028888, :created-at 1615735028888, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=4"}, :body ";; Given a file named \"example.clj\" is available in the current folder\n;; with content:\n\n(ns example)\n(when *compile-files* (println \"Compiling:\" *file*))\n\n;; If we start a REPL adding \".\" as part of the classpath,\n;; then we can see the following:\n\n(binding [*compile-path* \".\"]\n (compile 'example))\n;; Compiling: example.clj\n;; example\n", :_id "604e28f4e4b0b1e3652d7490"}], :notes [{:updated-at 1324600617000, :body "Does this actually work? I couldn't get it to print anything but NO_SOURCE_PATH. (And no, this wasn't in the REPL.)", :created-at 1324600599000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fd3"} {:updated-at 1349216667000, :body "If you're having trouble getting this feature to work as advertised, check out [this StackOverflow Question](http://stackoverflow.com/questions/12692698/file-variable-not-working/12693068).", :created-at 1349216667000, :author {:login "Jeff Terrell", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/658b2643cf2a8192286b5bb1ecb62cf8?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fe8"}], :arglists [], :doc "The path of the file being evaluated, as a String.\n\n When there is no file, e.g. in the REPL, the value is not defined.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*file*"} {:added "1.0", :ns "clojure.core", :name "compare-and-set!", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1350642558000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "atom", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b1e"} {:created-at 1360265895000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "reset!", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b1f"} {:created-at 1360265902000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "swap!", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b20"} {:created-at 1527705104286, :author {:login "agarman", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/138454?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "swap-vals!", :ns "clojure.core"}, :_id "5b0eee10e4b045c27b7fac7f"}], :line 2368, :examples [{:author {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}, :editors [{:login "franks42", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; 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", :created-at 1308629522000, :updated-at 1420734640517, :_id "542692cfc026201cdc326e27"} {:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}], :body ";; 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.", :author {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1553605079299, :updated-at 1584291384572, :_id "5c9a21d7e4b0ca44402ef6cb"}], :notes [{:author {:login "chbrown", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/360279?v=3"}, :updated-at 1471197839931, :created-at 1471197839931, :body "`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", :_id "57b0b28fe4b02d8da95c2700"} {:author {:login "favila", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1603620?v=3"}, :updated-at 1492977098400, :created-at 1492977098400, :body "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.", :_id "58fd05cae4b01f4add58fe9a"}], :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!"} {:ns "clojure.core", :name "*use-context-classloader*", :type "var", :see-alsos nil, :examples [{:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=4"}], :body ";; *use-context-classloader* is always bound to true regarldess of any \n;; outer binding setting and thus ignored.\n;; The initial idea was to have a way to tell Clojure to ignore\n;; the context classloader (supposedly set by external libs or frameworks)\n;; in some pretty specific OSGi scenarios. Original context can be found at:\n;; https://groups.google.com/g/clojure/c/aXsFBdowdsA/m/1Ez894XuT30J and\n;; additional use cases https://clojure.atlassian.net/browse/CLJ-2593\n\n(import '[clojure.lang DynamicClassLoader])\n(def custom-classloader (DynamicClassLoader.))\n(.setContextClassLoader (Thread/currentThread) custom-classloader)\n\n(identical?\n (.. (fn []) getClass getClassLoader getParent)\n custom-classloader)\n;; true\n\n;; This should return false and use some other class loader\n(binding [*use-context-classloader* false]\n (identical?\n (.. (fn []) getClass getClassLoader getParent)\n custom-classloader))\n;; true\n\n;; WARNING: If the examples above don't seem to return the expected results, \n;; be aware that tools like Leiningen[https://leiningen.org/] or\n;; nRepl[https://github.com/nrepl/nrepl] alter the context class loader. \n;; Please use a vanilla REPL like \n;; clojure.deps[https://clojure.org/guides/getting_started] instead.", :author {:avatar-url "https://avatars.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1617620930283, :updated-at 1655802050958, :_id "606aefc2e4b0b1e3652d74b1"} {:updated-at 1655794528435, :created-at 1655794528435, :author {:login "KingMob", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/946421?v=4"}, :body ";; The above example has one minor caveat to be aware of for those who need \n;; to work with classloaders. *use-context-classloader* is not technically\n;; ignored, because RT/baseLoader will use it. But it's usually overridden \n;; by RT/makeClassLoader, which pushes a binding that sets it to true every \n;; time it's called. And RT/makeClassLoader is called every time eval or \n;; compile1 is called and in some versions of load(), so it happens a lot.", :_id "62b16b60e4b0b1e3652d7609"}], :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*use-context-classloader*"} {:ns "clojure.core", :name "await1", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1610778845682, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/19522656?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "await", :ns "clojure.core"}, :_id "600288dde4b0b1e3652d7434"} {:created-at 1610778852896, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/19522656?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "await-for", :ns "clojure.core"}, :_id "600288e4e4b0b1e3652d7435"}], :line 3291, :examples nil, :notes [{:body "Looking at the source, it seems to take an agent, wait until it's queue is empty, then return the agent. When the agent has a positive queue count, it implements the standard `(await a)` and then returns `a`, the agent.\n\nUse: `(await1 a)`", :created-at 1610778678000, :updated-at 1610778828434, :author {:avatar-url "https://avatars0.githubusercontent.com/u/19522656?v=4", :account-source "github", :login "Crowbrammer"}, :_id "60028836e4b0b1e3652d7433"}], :arglists ["a"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/await1"} {:added "1.0", :ns "clojure.core", :name "let", :special-form true, :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1290671337000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "letfn", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b09"} {:created-at 1399434293000, :author {:login "Chort409", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/73da2cf9145cfb9c900b31436ee435a6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "if-let", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ba0"} {:created-at 1412886358634, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "fn", :library-url "https://github.com/clojure/clojure"}, :_id "5436ef56e4b0ae795603157d"} {:created-at 1602614306958, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "for", :ns "clojure.core"}, :_id "5f85f422e4b0b1e3652d73de"}], :line 4481, :examples [{:author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:avatar-url "https://avatars2.githubusercontent.com/u/12958644?v=4", :account-source "github", :login "funkrider"} {:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4"}], :body ";; let is a Clojure special form, a fundamental building block of the language.\n;;\n;; In addition to parameters passed to functions, let provides a way to create\n;; lexical bindings of data structures to symbols. The binding, and therefore \n;; the ability to resolve the binding, is available only within the lexical \n;; context of the let. \n;; \n;; let uses pairs in a vector for each binding you'd like to make and the value \n;; of the let is the value of the last expression to be evaluated. let also \n;; allows for destructuring which is a way to bind symbols to only part of a \n;; collection.\n\n;; A basic use for a let:\nuser=> (let [x 1] \n x)\n1\n\n;; Note that the binding for the symbol y won't exist outside of the let:\nuser=> (let [y 1] \n y)\n1\nuser=> (prn y)\njava.lang.Exception: Unable to resolve symbol: y in this context (NO_SOURCE_FILE:7)\n\n;; Note that if you use def inside a let block, your interned variable is within \n;; the current namespace and will appear OUTSIDE of the let block. \nuser=> (let [y 1] \n (def z y) \n y)\n1\nuser=> z\n1\n\n;; Another valid use of let:\nuser=> (let [a 1 b 2] \n (+ a b))\n3\n\n;; The forms in the vector can be more complex (this example also uses\n;; the thread macro):\nuser=> (let [c (+ 1 2)\n [d e] [5 6]] \n (-> (+ d e) (- c)))\n8\n\n;; The bindings for let need not match up (note the result is a numeric\n;; type called a ratio):\nuser=> (let [[g h] [1 2 3]] \n (/ g h))\n1/2\n\n;; From http://clojure-examples.appspot.com/clojure.core/let with permission.", :created-at 1278720629000, :updated-at 1556647963303, :_id "542692c7c026201cdc3269bb"} {:updated-at 1285500534000, :created-at 1279162869000, :body "user=> (let [a (take 5 (range))\n {:keys [b c d] :or {d 10 b 20 c 30}} {:c 50 :d 100}\n [e f g & h] [\"a\" \"b\" \"c\" \"d\" \"e\"]\n _ (println \"I was here!\")\n foo 12\n bar (+ foo 100)]\n [a b c d e f g h foo bar])\nI was here!\n[(0 1 2 3 4) 20 50 100 \"a\" \"b\" \"c\" (\"d\" \"e\") 12 112]\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :_id "542692c7c026201cdc3269c2"} {:author {:login "johnfn", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ffffd204ecbbae82a04f5b574d76746b?r=PG&default=identicon"}, :editors [], :body "; :as example \n\nuser=> (let [[x y :as my-point] [5 3]]\n (println x y)\n (println my-point))\n\n5 3\n[5 3]\n\n; :as names the group you just destructured.\n\n; equivalent to (and better than)\n\nuser=> (let [[x y] [5 3]\n my-point [x y]]\n ;...", :created-at 1312965326000, :updated-at 1312965326000, :_id "542692c7c026201cdc3269c4"} {:author {:login "leifp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d2f37720f063404ef83b987d2824353d?r=PG&default=identicon"}, :editors [], :body ";;; map destructuring, all features\nuser=>\n(let [\n ;;Binding Map\n {:keys [k1 k2] ;; bind vals with keyword keys\n :strs [s1 s2] ;; bind vals with string keys\n :syms [sym1 sym2] ;; bind vals with symbol keys\n :or {k2 :default-kw, ;; default values\n s2 :default-s, \n sym2 :default-sym} \n :as m} ;; bind the entire map to `m`\n ;;Data\n {:k1 :keyword1, :k2 :keyword2, ;; keyword keys\n \"s1\" :string1, \"s2\" :string2, ;; string keys\n 'sym1 :symbol1, ;; symbol keys\n ;; 'sym2 :symbol2 ;; `sym2` will get default value\n }] \n [k1 k2 s1 s2 sym1 sym2 m]) ;; return value\n\n[:keyword1, :keyword2, \n :string1, :string2,\n :symbol1, :default-sym, ;; key didn't exist, so got the default\n {'sym1 :symbol1, :k1 :keyword1, :k2 :keyword2, \n \"s1\" :string1, \"s2\" :string2}]\n\n;; remember that vector and map destructuring can also be used with \n;; other macros that bind variables, e.g. `for` and `doseq`", :created-at 1335261849000, :updated-at 1335261849000, :_id "542692d3c026201cdc326ff3"} {:author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :editors [], :body ";;; no value of a key\nuser> (let [{:keys [a b] :as m} (:x {})]\n [a b m])\n[nil nil nil]\n\n;;; same as above\nuser> (let [{:keys [a b] :as m} nil]\n [a b m])\n[nil nil nil]\n\n;;; similar case on Vector\nuser> (let [[a b :as v] nil]\n [a b v])\n[nil nil nil]\n", :created-at 1399634796000, :updated-at 1399634796000, :_id "542692d3c026201cdc326ff4"} {:body ";; lexical clojure (or let-over-fn) is an idiom for doing, in functional languages,\n;; something very similar to object based programming.\n;; Using combinations of 'let' and 'fn' can produce many interesting results.\n\n;; note the use of the ! on the functions to indicate the side effect\n(defn counter []\n (let [cnt (atom 0)]\n {:inc! (fn [] (swap! cnt inc))\n :dec! (fn [] (swap! cnt dec)) \n :get (fn [] @cnt)} ))\n\n;; we can now make and use the object\n(let [cnt (counter)]\n ((:inc! cnt))\n ((:inc! cnt)) \n ((:get cnt)))\n;;=> 2", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1412885156677, :updated-at 1412886345817, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}], :_id "5436eaa4e4b0ae795603157c"} {:updated-at 1464664767084, :created-at 1464664767084, :author {:login "freezhan", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5796449?v=3"}, :body "(let [[a b & c :as d] [1 2 3 4 5]]\n (println a) ; 1\n (println b) ; 2\n (println c) ; (3 4 5)\n d) ;[1 2 3 4 5]", :_id "574d02bfe4b0bafd3e2a046b"} {:editors [{:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4"}], :body ";;define F1Car record\n(defrecord F1Car [team engine tyre oil])\n\n;;build the constructor distructing a single map with options\n(defn make-f1team [f1-team f1-engine {:keys [f1-tyre f1-oil] :as opts}]\n (let [{:keys [tyre oil]} opts]\n (map->F1Car {:team f1-team\n :engine f1-engine\n :tyre f1-tyre\n :oil f1-oil})))\n\n;;create a record\n(def mclaren (make-f1team \"RedBull\" \"Renault\" {:f1-tyre\"Pirelli\" :f1-oil \"Castrol\"}))\n\n;;retrieve values\n(keys mclaren)\n(vals mclaren)\n(:team mclaren)\n(:oil mclaren)", :author {:avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4", :account-source "github", :login "ibercode"}, :created-at 1510307566093, :updated-at 1556648054942, :_id "5a0576eee4b0a08026c48caa"} {:updated-at 1556559048678, :created-at 1556559048678, :author {:login "funkrider", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/12958644?v=4"}, :body ";;It is possible to enumerate the symbols created within a let using a macro.\n(defmacro local-context []\n (let [symbols (keys &env)]\n (zipmap (map (fn [sym] `(quote ~sym)) symbols) symbols)))\n\n(let [a :b lc (local-context)] lc)\n;; => {a :b}", :_id "5cc734c8e4b0ca44402ef713"} {:updated-at 1651606596047, :created-at 1651606596047, :author {:login "rgkirch", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6143833?v=4"}, :body ";; the destructuring key, k in this example, doesn't have to be a literal keyword\n(let [k (keyword \"name\")\n {person-name k} {:name \"john\"}]\n person-name)\n;; => \"john\"", :_id "62718444e4b0b1e3652d75e5"}], :macro true, :notes [{:updated-at 1297072373000, :body "Nota Bene: `let` in Clojure is like `let*` in Scheme -- each init-expr has access to the preceding binding forms. (There is also a `let*`, but it is more or less `let` without destructuring, and in fact is the underlying implementation.)", :created-at 1297072373000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fb2"} {:body "Be aware that `let`’s `:or` always evaluates the default value, unlike the `or` macro:\n\n user=> (let [{:keys [a]\n :or {a (do (println \"toto\") 1)}} {}]\n a)\n toto\n 1\n\n user=> (let [{:keys [a]\n :or {a (do (println \"toto\") 1)}} {:a 2}]\n a)\n toto\n 2 ", :created-at 1554372403311, :updated-at 1554372446160, :author {:avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4", :account-source "github", :login "bfontaine"}, :_id "5ca5d733e4b0ca44402ef6fd"}], :arglists ["bindings & body"], :doc "binding => binding-form init-expr\n\n Evaluates the exprs in a lexical context in which the symbols in\n the binding-forms are bound to their respective init-exprs or parts\n therein.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/let", :forms ["(let [bindings*] exprs*)"]} {:added "1.0", :ns "clojure.core", :name "ref-set", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1284616929000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "ref", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d91"} {:created-at 1498153558604, :author {:login "devn", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "alter", :ns "clojure.core"}, :_id "594c0256e4b06e730307db40"} {:created-at 1498153567222, :author {:login "devn", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "commute", :ns "clojure.core"}, :_id "594c025fe4b06e730307db41"} {:created-at 1498153571630, :author {:login "devn", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "dosync", :ns "clojure.core"}, :_id "594c0263e4b06e730307db42"}], :line 2455, :examples [{:updated-at 1285495563000, :created-at 1280777271000, :body "user=> (def foo (ref {}))\n#'user/foo\n\nuser=> (dosync\n (ref-set foo {:foo \"bar\"}))\n{:foo \"bar\"}\n\nuser=> @foo\n{:foo \"bar\"}\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692c9c026201cdc326acb"}], :notes nil, :arglists ["ref val"], :doc "Must be called in a transaction. Sets the value of ref.\n Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ref-set"} {:added "1.1", :ns "clojure.core", :name "pop-thread-bindings", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1374313672000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "push-thread-bindings", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eff"} {:created-at 1374313678000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "binding", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f00"}], :line 1931, :examples nil, :notes nil, :arglists [""], :doc "Pop one set of bindings pushed with push-binding before. It is an error to\n pop bindings without pushing before.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/pop-thread-bindings"} {:added "1.0", :ns "clojure.core", :name "interleave", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1293096421000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "interpose", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ed3"} {:created-at 1325197345000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "zipmap", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ed4"}], :line 4309, :examples [{:author {:login "cdorrat", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5dedcb7069d39421760f6d255def10c3?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; This example takes a list of keys and a separate list of values and \n;; inserts them into a map.\n(apply assoc {} \n (interleave [:fruit :color :temp] \n [\"grape\" \"red\" \"hot\"]))\n\n;;=> {:temp \"hot\", :color \"red\", :fruit \"grape\"}\n", :created-at 1278756097000, :updated-at 1421097481582, :_id "542692ccc026201cdc326c48"} {:author {:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"}, :editors [{:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; Simple example:\n(interleave [:a :b :c] [1 2 3])\n;;=> (:a 1 :b 2 :c 3)", :created-at 1279026371000, :updated-at 1421097499209, :_id "542692ccc026201cdc326c4c"} {:author {:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body ";; The shortest input stops interleave:\n\n(interleave [:a :b :c] [1 2])\n;;=> (:a 1 :b 2)\n\n(interleave [:a :b] [1 2 3])\n;;=> (:a 1 :b 2)", :created-at 1279026486000, :updated-at 1422937238232, :_id "542692ccc026201cdc326c4f"} {:author {:login "octopusgrabbus", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(def s1 [[:000-00-0000 \"TYPE 1\" \"JACKSON\" \"FRED\"]\n [:000-00-0001 \"TYPE 2\" \"SIMPSON\" \"HOMER\"]\n [:000-00-0002 \"TYPE 4\" \"SMITH\" \"SUSAN\"]])\n\n(interleave (map #(nth % 0 nil) s1) (map #(nth % 1 nil) s1))\n;;=> (:000-00-0000 \"TYPE 1\" \n;; :000-00-0001 \"TYPE 2\"\n;; :000-00-0002 \"TYPE 4\")", :created-at 1334887108000, :updated-at 1421097410949, :_id "542692d3c026201cdc326fd1"} {:author {:login "octopusgrabbus", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(def s1 [[:000-00-0000 \"TYPE 1\" \"JACKSON\" \"FRED\"]\n [:000-00-0001 \"TYPE 2\" \"SIMPSON\" \"HOMER\"]\n [:000-00-0002 \"TYPE 4\" \"SMITH\" \"SUSAN\"]])\n\n(def cols [0 2 3])\n\n(defn f1 \n [s1 col] \n (map #(get-in s1 [% col] nil) (range (count s1))))\n\n(apply interleave (map (partial f1 s1) cols))\n;;=> (:000-00-0000 \"JACKSON\" \"FRED\" \n;; :000-00-0001 \"SIMPSON\" \"HOMER\" \n;; :000-00-0002 \"SMITH\" \"SUSAN\")", :created-at 1334887172000, :updated-at 1421097441002, :_id "542692d3c026201cdc326fd2"} {:body "(interleave (repeat \"a\") [1 2 3])\n;;=>(\"a\" 1 \"a\" 2 \"a\" 3)\n", :author {:login "ttkk1024", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/145719?v=3"}, :created-at 1431650103962, :updated-at 1431650103962, :_id "55553f37e4b01ad59b65f4d1"} {:updated-at 1553297861379, :created-at 1553290561134, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :body ";; interleave can be used as an opposite of zipmap\n(let [m {:a 1, :b 2, :c 3}]\n (split-at (count m) (apply interleave m)))\n;; => [(:a :b :c) (1 2 3)]\n;; (but really, a simpler solution would be [(keys m) (vals m)].)", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4", :account-source "github", :login "bfontaine"}], :_id "5c955541e4b0ca44402ef6bc"}], :notes [{:body "Behaviour of
(interleave [4 5 6])
\napparently depends on which Clojure version you're using. In 1.10.0 the result is:\n
[4 5 6]
", :created-at 1567536152090, :updated-at 1567536173810, :author {:avatar-url "https://avatars2.githubusercontent.com/u/179958?v=4", :account-source "github", :login "holtzermann17"}, :_id "5d6eb418e4b0ca44402ef7ab"}], :arglists ["" "c1" "c1 c2" "c1 c2 & colls"], :doc "Returns a lazy seq of the first item in each coll, then the second etc.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/interleave"} {:added "1.0", :ns "clojure.core", :name "printf", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1329894578000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "format", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e35"} {:created-at 1330170804000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.pprint", :name "cl-format", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e36"} {:created-at 1417278644991, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "println", :library-url "https://github.com/clojure/clojure"}, :_id "5479f4b4e4b03d20a10242b9"}], :line 5746, :examples [{:author {:login "lambder", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1c0c20072f52de3a6335cae183b865f6?r=PG&default=identicon"}, :editors [{:login "jeffi", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1195619?v=3"}], :body "(printf \"1 + 2 is %s%n\" 3)", :created-at 1299610618000, :updated-at 1433459544222, :_id "542692ccc026201cdc326cad"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; Click the link to clojure.core/format under See also for\n;; more extensive examples. printf and format take the same\n;; arguments -- the difference is that format returns a formatted\n;; string, whereas printf sends the formatted string to *out*.\n\n;; Also note that printf output is buffered, and does not automatically\n;; flush at any time, not even when printing newlines. Thus the last few lines\n;; of output may never appear if your program exits before the buffer is\n;; flushed. Use (flush) or a (println ...) call to force flushing of the buffer.", :created-at 1331440764000, :updated-at 1417278553807, :_id "542692d4c026201cdc327038"}], :notes nil, :arglists ["fmt & args"], :doc "Prints formatted output, as per format", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/printf"} {:added "1.0", :ns "clojure.core", :name "map?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1411815243526, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "hash-map", :library-url "https://github.com/clojure/clojure"}, :_id "5426974be4b0d1509f919f73"} {:created-at 1414508257391, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "set?", :library-url "https://github.com/clojure/clojure"}, :_id "544faee1e4b0dc573b892fa9"} {:created-at 1414508398671, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "vector?", :library-url "https://github.com/clojure/clojure"}, :_id "544faf6ee4b03d20a1024283"} {:created-at 1550854368361, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "associative?", :ns "clojure.core"}, :_id "5c7028e0e4b0ca44402ef6a0"}], :line 167, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "(map? {:a 1 :b 2 :c 3})\n;;=> true\n\n(map? (hash-map :a 1 :b 2))\n;;=> true\n\n(map? (sorted-map :a 1 :b 2))\n;;=> true\n\n(map? (array-map :a 1 :b 2))\n;;=> true\n\n(map? '(1 2 3))\n;;=> false\n\n(map? #{:a :b :c})\n;;=> false", :created-at 1279074290000, :updated-at 1423276232206, :_id "542692cbc026201cdc326bdf"} {:updated-at 1443731276562, :created-at 1443731276562, :author {:login "hura", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/671872?v=3"}, :body "\"Note that Records also implement `clojure.lang.IPersistentMap`:\"\n\n(defrecord XRec [])\n(map? (->XRec))\n;; => true", :_id "560d974ce4b08e404b6c1c8c"}], :notes nil, :arglists ["x"], :doc "Return true if x implements IPersistentMap", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/map_q"} {:added "1.0", :ns "clojure.core", :name "->", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1289746069000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "->>", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c48"} {:created-at 1412262619860, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "as->", :library-url "https://github.com/clojure/clojure"}, :_id "542d6adbe4b05f4d257a298a"} {:created-at 1412882642031, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "get-in", :library-url "https://github.com/clojure/clojure"}, :_id "5436e0d2e4b06dbffbbb00c5"} {:created-at 1431612379634, :author {:login "pladdy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11509380?v=3"}, :to-var {:ns "clojure.core", :name "some->", :library-url "https://github.com/clojure/clojure"}, :_id "5554abdbe4b03e2132e7d162"} {:created-at 1436359125547, :author {:login "jw-00000", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2936?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "doto", :ns "clojure.core"}, :_id "559d19d5e4b00f9508fd66fd"} {:created-at 1471532173241, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "..", :ns "clojure.core"}, :_id "57b5cc8de4b0b5e6d7a4fa59"}], :line 1677, :examples [{:updated-at 1447300863348, :created-at 1278953347000, :body ";; 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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://www.gravatar.com/avatar/34f159f89cbd1d9beac0276f5a7af552?r=PG&default=identicon", :account-source "clojuredocs", :login "uvtc"} {:avatar-url "https://www.gravatar.com/avatar/34f159f89cbd1d9beac0276f5a7af552?r=PG&default=identicon", :account-source "clojuredocs", :login "uvtc"} {:avatar-url "https://www.gravatar.com/avatar/34f159f89cbd1d9beac0276f5a7af552?r=PG&default=identicon", :account-source "clojuredocs", :login "uvtc"} {:avatar-url "https://www.gravatar.com/avatar/1fabe200e8b19ec248fa8285cd6b493b?r=PG&default=identicon", :account-source "clojuredocs", :login "amithgeorge"} {:avatar-url "https://avatars.githubusercontent.com/u/333974?v=3", :account-source "github", :login "eneroth"} {:login "yang-wei", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5494874?v=3"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}, :_id "542692ccc026201cdc326c53"} {:author {:login "na_ka_na", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/38aaeb9ed42ddefd5aa63f8b9c4b84a4?r=PG&default=identicon"}, :editors [], :body ";; 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", :created-at 1294071196000, :updated-at 1294071196000, :_id "542692ccc026201cdc326c5a"} {:author {:login "BertrandDechoux", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/528360?v=3"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"} {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"} {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}], :body "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", :created-at 1339249204000, :updated-at 1339250710000, :_id "542692d1c026201cdc326f3c"} {:body ";; 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\"", :author {:login "arathunku", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/749393?v=3"}, :created-at 1429647887382, :updated-at 1429647887382, :_id "5536b20fe4b01bb732af0a85"} {:editors [{:login "alvarogarcia7", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4199136?v=3"}], :body "(-> 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/4446025?v=3", :account-source "github", :login "expert0226"}, :created-at 1452151863527, :updated-at 1454886061151, :_id "568e1437e4b0e0706e05bd9e"} {:updated-at 1462650593323, :created-at 1462650593323, :author {:login "eggsyntax", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1233514?v=3"}, :body ";; 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", :_id "572e46e1e4b039e78aadabfc"} {:editors [{:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"}, :created-at 1464759684437, :updated-at 1464761625892, :_id "574e7584e4b0bafd3e2a046d"} {:editors [{:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"}], :body ";; 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])", :author {:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"}, :created-at 1464761041214, :updated-at 1464761604810, :_id "574e7ad1e4b0bafd3e2a046e"} {:updated-at 1503919516240, :created-at 1503919516240, :author {:login "MokkeMeguru", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/30849444?v=4"}, :body ";; 4Clojure Question 38\n\n(= (#(-> %& \n sort \n reverse \n first) 1 8 3 4) 8)", :_id "59a3fd9ce4b09f63b945ac57"}], :macro true, :notes [{:updated-at 1280208863000, :body "See also ->> which is similar but threads the first expr as the last argument of the forms.", :created-at 1280208863000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f8e"} {:updated-at 1374299741000, :body "I have a [short blog](http://wangjinquan.me/show/Clojure%20线性(ç®å¤´ï¼‰æ“�作符) on this, in case you are still confused on it and understand Chinese.", :created-at 1374299714000, :author {:login "John Wang", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d66c259a1fa85832e41fb9b90c7e613c?r=PG&default=identicon"}, :_id "542692edf6e94c6970522008"} {:body "Can be used as an alternative to get-in.", :created-at 1412882630144, :updated-at 1412882630144, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :_id "5436e0c6e4b0ae795603157a"}], :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/->"} {:added "1.0", :ns "clojure.core", :name "defstruct", :file "clojure/core.clj", :static true, :type "macro", :column 1, :see-alsos [{:created-at 1312838555000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "struct", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a87"} {:created-at 1312849643000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "create-struct", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a88"} {:created-at 1335411176000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defrecord", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a89"} {:created-at 1446587127297, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "deftype", :ns "clojure.core"}, :_id "56392af7e4b04b157a6648e3"} {:created-at 1446587141438, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "defprotocol", :ns "clojure.core"}, :_id "56392b05e4b04b157a6648e4"}], :line 4045, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (defstruct person :name :age :height)\n#'user/person\n\nuser=> (struct person \"george\" 22 115)\n{:name \"george\", :age 22, :height 115}", :created-at 1280748955000, :updated-at 1285495885000, :_id "542692c7c026201cdc3269d6"}], :macro true, :notes [{:updated-at 1335411165000, :body "Structs are obsolete. Use records instead. See `defrecord`.", :created-at 1335411165000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fe0"} {:updated-at 1391537723000, :body "Are structs obsolete ? Or will become obsolete ? The docs for 'defrecord' have 'Alpha - Subject To Change' ?", :created-at 1391537723000, :author {:login "monojohnny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/79d11fd92782ff24d9ae806b72b73d2f?r=PG&default=identicon"}, :_id "542692edf6e94c697052201c"} {:updated-at 1392247001000, :body "The doc string for defrecord has been changed in Clojure 1.6 to remove the 'alpha' designation, along with many other Clojure functions: https://github.com/clojure/clojure/commit/93d13d0c0671130b329863570080c72799563ac7", :created-at 1392247001000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :_id "542692edf6e94c697052201d"} {:author {:login "jhigdon", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/45405?v=4"}, :updated-at 1550940905930, :created-at 1550940905930, :body "Adding to why people are saying it's obsolete:\n\nhttps://clojure.org/reference/datatypes#_deftype_and_defrecord\n\nexplains how where defstruct/deftype/defrecord differ\n\nand https://clojure.org/reference/data_structures#StructMaps is where they suggest a record might better serve your needs", :_id "5c717ae9e4b0ca44402ef6a1"} {:author {:login "metasoarous", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/88556?v=4"}, :updated-at 1605646244437, :created-at 1605646169773, :body "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.\n\nHowever, note that to use structs dynamically, you have to use `create-struct`, rather than `defstruct`, as above. So if anything, one could argue that `defstruct` is obsolete, but not necessary `create-struct` & `struct`.", :_id "5fb43759e4b0b1e3652d740d"}], :arglists ["name & keys"], :doc "Same as (def name (create-struct keys...))", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/defstruct"} {:added "1.0", :ns "clojure.core", :name "*err*", :type "var", :see-alsos nil, :examples nil, :notes nil, :arglists [], :doc "A java.io.Writer object representing standard error for print operations.\n\n Defaults to System/err, wrapped in a PrintWriter", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*err*"} {:added "1.0", :ns "clojure.core", :name "get", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1324306493000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "map-indexed", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bb1"} {:created-at 1359887523000, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "get-in", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bb2"} {:created-at 1360286957000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "find", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bb3"} {:created-at 1416824761214, :author {:login "alilee", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/16739?v=3"}, :to-var {:ns "clojure.core", :name "select-keys", :library-url "https://github.com/clojure/clojure"}, :_id "547307b9e4b03d20a10242b2"} {:created-at 1416824821178, :author {:login "alilee", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/16739?v=3"}, :to-var {:ns "clojure.core", :name "nth", :library-url "https://github.com/clojure/clojure"}, :_id "547307f5e4b03d20a10242b3"}], :line 1494, :examples [{:updated-at 1545395916321, :created-at 1280321427000, :body "(get [1 2 3] 1)\n;;=> 2\n\n(get [1 2 3] 5)\n;;=> nil\n\n(get [1 2 3] 5 100)\n;;=> 100\n\n(get {:a 1 :b 2} :b)\n;;=> 2\n\n(get {:a 1 :b 2} :z \"missing\")\n;;=> \"missing\"\n\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "sanel", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/213914?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon", :account-source "clojuredocs", :login "gstamp"}, :_id "542692cdc026201cdc326cd7"} {:author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; to get an index of the element of a vector, use .indexOf\n(def v [\"one\" \"two\" \"three\" \"two\"])\n;; #'user/v\n\n(.indexOf v \"two\")\n;;=> 1\n\n(.indexOf v \"foo\")\n;;=> -1\n", :created-at 1324306658000, :updated-at 1421261046680, :_id "542692d3c026201cdc326fbd"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; the system environment has a hash-map semantic\n(get (System/getenv) \"SHELL\")\n;;=> \"/bin/bash\"\n\n(get (System/getenv) \"PATH\")\n;;=> \"/usr/local/bin:/sbin:/usr/sbin:/usr/bin:/bin\"", :created-at 1324314703000, :updated-at 1421261106767, :_id "542692d3c026201cdc326fbe"} {:updated-at 1421261190882, :created-at 1340441156000, :body ";; 'get' is not the only option\n(def my-map {:a 1 :b 2 :c 3})\n\n;; maps act like functions taking keys \n(my-map :a)\n;;=> 1\n\n;; even keys (if they are keywords) act like functions\n(:b my-map)\n;;=> 2", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"}, :_id "542692d3c026201cdc326fbf"} {:author {:login "cympfh", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7ad064788bb989f0c9ae552257355d6?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; it is tempting to try an index on a list\n(get '(a b c) 1)\n;;=> nil\n\n;; but you should use nth\n(nth '(a b c) 1)\n;;=> b", :created-at 1394404668000, :updated-at 1421261345010, :_id "542692d3c026201cdc326fc0"} {:updated-at 1461265877674, :created-at 1461265877674, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :body ";; Get also works with strings:\n(get \"abc\" 1)\n;;=> \\b", :_id "571925d5e4b0fc95a97eab50"} {:updated-at 1496171084580, :created-at 1492450542481, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/20086?v=3"}, :body ";; For sorted stuff, \"key\" must be of the same type of the existing keys. \n;; This allows descending the sorted tree in log(N) average.\n\n(get (hash-map :a 1 :b 2) \"a\" \"not found\")\n;; \"not found\"\n\n(get (sorted-map :a 1 :b 2) \"a\" \"not found\")\n;; ClassCastException\n\n;; get works on transient maps, but silently fails on transient sets.\n;; A similar issue affects contains?.\n\n(get (transient #{0 1 2}) 1)\n;; nil\n\n;; get uses int cast with precision loss, with (.intValue x).\n;; The example below is explained because 4294967296 equal 2^32, thus\n;; (.intValue 4294967296) returns 0.\n;; Be careful with sufficiently large keys:\n\n(get [\"a\" \"b\" \"c\"] 4294967296)\n;; \"a\"", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/20086?v=3", :account-source "github", :login "reborg"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/109629?v=3"}], :_id "58f4fceee4b01f4add58fe94"} {:editors [{:login "puppe", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1393865?v=4"}], :body ";; Specifying 'not-found' does NOT guarantee that the return value is\n;; not 'nil'.\n\n(get {} :a 42)\n;;=> 42\n\n(get {:a nil} :a 42)\n;;=> nil\n\n;; This may be especially relevant if you use records, as all pre-defined keys\n;; will usually be present.\n\n(defrecord R [a b])\n(def r (map->R {}))\n\nr\n;;=> #user.R{:a nil :b nil}\n\n(get r :a 42)\n;;=> nil\n\n;; Consider using 'or' instead, as 'nil' is \"falsy\".\n\n(or (get {:a nil} :a) 42)\n;;=> 42", :author {:avatar-url "https://avatars2.githubusercontent.com/u/1393865?v=4", :account-source "github", :login "puppe"}, :created-at 1576172735814, :updated-at 1576172805891, :_id "5df27cbfe4b0ca44402ef7f8"} {:editors [{:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}], :body ";; Specifying not-found doesn't mean that the expression won't be evaluated.\n;; This can be a problem if you intend to materialize the not-found value \n;; only if key is not set.\n\n(get {:a 1} :a (#(println \"else\")))\n;; else\n;;=> 1\n\n;; using an `or` can solve your problem here\n(or (get {:a 1} :a)\n (println \"not found\"))\n;;=> 1", :author {:avatar-url "https://avatars2.githubusercontent.com/u/633523?v=4", :account-source "github", :login "timofeytt"}, :created-at 1595920651962, :updated-at 1666965797097, :_id "5f1fd10be4b0b1e3652d7326"} {:updated-at 1690985032681, :created-at 1690985032681, :author {:login "usametov", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5256128?v=4"}, :body ";; how to deal with nil map, defensive coding example:\n;; try to get :a key from nil map \n(get nil :a :a1)\n;;=> :a1\n", :_id "64ca6248e4b08cf8563f4bd7"}], :notes [{:body "Why is this character/string?", :created-at 1420334049781, :updated-at 1420334049781, :author {:login "Pierre-Thibault", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10163425?v=3"}, :_id "54a893e1e4b09260f767ca86"} {:author {:login "hgijeon", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7885562?v=3"}, :updated-at 1449649145088, :created-at 1449649145088, :body "(:mykey my-hash-map :none) means the same as (get my-hash-map :mykey :none) and \n('mysym my-hash-map :none) means the same as (get my-hash-map 'mysym :none). \nSo, you can use (:a {:a 1 :b 2} :not-inserted) as (get {:a 1 :b 2} :a :not-inserted). \nSee \nhttp://clojure.org/data_structures#Data Structures-Keywords and\nhttp://clojure.org/data_structures#Data Structures-Symbols", :_id "5667e3f9e4b0f47c7ec61147"} {:author {:login "navigaid", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/10371727?v=4"}, :updated-at 1545127452738, :created-at 1545127452738, :body "`(get get get get)` is equivalent to `get`\n\nas in:\n\n```\n((get get get get) {:a 1} :a)\n```", :_id "5c18c61ce4b0ca44402ef5ec"}], :arglists ["map key" "map key not-found"], :doc "Returns the value mapped to key, not-found or nil if key not present.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/get"} {:added "1.0", :ns "clojure.core", :name "doto", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1436359076539, :author {:login "jw-00000", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2936?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "->", :ns "clojure.core"}, :_id "559d19a4e4b00f9508fd66fb"} {:created-at 1436359083907, :author {:login "jw-00000", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2936?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "->>", :ns "clojure.core"}, :_id "559d19abe4b00f9508fd66fc"} {:created-at 1557781859408, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "..", :ns "clojure.core"}, :_id "5cd9dd63e4b0ca44402ef722"}], :line 3852, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "ozzloy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c546d3f104228c483309c760926e6e3?r=PG&default=identicon"} {:avatar-url "https://avatars.githubusercontent.com/u/37649?v=3", :account-source "github", :login "fasiha"} {:login "dominem", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11671382?v=4"}], :body ";; Note that even though println returns nil, doto still returns the HashMap object\n(doto (java.util.HashMap.)\n (.put \"a\" 1)\n (.put \"b\" 2)\n (println))\n;;=> #\n;;=> {\"b\" 2, \"a\" 1}\n\n;; Equivalent to\n(def m (java.util.HashMap.))\n(.put m \"a\" 1)\n(.put m \"b\" 2)\nm\n;;=> {\"a\" 1, \"b\" 2}\n(println m)\n;;=> #object[java.util.HashMap 0x727fcc37 {a=1, b=2}]", :created-at 1293673034000, :updated-at 1565336332524, :_id "542692c9c026201cdc326ae6"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"} {:login "jakebasile", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/766907?v=2"}], :body ";; quick demonstration of using a Collections function on the resulting ArrayList\n\nuser=> (def al (doto (java.util.ArrayList.) (.add 11) (.add 3) (.add 7)))\n#'user/al\nuser=> al\n#\nuser=> (java.util.Collections/sort al)\nnil\nuser=> al\n#\nuser=>", :created-at 1313965605000, :updated-at 1412632698246, :_id "542692c9c026201cdc326ae8"} {:author {:login "jimpil", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c3cf214ed0c5f0bca153b1c1177575d6?r=PG&default=identicon"}, :editors [{:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"} {:login "schmee", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/3405586?v=3"}], :body ";; careful when calling 'dotimes' from within a 'doto' statement\nuser=> (doto (java.util.ArrayList.)\n (.add -2)\n (.add -1)\n (dotimes [i 3] (.add i)))\njava.lang.IllegalArgumentException: dotimes requires a vector for its binding (NO_SOURCE_FILE:1)\n\n; what has happened is that (java.util.ArrayList.) has secretly\n; become the first argument to 'dotimes' and thus the exception\n; informs us that it can't find the binding vector required for\n; 'dotimes' to expand. You can cure this behaviour by simply using\n; 'do' instead of 'doto' or by wrapping the call to 'dotimes' in\n; a function. e.g:\n\n;using 'let' with implicit 'do' instead of 'doto'\nuser=> (let [al (java.util.ArrayList.)]\n (.add al -2)\n (.add al -1)\n (dotimes [i 3] (.add al i))\n al);return the ArrayList\n# ;exactly what we intended\n\n;wrapping 'dotimes' in a function literal\nuser=>(doto (java.util.ArrayList.)\n (.add -2)\n (.add -1)\n (#(dotimes [i 3] (.add % i))))\n# ;exactly what we intended again\n", :created-at 1339783113000, :updated-at 1421092637298, :_id "542692d2c026201cdc326f98"} {:updated-at 1650763751893, :created-at 1633711183120, :author {:login "benjamin-asdf", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/38900087?v=4"}, :body "; useful during development when you want to log something\n; without changing the structure of your code\n\n(+\n (doto 42 println)\n 10)\n\n=> 52\n\n; similarly wrapping tap> in a threading macro for intermediate results\n\n(-> :hello\n {:hello \"Hello\"}\n (doto tap>) ; tap> \"Hello\"\n (str \" World!\"))\n\n=> \"Hello World!\"", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/38900087?v=4", :account-source "github", :login "benjamin-asdf"} {:login "dgb23", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10947371?v=4"}], :_id "6160744fe4b0b1e3652d7554"}], :macro true, :notes nil, :arglists ["x & forms"], :doc "Evaluates x then calls all of the methods and functions with the\n value of x supplied at the front of the given arguments. The forms\n are evaluated in order. Returns x.\n\n (doto (new java.util.HashMap) (.put \"a\" 1) (.put \"b\" 2))", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/doto"} {:added "1.0", :ns "clojure.core", :name "identity", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1365638085000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "nil?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e76"} {:created-at 1493319344537, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "some?", :ns "clojure.core"}, :_id "59023eb0e4b01f4add58fe9e"} {:created-at 1544362967323, :author {:login "Ramblurr", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/14830?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "constantly", :ns "clojure.core"}, :_id "5c0d1bd7e4b0ca44402ef5e9"}], :line 1451, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (identity 4)\n4", :created-at 1279071803000, :updated-at 1332950516000, :_id "542692ccc026201cdc326c9a"} {:author {:login "cschreiner", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/93bff5e102f3d5bcc426e28e06c3c503?r=PG&default=identicon"}, :editors [{:login "cschreiner", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/93bff5e102f3d5bcc426e28e06c3c503?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (filter identity [1 2 3 nil 4 false true 1234])\n(1 2 3 4 true 1234)", :created-at 1279209894000, :updated-at 1332950531000, :_id "542692ccc026201cdc326c9c"} {:author {:login "cschreiner", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/93bff5e102f3d5bcc426e28e06c3c503?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "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", :created-at 1279209982000, :updated-at 1285500217000, :_id "542692ccc026201cdc326c9f"} {:author {:login "cschreiner", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/93bff5e102f3d5bcc426e28e06c3c503?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (partition-by identity (sort \"abcdaabccc\"))\n((\\a \\a \\a) (\\b \\b) (\\c \\c \\c \\c) (\\d))\n", :created-at 1280212301000, :updated-at 1285501489000, :_id "542692ccc026201cdc326ca1"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body "user=> (map first (partition-by identity [1 1 2 3 3 1 1 5 5]))\n(1 2 3 1 5)", :created-at 1310849421000, :updated-at 1310849421000, :_id "542692ccc026201cdc326ca3"} {:author {:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"}, :editors [], :body "user=> (group-by identity \"abracadabra\")\n{\\a [\\a \\a \\a \\a \\a], \\b [\\b \\b], \\r [\\r \\r], \\c [\\c], \\d [\\d]}", :created-at 1312216209000, :updated-at 1312216209000, :_id "542692ccc026201cdc326ca4"} {:body "user=> (map #(identity %) [1 2 3 4]) ; ~ (map (fn [x] x) [1 2 3 4])\n(1 2 3 4)", :author {:login "protsenkovi", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/431393?v=3"}, :created-at 1417761372684, :updated-at 1417761372684, :_id "5481525ce4b03d20a10242c3"} {:updated-at 1539899393566, :created-at 1539899393566, :author {:login "peter-kehl", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/4270240?v=4"}, :body "; `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", :_id "5bc90001e4b00ac801ed9ee7"}], :notes [{:updated-at 1280212784000, :body "I don't quite see the usefulness of this :P", :created-at 1280212784000, :author {:login "Jacolyte", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f91"} {:updated-at 1313418353000, :body "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))", :created-at 1313418233000, :author {:login "dturczanski", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22c58e86fe0fa676e1fcbe71c1dba1bf?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fc5"} {:updated-at 1316077178000, :body "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)))", :created-at 1316077178000, :author {:login "lancepantz", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9fbd3eb69f978b77c1bd66436971cdb2?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fcb"} {:body "user=> (mapcat identity [[[0 1] [1 2]] [[11 12]]])\n([0 1] [1 2] [11 12])\n", :created-at 1424195865165, :updated-at 1424195865165, :author {:login "tlightsky", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/429211?v=3"}, :_id "54e38119e4b0b716de7a652c"}], :arglists ["x"], :doc "Returns its argument.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/identity"} {:added "1.0", :ns "clojure.core", :name "into", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1399644560000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "conj", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c52"} {:created-at 1539774381439, :author {:login "witek", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/209520?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "concat", :ns "clojure.core"}, :_id "5bc717ade4b00ac801ed9edb"}], :line 6887, :examples [{:author {:login "Miki", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/52338b3d753f00bb7724f2d2ca060a4?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "cloojure", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon"}], :body "; Maps can be constructed from a sequence of 2-vectors or a sequence \n; of maps\nuser=> (into (sorted-map) [ [:a 1] [:c 3] [:b 2] ] )\n{:a 1, :b 2, :c 3}\nuser=> (into (sorted-map) [ {:a 1} {:c 3} {:b 2} ] )\n{:a 1, :b 2, :c 3}\n\n; When maps are the input source, they convert into an unordered sequence \n; of key-value pairs, encoded as 2-vectors\nuser=> (into [] {1 2, 3 4})\n[[1 2] [3 4]]\n", :created-at 1278846273000, :updated-at 1404822264000, :_id "542692cbc026201cdc326bac"} {:author {:login "cran1988", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/6261b9b7e6263f013dfb1330a43a501?r=PG&default=identicon"}, :editors [{:login "cloojure", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon"} {:avatar-url "https://avatars.githubusercontent.com/u/4881607?v=3", :account-source "github", :login "sa2812"}], :body "; Items are conj'ed one at a time, which puts them at the head of \n; the destination list\nuser=> (into () '(1 2 3))\n(3 2 1)\n\n; This does not happen for a vector, however, due to the behavior of conj:\nuser=> (into [1 2 3] '(4 5 6))\n[1 2 3 4 5 6]\n", :created-at 1310276614000, :updated-at 1436264587298, :_id "542692cbc026201cdc326baf"} {:updated-at 1514491228692, :created-at 1334632023000, :body "(defn test-key-inclusion-cols\n \"return all values in column1 that aren't in column2\"\n [column1 column2]\n (filter (complement (into #{} column2)) column1))\n", :editors [{:login "jcburley", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/430319?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon", :account-source "clojuredocs", :login "octopusgrabbus"}, :_id "542692d3c026201cdc326fd8"} {:author {:login "cloojure", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon"}, :editors [], :body "; Change from one type of map to another\nuser=> (into (sorted-map) {:b 2 :c 3 :a 1})\n{:a 1, :b 2, :c 3}", :created-at 1399534625000, :updated-at 1399534625000, :_id "542692d3c026201cdc326fd9"} {:updated-at 1448739135641, :created-at 1448739135641, :author {:login "dxlr8r", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1648056?v=3"}, :body "; Convert a nested ordering map to hash-map (or another)\nuser=> (use 'flatland.ordered.map)\nuser=> (def ord-map (ordered-map :a \"a\" :b \"b\" :c {:d \"d\" :e \"e\"}))\nuser=> ord-map\n#ordered/map ([:a \"a\"] [:b \"b\"] [:c {:d \"d\", :e \"e\"}]) \n\nuser=> (use 'clojure.walk)\nuser=> (defn disorder [ordering-map map-fn] \n (postwalk #(if (map? %) (into map-fn %) %) ordering-map))\n\nuser=> (disorder ord-map {})\n{:a \"a\", :b \"b\", :c {:d \"d\", :e \"e\"}}", :_id "565a013fe4b0be225c0c47a0"} {:updated-at 1458739828450, :created-at 1458739828450, :author {:login "ha0ck", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/3716736?v=3"}, :body ";impl apply merge\nuser=> (into {:x 4} [{:a 1} {:b 2} {:c 3}])\n\n{:x 4, :a 1, :b 2, :c 3}", :_id "56f29a74e4b07ac9eeceed15"} {:updated-at 1462324693090, :created-at 1462324000684, :author {:login "fasiha", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/37649?v=3"}, :body ";; How do we use a transducer?\n\n; Define the transducer with `comp` but in `->` order:\n(def xform (comp (map #(+ 2 %))\n (filter odd?)))\n; adds 2, then omits if result is even.\n\n(into [-1 -2] xform (range 10))\n; => [-1 -2 3 5 7 9 11]\n\n\n; Alternatively, using `transduce` directly:\n(transduce xform conj [-1 -2] (range 10))\n; => [-1 -2 3 5 7 9 11]\n\n; Alternatively, using reduce and explicitly calling `map` and `filter`:\n(reduce conj [-1 -2] (->> (range 10)\n (map #(+ 2 %))\n (filter odd?)))\n; => [-1 -2 3 5 7 9 11]\n\n\n;; Let's benchmark, using Criterium (https://github.com/hugoduncan/criterium)\n(require '[criterium.core :refer [quick-bench]])\n(quick-bench (into [-1 -2] xform (range 1000000)))\n; Execution time lower quantile : 54.368948 ms ( 2.5%)\n; Execution time upper quantile : 55.976303 ms (97.5%)\n\n(quick-bench (transduce xform conj [-1 -2] (range 1000000)))\n; Execution time lower quantile : 77.738505 ms ( 2.5%)\n; Execution time upper quantile : 87.088016 ms (97.5%): 1.5x slower than into\n\n(quick-bench (reduce conj [-1 -2] (->> (range 1000000) \n (map #(+ 2 %))\n (filter odd?))))\n; Execution time lower quantile : 92.607522 ms ( 2.5%)\n; Execution time upper quantile : 100.426780 ms (97.5%): 1.8x slower than into", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/37649?v=3", :account-source "github", :login "fasiha"}], :_id "57294b20e4b050526f331420"} {:updated-at 1482220266209, :created-at 1482220266209, :author {:login "aksenov", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1590180?v=3"}, :body ";; Interesting case you can't directly convert list or sequence into map (due performance reasons). One should use vector instead.\n\n;; This is ok:\n(into {} [[:a \"a\"] [:b \"b\"]])\n;;=> {:a \"a\", :b \"b\"}\n\n;; But this isn't:\n(into {} ['(:a \"a\") '(:b \"b\")])\n;;=> ClassCastException clojure.lang.Keyword cannot be cast to java.util.Map$Entry clojure.lang.ATransientMap.conj (ATransientMap.java:44)", :_id "5858e2eae4b004d3a355e2c8"} {:editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}], :body ";; merging two arrays using the transducer `cat`\n(into [] cat [[1 2 3 ] [4 5 6 ]])\n;=> [1 2 3 4 5 6]\n\n(into '() cat [[1 2 3 ] [4 5 6 ]])\n;=> (6 5 4 3 2 1)\n\n(into '() [1 2 3 4 5 6])\n;=> (6 5 4 3 2 1)", :author {:avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4", :account-source "github", :login "phreed"}, :created-at 1517940935300, :updated-at 1519691300149, :_id "5a79f0c7e4b0e2d9c35f741e"} {:editors [{:login "lsevero", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/3440467?v=4"}], :body ";Into is useful to concatenate vectors of maps\n(def a [{:a 1 :b 2} {:a 3 :b 4}])\n(def b [{:c \"c\" :d \"d\"} {:c \"cc\" :d \"dd\"}])\n\n(into a b)\n;=> [{:a 1, :b 2} {:a 3, :b 4} {:c \"c\", :d \"d\"} {:c \"cc\", :d \"dd\"}]\n\n;concat will return a similar result, but will be a lazy-seq instead of a vector", :author {:avatar-url "https://avatars2.githubusercontent.com/u/3440467?v=4", :account-source "github", :login "lsevero"}, :created-at 1582056539595, :updated-at 1582056838335, :_id "5e4c445be4b0ca44402ef83d"} {:editors [{:login "littleli", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/544082?v=4"}], :body ";; Java 9 introduced immutable collections constructed with static 'of' methods\n;; These collections have specific implementation details and are used usually along with Java streams\n;; They cannot be used as operators like this (a-map :key)\n;; Use 'into' to convert them to Clojure collections with improved utility\n\n(into [] (java.util.List/of :a :b :c))\n;=> [:a :b :c]\n\n(into #{} (java.util.Set/of :a :b :c))\n;=> #{:c :b :a}\n\n(into {} (java.util.Map/of :a \"aa\" :b \"bb\" :c \"cc\"))\n;=> {:c \"cc\", :b \"bb\", :a \"aa\"}\n", :author {:avatar-url "https://avatars0.githubusercontent.com/u/544082?v=4", :account-source "github", :login "littleli"}, :created-at 1588591562483, :updated-at 1596476819086, :_id "5eaffbcae4b087629b5a18fd"} {:updated-at 1600132004721, :created-at 1600132004721, :author {:login "luiszambon", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/41161270?v=4"}, :body "; into will return the coll type of the first parameter\n\n(def list-example '(1 2 3 4))\n;=> #'list-example\n(def vector-example [1 2 3 4])\n;=> #'vector-example\n(def set-example #{1 2 3 4})\n;=> #'set-example\n\n(class (into list-example vector-example))\n;=> clojure.lang.PersistentList\n(class (into vector-example list-example))\n;=> clojure.lang.PersistentVector\n(class (into set-example list-example))\n;=> clojure.lang.PersistentHashSet", :_id "5f6013a4e4b0b1e3652d73bd"}], :notes nil, :arglists ["" "to" "to from" "to xform from"], :doc "Returns a new coll consisting of to-coll with all of the items of\n from-coll conjoined. A transducer may be supplied.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/into"} {:added "1.0", :ns "clojure.core", :name "areduce", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "amap", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342853655000, :_id "542692ebf6e94c6970521ec7"}], :line 5265, :examples [{:updated-at 1446748965601, :created-at 1281617241000, :body ";; This should be about as quick as summing up a array of floats in java.\n\nuser=> (defn asum [^floats xs]\n (areduce xs i ret (float 0)\n (+ ret (aget xs i))))\n\nuser=> (asum (float-array [1 2 3]))\n6.0\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon", :account-source "clojuredocs", :login "gstamp"}, :_id "542692cec026201cdc326df8"}], :macro true, :notes nil, :arglists ["a idx ret init expr"], :doc "Reduces an expression across an array a, using an index named idx,\n and return value named ret, initialized to init, setting ret to the \n evaluation of expr at each step, returning ret.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/areduce"} {:added "1.0", :ns "clojure.core", :name "long", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "int", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917169000, :_id "542692eaf6e94c6970521b73"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "longs", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917368000, :_id "542692eaf6e94c6970521b74"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "long-array", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917373000, :_id "542692eaf6e94c6970521b75"} {:created-at 1496088186511, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unchecked-long", :ns "clojure.core"}, :_id "592c7e7ae4b093ada4d4d79c"}], :line 3480, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "rand0m86", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/aa88f28de4d9335e744f8d10d5ebf8a6?r=PG&default=identicon"} {:login "rand0m86", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/aa88f28de4d9335e744f8d10d5ebf8a6?r=PG&default=identicon"}], :body "v.1.3.0\nuser=> (let [num (* 1234567890 21)] [num (int num) (long num)])\n[25925925690 156121914 25925925690]\n\nv.1.6.0\nuser=> (let [num (* 1234567890 21)] [num (int num) (long num)])\nIllegalArgumentException Value out of range for int: 25925925690", :created-at 1281031682000, :updated-at 1406257844000, :_id "542692c7c026201cdc326992"} {:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "rand0m86", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/aa88f28de4d9335e744f8d10d5ebf8a6?r=PG&default=identicon"} {:login "rand0m86", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/aa88f28de4d9335e744f8d10d5ebf8a6?r=PG&default=identicon"}], :body "v.1.3.0\nuser=> (= 21 (long 21))\ntrue \n\n;; but\nuser=> (.equals 21 (long 21))\nfalse \n\n;; and thus\nuser=> (get {21 :twenty-one} (long 21))\nnil \n\nv.1.6.0\nuser=> (= 21 (long 21))\ntrue \n\nuser=> (.equals 21 (long 21))\ntrue\n\nuser=> (.equals 21.0 (long 21))\nfalse\n\nuser=> (.equals (long 21.0) (long 21)) \ntrue", :created-at 1281031694000, :updated-at 1406257882000, :_id "542692c7c026201cdc326996"} {:updated-at 1596590278008, :created-at 1596590278008, :author {:login "wdhowe", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4631165?v=4"}, :body "(long 123)\n;;=> 123\n\n(long 1.23)\n;;=> 1\n\n(long 1.2345678901234567890)\n;;=> 1\n\n(long -1)\n;;=> -1\n\n;; Casting a string does not work\n(long \"123\")\n;;=> Execution error (ClassCastException) at user/eval187 (REPL:1).\n;;java.lang.String cannot be cast to java.lang.Number\n\n;; Use Java interop instead\n(Long/parseLong \"123\")\n;;=> 123\n\n;; Content originally posted by u/didibus on https://clojuredocs.org/clojure.core/num", :_id "5f2a08c6e4b0b1e3652d7361"}], :notes [{:updated-at 1394070050000, :body "the second example is no longer true.", :created-at 1394070050000, :author {:login "clojureking", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/92625b8a6be91bb8c688d0d07b4e2a32?r=PG&default=identicon"}, :_id "542692edf6e94c6970522020"}], :arglists ["x"], :doc "Coerce to long", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/long"} {:added "1.0", :ns "clojure.core", :name "double", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1579780040730, :author {:login "Hindol", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/705227?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "float", :ns "clojure.core"}, :_id "5e2987c8e4b0ca44402ef81c"} {:created-at 1579780063873, :author {:login "Hindol", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/705227?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bigdec", :ns "clojure.core"}, :_id "5e2987dfe4b0ca44402ef81d"}], :line 3492, :examples [{:author {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (double 1)\n1.0", :created-at 1283814485000, :updated-at 1332952958000, :_id "542692cec026201cdc326ddb"} {:updated-at 1522204835943, :created-at 1522204835943, :author {:login "yuxuan813", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/22159831?v=4"}, :body ";; Ratios can be explicitly coerced to a floating-point representation:\nuser=> (double 1/3)\n;= 0.3333333333333333", :_id "5abb00a3e4b045c27b7fac28"} {:updated-at 1596590762065, :created-at 1596590762065, :author {:login "wdhowe", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4631165?v=4"}, :body ";; Casting a string does not work\n(double \"123.456\")\n;;=> Execution error (ClassCastException) at user/eval197 (REPL:1).\n;;java.lang.String cannot be cast to java.lang.Number\n\n;; Use Java interop instead\n(Double/parseDouble \"123.456\")\n;;=> 123.456\n\n;; Content originally posted by u/didibus on https://clojuredocs.org/clojure.core/num", :_id "5f2a0aaae4b0b1e3652d7366"}], :notes nil, :arglists ["x"], :doc "Coerce to double", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/double"} {:added "1.7", :ns "clojure.core", :name "volatile?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1437146147516, :author {:login "claj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/353113?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "volatile!", :ns "clojure.core"}, :_id "55a91c23e4b0080a1b79cda6"} {:created-at 1492395420814, :author {:login "didibus", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/601540?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "vswap!", :ns "clojure.core"}, :_id "58f4259ce4b01f4add58fe8e"} {:created-at 1492395448747, :author {:login "didibus", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/601540?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "vreset!", :ns "clojure.core"}, :_id "58f425b8e4b01f4add58fe8f"}], :line 2548, :examples [{:editors [{:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}], :body "(def a (volatile! 0))\n\nuser=> (volatile? a)\n;;=> true\n\n(def b 0)\n\nuser=> (volatile? b)\n;;=> false", :author {:avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3", :account-source "github", :login "ertugrulcetin"}, :created-at 1460034117197, :updated-at 1460034139185, :_id "57065a45e4b075f5b2c864cf"}], :notes nil, :arglists ["x"], :doc "Returns true if x is a volatile.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/volatile_q"} {:added "1.0", :ns "clojure.core", :name "definline", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1612735270827, :author {:login "KingMob", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/946421?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "defmacro", :ns "clojure.core"}, :_id "60206326e4b0b1e3652d744b"}], :line 5229, :examples nil, :macro true, :notes [{:updated-at 1354753534000, :body "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", :created-at 1354753534000, :author {:login "glchapman", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a5176d5d971ba68c15f4afe376aeaf18?r=PG&default=identicon"}, :_id "542692edf6e94c6970521ff8"} {:updated-at 1385846788000, :body "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", :created-at 1385846788000, :author {:login "Alexey Tarasevich", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/43e0398b89022d32b43de4c968069312?r=PG&default=identicon"}, :_id "542692edf6e94c6970522013"}], :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"} {:added "1.0", :ns "clojure.core", :name "nfirst", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1343067247000, :author {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "next", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eb5"} {:created-at 1482184108272, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "first", :ns "clojure.core"}, :_id "585855ace4b004d3a355e2c3"} {:created-at 1482184112724, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ffirst", :ns "clojure.core"}, :_id "585855b0e4b004d3a355e2c4"} {:created-at 1482184132251, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "fnext", :ns "clojure.core"}, :_id "585855c4e4b004d3a355e2c5"} {:created-at 1482184136369, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "nnext", :ns "clojure.core"}, :_id "585855c8e4b004d3a355e2c6"}], :line 105, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (nfirst [])\nnil \n\nuser=> (nfirst ['(a b c) '(b a c) '(c b a) '(a c b)])\n(b c)\n\nuser=> (nfirst {:a 1, :b 2, :c 3, :d 4})\n(1)\n\nuser=> (nfirst #{1 2 3})\njava.lang.IllegalArgumentException: Don't know how to create ISeq from: java.lang.Integer (NO_SOURCE_FILE:0)", :created-at 1281033567000, :updated-at 1332950990000, :_id "542692cec026201cdc326d83"}], :notes nil, :arglists ["x"], :doc "Same as (next (first x))", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/nfirst"} {:added "1.0", :ns "clojure.core", :name "meta", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1302719092000, :author {:login "dnaumov", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/361cb3cfa29928ddff4c49cbb5ad0cbd?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-meta", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ec0"} {:created-at 1302719254000, :author {:login "dnaumov", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/361cb3cfa29928ddff4c49cbb5ad0cbd?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "*print-meta*", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ec1"} {:created-at 1489661787389, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "vary-meta", :ns "clojure.core"}, :_id "58ca6f5be4b01f4add58fe75"}], :line 202, :examples [{:author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(use 'clojure.pprint)\n(pprint (meta #'first))\n;;=> prints the following...\n{:ns #,\n :name first,\n :added \"1.0\",\n :file \"clojure/core.clj\",\n :static true,\n :column 1,\n :line 49,\n :arglists ([coll]),\n :doc\n \"Returns the first item in the collection. Calls seq on its\\n \n argument. If coll is nil, returns nil.\"}", :created-at 1280777073000, :updated-at 1434396446014, :_id "542692cfc026201cdc326e8f"} {:updated-at 1519676797874, :created-at 1519670280917, :author {:login "finalfantasia", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/2316604?v=4"}, :body ";; attach metadata to s.\n;; ^:private is a shorthand notation for ^{:private true} and\n;; ^String is a shorthand notation for ^{:tag java.lang.String}.\n(def ^:private ^String s \"Hello, world!\")\n\n;; inspect the metadata attached to s.\n;; note, you need to use the var #'s, instead of the symbol s, as the argument.\n(clojure.pprint/pprint (meta #'s))\n;; =>\n{:private true,\n :tag java.lang.String,\n :line 3,\n :column 1,\n :file \"/tmp/form-init5430922801479403331.clj\",\n :name s,\n :ns #object[clojure.lang.Namespace 0x13fca031 \"user\"]}\n", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/2316604?v=4", :account-source "github", :login "finalfantasia"}], :_id "5a945408e4b0316c0f44f8f0"} {:editors [{:login "randomizedthinking", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5283430?v=4"}], :body ";; attach metadata to var x\n(def ^{:version 1} x [1 2 3])\n\n;; retrieve metadata of var x: note the notation\n(meta #'x)\n;; =>\n{:version 1,\n :line 3,\n :column 1,\n :file \"...\",\n :name x,\n :ns ...}\n\n;; attach metadata to an obj\n(def y ^{:version 1} [1 2 3])\n\n(meta y) ;=> {:version 1}\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/5283430?v=4", :account-source "github", :login "randomizedthinking"}, :created-at 1670874928008, :updated-at 1670875211552, :_id "63978730e4b0b1e3652d7699"}], :notes nil, :arglists ["obj"], :doc "Returns the metadata of obj, returns nil if there is no metadata.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/meta"} {:ns "clojure.core", :name "find-protocol-impl", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos nil, :line 535, :examples nil, :notes nil, :arglists ["protocol x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/find-protocol-impl"} {: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 [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (bit-and-not 2r1100 2r1001) ; (and X (not Y))\n4\n;; 4 = 2r0100", :created-at 1280339735000, :updated-at 1332952979000, :_id "542692cfc026201cdc326e25"} {:body ";; 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", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1414515398672, :updated-at 1414515782150, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}], :_id "544fcac6e4b03d20a1024296"} {:updated-at 1666990058605, :created-at 1666990058605, :author {:login "bhlieberman", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/60364696?v=4"}, :body ";;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", :_id "635c3feae4b0b1e3652d767d"}], :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"} {:added "1.5", :ns "clojure.core", :name "*default-data-reader-fn*", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [{:created-at 1529611952524, :author {:login "puredanger", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/171129?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "*data-readers*", :ns "clojure.core"}, :_id "5b2c06b0e4b00ac801ed9e1a"} {:created-at 1529611964217, :author {:login "puredanger", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/171129?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "tagged-literal", :ns "clojure.core"}, :_id "5b2c06bce4b00ac801ed9e1b"}], :dynamic true, :line 7787, :examples [{:editors [{:login "puredanger", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/171129?v=4"}], :body ";; Clojure includes a generic tagged-literal type, able to read any\n;; tagged literal. This makes a great default-data-reader-fn.\n\n;; Clojure can't read tagged literals without a registered reader:\nuser=> #object[clojure.lang.Namespace 0x23bff419 \"user\"]\nRuntimeException No reader function for tag object clojure.lang.LispReader$CtorReader.readTagged (LispReader.java:1430)\n\n;; Set tagged-literal to be the default tagged value reader:\nuser=> (set! *default-data-reader-fn* tagged-literal)\n\n;; Try again\nuser=> #object[clojure.lang.Namespace 0x23bff419 \"user\"]\n#object [clojure.lang.Namespace 599782425 \"user\"]\n\n;; Now it works, and reads to a TaggedLiteral object, which\n;; supports ILookup on :tag and :form keys\nuser=> [(:tag *1) (:form *1)]\n[object [clojure.lang.Namespace 599782425 \"user\"]]\n", :author {:avatar-url "https://avatars0.githubusercontent.com/u/171129?v=4", :account-source "github", :login "puredanger"}, :created-at 1529611907877, :updated-at 1529636650211, :_id "5b2c0683e4b00ac801ed9e19"}], :notes nil, :arglists [], :doc "When no data reader is found for a tag and *default-data-reader-fn*\n is non-nil, it will be called with two arguments,\n the tag and the value. If *default-data-reader-fn* is nil (the\n default), an exception will be thrown for the unknown tag.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*default-data-reader-fn*"} {:added "1.0", :ns "clojure.core", :name "var?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289214474000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "def", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dc9"} {:created-at 1289214479000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "var", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dca"} {:created-at 1362015178000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "var-get", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dcc"} {:created-at 1362015184000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "var-set", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dcd"} {:created-at 1362015190000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-local-vars", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dce"}], :line 4975, :examples [{:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [], :body "(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", :created-at 1289214469000, :updated-at 1289214469000, :_id "542692cac026201cdc326b63"} {:author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :editors [], :body "=> *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", :created-at 1362015139000, :updated-at 1362015139000, :_id "542692d5c026201cdc3270b2"}], :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"} {:ns "clojure.core", :name "method-sig", :file "clojure/core_proxy.clj", :type "function", :column 1, :see-alsos nil, :line 20, :examples [{:updated-at 1682607087713, :created-at 1496052873728, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body ";;;; (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])", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4", :account-source "github", :login "tomdl89"}], :_id "592bf489e4b093ada4d4d791"}], :notes nil, :arglists ["meth"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/method-sig"} {:added "1.0", :ns "clojure.core", :name "unchecked-add-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1423522083291, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "+", :library-url "https://github.com/clojure/clojure"}, :_id "54d93923e4b0e2ac61831d2d"} {:created-at 1423522088305, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "+'", :library-url "https://github.com/clojure/clojure"}, :_id "54d93928e4b081e022073c73"} {:created-at 1488034480881, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unchecked-subtract-int", :ns "clojure.core"}, :_id "58b19ab0e4b01f4add58fe63"}], :line 1191, :examples [{:updated-at 1488034461415, :created-at 1488034461415, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :body ";; Adding two int-range Longs works\n(unchecked-add-int 1 1)\n;;=> 2\n\n;; Adding two int-range BigInts works\n(unchecked-add-int 1N 1N)\n;;=> 2\n\n;; Doubles are truncated\n(unchecked-add-int 1 1.9)\n;;=> 2\n\n;; BigDecimals are truncated\n(unchecked-add-int 1 1.9M)\n;;=> 2\n\n;; Uncaught integer overflow\n(unchecked-add-int Integer/MAX_VALUE 1)\n;;=> -2147483648\n\n;; Uncaught integer underflow\n(unchecked-add-int Integer/MIN_VALUE -1)\n;;=> 2147483647\n\n;; Fails for Longs outside of int range\n(unchecked-add-int 2147483648 0)\n;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)\n\n;; Fails for BigInts outside of int range\n(unchecked-add-int 2147483648N 0)\n;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)\n\n;; Fails for Doubles outside of int range\n(unchecked-add-int 2147483648.0 0)\n;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)\n\n;; Fails for BigDecimals outside of int range\n(unchecked-add-int 2147483648.0M 0)\n;;=> IllegalArgumentException Value out of range for int: 2147483648 clojure.lang.RT.intCast (RT.java:1205)", :_id "58b19a9de4b01f4add58fe62"}], :notes nil, :arglists ["x y"], :doc "Returns the sum of x and y, both int.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-add-int"} {:ns "clojure.core", :name "unquote-splicing", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [{:created-at 1319195960000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unquote", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d37"}], :line 14, :examples [{:author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=2"}, :editors [], :body "user=> (let [x `(2 3)] \n `(1 ~x))\n(1 (2 3))\n\nuser=> (let [x `(2 3)] \n `(1 ~@x)) \n(1 2 3)\n", :created-at 1305077817000, :updated-at 1305077817000, :_id "542692c8c026201cdc326a73"} {:author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :editors [], :body "user=> `(1 2 ~(list 3 4))\n\n(1 2 (3 4))\n\nuser=> `(1 2 ~@(list 3 4))\n\n(1 2 3 4)\n\n; borrowed from StackOverflow: \n; http://stackoverflow.com/questions/4571042/can-someone-explain-clojures-unquote-splice-in-simple-terms", :created-at 1319196585000, :updated-at 1319196585000, :_id "542692d5c026201cdc3270b0"} {:editors [{:login "green-coder", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4"}], :body ";; The splicing works at any location in the enclosing structure.\n`(1 ~@(list 2 3) 4 ~@(list 5 6) 7)\n=> (1 2 3 4 5 6 7)\n\n;; The enclosing structure can be a list, a vector or a set.\n`[1 ~@(list 2 3) 4 ~@(list 5 6) 7]\n=> [1 2 3 4 5 6 7]\n\n`#{1 ~@(list 2 3) 4 ~@(list 5 6) 7}\n=> #{7 1 4 6 3 2 5}\n\n;; The splicing produces a sequence from any `sequential?` value.\n`(1 ~@'(2 3) 4 ~@[5 6] 7 ~@(range 8 10))\n=> (1 2 3 4 5 6 7 8 9)\n\n`(1 ~@{2 3 4 5} 6)\n=> (1 [2 3] [4 5] 6)\n\n;; It currently does not work well inside maps.\n;; https://dev.clojure.org/jira/browse/CLJ-1425\n`{1 2 ~@[3 4]}\nSyntax error reading source at (REPL:1:15).\nMap literal must contain an even number of forms\n\n`{1 ~@[2 3] 4 ~@[5 6]}\n=> {1 2, 3 4, 5 6}\n\n;; Workaround: don't use the map literals\n`(hash-map 1 2 ~@[3 4])\n=> (clojure.core/hash-map 1 2 3 4)", :author {:avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4", :account-source "github", :login "green-coder"}, :created-at 1547668738996, :updated-at 1547671826780, :_id "5c3f8d02e4b0ca44402ef61c"}], :notes nil, :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unquote-splicing"} {:added "1.6", :ns "clojure.core", :name "hash-ordered-coll", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1495656275875, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "hash-unordered-coll", :ns "clojure.core"}, :_id "5925e753e4b093ada4d4d744"} {:created-at 1495656285147, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "hash", :ns "clojure.core"}, :_id "5925e75de4b093ada4d4d745"}], :line 5186, :examples [{:updated-at 1495656268428, :created-at 1495656268428, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body ";;;; 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", :_id "5925e74ce4b093ada4d4d743"} {:updated-at 1495657079980, :created-at 1495657079980, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body ";;;;\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", :_id "5925ea77e4b093ada4d4d747"}], :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"} {:added "1.1", :ns "clojure.core", :name "future", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1332389737000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "future-cancel", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c95"} {:created-at 1336536261000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "shutdown-agents", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c96"} {:created-at 1349259124000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "promise", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c97"} {:created-at 1349558136000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "realized?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c98"} {:created-at 1291441344000, :author {:login "pauldoo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5cb916d3c8abc9f45a093209e72489fb?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "delay", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e73"} {:created-at 1291473035000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "future?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e74"} {:created-at 1300437104000, :author {:login "ninjudd", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7ced25585a7556e9b9b975c1f9e136e3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "future-call", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e75"} {:created-at 1413483298913, :author {:login "Chort409", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1062637?v=2"}, :to-var {:ns "clojure.core", :name "future-done?", :library-url "https://github.com/clojure/clojure"}, :_id "54400b22e4b05802a3cc25dc"} {:created-at 1537551889359, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "locking", :ns "clojure.core"}, :_id "5ba52e11e4b00ac801ed9ea3"}], :line 6990, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "azkesz", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/467196a4f2498080c9740a81fcbde855?r=PG&default=identicon"} {:login "azkesz", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/467196a4f2498080c9740a81fcbde855?r=PG&default=identicon"} {:login "azkesz", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/467196a4f2498080c9740a81fcbde855?r=PG&default=identicon"} {:login "yayitswei", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/179c73a6ff978b738c014abeb1ead0f9?r=PG&default=identicon"} {:login "luke", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ac463e1534de6c3a7bbe42365286cd?r=PG&default=identicon"}], :body ";; A future's calculation is started here and it runs in another thread\nuser=> (def f (future (Thread/sleep 10000) (println \"done\") 100))\n#'user/f\n;;if you wait 10 seconds before dereferencing it you'll see \"done\"\n\n;; When you dereference it you will block until the result is available.\nuser=> @f\ndone\n100\n\n;; Dereferencing again will return the already calculated value.\n=> @f\n100\n", :created-at 1281077331000, :updated-at 1346904770000, :_id "542692c9c026201cdc326a74"} {:author {:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "yayitswei", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/179c73a6ff978b738c014abeb1ead0f9?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/2139?v=3", :account-source "github", :login "jamieorc"} {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}], :body ";; save the example in a script (e.g. test-future.clj) then run it in the console\n;;\n;; > clojure test-future.clj\n\n(println \"[Main] calculate the answer to life the universe and everything\")\n\n;; Used Thread/sleep to simulate long running process\n(def what-is-the-answer-to-life\n (future \n (println \"[Future] started computation\")\n (Thread/sleep 3000) ;; running for 3 seconds\n (println \"[Future] completed computation\")\n 42))\n \n(println \"[Main] created future\")\n\n(Thread/sleep 1000)\n(println \"[Main] do other things while waiting for the answer\")\n(println \"[Main] get the answer\")\n(println \"[Main] the result\" @what-is-the-answer-to-life)\n(shutdown-agents)\n\n\n;; You may get something like this\n;;\n;; [Main] calculate the answer to life, the universe and everything\n;; [Future] started computation\n;; [Main] created future\n;; [Main] do other things while waiting for the answer\n;; [Main] get the answer\n;; [Future] completed computation\n;; [Main] the result 42\n\n\n;; Note: If you leave out the call to (shutdown-agents), the program\n;; will on most (all?) OS/JVM combinations \"hang\" for 1 minute before\n;; the process exits. It is waiting for a thread created by the\n;; future call to be shut down. shutdown-agents will shut them down\n;; immediately, or (System/exit ) will exit immediately\n;; without waiting for them to shut down.\n\n;; This wait occurs even if you use futures indirectly through some other Clojure\n;; functions that use them internally, such as pmap or clojure.java.shell/sh\n\n;; http://dev.clojure.org/jira/browse/CLJ-124 is a ticket opened against Clojure,\n;; as this 1-minute wait is not considered desirable behavior.", :created-at 1312375403000, :updated-at 1518117159450, :_id "542692c9c026201cdc326a7b"} {:editors [{:avatar-url "https://avatars.githubusercontent.com/u/367789?v=3", :account-source "github", :login "mattvvhat"} {:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}], :updated-at 1462724896381, :created-at 1428550055119, :author {:avatar-url "https://avatars.githubusercontent.com/u/367789?v=3", :account-source "github", :login "mattvvhat"}, :body ";; Futures will not raise their exceptions...\n=> (def my-future (future (/ 1 0))\n\n;; ...until dereferenced!\n=> @my-future\nArithmeticException Divide by zero clojure.lang.Numbers.divide", :_id "5525f1a7e4b033f34014b768"} {:editors [{:login "siddharthjain-in", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6537820?v=4"}], :body ";; Given two URLs, create two futures to slurp their HTML, and return \n;; the page that returns first.\n;; This works because promises can only be delivered once.\n(let [p (promise)]\n (let [angieslist \"https://angieslist.com\" \n homeadvisor \"https://homeadvisor.com\"]\n (doseq [url [angieslist homeadvisor]]\n (future (let [response (slurp url)]\n (deliver p response)))))\n @p)\n", :author {:avatar-url "https://avatars1.githubusercontent.com/u/1291508?v=4", :account-source "github", :login "tomgeorge"}, :created-at 1590118285193, :updated-at 1627314798087, :_id "5ec7478de4b087629b5a190e"} {:editors [{:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}], :body ";; You may want to do some cleanup whenever you cancel your `future`\n;; InterruptedException is the catch!\n\n;; lets say we want to feed our doge, but only a limited time...\n(defn connect! [conn] (println (reset! conn \"[doge] very yum\")))\n(defn response [conn] (println (reset! conn \"[doge] so full\")))\n(defn clean [conn] (println (reset! conn \"[doge] so hungry\")))\n\n(let [feed-time (rand-int 2000)\n connection (atom \"[doge] such ready\")\n doge-ops (future\n (try\n (println @connection)\n (connect! connection)\n (Thread/sleep 1000)\n (response connection)\n (catch InterruptedException ie\n (clean connection))\n (finally (println \"[doge] wow\"))))]\n (printf \"[Main] granting many feeding time: %dms\\n\" feed-time)\n (if (= :too-late (deref doge-ops feed-time :too-late))\n (do (println \"[Main] stop!\")\n (future-cancel doge-ops))\n @doge-ops))\n\n;; if he's lucky:\n[Main] granting many feeding time: 1582ms\n[doge] such ready\n[doge] very yum\n[doge] so full\n[doge] wow\n=> nil\n\n;; if he's unlucky:\n[Main] granting many feeding time: 569ms\n[doge] such ready\n[doge] very yum\n[Main] stop!\n=> true\n[doge] so hungry\n[doge] wow\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4", :account-source "github", :login "loeschzwerg"}, :created-at 1651240015047, :updated-at 1651241054178, :_id "626bec4fe4b0b1e3652d75d8"}], :macro true, :notes nil, :arglists ["& body"], :doc "Takes a body of expressions and yields a future object that will\n invoke the body 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 of\n deref with timeout is used. See also - realized?.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/future"} {:added "1.0", :ns "clojure.core", :name "reset-meta!", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1458508963890, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "meta", :ns "clojure.core"}, :_id "56ef14a3e4b09295d75dbf31"} {:created-at 1458508972022, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "vary-meta", :ns "clojure.core"}, :_id "56ef14ace4b09295d75dbf32"} {:created-at 1458508987478, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "alter-meta!", :ns "clojure.core"}, :_id "56ef14bbe4b09295d75dbf33"} {:created-at 1458509000330, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "with-meta", :ns "clojure.core"}, :_id "56ef14c8e4b09295d75dbf34"}], :line 2416, :examples [{:updated-at 1458508861290, :created-at 1458508861290, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :body "(def ^{:key \"val\"} my-var \"\")\n;;=> #'user/my-var\n\n(meta #'my-var)\n;;=> {:key \"val\", :ns #, :name my-var, :file \"NO_SOURCE_PATH\", :column 1, :line 1}\n\n(reset-meta! #'my-var {:new-key \"new-val\"}) ; replace all metadata\n;;=> {:new-key \"new-val\"}\n\n(meta #'my-var)\n;;=> {:new-key \"new-val\"}\n\n", :_id "56ef143de4b0b41f39d96ceb"}], :notes nil, :arglists ["iref metadata-map"], :doc "Atomically resets the metadata for a namespace/var/ref/agent/atom", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reset-meta!"} {:added "1.0", :ns "clojure.core", :name "cycle", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1360759662000, :author {:login "rahulpilani", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3c3585fc1c6bf074ed5f268c9ebcb2f?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "lazy-seq", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ea1"} {:created-at 1434128252248, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :to-var {:ns "clojure.core", :name "map", :library-url "https://github.com/clojure/clojure"}, :_id "557b0f7ce4b03e2132e7d18d"} {:created-at 1553543700422, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "repeat", :ns "clojure.core"}, :_id "5c993214e4b0ca44402ef6c9"}], :line 2979, :examples [{:author {:login "nipra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/142529?v=3"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"}], :body "user=> (take 5 (cycle [\"a\" \"b\"]))\n(\"a\" \"b\" \"a\" \"b\" \"a\")\n\nuser=> (take 10 (cycle (range 0 3)))\n(0 1 2 0 1 2 0 1 2 0)\n\n", :created-at 1279160241000, :updated-at 1305843374000, :_id "542692ccc026201cdc326c30"} {:body ";; Typically map works through its set of collections\n;; until any one of the collections is consumed.\n;; 'cycle' can be used to repeat the shorter collections\n;; until the longest collection is consumed.\n(mapv #(vector %2 %1) (cycle [1 2 3 4]) [:a :b :c :d :e :f :g :h :i :j :k :l])\n;;=> [[:a 1] [:b 2] [:c 3] [:d 4] [:e 1] [:f 2] [:g 3] [:h 4] [:i 1] [:j 2] [:k 3] [:l 4]]", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :created-at 1434128630375, :updated-at 1434128842939, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :_id "557b10f6e4b01ad59b65f4f2"}], :notes nil, :arglists ["coll"], :doc "Returns a lazy (infinite!) sequence of repetitions of the items in coll.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/cycle"} {:added "1.0", :ns "clojure.core", :name "fn", :special-form true, :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1360339005000, :author {:login "ViljamiPeltola", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1535c08820796d57a212a46a6bdd4cca?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defn", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c77"}], :line 4513, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"} {:login "jumblerg", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f9e06cdf33ea6f2958a8b6430d9fe22?r=PG&default=identicon"} {:login "jumblerg", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f9e06cdf33ea6f2958a8b6430d9fe22?r=PG&default=identicon"}], :body ";; simple anonymous function passed to (map )\nuser=> (map (fn [x] (* x x)) (range 1 10))\n(1 4 9 16 25 36 49 64 81) \n\n;; anonymous function with a name. not so anonymous now is it?\n;; this is useful in stack traces\n(fn add [a b] (+ a b))\n\n;; anonymous function with two params, the second is destructured\nuser=> (reduce (fn [m [k v]] (assoc m v k)) {} {:b 2 :a 1 :c 3})\n{2 :b, 1 :a, 3 :c} \n\n;; define and instantly call an anonymous function\nuser=> ((fn [a b c] (+ a b c)) 2 4 6)\n12\n\n;; define and instantly call an anonymous variadic function \n;; \"nums\" is a list here\nuser=> ((fn [& nums] (/ (apply + nums) (count nums))) 1 2 3 4)\n5/2 \n\n;; define and instantly call an anonymous mixed function\n;; \"nums\" is a list, while \"int\" is a number\nuser=> ((fn [int & nums] (+ int (/ (apply + nums) (count nums)))) 10 1 2 3 4)\n25/2 \n\n;; define and instantly call an anonymous overloaded function \n;; even though it is quite pointless\nuser=> ((fn ([a] (inc a)) ([a b] (+ a b))) 3)\n4\n\n", :created-at 1280346731000, :updated-at 1410072276000, :_id "542692c7c026201cdc326977"} {:author {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; the shortcut form for (fn ) is #( )\n;; where parameters are referred by their index with the prefix %\n\n;; the equivalent of \nuser=> ((fn [a b c] (+ a b c)) 2 4 6)\n12\n\n;; is\nuser=> (#(+ %1 %2 %3) 2 4 6)\n12\n", :created-at 1284093085000, :updated-at 1285487263000, :_id "542692c7c026201cdc326983"} {:editors [{:login "enc7", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/12020265?v=3"}], :body ";; shortcut form #() cannot be used for maps etc.\n\nuser=> ((fn [] {:a 1}))\n{:a 1}\n\nuser=> (#({:a 1}))\nArityException Wrong number of args (0) passed to: PersistentArrayMap\n\nuser=> (#([1]))\nArityException Wrong number of args (0) passed to: PersistentVector\n\n;; explanation for the\tfirst error:\n;; #(f) is a shortcut for (fn [] (f))\n;; that means (#({:a 1})) is shortcut for ((fn [] ({:a 1})))\n;; which leads to the error above because you cannot apply a map to an empty\n;; argument list.\n\n;; i.e. you can only use #() shortcut if the fn body is a list.\n;; As ((fn [] {:a 1})) has the same result \n;; as ((fn [] (identity {:a 1}))), you can write:\n\nuser=> (#(identity {:a 1}))\n{:a 1}", :author {:avatar-url "https://avatars.githubusercontent.com/u/5733420?v=3", :account-source "github", :login "trimtab613"}, :created-at 1442862274788, :updated-at 1448575959557, :_id "560054c2e4b08e404b6c1c80"} {:updated-at 1515615145069, :created-at 1515615145069, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;map and anonymous function\n;;apply a function to a collection using an anonymous function\n\n(defn byten\n [nums]\n (map #(* 10 %) nums))\n\n(byten [1 2 3 4 5])\n;;(10 20 30 40 50)", :_id "5a5673a9e4b0a08026c48ceb"} {:updated-at 1565772877274, :created-at 1565772877274, :author {:login "terjedahl", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/11754710?v=4"}, :body ";; shortcut form #() expands to an args-list-count as per \n;; the highest N in %N references within it, \n;; irrespective of whether a lower %N is referenced or not:\n\n(macroexpand-1 '#(prn))\n;;=> (fn* [] (prn))\n\n(macroexpand-1 '#(prn %))\n;;=> (fn* [p1__13122#] (prn p1__13122#))\n\n(macroexpand-1 '#(prn %1))\n;;=> (fn* [p1__13127#] (prn p1__13127#))\n\n(macroexpand-1 '#(prn %2))\n;;=> (fn* [p1__13133# p2__13132#] (prn p2__13132#))\n\n\n;; This will not work because the shortcut expands to a 0-arg fn:\n(let [a (atom :val0)] \n (add-watch a :key #(prn 'CHANGED))\n (reset! a :val1))\n;; Execution error (ArityException) at user/eval13174 (form-init5982058823921663207.clj:3).\n;; Wrong number of args (4) passed to: user/eval13174/fn--13175\n\n;; But this will work because simply referring to %4 expands it to a 4-arg fn:\n(let [a (atom :val0)] \n (add-watch a :key #(do %4 (prn 'CHANGED)))\n (reset! a :val1))\n;;CHANGED\n;;=> :val1 \n\n;; See the 4th bullet-point under \"dispatch macro\":\n;; https://clojure.org/reference/reader#_dispatch", :_id "5d53cc4de4b0ca44402ef7a3"}], :macro true, :notes [{:updated-at 1396626727000, :body "The signature is wrong. It should be (quoting from [clojure.org][1])\r\n\r\n`(fn name? [params* ] exprs*)`\r\n\r\n`(fn name? ([params* ] exprs*)+)`\r\n\r\n\r\n [1]: http://clojure.org/special_forms#fn", :created-at 1396626504000, :author {:login "Thumbnail", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/db68e51797a2382e185b42ce6534b7a4?r=PG&default=identicon"}, :_id "542692edf6e94c6970522023"} {:author {:login "terjedahl", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11754710?v=3"}, :updated-at 1461052793332, :created-at 1461052793332, :body "What is the purpose of `name?` ?", :_id "5715e579e4b0fc95a97eab4d"} {:author {:login "vvvvalvalval", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5859120?v=3"}, :updated-at 1463756441418, :created-at 1463756441418, :body "@terjedahl `name?` allows for self-recursion, as well as generating more human-friendly class names; it can also make the code clearer.", :_id "573f2699e4b0a1a06bdee494"} {:author {:login "battlmonstr", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11477595?v=3"}, :updated-at 1471784633567, :created-at 1471784633567, :body "This leaves more questions. What is the performance cost? Why (fn name...) is repeated twice? What is a \"binding-form\"?\n\nThe syntax looks good compared to [lambda function](http://dobegin.com/lambda-functions-everywhere/) syntax in other programming languages.", :_id "57b9a6b9e4b0709b524f04d2"} {:author {:login "bfabry", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/29587?v=3"}, :updated-at 1475793669553, :created-at 1475793669553, :body "`fn` also supports the prepost map, the same as `defn`\n```\nboot.user=> (def adder (fn [x] {:post [(pos? %)]} (inc x)))\n#'boot.user/adder\nboot.user=> (adder -2)\n\njava.lang.AssertionError: Assert failed: (pos? %)\n```", :_id "57f6d305e4b0709b524f052a"} {:body "A function can be defined taking specified keyword arguments:\n\n```clojure\n(defn foo [req-1 req-2 & {:keys [key-1 key-2]}\n (list req-1 req-2 key-1 key-2))\n\n(foo a b)\n(foo a b :key-1 100)\n(foo a b :key-2 200)\n(foo a b :key-2 100 :key-1 200)\n```", :created-at 1602578421430, :updated-at 1602578490558, :author {:avatar-url "https://avatars1.githubusercontent.com/u/6414129?v=4", :account-source "github", :login "jimka2001"}, :_id "5f8567f5e4b0b1e3652d73d9"}], :arglists ["& sigs"], :doc "params => positional-params* , or positional-params* & next-param\n positional-param => binding-form\n next-param => binding-form\n name => symbol\n\n Defines a function", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/fn", :forms ["(fn name? [params*] exprs*)" "(fn name? ([params*] exprs*) +)"]} {:added "1.0", :ns "clojure.core", :name "seque", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 5397, :examples [{:author {:login "Chouser", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7a0192050ed6488670acfd3f59405c10?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (let [start (System/nanoTime)\n q (seque\n (iterate\n #(do (Thread/sleep 400) (inc %))\n 0))]\n (println \"sleep five seconds...\")\n (Thread/sleep 5000)\n (doseq [i (take 20 q)]\n (println (int (/ (- (System/nanoTime) start) 1e7))\n \":\" i)))\n\n\n;; The iterate form returns a lazy seq that delays nearly a half-second \n;; before returning each subsequent item. Here seque starts a thread \n;; generating the lazy seq.\n\n;; The body of the let allows the seque thread to get ahead by five seconds\n;; before it begins consuming the seq using doseq. The doseq prints a \n;; timestamp and the value from the seq when it becomes available. The\n;; first 11 or so are available almost instantly, until the consuming \n;; doseq catches up with the producing iterate, at which point the consumer\n;; blocks for 400ms before each item can be printed.\n\n;;sleep five seconds...\n500 : 0\n500 : 1\n500 : 2\n500 : 3\n500 : 4\n500 : 5\n500 : 6\n500 : 7\n500 : 8\n500 : 9\n500 : 10\n500 : 11\n520 : 12\n560 : 13\n600 : 14\n640 : 15\n680 : 16\n720 : 17\n760 : 18\n800 : 19\n\n", :created-at 1283038869000, :updated-at 1285494350000, :_id "542692c9c026201cdc326ad1"} {:updated-at 1519066526582, :created-at 1519066439016, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; A relatively fast producer (a file filter) and a variable speed consumer\n;; (because of pagination) are piped together. Use seque to enable search ahead \n;; of \"n\" items assuming consumer will soon paginate.\n\n(defn search-files [q root n]\n (->> (java.io.File. root)\n file-seq\n (map (memfn getPath))\n (filter #(re-find q %))\n (seque n)))\n\n(defn paginate [n]\n (let [root (System/getProperty \"user.home\")\n search (search-files #\"\\.clj$\" root 1000)]\n (loop [results (partition n search)]\n (println (with-out-str (clojure.pprint/write (first results))))\n (println \"more?\")\n (when (= \"y\" (read-line))\n (recur (rest results))))))\n\n(paginate 3)\n;; (\"/Users/reborg/.atom/fixtures/bad.clj\"\n;; \"/Users/reborg/.atom/fixtures/empty.clj\"\n;; \"/Users/reborg/.atom/fixtures/good.clj\")\n;; more?\n\n;; Note: seque is now producing 997 items ahead.", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :_id "5a8b1d47e4b0316c0f44f8cd"}], :notes nil, :arglists ["s" "n-or-q s"], :doc "Creates a queued seq on another (presumably lazy) seq s. The queued\n seq will produce a concrete seq in the background, and can get up to\n n items ahead of the consumer. n-or-q can be an integer n buffer\n size, or an instance of java.util.concurrent BlockingQueue. Note\n that reading from a seque can block if the reader gets ahead of the\n producer.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/seque"} {:added "1.0", :ns "clojure.core", :name "empty?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1350338539000, :author {:login "dansalmo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "seq", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ba1"} {:created-at 1435246118250, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:ns "clojure.core", :name "empty", :library-url "https://github.com/clojure/clojure"}, :_id "558c1e26e4b0fad27b85f926"} {:created-at 1448373938039, :author {:login "BernhardBln", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4759839?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "not-empty", :ns "clojure.core"}, :_id "56546eb2e4b0538444398279"}], :line 6206, :examples [{:updated-at 1441306150425, :created-at 1279073789000, :body "user=> (empty? ())\ntrue\nuser=> (empty? '(1))\nfalse", :editors [{:login "Ortuna", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/221008?v=3"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/147981?v=3", :account-source "github", :login "dpritchett"}, :_id "542692cac026201cdc326b85"} {:updated-at 1350271972000, :created-at 1279386965000, :body "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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon", :account-source "clojuredocs", :login "dansalmo"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :_id "542692cac026201cdc326b86"} {:updated-at 1441306161007, :created-at 1280205236000, :body "user=> (drop-while empty? [\"\" [] \"foobar\"])\n(\"foobar\")", :editors [{:login "Ortuna", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/221008?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon", :account-source "clojuredocs", :login "Jacolyte"}, :_id "542692cac026201cdc326b89"} {:author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :editors [], :body "user=> (empty? nil)\ntrue", :created-at 1401128995000, :updated-at 1401128995000, :_id "542692d2c026201cdc326f9c"} {:editors [{:login "nodename", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/48810?v=4"}], :body ";; 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? '())]))", :author {:avatar-url "https://avatars.githubusercontent.com/u/7597818?v=3", :account-source "github", :login "Jjunior130"}, :created-at 1482301932387, :updated-at 1664300394921, :_id "585a21ece4b004d3a355e2d4"}], :notes [{:updated-at 1402523411000, :body "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).", :created-at 1402523411000, :author {:login "cap10morgan", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ccd26ba29b49316b38a46f0aa0e96893?r=PG&default=identicon"}, :_id "542692edf6e94c6970522029"} {:updated-at 1405724559000, :body "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)) ", :created-at 1405724559000, :author {:login "phreed", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3a0c739cf289be18be932dc3022e6fd3?r=PG&default=identicon"}, :_id "542692edf6e94c697052202d"} {:body "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```", :created-at 1421094984999, :updated-at 1421094984999, :author {:login "moea", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1453611?v=3"}, :_id "54b43048e4b081e022073c01"} {:author {:login "cmal", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1773318?v=3"}, :updated-at 1478343485388, :created-at 1478343485388, :body "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? ...))?", :_id "581dbb3de4b024b73ca35a22"} {:author {:login "yogsototh", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/93899?v=3"}, :updated-at 1481783695983, :created-at 1481783695983, :body "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~~~", :_id "5852398fe4b004d3a355e2ba"} {:body "```\nuser> (let [r (and (not (empty? [])))] r)\n;; => false\nuser> (let [r (and (seq []))] r)\n;; => nil\n```\n", :created-at 1605311878358, :updated-at 1605311895281, :author {:avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4", :account-source "github", :login "MicahElliott"}, :_id "5faf1d86e4b0b1e3652d7405"} {:author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4"}, :updated-at 1685380825029, :created-at 1685380764695, :body "`(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.)", :_id "6474de9ce4b08cf8563f4bc3"}], :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"} {:added "1.0", :ns "clojure.core", :name "short", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "int", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917689000, :_id "542692ebf6e94c6970521f21"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "byte", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917692000, :_id "542692ebf6e94c6970521f22"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "shorts", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917699000, :_id "542692ebf6e94c6970521f23"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "short-array", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917703000, :_id "542692ebf6e94c6970521f24"} {:created-at 1496261330759, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unchecked-short", :ns "clojure.core"}, :_id "592f22d2e4b06e730307db1a"}], :line 3498, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (class (short 1))\njava.lang.Short", :created-at 1281948540000, :updated-at 1332952892000, :_id "542692c7c026201cdc3269a1"} {:editors [{:login "wdhowe", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4631165?v=4"}], :body "(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", :author {:avatar-url "https://avatars0.githubusercontent.com/u/4631165?v=4", :account-source "github", :login "wdhowe"}, :created-at 1596573268703, :updated-at 1596590353567, :_id "5f29c654e4b0b1e3652d735f"}], :notes nil, :arglists ["x"], :doc "Coerce to short", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/short"} {:added "1.2", :ns "clojure.core", :name "definterface", :file "clojure/core_deftype.clj", :type "macro", :column 1, :see-alsos [{:created-at 1432923318577, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :to-var {:ns "clojure.core", :name "defprotocol", :library-url "https://github.com/clojure/clojure"}, :_id "5568acb6e4b03e2132e7d17b"} {:created-at 1432923344729, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :to-var {:ns "clojure.core", :name "gen-interface", :library-url "https://github.com/clojure/clojure"}, :_id "5568acd0e4b01ad59b65f4e9"} {:created-at 1432923416186, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :to-var {:ns "clojure.core", :name "defrecord", :library-url "https://github.com/clojure/clojure"}, :_id "5568ad18e4b01ad59b65f4ea"} {:created-at 1432923425325, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :to-var {:ns "clojure.core", :name "deftype", :library-url "https://github.com/clojure/clojure"}, :_id "5568ad21e4b03e2132e7d17d"}], :line 20, :examples [{:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; Part of a definterface from a Clojure program for the n-body problem\n;; at the Computer Language Benchmarks Game web site.\n;; For the rest of the program using it, see:\n;; http://github.com/jafingerhut/clojure-benchmarks/blob/master/nbody/nbody.clj-14.clj\n\n;; Currently Clojure does not permit type hints of arrays, e.g. ^ints as\n;; argument types or return types in a definterface. This may be enhanced\n;; later.\n\n(definterface IBody\n (^String name []) ;; return type String, no arguments\n (^double mass []) ;; return type double\n (^double x [])\n (clone [] \"returns copy of self\") ; return type defaults to ^Object\n ;; 3 arguments of type double. A deftype that implements this interface\n ;; must implement the method p! The definterface must use:\n ;; _BANG_ for ! in Clojure method name\n ;; _PLUS_ for +\n ;; _ for -\n (p_BANG_ [^double x ^double y ^double z] \"set pos.\")\n ;; After name demangling, this must be implemented by Clojure method named v+!\n (v_PLUS__BANG_ [^double vx ^double vy ^double vz] \"add to velocity\"))\n", :created-at 1298555484000, :updated-at 1298556086000, :_id "542692cdc026201cdc326d3c"} {:body ";; Note these differences between defprotocol and definterface:\n\n;; defprotocol requires that methods specify a first parameter, which \n;; will be the record object, while definterface requires that this\n;; parameter be left out:\n(definterface I (fooey []))\n;=> user.I\n(defprotocol P (fooey []))\n;=> IllegalArgumentException Definition of function fooey in protocol P must take at least one arg. clojure.core/emit-protocol/fn--5964 (core_deftype.clj:612)\n(defprotocol P (fooey [this]))\n;=> P\n\n;; However, defrecord requires that a parameter for the record object\n;; be used, even with interfaces. (A similar point applies to deftype.)\n(defrecord Irec [stuff] I (fooey [] \"foo\"))\n;=> CompilerException java.lang.IllegalArgumentException: Must supply at least one argument for 'this' in: fooey, compiling:(NO_SOURCE_PATH:1:1) \n(defrecord Irec [stuff] I (fooey [this] \"foo\"))\n;=> user.Irec\n(defrecord Prec [stuff] P (fooey [this] \"foo\"))\n;=> user.Prec\n\n;; Using an interface, only the dot form of the method is available with \n;; defrecord, while the protocol also allows use of normal Clojure function\n;; syntax. (Similar points apply to deftype.)\n(.fooey (Irec. 42))\n;=> \"foo\"\n(fooey (Irec. 42))\n;=> IllegalArgumentException No implementation of method: :fooey of protocol: #'user/P found for class: user.Irec clojure.core/-cache-protocol-fn (core_deftype.clj:544)\n(.fooey (Prec. 42))\n;=> \"foo\"\n(fooey (Prec. 42))\n;=> \"foo\"\n", :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :created-at 1432922847490, :updated-at 1432923131996, :editors [{:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}], :_id "5568aadfe4b03e2132e7d175"}], :macro true, :notes nil, :arglists ["name & sigs"], :doc "Creates a new Java interface with the given name and method sigs.\n The method return types and parameter types may be specified with type hints,\n defaulting to Object if omitted.\n\n (definterface MyInterface\n (^int method1 [x])\n (^Bar method2 [^Baz b ^Quux q]))", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/definterface"} {:added "1.10", :ns "clojure.core", :name "add-tap", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1590688364048, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "tap>", :ns "clojure.core"}, :_id "5ecffa6ce4b087629b5a1919"} {:created-at 1590688390865, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "remove-tap", :ns "clojure.core"}, :_id "5ecffa86e4b087629b5a191c"} {:created-at 1661551771193, :author {:login "djblue", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1986211?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "datafy", :ns "clojure.datafy"}, :_id "6309449be4b0b1e3652d765a"}], :line 7868, :examples [{:updated-at 1660914021711, :created-at 1660914021711, :author {:login "earthfail", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/21296448?v=4"}, :body ";; log to a file\n(defn log [x] \n (spit \"event.log\" (str x \\newline) :append true))\n\n;; add log function to tap\n(add-tap log) ;;_=> returns nil\n\n(add-tap println)\n\n\n(tap> \"hello\") \n;; prints hello\n;; returns true if successful\n;; event.log:\n;; hello\\n\n(tap> \"clojure\")\n;; prints clojure\n;; returns true\n;; event.log:\n;; hello\\n\n;; clojure\\n\n\n;; the tap set is a hash-set so every adding the same function twice has no effect \n(add-tap println) \n(tap> \"<3\")\n;; prints <3\n;; returns true\n;; event.log:\n;; hello\\n\n;; clojure\\n\n;; <3\\n", :_id "62ff8965e4b0b1e3652d763e"} {:editors [{:login "djblue", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1986211?v=4"}], :body ";; Your tap target function can do interesting things when it receives a value\n;; before printing it\n(require '[clojure.datafy :refer [datafy]])\n(add-tap (comp prn datafy))\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/1986211?v=4", :account-source "github", :login "djblue"}, :created-at 1661551901572, :updated-at 1662581217249, :_id "6309451de4b0b1e3652d765b"}], :notes nil, :arglists ["f"], :doc "adds f, a fn of one argument, to the tap set. This function will be called with anything sent via tap>.\n This function may (briefly) block (e.g. for streams), and will never impede calls to tap>,\n but blocking indefinitely may cause tap values to be dropped.\n Remember f in order to remove-tap", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/add-tap"} {:added "1.4", :ns "clojure.core", :name "filterv", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1413317009497, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "filter", :library-url "https://github.com/clojure/clojure"}, :_id "543d8191e4b02688d208b1b7"} {:created-at 1534449404739, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "mapv", :ns "clojure.core"}, :_id "5b75d6fce4b00ac801ed9e61"}], :line 6921, :examples [{:editors [{:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4"}], :updated-at 1550019407140, :created-at 1413316994942, :author {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=2", :account-source "github", :login "phreed"}, :body ";; very similar to filter but returns a vector\n(filterv even? (range 10))\n;;=> [0 2 4 6 8]\n\n(filterv (fn [x]\n (= (count x) 1))\n [\"a\" \"aa\" \"b\" \"n\" \"f\" \"lisp\" \"clojure\" \"q\" \"\"])\n;;=> [\"a\" \"b\" \"n\" \"f\" \"q\"]\n\n(filterv #(= (count %) 1)\n [\"a\" \"aa\" \"b\" \"n\" \"f\" \"lisp\" \"clojure\" \"q\" \"\"])\n;;=> [\"a\" \"b\" \"n\" \"f\" \"q\"]\n", :_id "543d8182e4b0a3cf052fe477"}], :notes nil, :arglists ["pred coll"], :doc "Returns a vector of the items in coll for which\n (pred item) returns logical true. pred must be free of side-effects.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/filterv"} {:added "1.0", :ns "clojure.core", :name "hash", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1369891154000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "get", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aa5"} {:created-at 1495647939893, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "hash-ordered-coll", :ns "clojure.core"}, :_id "5925c6c3e4b093ada4d4d737"} {:created-at 1495647979480, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "hash-unordered-coll", :ns "clojure.core"}, :_id "5925c6ebe4b093ada4d4d738"}], :line 5165, :examples [{:updated-at 1456675282601, :created-at 1280319931000, :body "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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon", :account-source "clojuredocs", :login "gstamp"}, :_id "542692cbc026201cdc326bc4"} {:updated-at 1548542144072, :created-at 1548542144072, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :body ";; 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", :_id "5c4ce0c0e4b0ca44402ef640"} {:editors [{:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4", :account-source "github", :login "loeschzwerg"}, :created-at 1647338501091, :updated-at 1647339498450, :_id "62306405e4b0b1e3652d75bb"}], :notes [{:author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :updated-at 1456676195346, :created-at 1456676195346, :body "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).", :_id "56d31d63e4b0b41f39d96cd5"}], :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"} {:added "1.0", :ns "clojure.core", :name "quot", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1305751242000, :author {:login "Kototama", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a54a4dc204925d397ca010b9a332e74d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rem", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b7e"} {:created-at 1305751245000, :author {:login "Kototama", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a54a4dc204925d397ca010b9a332e74d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "mod", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b7f"} {:created-at 1435174860426, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:ns "clojure.core", :name "unchecked-divide-int", :library-url "https://github.com/clojure/clojure"}, :_id "558b07cce4b0fad27b85f923"} {:created-at 1468958158412, :author {:login "chrismurrph", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10278575?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "/", :ns "clojure.core"}, :_id "578e85cee4b0bafd3e2a04b2"}], :line 1261, :examples [{:updated-at 1632985121009, :created-at 1279992131000, :body ";; (quot m n) is the value of m/n, rounded towards 0 to the nearest integer.\n;; m, n need not be integers.\n\nuser=> (quot 10 3)\n3\n\nuser=> (quot 11 3)\n3\n\nuser=> (quot 12 3)\n4\n\nuser=> (quot -5.9 3)\n-1.0\n\nuser=> (quot 10 -3)\n-3\n\nuser=> (quot 15 0)\nArithmeticException / by zero clojure.lang.Numbers.quotient (Numbers.java:1764)\n\n\n;; For ClojureScript (at least v1.10.597), `num`, `div` should be integer.\n;; Otherwise, it does not work correctly due to its implementation:\nhttp://cljs.github.io/api/cljs.core/quot\n\n;; in clojure,\nuser=> (quot 286.3 21.2)\n13.0\n\n;; in clojurescript\ncljs.user=> (quot 286.3 21.2)\n12", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:login "jngbng", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/552977?v=4"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}, :_id "542692cbc026201cdc326bec"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}], :body ";; note that the \"/\" function and the quot function are not equivalent\n\nuser=> (= (/ 4 2) (quot 4 2))\ntrue\n\nuser=> (= (/ 3 2) (quot 3 2))\nfalse\n", :created-at 1316301245000, :updated-at 1316301327000, :_id "542692cbc026201cdc326bf0"}], :notes nil, :arglists ["num div"], :doc "quot[ient] of dividing numerator by denominator.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/quot"} {:added "1.0", :ns "clojure.core", :name "ns-aliases", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1374148394000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "alias", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b61"} {:created-at 1512036368133, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ns-unalias", :ns "clojure.core"}, :_id "5a1fd810e4b0a08026c48cc7"}], :line 4274, :examples [{:editors [{:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "domokato", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2388832?v=4"}], :updated-at 1646765005254, :created-at 1416004195771, :author {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"}, :body ";; clojure.core contains an alias\n(ns-aliases 'clojure.core)\n;;=> {jio #}\n\n;; To start with there are no namespace aliases in the user namespace.\n(ns-aliases 'user)\n;;=> {}\n\n;; ...but we can add an alias to the user namespace.\n(alias 'string 'clojure.string) \n(ns-aliases 'user)\n;;=> {string #{Namespace clojure.string>}\n\n", :_id "54668263e4b0dc573b892fc9"} {:body ";; Suppose you want to pass a namespace as an argument...\n(ns wip (:require [clojure.string :as string]\n [clojure.pprint :as pp]))\n(defn foo [nspace] nspace)\n\n;; ...pretty easy to do if you use the namespace symbol.\n(foo (the-ns 'clojure.string))\n;;=> #\n\n;; but, a bit of a problem if you want to pass the alias.\n(foo (the-ns 'string))\n;; java.lang.Exception: No namespace: string found...\n\n;; We can make a function that will serve using ns-aliases.\n(defn the-alias [name] (get (ns-aliases *ns*) name))\n(the-alias 'string)\n;;=> #\n\n(foo (the-alias 'string))\n;;=> #\n\n;; A more direct function can be written.\n;; but this uses an undocumented function.\n(defn the-alias [alias-name] (.lookupAlias *ns* (symbol alias-name)))\n(the-alias \"pp\")\n;;=> #\n\n\n\n\n", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :created-at 1416006101219, :updated-at 1416243613962, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :_id "546689d5e4b0dc573b892fcc"}], :notes nil, :arglists ["ns"], :doc "Returns a map of the aliases for the namespace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ns-aliases"} {:added "1.0", :ns "clojure.core", :name "read", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1313054766000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "read-string", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f56"} {:created-at 1352963657000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "*read-eval*", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f57"}], :line 3741, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [], :body "user=> (read)\n( + 1 1 ) ; <= User types this\n(+ 1 1)\nuser=> (eval (read))\n(+ 1 1) ; <= User types this\n2\n", :created-at 1286263972000, :updated-at 1286263972000, :_id "542692c8c026201cdc326a15"} {:author {:login "Chris Riddoch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c908fbef70e8540f700a6b362cf57e9e?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; WARNING: You SHOULD NOT use clojure.core/read or\n;; clojure.core/read-string to read data from untrusted sources. They\n;; were designed only for reading Clojure code and data from trusted\n;; sources (e.g. files that you know you wrote yourself, and no one\n;; else has permission to modify them).\n\n;; Instead, either:\n\n;; (1) Use another data serialization format such as JSON, XML,\n;; etc. and a library for reading them that you trust not to have\n;; vulnerabilities, or\n\n;; (2) if you want a serialization format that can be read safely and\n;; looks like Clojure data structures, use edn\n;; (https://github.com/edn-format/edn). For Clojure 1.3 and later,\n;; the tools.reader contrib library provides an edn reader\n;; (http://github.com/clojure/tools.reader). There is also\n;; clojure.edn/read and clojure.edn/read-string provided in Clojure\n;; 1.5.\n\n;; You definitely should not use clojure.core/read or read-string if\n;; *read-eval* has its default value of true, because an attacker\n;; could cause your application to execute arbitrary code while it is\n;; reading. Example:\n\nuser=> (read-string \"#=(clojure.java.shell/sh \\\"echo\\\" \\\"hi\\\")\")\n{:exit 0, :out \"hi\\n\", :err \"\"}\n\n;; It is straightforward to modify the example above into more\n;; destructive ones that remove all of your files, copy them to\n;; someone else's computer over the Internet, install Trojans, etc.\n\n;; Even if you do bind *read-eval* to false first, like so:\n\n(defn read-string-unsafely [s]\n (binding [*read-eval* false]\n (read-string s)))\n\n;; you may hope you are safe reading untrusted data that way, but in\n;; Clojure 1.4 and earlier, an attacker can send data that causes your\n;; system to execute arbitrary Java constructors. Most of these are\n;; benign, but it only takes one to ruin your application's day.\n;; Examples that should scare you:\n\n;; This causes a socket to be opened, as long as the JVM sandboxing\n;; allows it.\n(read-string-unsafely \"#java.net.Socket[\\\"www.google.com\\\" 80]\")\n\n;; This causes precious-file.txt to be created if it doesn't exist, or\n;; if it does exist, its contents will be erased (given appropriate\n;; JVM sandboxing permissions, and underlying OS file permissions).\n(read-string-unsafely \"#java.io.FileWriter[\\\"precious-file.txt\\\"]\")\n\n;; The particular issue of executing arbitrary Java constructors used\n;; in the examples above no longer works in Clojure 1.5 when\n;; *read-eval* is false. Even so, you SHOULD NEVER USE\n;; clojure.core/read or clojure.core/read-string for reading untrusted\n;; data. Use an edn reader or a different data serialization format.\n\n;; Why should I do this, you may ask, if Clojure 1.5 closes the Java\n;; constructor hole? Because clojure.core/read and read-string are\n;; designed to be able to do dangerous things, and they are not\n;; documented nor promised to be safe from unwanted side effects. If\n;; you use them for reading untrusted data, and a dangerous side\n;; effect is found in the future, you will be told that you are using\n;; the wrong tool for the job. clojure.edn/read and read-string, and\n;; the tools.reader.edn library, are documented to be safe from\n;; unwanted side effects, and if any bug is found in this area it\n;; should get quick attention and corrected.\n\n;; If you understand all of the above, and want to use read or\n;; read-string to read data from a _trusted_ source, continue on\n;; below.\n\n;; read wants its reader arg (or *in*) to be a java.io.PushbackReader.\n;; with-open closes r after the with-open body is done. *read-eval*\n;; specifies whether to allow #=() forms when reading, and evaluate\n;; them as a side effect while reading.\n\n(defn read-from-file-with-trusted-contents [filename]\n (with-open [r (java.io.PushbackReader.\n (clojure.java.io/reader filename))]\n (binding [*read-eval* false]\n (read r))))\n\nuser=> (spit \"testfile.txt\" \"{:a 1 :b 2 :c 3}\")\nnil\nuser=> (read-from-file-with-trusted-contents \"testfile.txt\")\n{:a 1, :b 2, :c 3}\n", :created-at 1325831086000, :updated-at 1364783739000, :_id "542692d5c026201cdc327056"}], :notes [{:updated-at 1286264042000, :body "This function is for reading clojure objects not a general input function.", :created-at 1286264042000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f98"}], :arglists ["" "stream" "stream eof-error? eof-value" "stream eof-error? eof-value recursive?" "opts stream"], :doc "Reads the next object from stream, which must be an instance of\n java.io.PushbackReader or some derivee. stream defaults to the\n current value of *in*.\n\n Opts is a persistent map with valid keys:\n :read-cond - :allow to process reader conditionals, or\n :preserve to keep all branches\n :features - persistent set of feature keywords for reader conditionals\n :eof - on eof, return value unless :eofthrow, then throw.\n if not specified, will throw\n\n Note that read can execute code (controlled by *read-eval*),\n and as such should be used only with trusted sources.\n\n For data structure interop use clojure.edn/read", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/read"} {:added "1.3", :ns "clojure.core", :name "unchecked-double", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 3552, :examples [{:updated-at 1507300542297, :created-at 1507300542297, :author {:login "PhillRoyle", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/7779270?v=4"}, :body "\n;; the function taking a BigDecimal with limited decimal places\n(unchecked-double 1.77M)\n=> 1.77\n\n;; the function taking a double with limited decimal places\n(unchecked-double 1.22)\n=> 1.22\n\n;; the function taking '0'\n(unchecked-double 0)\n=> 0.0\n\n;; the function does (eventually) round up...:\n(unchecked-double 1.000000000123456789)\n=> 1.0000000001234568\n;;...or down:\n(unchecked-double 1.000000000123456489)\n=> 1.0000000001234566", :_id "59d794bee4b03026fe14ea51"}], :notes nil, :arglists ["x"], :doc "Coerce to double. Subject to rounding.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-double"} {:added "1.0", :ns "clojure.core", :name "key", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1318592856000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "keys", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f60"} {:created-at 1434396249722, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :to-var {:ns "clojure.core", :name "val", :library-url "https://github.com/clojure/clojure"}, :_id "557f2659e4b01ad59b65f4f4"} {:created-at 1517622978859, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "map", :ns "clojure.core"}, :_id "5a7516c2e4b0e2d9c35f7411"} {:created-at 1517622990497, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "hash-map", :ns "clojure.core"}, :_id "5a7516cee4b0e2d9c35f7412"}], :line 1567, :examples [{:updated-at 1434395508050, :created-at 1280777907000, :body ";; the following emulates 'keys'\n(map key {:a 1 :b 2})\n;;=> (:a :b)\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692cac026201cdc326b66"} {:body ";; extracts the key of a map entry\n(key (clojure.lang.MapEntry. :a :b))\n;;=> :a\n", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :created-at 1434396125134, :updated-at 1434396125134, :_id "557f25dde4b03e2132e7d191"}], :notes nil, :arglists ["e"], :doc "Returns the key of the map entry.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/key"} {:added "1.0", :ns "clojure.core", :name "longs", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "long-array", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917385000, :_id "542692ebf6e94c6970521f53"}], :line 5383, :examples [{:updated-at 1656673080931, :created-at 1656673080931, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body "(def my-floats (float-array [1.1 2.2 3.3]));; => #'user/my-floats\n\n;; long-array will convert where possible\n(long-array my-floats);; => [1, 2, 3]\n\n;; longs will not\n(try (longs my-floats)\n (catch ClassCastException e (ex-message e)));; => \"[F cannot be cast to [J\"", :_id "62bed338e4b0b1e3652d7614"} {:editors [{:login "randomizedthinking", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5283430?v=4"}], :body ";; longs does cast but not convert arrays\n;; it is used as a type-hinting device to avoid reflections\n;; very important for computation intensive codes\n(binding [*print-meta* true]\n (def ^longs x (long-array [1 2 4]))\n (clojure.pprint/pprint #'x)) ;; ^{:tag #function[clojure.core/longs], ...}", :author {:avatar-url "https://avatars.githubusercontent.com/u/5283430?v=4", :account-source "github", :login "randomizedthinking"}, :created-at 1679352950506, :updated-at 1679353150365, :_id "6418e476e4b08cf8563f4b80"} {:updated-at 1682270999390, :created-at 1682270999390, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; Casting avoids expensive reflection, so to see the benefit, enable warning:\n(set! *warn-on-reflection* true)\n\n;; We'll def a long-array but won't type-hint the var:\n(def my-array (long-array [10 20 30 40 50 60]))\n\n;; and try to amap over it without using `longs` or type hinting amap's args:\n(amap my-array i _ (unchecked-inc ^long (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, long).\n;; => [11, 21, 31, 41, 51, 61]\n\n;; We can use `longs` to avoid reflection:\n(amap (longs my-array) i _ (unchecked-inc ^long (aget (longs my-array) i)))\n;; => [11, 21, 31, 41, 51, 61]\n\n;; Just as we can type hint in place:\n(amap ^longs my-array i _ (unchecked-inc ^long (aget ^longs my-array i)))\n;; => [11, 21, 31, 41, 51, 61]\n\n;; Or type hint the var:\n(def ^\"[J\" my-array (long-array [10 20 30 40 50 60]))\n(amap my-array i _ (unchecked-inc ^long (aget my-array i)))\n;; => [11, 21, 31, 41, 51, 61]\n", :_id "64456b17e4b08cf8563f4b90"}], :notes nil, :arglists ["xs"], :doc "Casts to long[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/longs"} {:added "1.0", :ns "clojure.core", :name "not=", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1412341716329, :author {:login "verma", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/242524?v=2"}, :to-var {:ns "clojure.core", :name "=", :library-url "https://github.com/clojure/clojure"}, :_id "542e9fd4e4b05f4d257a29a0"} {:created-at 1412341728824, :author {:login "verma", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/242524?v=2"}, :to-var {:ns "clojure.core", :name "not", :library-url "https://github.com/clojure/clojure"}, :_id "542e9fe0e4b05f4d257a29a1"}], :line 819, :examples [{:author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"} {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (not= 1 1)\nfalse\n\nuser=> (not= 1 2)\ntrue\n\nuser=> (not= true true)\nfalse\n\nuser=> (not= true false)\ntrue\n\nuser=> (not= true true true true)\nfalse\n\nuser=> (not= true true false true)\ntrue\n", :created-at 1280778104000, :updated-at 1285495471000, :_id "542692c6c026201cdc32690f"} {:updated-at 1565641574887, :created-at 1565641574887, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}, :body ";; See the Clojure Equality guide for more details:\n;; https://clojure.org/guides/equality", :_id "5d51cb66e4b0ca44402ef7a1"} {:updated-at 1677517538988, :created-at 1677513608119, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; An exception to the docstring:\n\n(not= ##NaN ##NaN)\n;; => false\n\n(not (= ##NaN ##NaN))\n;; => true\n\n;; This is because of various shortcuts for checking identity when checking equality.\n;; As a rule of thumb, don't rely on either for testing against the ##NaN literal.\n;; Decide on which logic you want, and explicitly test. E.g.\n\n(defn != [x y]\n (or (not= x y)\n (Double/isNaN x)\n (Double/isNaN y)))\n\n(!= ##NaN ##NaN)\n;; => true", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4", :account-source "github", :login "tomdl89"}], :_id "63fcd388e4b08cf8563f4b73"}], :notes nil, :tag "java.lang.Boolean", :arglists ["x" "x y" "x y & more"], :doc "Same as (not (= obj1 obj2))", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/not="} {:added "1.0", :ns "clojure.core", :name "string?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1596596389180, :author {:login "wdhowe", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4631165?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "str", :ns "clojure.core"}, :_id "5f2a20a5e4b0b1e3652d7371"}], :line 160, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "user=> (string? \"abc\")\ntrue\n\nuser=> (string? \"\")\ntrue\n\nuser=> (string? \\a)\nfalse\n\nuser=> (string? 1)\nfalse\n\nuser=> (string? [\"a\" \"b\" \"c\"])\nfalse\n\nuser=> (string? nil)\nfalse", :created-at 1280546643000, :updated-at 1423277887409, :_id "542692c7c026201cdc326945"}], :notes nil, :arglists ["x"], :doc "Return true if x is a String", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/string_q"} {:added "1.9", :ns "clojure.core", :name "uri?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1627821463966, :author {:login "Okwori", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/16775439?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "instance?", :ns "clojure.core"}, :_id "61069597e4b0b1e3652d7525"}], :line 7845, :examples [{:updated-at 1495999488091, :created-at 1495999488091, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body "(uri? (new java.net.URI \"http://clojuredocs.org/\"))\n;;=> true\n\n(uri? (new java.net.URL \"http://clojuredocs.org/\"))\n;;=> false\n(uri? \"http://clojuredocs.org/\")\n;;=> false\n", :_id "592b2400e4b093ada4d4d781"} {:updated-at 1627822753593, :created-at 1627822683340, :author {:login "Okwori", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/16775439?v=4"}, :body ";; When fetching URI db.type\n\n;;(uri? #object[com.cognitect.transit.impl.URIImpl 0x3ec31528 \"https://www.datomic.com/details.html\")\n(uri? (com.cognitect.transit.impl.URIImpl. \"https://www.datomic.com/details.html\"))\n;;=> false\n\n(instance? com.cognitect.transit.impl.URIImpl \n (com.cognitect.transit.impl.URIImpl. \"https://www.datomic.com/details.html\")) \n;;=> true\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/16775439?v=4", :account-source "github", :login "Okwori"}], :_id "61069a5be4b0b1e3652d7526"}], :notes nil, :arglists ["x"], :doc "Return true if x is a java.net.URI", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/uri_q"} {:added "1.0", :ns "clojure.core", :name "aset-double", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1349125867000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "double-array", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521abb"}], :line 3966, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; create an array of 10 doubles and set one of the elements to 3.1415\n\nuser=> (def ds (double-array 10))\n#'user/ds\nuser=> (vec ds)\n[0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0]\nuser=> (aset-double ds 3 3.1415)\n3.1415\nuser=> (vec ds)\n[0.0 0.0 0.0 3.1415 0.0 0.0 0.0 0.0 0.0 0.0]\nuser=>", :created-at 1313914664000, :updated-at 1313914664000, :_id "542692ccc026201cdc326c88"}], :notes [{:body "See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax.", :created-at 1432829167201, :updated-at 1432829167201, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :_id "55673cefe4b01ad59b65f4e1"}], :arglists ["array idx val" "array idx idx2 & idxv"], :doc "Sets the value at the index/indices. Works on arrays of double. Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aset-double"} {:added "1.0", :ns "clojure.core", :name "unchecked-multiply-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 1219, :examples nil, :notes nil, :arglists ["x y"], :doc "Returns the product of x and y, both int.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-multiply-int"} {:ns "clojure.core", :name "chunk-rest", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1443934917158, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk-first", :ns "clojure.core"}, :_id "5610b2c5e4b08e404b6c1c95"} {:created-at 1443934931280, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk-next", :ns "clojure.core"}, :_id "5610b2d3e4b0686557fcbd45"}], :line 704, :examples [{:updated-at 1443935100136, :created-at 1443935100136, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :body "(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)", :_id "5610b37ce4b08e404b6c1c96"}], :notes nil, :tag "clojure.lang.ISeq", :arglists ["s"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/chunk-rest"} {:added "1.0", :ns "clojure.core", :name "pcalls", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1299212798000, :author {:login "weakreference", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/86146f8bd5207b97701c0f16f0017334?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "pvalues", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521be6"} {:created-at 1336537809000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "future", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521be7"} {:created-at 1518042729804, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "pmap", :ns "clojure.core"}, :_id "5a7b7e69e4b0316c0f44f8aa"}], :line 7037, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (pcalls function-1 function-2 ...)\n\n(result1 result2 ...)", :created-at 1281093054000, :updated-at 1332951378000, :_id "542692cdc026201cdc326ccf"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; pcalls 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.", :created-at 1336537804000, :updated-at 1336537804000, :_id "542692d4c026201cdc32702e"}], :notes nil, :arglists ["& fns"], :doc "Executes the no-arg fns in parallel, returning a lazy sequence of\n their values", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/pcalls"} {:ns "clojure.core", :name "*allow-unresolved-vars*", :type "var", :see-alsos nil, :examples [{:updated-at 1596399672161, :created-at 1596398748332, :author {:login "eltonlaw", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/14999531?v=4"}, :body ";; Symbols are resolved during analysis phase, throws error\n;; because a is not defined anywhere reachable\nuser=> (clojure.lang.Compiler/analyze clojure.lang.Compiler$C/EXPRESSION '(+ 1 a))\n\nSyntax error compiling at (REPL:1:68).\nUnable to resolve symbol: a in this context\n\n;; Don't throw an exception on unresolvable symbol, assumption that\n;; there's somewhere else vars are defined not visible to analyzer\n;; (Ex. some external javascript library)\nuser=> (binding [*allow-unresolved-vars* true]\n #_=> (clojure.lang.Compiler/analyze clojure.lang.Compiler$C/EXPRESSION '(+ 1 a)))\n\n#object[clojure.lang.Compiler$StaticMethodExpr 0x1441fb4f \"clojure.lang.Compiler$StaticMethodExpr@1441fb4f\"]\n", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/14999531?v=4", :account-source "github", :login "eltonlaw"}], :_id "5f271c9ce4b0b1e3652d732e"}], :notes [{:author {:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=4"}, :updated-at 1617633337145, :created-at 1617633337145, :body "Originally added to support specific ClojureScript use of the analyzer in the preliminary version of ClojureScript by C.Houser, see https://github.com/richhickey/clojure-contrib/blob/master/clojurescript/src/clojure/contrib/clojurescript.clj#L307-L310.", :_id "606b2039e4b0b1e3652d74b3"}], :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*allow-unresolved-vars*"} {:added "1.2", :ns "clojure.core", :name "remove-all-methods", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1337585106000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "remove-method", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c88"} {:created-at 1341270438000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "prefers", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c89"} {:created-at 1341270443000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "methods", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c8a"} {:created-at 1341270446000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "get-method", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c8b"} {:created-at 1341270452000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defmulti", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c8c"} {:created-at 1341270455000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defmethod", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c8d"}], :line 1789, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; example showing use of multi-methods before and after remove-all-methods\n;; after removing all the methods, both circle and line tos functions throw\n;; exceptions\n\nuser=> (defmulti tos :Ob)\nnil\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=> (remove-all-methods tos)\n#\nuser=> (println (tos (circle [2 3] 3.3)))\njava.lang.IllegalArgumentException: No method in multimethod 'tos' for dispatch\nvalue: :circle (NO_SOURCE_FILE:0)\nuser=> (println (tos (line [1 1][0 0])))\njava.lang.IllegalArgumentException: No method in multimethod 'tos' for dispatch\nvalue: :line (NO_SOURCE_FILE:0)\nuser=>", :created-at 1313920017000, :updated-at 1313920017000, :_id "542692ccc026201cdc326c6b"}], :notes nil, :arglists ["multifn"], :doc "Removes all of the methods of multimethod.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/remove-all-methods"} {:added "1.0", :ns "clojure.core", :name "ns-resolve", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289661007000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "resolve", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b3d"}], :line 4359, :examples [{:author {:login "jamesqiu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc1268deaa7f2e78fe2b5ea76e6481d8?r=PG&default=identicon"}, :editors [], :body "user=> (defn f [n] (* n n n))\n#'user/f\nuser=> ((ns-resolve *ns* (symbol \"f\")) 10)\n1000", :created-at 1328007015000, :updated-at 1328007015000, :_id "542692d4c026201cdc32701e"} {:author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :editors [], :body ";; See also http://clojure.org/namespaces for information on namespaces in Clojure and how to inspect and manipulate them", :created-at 1348479408000, :updated-at 1348479408000, :_id "542692d4c026201cdc32701f"} {:updated-at 1601821751716, :created-at 1601821751716, :author {:login "jimka2001", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/6414129?v=4"}, :body ";; In the binary form of `ns-resolve`, if a fully qualified symbol is given as second argument of `ns-resolve`, then the namespace (given as first argument) is ignored\n(ns-resolve (find-ns 'clojure.core) 'clojure-rte.core/xyzzy)\n;; => #'clojure-rte.core/xyzzy", :_id "5f79dc37e4b0b1e3652d73c8"}], :notes [{:updated-at 1332557686000, :body "The appropriate value for the env arg is what you get from the implicit &env arg available to a macro.", :created-at 1332557686000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fdb"}], :arglists ["ns sym" "ns env sym"], :doc "Returns the var or Class to which a symbol will be resolved in the\n namespace (unless found in the environment), else nil. Note that\n if the symbol is fully qualified, the var/Class to which it resolves\n need not be present in the namespace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ns-resolve"} {:added "1.5", :ns "clojure.core", :name "as->", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1411997691800, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "->", :library-url "https://github.com/clojure/clojure"}, :_id "54295ffbe4b09282a148f1ed"} {:created-at 1411997716841, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "->>", :library-url "https://github.com/clojure/clojure"}, :_id "54296014e4b09282a148f1ee"} {:created-at 1411997732554, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "cond->", :library-url "https://github.com/clojure/clojure"}, :_id "54296024e4b09282a148f1ef"} {:created-at 1411997750265, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "cond->>", :library-url "https://github.com/clojure/clojure"}, :_id "54296036e4b09282a148f1f1"} {:created-at 1411997759234, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "some->", :library-url "https://github.com/clojure/clojure"}, :_id "5429603fe4b09282a148f1f2"} {:created-at 1411997771032, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "some->>", :library-url "https://github.com/clojure/clojure"}, :_id "5429604be4b09282a148f1f3"}], :line 7572, :examples [{:body "(def owners [{:owner \"Jimmy\"\n :pets (ref [{:name \"Rex\"\n :type :dog}\n {:name \"Sniffles\"\n :type :hamster}])} \n {:owner \"Jacky\" \n :pets (ref [{:name \"Spot\" \n :type :mink}\n {:name \"Puff\" \n :type :magic-dragon}])}])\n\n;; This example is contrived as there are other more \n;; terse ways of expressing the idea. It demonstrates\n;; several of the ways to extract items from a collection.\n;; Notice how the collection can be used in function or \n;; parameter position.\n(as-> owners $ (nth $ 0) (:pets $) (deref $) ($ 1) ($ :type))\n;;=> :hamster", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1412263021928, :updated-at 1412263021928, :_id "542d6c6de4b05f4d257a298b"} {:body "(as-> 0 n\n (inc n) ; n is 0 here passed from first parameter to as->\n (inc n)) ; n is 1 here passed from result of previous inc expression\n;;=> 2", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1422928871993, :updated-at 1422928871993, :_id "54d02be7e4b0e2ac61831cf2"} {:editors [{:login "jamesmacaulay", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/340?v=3"}], :body "; use it in the middle of a -> pipeline to sprinkle in some flexibility\n(-> [10 11]\n (conj 12)\n (as-> xs (map - xs [3 2 1]))\n (reverse))\n; (11 9 7)", :author {:avatar-url "https://avatars.githubusercontent.com/u/340?v=3", :account-source "github", :login "jamesmacaulay"}, :created-at 1452207578399, :updated-at 1452207828195, :_id "568eeddae4b0f37b65a3c280"} {:updated-at 1456947738297, :created-at 1456947738297, :author {:login "x", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/693546?v=3"}, :body ";; when you want to use arbitrary positioning of your argument in a thread macro\n(as-> {:a 1 :b 2} m\n (update m :a + 10)\n (reduce (fn [s [_ v]] (+ s v)) 0 m))\n\n;; when you'd like an if statement in your thread\n(as-> {:a 1 :b 2} m\n (update m :a + 10)\n (if update-b\n (update m :b + 10)\n m))", :_id "56d7421ae4b0b41f39d96cdb"} {:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"} {:login "greydrizzle", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/5403136?v=4"}], :body ";; as-> with destructured binding\n\n(let [req {:host \"//mysite.com\" :path \"/a/123\" :x \"15.1\" :y \"84.2\"}]\n (as-> req {:keys [host path x y] :as m}\n (assoc m :url (str host path))\n (assoc m :coord [(Double/valueOf x) (Double/valueOf y)])))\n\n;; {:host \"//mysite.com\" :path \"/a/123\" :x \"15.1\" :y \"84.2\" :url \"//mysite.com/a/123\" :coord [15.1 84.2]}", :author {:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1532889321412, :updated-at 1554166083397, :_id "5b5e08e9e4b00ac801ed9e3a"}], :macro true, :notes nil, :arglists ["expr name & forms"], :doc "Binds name to expr, evaluates the first form in the lexical context\n of that binding, then binds name to that result, repeating for each\n successive form, returning the result of the last form.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/as->"} {:added "1.0", :ns "clojure.core", :name "aset-boolean", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1493752979563, :author {:login "barak-haviv", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/2076998?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "boolean-array", :ns "clojure.core"}, :_id "5908dc93e4b01f4add58fea1"}], :line 3956, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; create an array of 10 booleans and set one value to true\n;; using aset-boolean\n\nuser=> (def bs (boolean-array 10))\n#'user/bs\nuser=> (vec bs)\n[false false false false false false false false false false]\nuser=> (aset-boolean bs 2 true)\ntrue\nuser=> (vec bs)\n[false false true false false false false false false false]\nuser=>", :created-at 1313914167000, :updated-at 1313914167000, :_id "542692ccc026201cdc326c67"}], :notes [{:body "See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax.", :created-at 1432829103674, :updated-at 1432829103674, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :_id "55673cafe4b03e2132e7d171"}], :arglists ["array idx val" "array idx idx2 & idxv"], :doc "Sets the value at the index/indices. Works on arrays of boolean. Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aset-boolean"} {:added "1.0", :ns "clojure.core", :name "trampoline", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289618007000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "loop", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521df6"} {:created-at 1289618015000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "recur", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521df7"} {:created-at 1422376146394, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :to-var {:ns "clojure.core", :name "letfn", :library-url "https://github.com/clojure/clojure"}, :_id "54c7bcd2e4b081e022073c35"}], :line 6299, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(defn foo [x]\n (if (< x 0)\n (println \"done\")\n #(foo (do (println :x x) (dec x)))))\n;; #'user/foo\n\n;; `trampoline` will keep calling the function \n;; for as long as \"foo\" returns a function.\n\n(trampoline foo 10)\n;; :x 10\n;; :x 9\n;; :x 8\n;; :x 7\n;; :x 6\n;; :x 5\n;; :x 4\n;; :x 3\n;; :x 2\n;; :x 1\n;; :x 0\n;; done\n;;=> nil", :created-at 1293675043000, :updated-at 1422375388791, :_id "542692cfc026201cdc326e3b"} {:body ";; Short tutorial-style article with example of using trampoline at this link:\n;; http://jakemccrary.com/blog/2010/12/06/trampolining-through-mutual-recursion/", :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :created-at 1421338043181, :updated-at 1421338043181, :_id "54b7e5bbe4b0e2ac61831cb5"} {:body ";; Using mutually recursive functions to implement a finite state machine (FSM)\n;; This machine has three states {a b c} and \n;; seven transitions {:a-b :a-c :b-a :b-c :c-a :c-b :final}.\n\n(defn foo [cmds]\n(letfn\n [(a-> [[_ & rs]]\n #(case _ \n :a-b (b-> rs)\n :a-c (c-> rs)\n false))\n (b-> [[_ & rs]]\n #(case _ \n :b-a (a-> rs)\n :b-c (c-> rs)\n false))\n (c-> [[_ & rs]]\n #(case _ \n :c-a (a-> rs)\n :c-b (c-> rs)\n :final true\n false))]\n (trampoline a-> cmds)))\n \n(foo [:a-b :b-c :c-a :a-c :final])\n;;=> true", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :created-at 1422376023904, :updated-at 1422376335709, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :_id "54c7bc57e4b081e022073c33"} {:body ";; from \n;; Mutually recursive functions are nice for implementing \n;; finite state machines (FSAs)\n\n(defn elevator [commands]\n (letfn\n [(ff-open [[_ & r]]\n \"When the elevator is open on the 1st floor\n it can either close or be done.\"\n #(case _\n :close (ff-closed r)\n :done true\n false))\n (ff-closed [[_ & r]]\n \"When the elevator is closed on the 1st floor\n it can either open or go up.\"\n #(case _\n :open (ff-open r)\n :up (sf-closed r)\n false))\n (sf-closed [[_ & r]]\n \"When the elevator is closed on the 2nd floor\n it can either go down or open.\"\n #(case _\n :down (ff-closed r)\n :open (sf-open r)\n false))\n (sf-open [[_ & r]]\n \"When the elevator is open on the 2nd floor\n it can either close or be done\"\n #(case _\n :close (sf-closed r)\n :done true\n false))]\n\n (trampoline ff-open commands)))\n\n(elevator [:close :open :close :up :open :open :done])\n ;=> false\n(elevator [:close :up :open :close :down :open :done])\n ;=> true\n;; run at your own risk!\n(elevator (cycle [:close :open])) \n ; ... runs forever", :author {:login "foxlog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/150418?v=3"}, :created-at 1431484190885, :updated-at 1592576350068, :editors [{:login "foxlog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/150418?v=3"} {:avatar-url "https://avatars0.githubusercontent.com/u/1719584?v=4", :account-source "github", :login "eihli"}], :_id "5552b71ee4b01ad59b65f4cf"} {:updated-at 1482914635322, :created-at 1482914635322, :author {:login "mhmdsalem1993", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10787314?v=3"}, :body ";; without trampoline\n(declare hatt)\n(defn catt [n]\n (when-not (zero? n)\n (when (zero? (rem n 100))\n (println \"catt:\" n))\n (hatt (dec n))))\n(defn hatt [n]\n (when-not (zero? n)\n (if (zero? (rem n 100))\n (println \"hatt:\" n))\n (catt (dec n))))\n\n;; std=> catt: 100000000\n;; std=> catt: 99999900\n;; std=> catt: 99999800\n;; std=> catt: 99999700\n;; std=> catt: 99999600\n;; std=> catt: 99999500\n;; std=> catt: 99999400\n;; .\n;; .\n;; .\n;; std => CompilerException java.lang.StackOverflowError\n\n;; with trampoline\n\n(declare hattr)\n\n(defn cattr [n]\n (when-not (zero? n)\n (when (zero? (rem n 100))\n (println \"cattr:\" n))\n (fn [] (hattr (dec n)))))\n(defn hattr [n]\n (when-not (zero? n)\n (if (zero? (rem n 100))\n (println \"hatttr:\" n))\n (fn [] (cattr (dec n)))))\n\n(trampoline cattr 10000000)\n\n;; std=> catt: 100000000\n;; std=> catt: 99999900\n;; std=> catt: 99999800\n;; std=> catt: 99999700\n;; std=> catt: 99999600\n;; std=> catt: 99999500\n;; std=> catt: 99999400\n;; .\n;; .\n;; .\n;; std=> catt: 100\n", :_id "58637b4be4b0fd5fb1cc9645"}], :notes [{:updated-at 1291742621000, :body "A tutorial on how to use trampoline is available here: \r\n\r\nhttp://pramode.net/clojure/2010/05/08/clojure-trampoline/\r\n\r\nand here:\r\n\r\nhttp://jakemccrary.com/blog/2010/12/06/trampolining-through-mutual-recursion.html", :created-at 1286956413000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f9a"} {:author {:login "dvingo", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/467827?v=4"}, :updated-at 1588175434827, :created-at 1588175434827, :body "The links above are dead. Here are the archived versions:\n\nhttps://web.archive.org/web/20190626232715/http://pramode.net:80/clojure/2010/05/08/clojure-trampoline/\n\nhttps://web.archive.org/web/20110111121137/http://jakemccrary.com:80/blog/2010/12/06/trampolining-through-mutual-recursion.html", :_id "5ea9a24ae4b087629b5a18eb"}], :arglists ["f" "f & args"], :doc "trampoline can be used to convert algorithms requiring mutual\n recursion without stack consumption. Calls f with supplied args, if\n any. If f returns a fn, calls that fn with no arguments, and\n continues to repeat, until the return value is not a fn, then\n returns that non-fn value. Note that if you want to return a fn as a\n final value, you must wrap it in some data structure and unpack it\n after trampoline returns.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/trampoline"} {:added "1.9", :ns "clojure.core", :name "double?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1496005756299, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "float?", :ns "clojure.core"}, :_id "592b3c7ce4b093ada4d4d784"} {:created-at 1496005947631, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "decimal?", :ns "clojure.core"}, :_id "592b3d3be4b093ada4d4d785"} {:created-at 1496005954103, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bigdec?", :ns "clojure.core"}, :_id "592b3d42e4b093ada4d4d786"}], :line 1426, :examples [{:updated-at 1496005747580, :created-at 1496005747580, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body ";;;; true for instances of java.lang.Double\n\n(double? 1.0)\n;;=> true\n(double? (new Double \"1\"))\n;;=> true\n\n;;;; false for instances of java.lang.Float, java.lang.BigDecimal\n\n(double? (new Float \"1\"))\n;;=> false\n(double? 1.0M)\n;;=> false\n(double? (new BigDecimal \"1\"))\n;;=> false\n", :_id "592b3c73e4b093ada4d4d783"}], :notes nil, :arglists ["x"], :doc "Return true if x is a Double", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/double_q"} {:added "1.0", :ns "clojure.core", :name "when-not", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1302596050000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d1b"} {:created-at 1323280013000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when-let", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d1c"} {:created-at 1334293346000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "if", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d1d"}], :line 499, :examples [{:updated-at 1423066223241, :created-at 1280776138000, :body ";; build tuples over sets with the same cardinality \n(map\n #(when-not (= %2 %3) [%1 %2 %3])\n (iterate inc 0) ; a lazy list of indecies\n [:a :b :c]\n [:a :a :a])\n;;=> (nil [1 :b :a] [2 :c :a])\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692c8c026201cdc326a4a"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; See examples for \"if\" explaining Clojure's idea of logical true\n;; and logical false.", :created-at 1334293370000, :updated-at 1334293370000, :_id "542692d6c026201cdc3270b7"} {:body ";; when-not is similar to unless (in other languages).\n;; An alias can be provided with a macro\n(defmacro unless [& args] `(when-not ~@args))\n\n(map #(unless (= %2 %3) [%1 %2 %3])\n (iterate inc 0) ; a lazy list for indecies\n [:a :b :c]\n [:a :a :a]) \n;;=> (nil [1 :b :a] [2 :c :a])", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}, :created-at 1423066081989, :updated-at 1423066244981, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :_id "54d243e1e4b081e022073c5c"} {:updated-at 1546901293467, :created-at 1546901293467, :author {:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4"}, :body "(when-not false 2)\n;; 2\n", :_id "5c33d72de4b0ca44402ef614"} {:updated-at 1546901306925, :created-at 1546901306925, :author {:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4"}, :body "(when-not true 2)\n;; nil\n", :_id "5c33d73ae4b0ca44402ef615"}], :macro true, :notes nil, :arglists ["test & body"], :doc "Evaluates test. If logical false, evaluates body in an implicit do.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/when-not"} {:added "1.0", :ns "clojure.core", :name "*1", :file "clojure/core.clj", :type "var", :column 1, :see-alsos [{:created-at 1302912238000, :author {:login "hoornet", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5834f829a9def19620d4014c46642172?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "*2", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b4a"} {:created-at 1302912243000, :author {:login "hoornet", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5834f829a9def19620d4014c46642172?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "*3", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b4b"}], :dynamic true, :line 6279, :examples [{:updated-at 1412880834853, :created-at 1279047952000, :body "\"Hello!\"\n;;=> \"Hello!\"\n\n*1\n;;=> \"Hello!\"\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=2", :account-source "github", :login "phreed"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :_id "542692cac026201cdc326b1a"}], :notes nil, :arglists [], :doc "bound in a repl thread to the most recent value printed", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*1"} {:added "1.0", :ns "clojure.core", :name "vec", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1291951288000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vector", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521adb"} {:created-at 1291951295000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vector?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521adc"} {:created-at 1291951303000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vector-of", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521add"}], :line 367, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4", :account-source "github", :login "dijonkitchen"} {:login "whiteknees", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/67022623?v=4"}], :body "user=> (vec '(1 2 3))\n[1 2 3]\n\nuser=> (vec [1 2 3])\n[1 2 3]\n\nuser=> (vec #{1 2 3})\n[1 2 3]\n\nuser=> (vec {:a 1 :b 2 :c 3})\n[[:a 1] [:b 2] [:c 3]]\n\nuser=> (vector {:a 1 :b 2 :c 3})\n[{:a 1, :b 2, :c 3}]\n\nuser=> (vec '())\n[]\n\nuser=> (vec nil)\n[]", :created-at 1279075384000, :updated-at 1663872522168, :_id "542692c9c026201cdc326a97"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; Warning. If the arg is a Java array, then the returned vector will alias it,\n;; and modifying the array will thus modify the vector. To avoid this, do\n;; not modify the array after the vec call. One way to guarantee this is to\n;; make a copy of the array, call vec on the new array, and then lose all\n;; references to the copy so it cannot be accessed in any way.\n\nuser=> (def a (to-array (repeat 4 0)))\n#'user/a\nuser=> (seq a)\n(0 0 0 0)\nuser=> (def v (vec a))\n#'user/v\nuser=> v\n[0 0 0 0]\n\n;; Now change a, and v changes, too, since they share state.\nuser=> (aset a 2 -5)\n-5\nuser=> v\n[0 0 -5 0]\n\n;; One way to avoid this\nuser=> (def v (vec (aclone a)))\n#'user/v\nuser=> v\n[0 0 -5 0]\nuser=> (aset a 2 -20)\n-20\nuser=> v\n[0 0 -5 0]\n", :created-at 1334463665000, :updated-at 1334463665000, :_id "542692d5c026201cdc3270b4"}], :notes nil, :arglists ["coll"], :doc "Creates a new vector containing the contents of coll. Java arrays\n will be aliased and should not be modified.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/vec"} {:added "1.0", :ns "clojure.core", :name "*print-meta*", :type "var", :see-alsos [{:created-at 1351128584000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "pr", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e5d"} {:created-at 1623879909739, :author {:login "squiter", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/238017?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "pprint", :ns "clojure.pprint"}, :_id "60ca70e5e4b0b1e3652d750d"}], :examples [{:author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :editors [{:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"} {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}], :body "user=> (binding [*print-meta* true] \n (pr (var defmacro)) )\n;;^{:macro true, :ns #, :name defmacro, :arglists ^{:line 424, :column 15} ([name doc-string? attr-map? [params*] body] [name doc-string? attr-map? ^{:line 425, :column 46} ([params*] body) + attr-map?]), :column 1, :added \"1.0\", :doc \"Like defn, but the resulting function name is declared as a\\n macro and will be used as a macro by the compiler when it is\\n called.\", :line 419, :file \"clojure/core.clj\"} #'clojure.core/defmacro\nnil\n", :created-at 1351126556000, :updated-at 1351126806000, :_id "542692d1c026201cdc326f37"} {:updated-at 1623879875905, :created-at 1623879875905, :author {:login "squiter", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/238017?v=4"}, :body "user=> (binding [*print-meta* true]\n (-> \"{:a ^{:b :c} {}}\"\n clojure.edn/read-string\n clojure.pprint/pprint))\n{:a ^{:b :c} {}}\nnil", :_id "60ca70c3e4b0b1e3652d750c"}], :notes [{:updated-at 1351128651000, :body "\"printing an object\" means via **pr** not print or println", :created-at 1351128651000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :_id "542692edf6e94c6970521ff1"} {:author {:login "squiter", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/238017?v=4"}, :updated-at 1623879652487, :created-at 1623879652487, :body "The `*print-meta*` works for `print` and `pprint` after Clojure 1.10.2. Source: https://clojure.atlassian.net/browse/CLJ-1445", :_id "60ca6fe4e4b0b1e3652d750b"}], :arglists [], :doc "If set to logical true, when printing an object, its metadata will also\n be printed in a form that can be read back by the reader.\n\n Defaults to false.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*print-meta*"} {:added "1.0", :ns "clojure.core", :name "when", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1323279976000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when-not", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aed"} {:created-at 1323279997000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when-let", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aee"} {:created-at 1334293253000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "if", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aef"} {:created-at 1602793798332, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "boolean", :ns "clojure.core"}, :_id "5f88b146e4b0b1e3652d73e5"}], :line 493, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"} {:login "frangio", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/646001f0ba2b7df47a16c0a1d5b62225?r=PG&default=identicon"}], :body "user=> (when (= 1 1) true)\ntrue\n\nuser=> (when (not= 1 1) true)\nnil", :created-at 1279071998000, :updated-at 1325845615000, :_id "542692cec026201cdc326df2"} {:author {:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"}, :editors [{:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"} {:login "ElieLabeca", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/724e1112a2be4d5af767c0cf152d087e?r=PG&default=identicon"}], :body "user=> (def has-value (when true\n (println \"Hello World\")\n \"Returned Value\"))\nHello World\n#'user/has-value\n\nuser=> has-value\n\"Returned Value\"\n\n", :created-at 1311798084000, :updated-at 1331756178000, :_id "542692cec026201cdc326df5"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; See examples for \"if\" explaining Clojure's idea of logical true\n;; and logical false.", :created-at 1334293296000, :updated-at 1334293296000, :_id "542692d6c026201cdc3270b5"} {:body ";; When is a macro of (if .. do ..)\n\nuser=> (macroexpand '(when 1 2 3 4))\n(if 1 (do 2 3 4))\n\n;; if 1 is true, do will evaluate 2 3 4, but return values of 2 and 3 would be \n;; ignored. Value of 4 (last value) would always be returned. \n;; See https://clojuredocs.org/clojure.core/do for details\n\nuser=> (if 1 (do 2 3 4))\n4\n\n", :author {:login "nickzam", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/89377?v=3"}, :created-at 1421838215231, :updated-at 1421838215231, :_id "54bf8787e4b0e2ac61831cbe"}], :macro true, :notes nil, :arglists ["test & body"], :doc "Evaluates test. If logical true, evaluates body in an implicit do.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/when"} {:added "1.0", :ns "clojure.core", :name "int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1333595304000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "char", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d49"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "long", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917185000, :_id "542692ebf6e94c6970521d4a"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "integer?", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917243000, :_id "542692ebf6e94c6970521d4b"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "ints", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917294000, :_id "542692ebf6e94c6970521d4c"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "int-array", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917326000, :_id "542692ebf6e94c6970521d4d"} {:to-var {:library-url "https://github.com/clojure/clojure", :name "short", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917681000, :_id "542692ebf6e94c6970521d4e"}], :line 882, :examples [{:updated-at 1661231771832, :created-at 1280208450000, :body "user=> (int 1)\n1\n\nuser=> (int 1M)\n1\n\nuser=> (int 1.2)\n1\n\nuser=> (int \\1)\n49\n\nuser=> (int \\a)\n97\n\n;; Strings cannot be cast to an int.\nuser=> (int \"1\")\nExecution error (ClassCastException) at user/eval175 (REPL:1).\njava.lang.String cannot be cast to java.lang.Character\n\n;; Use Java interop instead\n(Integer/parseInt \"1\")\n;;=> 1\n\n;; Using JavaScript interop for ClojureScript\n(js/parseInt \"5\")\n;;=> 5\n\n(js/parseInt \"5.22\")\n;;=> 5", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/138993?v=3", :account-source "github", :login "Dimagog"} {:avatar-url "https://avatars.githubusercontent.com/u/138993?v=3", :account-source "github", :login "Dimagog"} {:avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon", :account-source "clojuredocs", :login "Ljos"} {:login "wdhowe", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4631165?v=4"} {:avatar-url "https://avatars.githubusercontent.com/u/747125?v=4", :account-source "github", :login "metehan"} {:login "mathisto", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8226466?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon", :account-source "clojuredocs", :login "Jacolyte"}, :_id "542692cec026201cdc326d78"}], :notes [{:author {:login "jw-00000", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/2936?v=4"}, :updated-at 1529869571125, :created-at 1529869571125, :body "To convert a string containing a number to an integer, use Java's Integer/parseInt, e.g. `(Integer/parseInt \"-10\")`.", :_id "5b2ff503e4b00ac801ed9e1e"}], :arglists ["x"], :doc "Coerce to int", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/int"} {:added "1.8", :ns "clojure.core", :name "map-entry?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1602615292813, :author {:login "victoraldecoa", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/2746668?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "key", :ns "clojure.core"}, :_id "5f85f7fce4b0b1e3652d73e3"} {:created-at 1602615302919, :author {:login "victoraldecoa", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/2746668?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "val", :ns "clojure.core"}, :_id "5f85f806e4b0b1e3652d73e4"}], :line 1478, :examples [{:updated-at 1476873674402, :created-at 1476873674402, :author {:login "G1enY0ung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/15034155?v=3"}, :body "user=> (class {:a 1 :b 2})\nclojure.lang.PersistentArrayMap\n\nuser=> (class (first {:a 1 :b 2}))\nclojure.lang.MapEntry\n;; A map entry is treated as an ordered collection of key and value.\n;; https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/MapEntry.java\n\nuser=> (map-entry? (first {:a 1 :b 2}))\ntrue", :_id "58074dcae4b001179b66bdce"}], :notes nil, :arglists ["x"], :doc "Return true if x is a map entry", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/map-entry_q"} {:added "1.0", :ns "clojure.core", :name "ns-refers", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1288055172000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "ns-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a82"}], :line 4254, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [], :body "user> (ns-refers 'clojure.main)\n{sorted-map #'clojure.core/sorted-map, read-line #'clojure.core/read-line, re-pattern #'clojure.core/re-pattern, keyword? #'clojure.core/keyword?, val #'clojure.core/val, chunked-seq? #'clojure.core/chunked-seq?, *compile-path* #'clojure.core/*compile-path*, ...chop...}", :created-at 1288075058000, :updated-at 1288075058000, :_id "542692c9c026201cdc326af9"}], :notes nil, :arglists ["ns"], :doc "Returns a map of the refer mappings for the namespace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ns-refers"} {:added "1.0", :ns "clojure.core", :name "rand", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1292321223000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rand-int", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f6a"} {:created-at 1311342603000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rand-nth", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f6b"} {:created-at 1434034912362, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:ns "clojure.core", :name "shuffle", :library-url "https://github.com/clojure/clojure"}, :_id "5579a2e0e4b03e2132e7d18c"}], :line 4911, :examples [{:author {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; Test `rand` never returns `n`:\nuser=> (some (partial <= 10) (take 100000 (repeatedly (fn [] (int (rand 10))))))\nnil\n", :created-at 1279658909000, :updated-at 1285497610000, :_id "542692c8c026201cdc326a0f"} {:author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :editors [], :body "user=> (rand)\n0.17469201779243182\n\nuser=> (rand 100)\n49.542391492950834", :created-at 1286329327000, :updated-at 1286329327000, :_id "542692c8c026201cdc326a11"}], :notes nil, :arglists ["" "n"], :doc "Returns a random floating point number between 0 (inclusive) and\n n (default 1) (exclusive).", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/rand"} {:added "1.0", :ns "clojure.core", :name "second", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1295238626000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "first", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b2a"} {:created-at 1303125643000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "nth", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b2b"} {:created-at 1374512098000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "fnext", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b2c"} {:created-at 1374512133000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "next", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b2d"}], :line 91, :examples [{:updated-at 1423275208669, :created-at 1279071308000, :body "user=> (second '(:alpha :bravo :charlie))\n:bravo\n\nuser=> (second [1 2 3])\n2\n\nuser=> (second {:a 1 :b 2 :c 3})\n[:b 2]\n\nuser=> (second #{1 2 3})\n2\n\nuser=> (second [1 2])\n2\n\nuser=> (second [1])\nnil\n\nuser=> (second [])\nnil\n\nuser=> (second nil)\nnil", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"} {:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"} {:avatar-url "https://avatars.githubusercontent.com/u/138993?v=3", :account-source "github", :login "Dimagog"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/147981?v=3", :account-source "github", :login "dpritchett"}, :_id "542692c7c026201cdc326949"}], :notes [{:author {:login "glts", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1483271?v=4"}, :updated-at 1520169736267, :created-at 1520169736267, :body "Synonym of `fnext`.", :_id "5a9bf308e4b0316c0f44f90b"}], :arglists ["x"], :doc "Same as (first (next x))", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/second"} {:added "1.2", :ns "clojure.core", :name "vector-of", :file "clojure/gvec.clj", :type "function", :column 1, :see-alsos [{:created-at 1291951396000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vec", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c44"} {:created-at 1291951401000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vector", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c45"} {:created-at 1291951406000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vector?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c46"}], :line 484, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "user=> (conj (vector-of :int) 1 2 3)\n[1 2 3] ; <-- note, these are unboxed internally\n\nuser=> (vector-of :int 1 2 3)\n[1 2 3] ; same here\n\nuser=> (type (conj (vector-of :int) 1 2 3))\nclojure.core.Vec\n", :created-at 1284711309000, :updated-at 1423523824042, :_id "542692c6c026201cdc3268d1"}], :notes [{:author {:login "Hindol", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/705227?v=4"}, :updated-at 1581663088148, :created-at 1581663088148, :body "The primary use of `vector-of` is to be space efficient. As most of Clojure deals with boxed types, boxing/unboxing will happen everytime an element is taken out/inserted.", :_id "5e464370e4b0ca44402ef838"}], :arglists ["t" "t & elements"], :doc "Creates a new vector of a single primitive type t, where t is one\n of :int :long :float :double :byte :short :char or :boolean. The\n resulting vector complies with the interface of vectors in general,\n but stores the values unboxed internally.\n\n Optionally takes one or more elements to populate the vector.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/vector-of"} {:ns "clojure.core", :name "hash-combine", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos nil, :line 126, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; Calculates the hashes for x and y and produces a new hash that represents\n;; the combination of the two.\n\nuser=> (hash-combine 100 \"a\")\n-1640524969\n", :created-at 1280320404000, :updated-at 1285496804000, :_id "542692cdc026201cdc326d1e"}], :notes nil, :arglists ["x y"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/hash-combine"} {:added "1.0", :ns "clojure.core", :name ">", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1291975136000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "=", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c4f"} {:created-at 1291975141000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "not=", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c50"} {:created-at 1291975147000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "<", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c51"}], :line 1070, :examples [{:author {:login "mattdw", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ee24aacb65359196b0a1bad050f9a62f?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "Iceland_jack", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c889e0a95a3bb07f90ab28ad442f1127?r=PG&default=identicon"}], :body "user=> (> 1 2)\nfalse\nuser=> (> 2 1)\ntrue\nuser=> (> 2 2)\nfalse\nuser=> (> 6 5 4 3 2)\ntrue\nuser=> (sort > (vals {:foo 5, :bar 2, :baz 10}))\n(10 5 2)", :created-at 1280322039000, :updated-at 1340813399000, :_id "542692ccc026201cdc326c96"}], :notes nil, :arglists ["x" "x y" "x y & more"], :doc "Returns non-nil if nums are in monotonically decreasing order,\n otherwise false.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/>"} {:added "1.0", :ns "clojure.core", :name "replace", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1281451180000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.walk", :name "prewalk-replace", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dc2"} {:created-at 1281451198000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.walk", :name "postwalk-replace", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dc3"} {:created-at 1385849073000, :author {:login "Alexey Tarasevich", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/43e0398b89022d32b43de4c968069312?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dc4"} {:created-at 1439523160945, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "replace", :ns "clojure.string"}, :_id "55cd6158e4b072d7f27980e7"}], :line 5058, :examples [{:updated-at 1670326100220, :created-at 1280289240000, :body ";; Vectors in the first argument are implicitly treated like maps\n;; from zero-based indexes to values so this is equivalent to\n;;\n;; (replace {0 :zeroth, 1 :first, 2 :second, 3 :third, 4 :fourth} [0 2 4 0])\nuser=> (replace [:zeroth :first :second :third :fourth] [0 2 4 0])\n[:zeroth :second :fourth :zeroth]\n\nuser=> (replace [10 9 8 7 6] [0 2 4])\n[10 8 6]", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://www.gravatar.com/avatar/c889e0a95a3bb07f90ab28ad442f1127?r=PG&default=identicon", :account-source "clojuredocs", :login "Iceland_jack"} {:avatar-url "https://www.gravatar.com/avatar/c889e0a95a3bb07f90ab28ad442f1127?r=PG&default=identicon", :account-source "clojuredocs", :login "Iceland_jack"} {:login "agnul", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7526067?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/2c8ecc24181d171df85a26458b9cd5f?r=PG&default=identicon", :account-source "clojuredocs", :login "jneira"}, :_id "542692cbc026201cdc326bca"} {:author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=2"}, :editors [{:login "Iceland_jack", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c889e0a95a3bb07f90ab28ad442f1127?r=PG&default=identicon"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "user=> (replace {2 :two, 4 :four} [4 2 3 4 5 6 2])\n[:four :two 3 :four 5 6 :two]\n\nuser=> (replace '{0 ZERO, 1 ONE, 2 TWO} '(This is the code 0 1 2 0))\n(This is the code ZERO ONE TWO ZERO)", :created-at 1305078367000, :updated-at 1423093999544, :_id "542692cbc026201cdc326bce"} {:author {:login "Alexey Tarasevich", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/43e0398b89022d32b43de4c968069312?r=PG&default=identicon"}, :editors [], :body "; Behaves somewhat similar to map, but notice the differences\nuser=> (map [:zeroth :first :second :third :fourth] [0 2 4 0])\n(:zeroth :second :fourth :zeroth)\n\n; 1. replace returns a vector, while map returns a seq\n; 2. replace keeps unmatched values, while map replace with nil\nuser=> (map {} [0])\n(nil)\nuser=> (map [] [0])\nIndexOutOfBoundsException clojure.lang.PersistentVector.arrayFor (PersistentVector.java:107)\n", :created-at 1385849488000, :updated-at 1385849488000, :_id "542692d5c026201cdc327071"} {:updated-at 1472236519899, :created-at 1472236519899, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}, :body "user=> (replace {2 :a, 4 :b} [1 2 3 4])\n;;=> [1 :a 3 :b]", :_id "57c08be7e4b0709b524f04d5"} {:updated-at 1517940922527, :created-at 1517935073686, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; On hash-maps:\n\n(def user {:name \"jack\" :city \"London\" :id 123})\n(defn entry [k v] (clojure.lang.MapEntry/create k v))\n(def sub {(entry :city \"London\") [:postcode \"WD12\"]})\n\n(into {} (replace sub user))\n;; {:name \"jack\", :postcode \"WD12\", :id 123}", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :_id "5a79d9e1e4b0e2d9c35f741b"}], :notes [{:updated-at 1280289719000, :body "The behaviour for vectors was a little strange for me. I'd say replace \"selects\" from \"smap\" the indexes which are in \"coll\"", :created-at 1280289719000, :author {:login "jneira", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2c8ecc24181d171df85a26458b9cd5f?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f92"}], :arglists ["smap" "smap coll"], :doc "Given a map of replacement pairs and a vector/collection, returns a\n vector/seq with any elements = a key in smap replaced with the\n corresponding val in smap. Returns a transducer when no collection\n is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/replace"} {:added "1.9", :ns "clojure.core", :name "int?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1495654441434, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "integer?", :ns "clojure.core"}, :_id "5925e029e4b093ada4d4d73c"} {:created-at 1495654448767, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "number?", :ns "clojure.core"}, :_id "5925e030e4b093ada4d4d73d"} {:created-at 1495654503504, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "pos-int?", :ns "clojure.core"}, :_id "5925e067e4b093ada4d4d73e"} {:created-at 1495654510856, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "neg-int?", :ns "clojure.core"}, :_id "5925e06ee4b093ada4d4d73f"} {:created-at 1495654522385, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "nat-int?", :ns "clojure.core"}, :_id "5925e07ae4b093ada4d4d740"}], :line 1400, :examples [{:editors [{:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}], :body ";; Note that this will return true for things which aren't strictly Java ints:\n(int? 42) \n;; => true\n\n(int? (java.lang.Integer. 42)) \n;; => true\n\n(int? (java.lang.Long. 42)) \n;; => true\n\n(int? 42.0)\n;; => false\n\n(int? (bigdec 42))\n;; => false\n\n;; The distinction between int? and integer? is that integer? will return true \n;; for BigInts:\n\n(int? (bigint 42)) \n;; => false\n\n(integer? (bigint 42)) \n;; => true\n\n(int? java.math.BigInteger/ONE)\n;; => false\n\n(integer? java.math.BigInteger/ONE)\n;; => true\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/94482?v=3", :account-source "github", :login "timgilbert"}, :created-at 1495654364949, :updated-at 1495655962185, :_id "5925dfdce4b093ada4d4d73a"} {:editors [{:login "liuchong", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/236058?v=4"}], :body ";; Here is the definition, it's simple (and 呵呵哒):\n;;\n;; (defn int?\n;; \"Return true if x is a fixed precision integer\"\n;; {:added \"1.9\"}\n;; [x] (or (instance? Long x)\n;; (instance? Integer x)\n;; (instance? Short x)\n;; (instance? Byte x)))\n;;\n\n(int? (Long/MAX_VALUE))\n;; => true\n\n(int? (Long/MIN_VALUE))\n;; => true\n\n(int? 0.0)\n;; => false", :author {:avatar-url "https://avatars2.githubusercontent.com/u/236058?v=4", :account-source "github", :login "liuchong"}, :created-at 1572414469669, :updated-at 1572414534344, :_id "5db92405e4b0ca44402ef7d5"}], :notes nil, :arglists ["x"], :doc "Return true if x is a fixed precision integer", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/int_q"} {:added "1.0", :ns "clojure.core", :name "associative?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1570520657017, :author {:login "xmo-odoo", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/7571158?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "assoc", :ns "clojure.core"}, :_id "5d9c3e51e4b0ca44402ef7c5"} {:created-at 1570520665970, :author {:login "xmo-odoo", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/7571158?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "assoc-in", :ns "clojure.core"}, :_id "5d9c3e59e4b0ca44402ef7c6"} {:created-at 1570520672069, :author {:login "xmo-odoo", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/7571158?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "update", :ns "clojure.core"}, :_id "5d9c3e60e4b0ca44402ef7c7"} {:created-at 1570520678789, :author {:login "xmo-odoo", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/7571158?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "update-in", :ns "clojure.core"}, :_id "5d9c3e66e4b0ca44402ef7c8"}], :line 6244, :examples [{:author {:login "Clinton", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e460563f35b0b25d8671d6ef83f54ce?r=PG&default=identicon"}, :editors [], :body "user=> (associative? [1 2 3]) ; vector\ntrue\nuser=> (associative? '(1 2 3)) ; list\nfalse\nuser=> (associative? {:a 1 :b 2}) ; map\ntrue\nuser=> (associative? #{:a :b :c}) ; set\nfalse\nuser=> (associative? \"fred\") ; string\nfalse\n", :created-at 1327061297000, :updated-at 1327061297000, :_id "542692d2c026201cdc326f4d"}], :notes nil, :arglists ["coll"], :doc "Returns true if coll implements Associative", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/associative_q"} {:added "1.3", :ns "clojure.core", :name "unchecked-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1496090254478, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "int", :ns "clojure.core"}, :_id "592c868ee4b093ada4d4d79f"}], :line 3534, :examples [{:updated-at 1496090244589, :created-at 1496090244589, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body "(unchecked-int 1)\n;;=> 1\n(unchecked-int 1N)\n;;=> 1\n(unchecked-int 1.1)\n;;=> 1\n(unchecked-int 1.9)\n;;=> 1\n(unchecked-int 5/3)\n;;=> 1\n\n(unchecked-int -1)\n;;=> -1\n(unchecked-int -1N)\n;;=> -1\n(unchecked-int -1.1)\n;;=> -1\n(unchecked-int -1.9)\n;;=> -1\n(unchecked-int -5/3)\n;;=> -1\n\n;;;; Note that (unchecked-int) does not range check its argument\n;;;; so integer overflow or rounding may occur. \n;;;; Use (int) if you want to throw an exception in such cases.\n\n(unchecked-int 2147483648)\n;;=> -2147483648\n(unchecked-int -2147483649)\n;;=> 2147483647\n\n(int 2147483648)\n;;=> IllegalArgumentException Value out of range for int: 2147483648\n(long -2147483649)\n;;=> IllegalArgumentException Value out of range for int: -2147483649\n\n(unchecked-int 1.0E9)\n;;=> 1000000000\n(unchecked-int 1.0E10)\n;;=> 2147483647\n(unchecked-int 1.0E11)\n;;=> 2147483647\n\n(int 1.0E9)\n;;=> 1000000000\n(int 1.0E10)\n;;=> IllegalArgumentException Value out of range for int: 1.0E10\n(int 1.0E11)\n;;=> IllegalArgumentException Value out of range for int: 1.0E11", :_id "592c8684e4b093ada4d4d79e"}], :notes nil, :arglists ["x"], :doc "Coerce to int. Subject to rounding or truncation.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-int"} {:added "1.2", :ns "clojure.core", :name "set-error-handler!", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1287220602000, :author {:login "hugoduncan", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/80fa2a15219b987664e4d6f5c78b4c27?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "agent", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c1e"} {:created-at 1287220615000, :author {:login "hugoduncan", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/80fa2a15219b987664e4d6f5c78b4c27?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "agent-error", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c1f"} {:created-at 1329375224000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "restart-agent", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c20"}], :line 2194, :examples [{:author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :editors [{:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"} {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"} {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}], :body "(def bond (agent 7))\n\n(defn err-handler-fn [ag ex]\n (println \"evil error occured: \" ex \" and we still have value \" @ag))\n\n(set-error-handler! bond err-handler-fn)\n\n;;division by zero:\n\n(send bond (fn [x] (/ x 0)))\n=>evil error occured: #Divide by zero> and we still have value 7\n\n(send bond inc)\n=>FAILURE ;;Agent is failed, needs restart, but keeps the last OK value\n\n@bond\n=>7\n\n(restart-agent bond 7) ;; or replace 7 with @ag\n\n(send bond inc)\n=># ;;because of async update\n\n@bond\n=>8\n", :created-at 1329375108000, :updated-at 1329375308000, :_id "542692d5c026201cdc32707d"} {:updated-at 1497900465897, :created-at 1497900465897, :author {:login "cloojure", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/7083783?v=3"}, :body "(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", :_id "594825b1e4b06e730307db3c"}], :notes nil, :arglists ["a handler-fn"], :doc "Sets the error-handler of agent a to handler-fn. If an action\n being run by the agent throws an exception or doesn't pass the\n validator fn, handler-fn will be called with two arguments: the\n agent and the exception.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/set-error-handler!"} {:ns "clojure.core", :name "inst-ms*", :type "function", :see-alsos nil, :examples nil, :notes nil, :arglists ["inst"], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core/inst-ms*"} {:added "1.0", :ns "clojure.core", :name "keyword?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1495715288280, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "simple-keyword?", :ns "clojure.core"}, :_id "5926cdd8e4b093ada4d4d761"} {:created-at 1495715310898, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "qualified-keyword?", :ns "clojure.core"}, :_id "5926cdeee4b093ada4d4d763"} {:created-at 1548518287990, :author {:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "keyword", :ns "clojure.core"}, :_id "5c4c838fe4b0ca44402ef637"}], :line 568, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4", :account-source "github", :login "cljlc"} {:login "borkdude", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/284934?v=4"}], :body "(keyword? 'x)\n;;=> false\n\n(keyword? :x)\n;;=> true\n\n(keyword? true)\n;;=> false\n\n;; Note: some of the keywords below are non-conformant and will not work\n;; with destructuring. For more info see 'keyword'.\n\n(keyword? :-)\n;;=> true\n\n(keyword? :+)\n;;=> true\n\n(keyword? :-o)\n;;=> true\n\n(keyword? :')\n;;=> true\n\n(keyword? :#)\n;;=> true\n\n(keyword? :>)\n;;=> true\n\n(keyword? :'/-)\n;;=> true\n\n(keyword? :'//-)\n;;=> true\n\n(keyword? :////)\n;;=> true\n\n(keyword? :'//-,)\n;;=> true\n\n(keyword? :'//,-)\n;;=> ArityException Wrong number of args (2) passed to: core/keyword? clojure.lang.AFn.throwArity (AFn.java:429)\n;; Note: the comma is taken as space, so the code above is equivalent to\n(keyword? :'// -)\n\n(keyword? :-:)\n;;=> RuntimeException Invalid token: :-: clojure.lang.Util.runtimeException (Util.java:221)\n;;=> RuntimeException Unmatched delimiter: ) clojure.lang.Util.runtimeException (Util.java:221)\n;; https://clojure.org/reference/reader states:\n;; \"Symbols beginning or ending with ':' are reserved by Clojure.\"\n\n(keyword? :-:-)\n;;=> true\n;; https://clojure.org/reference/reader states:\n;; \"A symbol can contain one or more non-repeating ':'s\" and:\n;; \"Keywords are like symbols, [...]\"\n\n(keyword? :....)\n;;=> true\n\n(keyword? :,,,,)\n;;=> RuntimeException Invalid token: : clojure.lang.Util.runtimeException (Util.java:221)\n;;=> RuntimeException Unmatched delimiter: ) clojure.lang.Util.runtimeException (Util.java:221)\n;; Note: the comma is taken as space, so the code above is equivalent to\n(keyword? : )\n\n(keyword? :a:b:c)\n;;=> true\n\n(keyword? :a.b.c)\n;;=> true\n\n(keyword? :73)\n;;=> true\n\n", :created-at 1279074168000, :updated-at 1551304081227, :_id "542692c6c026201cdc3268cc"}], :notes nil, :arglists ["x"], :doc "Return true if x is a Keyword", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/keyword_q"} {:added "1.0", :ns "clojure.core", :name "force", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1342465196000, :author {:login "sergey", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/fbf950615302e00a14bceec914af32ca?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "delay", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d92"}], :line 761, :examples [{:author {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}, :editors [{:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"} {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}], :body ";; an example for delay using an event-queue\nuser> (import [java.util.concurrent PriorityBlockingQueue])\njava.util.concurrent.PriorityBlockingQueue\nuser> (defn create-event-element [delayed-event tme]\n (struct event delayed-event tme))\n#'user/create-event-element\nuser> (defn comp-queue [e1 e2]\n (if (< (:time e1) (:time e2))\n true false))\n#'user/comp-queue\nuser> (defn update [n]\n\t(reset! c n))\n#'user/update\nuser> (defn create-event-queue [comp-queue size]\n (new PriorityBlockingQueue size (comp comp-queue)))\n#'user/create-event-queue\nuser> (def queue (create-event-queue comp-queue 10))\n#'user/queue\nuser> (def elements (take 10 (repeatedly \n\t\t\t (fn[](create-event-element \n\t\t\t\t (delay (update (rand-int 20)))\n\t\t\t\t (rand))))))\n#'user/elements\nuser> (def c (atom 0))\n#'user/c\nuser> @c\n0\nuser> (doseq [e elements]\n\t (.add queue e))\nnil\nuser> (dotimes [_ 10]\n\t (let [e (.poll queue)]\n\t\t (println \"c=\" @c)\n\t\t (print \"time=\" (:time e) \":\")\n\t\t (println (force (:object e)))))\nc= 0\ntime= 0.07805244345581108 :19\nc= 19\ntime= 0.24297414417455565 :6\nc= 6\ntime= 0.24427040715816817 :0\nc= 0\ntime= 0.24938478920862384 :17\nc= 17\ntime= 0.33612588239752494 :6\nc= 6\ntime= 0.5148481493716295 :5\nc= 5\ntime= 0.5823642080700586 :7\nc= 7\ntime= 0.7674970100941858 :4\nc= 4\ntime= 0.9206272921555505 :14\nc= 14\ntime= 0.9958255204018474 :4\nnil\nuser> @c\n4\nuser> (def elements (take 10 (repeatedly \n\t\t\t (fn[](create-event-element \n\t\t\t\t (delay (update (rand-int 20)))\n\t\t\t\t (rand))))))\n#'user/elements\n;; if we check 'element', delay objects will be evaluated. The below is\n;; this example. Please compare the above with the below.\nuser> elements \n({:object #, :time 0.48566816399656854} {:object #, :time 0.9374202154797486} {:object #, :time 0.3271116626875401} {:object #, :time 0.8843712542267577} {:object #, :time 0.86383171974926} {:object #, :time 0.2120086056700251} {:object #, :time 0.9406336968276247} {:object #, :time 0.2150071400135528} {:object #, :time 0.7520042839572664} {:object #, :time 0.6264819751284463})\n;; The object of the last elements is #. Therefore,\n;; This indicates the atom 'c' has already updated.\nuser> @c \n1 \nuser> (doseq [e elements]\n\t (.add queue e))\nnil\n;; 'atom c' has never been updated because it has already\n;; been evaluated.\nuser> (dotimes [_ 10]\n\t (let [e (.poll queue)]\n\t\t (println \"c=\" @c)\n\t\t (print \"time=\" (:time e) \":\")\n\t\t (println (force (:object e)))))\nc= 1\ntime= 0.2120086056700251 :14\nc= 1\ntime= 0.2150071400135528 :0\nc= 1\ntime= 0.3271116626875401 :17\nc= 1\ntime= 0.48566816399656854 :16\nc= 1\ntime= 0.6264819751284463 :1\nc= 1\ntime= 0.7520042839572664 :7\nc= 1\ntime= 0.86383171974926 :10\nc= 1\ntime= 0.8843712542267577 :15\nc= 1\ntime= 0.9374202154797486 :19\nc= 1\ntime= 0.9406336968276247 :5\nnil\nuser> ", :created-at 1308852117000, :updated-at 1308852376000, :_id "542692cdc026201cdc326ce6"} {:author {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}, :editors [{:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}], :body ";; the tarai benchmark comparing non-lazy version with lazy-version\n(defn tarai [x y z]\n (if (<= (x) (y))\n (y)\n (recur (fn [] (tarai (fn [] (- (x) 1)) y z))\n (fn [] (tarai (fn [] (- (y) 1)) z x))\n (fn [] (tarai (fn [] (- (z) 1)) x y)))))\n\n(defn tarai-d [x y z]\n (if (<= (force x) (force y))\n (force y)\n (recur (delay (tarai-d (- (force x) 1) y z))\n (delay (tarai-d (- (force y) 1) z x))\n (delay (tarai-d (- (force z) 1) x y)))))\n\nuser> (dotimes [_ 10] (time (tarai (fn [] 192) (fn [] 96) (fn [] 0))))\n\"Elapsed time: 139.660729 msecs\"\n\"Elapsed time: 132.493587 msecs\"\n\"Elapsed time: 135.867772 msecs\"\n\"Elapsed time: 132.924774 msecs\"\n\"Elapsed time: 137.491084 msecs\"\n\"Elapsed time: 134.72752 msecs\"\n\"Elapsed time: 132.969652 msecs\"\n\"Elapsed time: 135.795754 msecs\"\n\"Elapsed time: 134.261724 msecs\"\n\"Elapsed time: 138.059968 msecs\"\n\nnil\nuser> (dotimes [_ 10 ] (time (tarai-d 192 96 0)))\n\"Elapsed time: 3.181795 msecs\"\n\"Elapsed time: 2.960096 msecs\"\n\"Elapsed time: 3.000855 msecs\"\n\"Elapsed time: 3.140536 msecs\"\n\"Elapsed time: 3.658821 msecs\"\n\"Elapsed time: 3.319659 msecs\"\n\"Elapsed time: 2.9182 msecs\"\n\"Elapsed time: 3.125442 msecs\"\n\"Elapsed time: 2.944342 msecs\"\n\"Elapsed time: 2.951613 msecs\"\nnil", :created-at 1308905934000, :updated-at 1308906319000, :_id "542692cdc026201cdc326ce9"} {:updated-at 1564512316203, :created-at 1564511910921, :author {:login "jordangedney", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/5439697?v=4"}, :body ";; Similarly to deref/@ you can evaluate a delay using force\n\nuser> (def new-delay (delay (println \"I only print once\") 5))\n#'user/new-delay\n\nuser> (force new-delay)\nI only print once\n5\n\nuser> (force new-delay)\n5\n\n;; force works with expressions other than delays: \n\nuser> (force (println \"\\\\O\"))\n\\O\nnil\n\nuser> (force :field)\n:field", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/5439697?v=4", :account-source "github", :login "jordangedney"}], :_id "5d408ea6e4b0ca44402ef78d"}], :notes nil, :arglists ["x"], :doc "If x is a Delay, returns the (possibly cached) value of its expression, else returns x", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/force"} {:added "1.1", :ns "clojure.core", :name "bound-fn*", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1350609405000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "bound-fn", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e82"}], :line 1994, :examples [{:author {:login "metajack", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/194d8437f5baed192c90be27369c4922?r=PG&default=identicon"}, :editors [], :body "(def ^:dynamic *some-var* nil)\n\n(defn f [] (println *some-var*))\n\n;; run f without a new binding\nuser=> (f)\nnil\nnil\n\n;; run f with a new binding\nuser=> (binding [*some-var* \"hello\"]\n (f))\nhello\nnil\n\n;; run f in a thread with a new binding\nuser=> (binding [*some-var* \"goodbye\"]\n (.start (Thread. f)))\nnil\nnil\n\n;; run a bound f in a thread with a new binding\nuser=> (binding [*some-var* \"goodbye\"]\n (.start (Thread. (bound-fn* f))))\ngoodbye\nnil\n", :created-at 1331769960000, :updated-at 1331769960000, :_id "542692d2c026201cdc326f5d"} {:updated-at 1613596413856, :created-at 1613596413856, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=4"}, :body ";; Capture thread local bindings so the lazy sequence can realize outside\n;; the binding block\n\n(def ^:dynamic *a* nil)\n\n(binding [*a* 1] (map #(+ % *a*) (range 10)))\n;; NullPointerException clojure.lang.Numbers.ops (Numbers.java:1013)\n\n(binding [*a* 1] (map (bound-fn* #(+ % *a*)) (range 10)))\n;; (1 2 3 4 5 6 7 8 9 10)\n", :_id "602d86fde4b0b1e3652d7456"}], :notes nil, :arglists ["f"], :doc "Returns a function, which will install the same bindings in effect as in\n the thread at the time bound-fn* was called and then call f with any given\n arguments. This may be used to define a helper function which runs on a\n different thread, but needs the same bindings in place.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bound-fn*"} {:added "1.2", :ns "clojure.core", :name "namespace-munge", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos [{:created-at 1559582586002, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "munge", :ns "clojure.core"}, :_id "5cf5577ae4b0ca44402ef747"}], :line 13, :examples [{:editors [{:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :body ";;; replace \"-\" to \"_\" (this is the only conversion this fn does)\nuser=> (namespace-munge \"hello-world\")\n\"hello_world\"", :author {:avatar-url "https://avatars.githubusercontent.com/u/932074?v=3", :account-source "github", :login "redraiment"}, :created-at 1487211126912, :updated-at 1683030639215, :_id "58a50a76e4b01f4add58fe58"}], :notes nil, :arglists ["ns"], :doc "Convert a Clojure namespace name to a legal Java package name.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/namespace-munge"} {:added "1.2", :ns "clojure.core", :name "group-by", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1318588913000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "partition-by", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bf8"} {:created-at 1332443915000, :author {:login "Cosmi", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10f2eae92de67116fa98d06ec55fcf29?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "frequencies", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bf9"}], :line 7146, :examples [{:author {:login "mvonrohr", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/59714f4428e8ef53b809ee923203531?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; group strings by their length\n(group-by count [\"a\" \"as\" \"asd\" \"aa\" \"asdf\" \"qwer\"])\n;;=> {1 [\"a\"], 2 [\"as\" \"aa\"], 3 [\"asd\"], 4 [\"asdf\" \"qwer\"]}\n\n;; group integers by a predicate\n(group-by odd? (range 10))\n;;=> {false [0 2 4 6 8], true [1 3 5 7 9]}\n", :created-at 1279083015000, :updated-at 1420742429526, :_id "542692cdc026201cdc326cd2"} {:author {:login "Brool", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/781c0e32be2a2f7117dabd76a3fb7c3?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "uvtc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/34f159f89cbd1d9beac0276f5a7af552?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; group by a primary key\n(group-by :user-id [{:user-id 1 :uri \"/\"} \n {:user-id 2 :uri \"/foo\"} \n {:user-id 1 :uri \"/account\"}])\n\n;;=> {1 [{:user-id 1, :uri \"/\"} \n;; {:user-id 1, :uri \"/account\"}],\n;; 2 [{:user-id 2, :uri \"/foo\"}]}\n", :created-at 1285069474000, :updated-at 1420742470832, :_id "542692cdc026201cdc326cd4"} {:editors [{:login "Canna71", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5303303?v=3"}], :body ";; group by multiple criteria\n(def words [\"Air\" \"Bud\" \"Cup\" \"Awake\" \"Break\" \"Chunk\" \"Ant\" \"Big\" \"Check\"])\n(group-by (juxt first count) words)\n\n;;{[\\A 3] [\"Air\" \"Ant\"], \n;;[\\B 3] [\"Bud\" \"Big\"], \n;;[\\C 3] [\"Cup\"], \n;;[\\A 5] [\"Awake\"], \n;;[\\B 5] [\"Break\"], \n;;[\\C 5] [\"Chunk\" \"Check\"]}", :author {:avatar-url "https://avatars.githubusercontent.com/u/5303303?v=3", :account-source "github", :login "Canna71"}, :created-at 1471771939875, :updated-at 1471772272493, :_id "57b97523e4b0709b524f04cf"} {:updated-at 1486507759173, :created-at 1486507759173, :author {:login "pavanred", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/60858?v=3"}, :body "user=> (group-by :category [{:category \"a\" :id 1}\n {:category \"a\" :id 2}\n {:category \"b\" :id 3}])\n;;{\"a\" [{:category \"a\", :id 1} {:category \"a\", :id 2}], \n;; \"b\" [{:category \"b\", :id 3}]}\n\nuser=> (group-by #(get % :category) [{:category \"a\" :id 1}\n {:category \"a\" :id 2}\n {:category \"b\" :id 3}])\n;;{\"a\" [{:category \"a\", :id 1} {:category \"a\", :id 2}], \n;; \"b\" [{:category \"b\", :id 3}]}\n\nuser=> (defn my-category [item] (get item :category))\n;;#'user/my-category\n\nuser=> (group-by my-category [{:category \"a\" :id 1}\n {:category \"a\" :id 2}\n {:category \"b\" :id 3}])\n;;{\"a\" [{:category \"a\", :id 1} {:category \"a\", :id 2}], \n;; \"b\" [{:category \"b\", :id 3}]}\n", :_id "589a4eefe4b01f4add58fe3f"} {:updated-at 1528069898970, :created-at 1528069898970, :author {:login "statcompute", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/4590938?v=4"}, :body "(require '[ultra-csv.core :refer [read-csv]])\n \n(def ds (read-csv \"/home/liuwensui/Downloads/nycflights.csv\"))\n \n(map\n (fn [x] {:year (first (key x))\n :month (last (key x))\n :flights (count (val x))})\n (group-by (juxt :year :month) ds))", :_id "5b147f0ae4b00ac801ed9e0b"} {:editors [{:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}], :body ";; Find anagrams\n(def words [\"meat\" \"mat\" \"team\" \"mate\" \"eat\" \"tea\"])\n\n(group-by set words)\n;;=> {#{\\a \\e \\m \\t} [\"meat\" \"team\" \"mate\"],\n;; #{\\a \\m \\t} [\"mat\"], \n;; #{\\a \\e \\t} [\"eat\" \"tea\"]}\n", :author {:avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4", :account-source "github", :login "MicahElliott"}, :created-at 1581460975386, :updated-at 1581461174115, :_id "5e432defe4b0ca44402ef830"}], :notes nil, :arglists ["f coll"], :doc "Returns a map of the elements of coll keyed by the result of\n f on each element. The value at each key will be a vector of the\n corresponding elements, in the order they appeared in coll.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/group-by"} {:added "1.0", :ns "clojure.core", :name "prn", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1290672937000, :author {:login "dale", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a7a1eca257c6cea943fea41e5cc3e9a3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "println", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cc3"} {:created-at 1291028040000, :author {:login "dale", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a7a1eca257c6cea943fea41e5cc3e9a3?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "pr", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cc4"}], :line 3714, :examples [{:updated-at 1402400103000, :created-at 1335592532000, :body "user=> (prn \"fred\" 1)\n\"fred\" 1\nnil\n\nuser=> (def items [ \"hello\" :a 1 (list :b 2) \\c {:d 4} #{5 6 7} ])\n#'user/items\n\n; prn outputs items in a machine-readable format, such as in a source\n; file. Note the double-quotes around the string \"hello\" and the escaped letter \"c\".\nuser=> (prn items)\n[\"hello\" :a 1 (:b 2) \\c {:d 4} #{5 6 7}]\nnil\n\n; println is for human-readable output, like a report. Note the lack of quotes around the string \"hello\", and the unescaped letter \"c\". \nuser=> (println items)\n[hello :a 1 (:b 2) c {:d 4} #{5 6 7}]\nnil\n\n; pr-str produces a string with escaped punctuation, so that println yields the same result as the original prn call.\nuser=> (println (pr-str items))\n[\"hello\" :a 1 (:b 2) \\c {:d 4} #{5 6 7}]\nnil\n\n", :editors [{:avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon", :account-source "clojuredocs", :login "cloojure"} {:avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon", :account-source "clojuredocs", :login "cloojure"} {:avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon", :account-source "clojuredocs", :login "cloojure"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d4c026201cdc32703b"}], :notes nil, :arglists ["& more"], :doc "Same as pr followed by (newline). Observes *flush-on-newline*", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/prn"} {:added "1.2", :ns "clojure.core", :name "extend", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos [{:created-at 1326611307000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "satisfies?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e53"} {:created-at 1326611311000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "extends?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e54"} {:created-at 1326611316000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "extenders", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e55"} {:created-at 1394618470000, :author {:login "Chort409", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/73da2cf9145cfb9c900b31436ee435a6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "extend-type", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e56"} {:created-at 1394618476000, :author {:login "Chort409", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/73da2cf9145cfb9c900b31436ee435a6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "extend-protocol", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e57"}], :line 768, :examples [{:author {:login "semperos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/edeae8e7534b3d554e4ec2c35ffc68d?r=PG&default=identicon"}, :editors [{:login "semperos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/edeae8e7534b3d554e4ec2c35ffc68d?r=PG&default=identicon"}], :body "; From Sean Devlin's talk on protocols at Clojure Conj\n(defprotocol Dateable\n (to-ms [t]))\n\n(extend java.lang.Number\n Dateable\n {:to-ms identity})\n\n(extend java.util.Date\n Dateable\n {:to-ms #(.getTime %)})\n\n(extend java.util.Calendar\n Dateable\n {:to-ms #(to-ms (.getTime %))})", :created-at 1296704103000, :updated-at 1296705296000, :_id "542692c7c026201cdc3269d3"} {:updated-at 1542060365406, :created-at 1542060009207, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; \"extend\" enables the definition of concrete implementations\n;; after declaration time. This provides \n;; a lightweight version of abstract methods/classes.\n\n(defprotocol IBaz\n (foo [_])\n (bar [_])\n (baz [_]))\n\n;; DefaultBaz contains some default implementations.\n(def DefaultBaz\n {:foo (fn [_] (str \"DefaultBaz::foo\"))\n :bar (fn [_] (str \"DefaultBaz::bar\"))})\n\n(defrecord MyBaz [])\n\n;; MyBaz accepts \"bar\" as default from the \"super-class\"\n;; but overrides \"foo\". \"baz\" is provided without override.\n(extend MyBaz\n IBaz\n (assoc DefaultBaz \n :foo (fn [this] (str \"MyBaz::foo\"))\n :baz (fn [this] (str \"MyBaz::baz\"))))\n\n(def my-baz (->MyBaz))\n(foo my-baz)\n;; \"MyBaz::foo\"\n\n;; Note: additional \"extend-*\" calls will change all instances\n;; created so far.\n\n(extend-type MyBaz\n IBaz\n (foo [this] (str \"NEW\")))\n\n(foo my-baz)\n;; \"NEW\"", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :_id "5be9f7e9e4b00ac801ed9ef3"}], :notes nil, :arglists ["atype & proto+mmaps"], :doc "Implementations of protocol methods can be provided using the extend construct:\n\n (extend AType\n AProtocol\n {:foo an-existing-fn\n :bar (fn [a b] ...)\n :baz (fn ([a]...) ([a b] ...)...)}\n BProtocol \n {...} \n ...)\n \n extend takes a type/class (or interface, see below), and one or more\n protocol + method map pairs. It will extend the polymorphism of the\n protocol's methods to call the supplied methods when an AType is\n provided as the first argument. \n\n Method maps are maps of the keyword-ized method names to ordinary\n fns. This facilitates easy reuse of existing fns and fn maps, for\n code reuse/mixins without derivation or composition. You can extend\n an interface to a protocol. This is primarily to facilitate interop\n with the host (e.g. Java) but opens the door to incidental multiple\n inheritance of implementation since a class can inherit from more\n than one interface, both of which extend the protocol. It is TBD how\n to specify which impl to use. You can extend a protocol on nil.\n\n If you are supplying the definitions explicitly (i.e. not reusing\n exsting functions or mixin maps), you may find it more convenient to\n use the extend-type or extend-protocol macros.\n\n Note that multiple independent extend clauses can exist for the same\n type, not all protocols need be defined in a single extend call.\n\n See also:\n extends?, satisfies?, extenders", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/extend"} {:added "1.0", :ns "clojure.core", :name "unchecked-multiply", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1423522441619, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "*", :library-url "https://github.com/clojure/clojure"}, :_id "54d93a89e4b081e022073c76"} {:created-at 1423522447793, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "*'", :library-url "https://github.com/clojure/clojure"}, :_id "54d93a8fe4b0e2ac61831d31"}], :line 1226, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "kentros", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/765acc548dfd021fd854d75f9da3d0a9?r=PG&default=identicon"}], :body ";; 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", :created-at 1313910992000, :updated-at 1407321150000, :_id "542692c6c026201cdc326917"}], :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"} {:added "1.5", :ns "clojure.core", :name "some->>", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1412083996468, :author {:login "jw-00000", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2936?v=2"}, :to-var {:ns "clojure.core", :name "->>", :library-url "https://github.com/clojure/clojure"}, :_id "542ab11ce4b0df9bb778a59d"} {:created-at 1412084003950, :author {:login "jw-00000", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2936?v=2"}, :to-var {:ns "clojure.core", :name "some->", :library-url "https://github.com/clojure/clojure"}, :_id "542ab123e4b0df9bb778a59e"}], :line 7598, :examples [{:editors [{:login "pzeldin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/12401420?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/1583002?v=3", :account-source "github", :login "superfunc"}, :created-at 1446217046027, :updated-at 1457975262515, :_id "56338556e4b04b157a6648dc"}], :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->>"} {:added "1.4", :ns "clojure.core", :name "default-data-readers", :file "clojure/core.clj", :type "var", :column 1, :see-alsos nil, :line 7750, :examples [{:updated-at 1546539310208, :created-at 1546539310208, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; As of Clojure 1.10 the content is:\ndefault-data-readers\n;; {uuid #'clojure.uuid/default-uuid-reader, \n;; inst #'clojure.instant/read-instant-date}\n\n;; Which allows reading of UUIDs and Instants:\n(type (read-string \"#inst \\\"2017-08-23T10:22:22.000-00:00\\\"\"))\n;; java.util.Date\n(type (read-string \"#uuid \\\"374c8c4-fd89-4f1b-a11f-42e334ccf5ce\\\"\"))\n;; java.util.UUID\n\n;; And is overridable with \"*data-readers*\"\n(binding [*data-readers* {'uuid identity}]\n (read-string \"#uuid \\\"374c8c4-fd89-4f1b-a11f-42e334ccf5ce\\\"\"))\n;; \"374c8c4-fd89-4f1b-a11f-42e334ccf5ce\"\n\n;; Or options from edn/read-string\n(require '[clojure.edn :as edn])\n(edn/read-string {:readers {'inst (constantly :nope)}} \n \"#inst \\\"2017-08-23T10:22:22.000-00:00\\\"\")\n;; :nope", :_id "5c2e512ee4b0ca44402ef60d"}], :notes nil, :arglists [], :doc "Default map of data reader functions provided by Clojure. May be\n overridden by binding *data-readers*.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/default-data-readers"} {:ns "clojure.core", :name "->VecSeq", :file "clojure/gvec.clj", :type "function", :column 1, :see-alsos nil, :line 58, :examples nil, :notes nil, :arglists ["am vec anode i offset"], :doc "Positional factory function for class clojure.core.VecSeq.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/->VecSeq"} {:added "1.0", :ns "clojure.core", :name "even?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "odd?", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1354423235000, :_id "542692ebf6e94c6970521dd1"}], :line 1386, :examples [{:updated-at 1406097631000, :created-at 1279073824000, :body "user=> (even? 2)\ntrue\n\nuser=> (even? 1)\nfalse", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/147981?v=3", :account-source "github", :login "dpritchett"}, :_id "542692ccc026201cdc326cb5"} {:author {:login "replore", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e7869fe1a48cb1814c657eaca6bea3eb?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (filter even? (range 10))\n(0 2 4 6 8)", :created-at 1321356072000, :updated-at 1332949375000, :_id "542692d2c026201cdc326f9e"}], :notes nil, :arglists ["n"], :doc "Returns true if n is even, throws an exception if n is not an integer", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/even_q"} {:added "1.0", :ns "clojure.core", :name "unchecked-dec", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1289217146000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-add", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c37"} {:created-at 1289217151000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-dec", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c38"} {:created-at 1289217154000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-inc", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c39"} {:created-at 1289217159000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-negate", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c3a"} {:created-at 1289217163000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-divide", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c3b"} {:created-at 1289217168000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-subtract", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c3c"} {:created-at 1289217172000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-multiply", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c3d"} {:created-at 1289217176000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "unchecked-remainder", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c3e"} {:created-at 1423522315984, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "dec", :library-url "https://github.com/clojure/clojure"}, :_id "54d93a0be4b0e2ac61831d2e"} {:created-at 1423522329856, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "dec'", :library-url "https://github.com/clojure/clojure"}, :_id "54d93a19e4b081e022073c75"}], :line 1170, :examples [{:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (unchecked-dec 4)\n3\n\nuser=> (unchecked-dec Integer/MIN_VALUE)\n2147483647\n\n", :created-at 1289217142000, :updated-at 1289267924000, :_id "542692c6c026201cdc326939"} {:updated-at 1488018651069, :created-at 1488018651069, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :body ";; Illustrates the difference between (dec), (dec') and (unchecked-dec)\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/MIN_VALUE\n;;=> -9223372036854775808\n\n(dec Long/MIN_VALUE)\n;;=> ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1501)\n\n(dec' Long/MIN_VALUE)\n;;=> -9223372036854775809N \n\n;; Notice how the resulting number becomes POSITIVE:\n(unchecked-dec Long/MIN_VALUE)\n;;=> 9223372036854775807 \n\n\n", :_id "58b15cdbe4b01f4add58fe5e"}], :notes nil, :arglists ["x"], :doc "Returns a number one less than x, a long.\n Note - uses a primitive operator subject to overflow.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-dec"} {:ns "clojure.core", :name "Inst", :file "clojure/core.clj", :type "var", :column 1, :see-alsos nil, :line 6780, :examples nil, :notes nil, :arglists [], :doc nil, :library-url "https://github.com/clojure/clojure", :href "/clojure.core/Inst"} {: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"} {:added "1.0", :ns "clojure.core", :name "double-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1349125799000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "doubles", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ac2"} {:created-at 1349125811000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "aget", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ac3"} {:created-at 1349125816000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "aset", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ac4"} {:created-at 1349125826000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "aset-double", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ac5"}], :line 5317, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; 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=>", :created-at 1313906832000, :updated-at 1313906832000, :_id "542692cac026201cdc326b10"} {:updated-at 1661427039227, :created-at 1661427039227, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=4"}, :body "(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]", :_id "63075d5fe4b0b1e3652d7651"}], :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"} {:added "1.0", :ns "clojure.core", :name "in-ns", :type "function", :see-alsos [{:created-at 1331258262000, :author {:login "frangio", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/646001f0ba2b7df47a16c0a1d5b62225?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ns", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c41"}], :examples [{:updated-at 1497795624520, :created-at 1285103646000, :body ";; Let's create new namespace, create new variable in it, then access it from\n;; another namespace\n\n;; create the namespace and switch to it\n(in-ns 'first-namespace)\n;;=> #\n\n;; create a variable and check it\n;; first-namespace=> \n(def my-var \"some value\")\n;;=> #'first-namespace/my-var\n\n;; first-namespace=> \nmy-var\n;;=> \"some value\"\n\n;; create another namespace and switch to this one\n;; first-namespace=> \n(in-ns 'second-namespace)\n;;=> #\n\n;; use variable from the other namespace here\n;; second-namespace=> \nfirst-namespace/my-var\n;;=> \"some value\"\n\n;; in-ns works within top-level forms (e.g. the compiler or the REPL)\n;; It may fail when called within a function at runtime because *ns* is a Var\n;; and unless there are thread-local bindings for *ns*, it cannot be set!\nsecond.namespace=> (defn swap-ns! [ns-name] (clojure.core/in-ns ns-name))\n;; #'second.namespace/swap-ns!\n\nsecond.namespace=> (swap-ns! 'other.ns)\n;; #namespace[other.ns]\n\n;; Later, at runtime...\n;; Throws IllegalStateException(\"Can't change/establish root binding of: *ns* with set\")\n;; Remember, *ns* is a root var and in-ns calls set!, which only works after\n;; someone somewhere calls the binding macro (or Java equivalent)\n(defn -main\n [& args]\n (println *ns*)\n (second.namespace/swap-ns! 'arbitrary-namespace))\n;; prints #namespace[clojure.core] and then will crash", :editors [{:avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon", :account-source "clojuredocs", :login "belun"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "Artiavis", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1834136?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon", :account-source "clojuredocs", :login "belun"}, :_id "542692cdc026201cdc326d10"} {:author {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; The \"in-ns\" function works almost the same as \"ns\", but does not load\n;; clojure.core \n\n;; user=>\n(in-ns 'my-namespace)\n;;=> #\n\n;; the function clojure.core/inc won't just work\n;; my-namespace=> \n(inc 1)\n;; java.lang.Exception: Unable to resolve symbol: inc in this context\n;; (NO_SOURCE_FILE:15)\n\n;; my-namespace=>\n(clojure.core/inc 1)\n;;=> 2\n", :created-at 1285105578000, :updated-at 1423811341705, :_id "542692cdc026201cdc326d13"}], :notes nil, :arglists ["name"], :doc "Sets *ns* to the namespace named by the symbol, creating it if needed.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/in-ns"} {:added "1.0", :ns "clojure.core", :name "create-ns", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1284970193000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "remove-ns", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cb1"} {:created-at 1284970227000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "find-ns", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cb2"} {:created-at 1502465564365, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "intern", :ns "clojure.core"}, :_id "598dce1ce4b0d19c2ce9d712"}], :line 4132, :examples [{:author {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:avatar-url "https://avatars.githubusercontent.com/u/412966?v=3", :account-source "github", :login "nasser"}], :body ";; 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", :created-at 1284947276000, :updated-at 1457302200380, :_id "542692cac026201cdc326b8f"} {:author {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"}, :editors [{:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:avatar-url "https://avatars.githubusercontent.com/u/340?v=3", :account-source "github", :login "jamesmacaulay"} {:login "siddharthjain-in", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6537820?v=4"}], :body ";; 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", :created-at 1284947982000, :updated-at 1651887290877, :_id "542692cac026201cdc326b91"} {:author {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"}, :editors [{:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; 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", :created-at 1285113908000, :updated-at 1285485928000, :_id "542692cbc026201cdc326b96"}], :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"} {:added "1.0", :ns "clojure.core", :name "re-matcher", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1282039999000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "re-find", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b2e"}], :line 4849, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"}], :body "user=> (def *matcher* (re-matcher #\"\\d+\" \"abc12345def\"))\n#'user/*matcher*\n\nuser=> (re-find *matcher*)\n\"12345\"", :created-at 1280546885000, :updated-at 1317219277000, :_id "542692c8c026201cdc326a0d"} {:updated-at 1622895302889, :created-at 1622895302889, :author {:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=4"}, :body ";\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", :_id "60bb6ac6e4b0b1e3652d7507"}], :notes [{:body "17:44 < mearnsh> tsdh: re-matcher should be avoided because the Matcher object it returns mutates in a non-thread-safe way", :created-at 1417436686825, :updated-at 1417436686825, :author {:login "r4um", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/629631?v=3"}, :_id "547c5e0ee4b0dc573b892fe8"} {:author {:login "timmc", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/78608?v=3"}, :updated-at 1461677086067, :created-at 1461677086067, :body "It's fine to use from a controlled context. For instance, if you have a let that creates a Matcher, pulls out groups, and returns the data, you're working in a single-threaded context and the mutable object never even escapes.\n", :_id "571f6c1ee4b0fc95a97eab57"}], :tag "java.util.regex.Matcher", :arglists ["re s"], :doc "Returns an instance of java.util.regex.Matcher, for use, e.g. in\n re-find.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/re-matcher"} {:added "1.0", :ns "clojure.core", :name "defn", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1334710750000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "def", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521edb"} {:created-at 1334710756000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defn-", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521edc"} {:created-at 1361269869000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defmacro", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521edd"} {:created-at 1399636777000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "fn", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ede"} {:created-at 1460434537177, :author {:login "ivanpierre", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/625541?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "declare", :ns "clojure.core"}, :_id "570c7669e4b075f5b2c864e7"}], :line 283, :examples [{:updated-at 1361268155000, :created-at 1279161740000, :body "user=> (defn foo [a b c]\n\t (* a b c))\n#'user/foo\nuser=> (foo 1 2 3)\n6\n\nuser=> (defn bar [a b & [c]]\n (if c\n (* a b c)\n (* a b 100)))\n#'user/bar\nuser=> (bar 5 6)\n3000\nuser=> (bar 5 6 2)\n60\n\nuser=> (defn baz [a b & {:keys [c d] :or {c 10 d 20}}]\n (* a b c d))\n#'user/baz\nuser=> (baz 2 3)\n1200\nuser=> (baz 2 3 :c 5)\n600\nuser=> (baz 2 3 :c 5 :d 6)\n180\n\nuser=> (defn boo [a b & {:keys [c d] :or {c 10 d 20} :as all-specified}]\n (println all-specified)\n (* a b c d))\n#'user/boo\nuser=> (boo 2 3)\nnil\n1200\nuser=> (boo 2 3 :c 5)\n{:c 5}\n600\nuser=> (boo 1 2 :d 3 :c 4)\n{:c 4, :d 3}\n24\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon", :account-source "clojuredocs", :login "AtKaaZ"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :_id "542692cbc026201cdc326bd1"} {:author {:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"}, :editors [{:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (defn bar\n ([a b] (bar a b 100))\n ([a b c] (* a b c)))\n#'user/bar\nuser=> (bar 5 6)\n3000\nuser=> (bar 5 6 2)\n60\n", :created-at 1279213901000, :updated-at 1285496324000, :_id "542692cbc026201cdc326bd6"} {:author {:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"}, :editors [{:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"}], :body ";; You can use destructuring to have keyword arguments. This would be a\n;; pretty verbose version of map (in an example a bit more verbose than\n;; the first above):\n\n(defn keyworded-map [& {function :function sequence :sequence}]\n (map function sequence))\n\n;; You can call it like this:\n\nuser=> (keyworded-map :sequence [1 2 3] :function #(+ % 2))\n(3 4 5)\n\n\n;; The declaration can be shortened with \":keys\" if your local variables \n;; should be named in the same way as your keys in the map:\n\n(defn keyworded-map [& {:keys [function sequence]}]\n (map function sequence))\n", :created-at 1280457897000, :updated-at 1317454000000, :_id "542692cbc026201cdc326bd9"} {:author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :editors [{:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"} {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"} {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}], :body "(defn somefn\n [req1 req2 ;required params\n & {:keys [a b c d e] ;optional params\n :or {a 1 ;optional params with preset default values other than the nil default\n ; b takes nil if not specified on call\n c 3 ; c is 3 when not specified on call\n d 0 ; d is 0 --//--\n ; e takes nil if not specified on call\n }\n :as mapOfParamsSpecifiedOnCall ;takes nil if no extra params(other than the required ones) are specified on call\n }]\n (println req1 req2 mapOfParamsSpecifiedOnCall a b c d e)\n )\n\n=> (somefn 9 10 :b 2 :d 4)\n;9 10 {:b 2, :d 4} 1 2 3 4 nil\nnil\n=> (somefn)\n;ArityException Wrong number of args (0) passed to: funxions$somefn ;clojure.lang.AFn.throwArity (AFn.java:437)\n=> (somefn 9 10)\n;9 10 nil 1 nil 3 0 nil\nnil\n=> (somefn 9 10 :x 123)\n;9 10 {:x 123} 1 nil 3 0 nil\nnil\n=> (somefn 9 10 123)\n;IllegalArgumentException No value supplied for key: 123 ;clojure.lang.PersistentHashMap.create (PersistentHashMap.java:77)\n=> (somefn 9 10 123 45)\n;9 10 {123 45} 1 nil 3 0 nil\nnil\n=> (try \n (somefn 9 10 123)\n (catch IllegalArgumentException e (println \"caught:\" e)))\n;caught: #\nnil", :created-at 1361269606000, :updated-at 1361269847000, :_id "542692d2c026201cdc326f7c"} {:updated-at 1442603127799, :created-at 1442603127799, :author {:login "dxlr8r", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1648056?v=3"}, :body ";; :as only include parameters provided, not the default (:or) ones.\n;; This is some boilerplate code to get around this. \n;; Hopefully not needed in the future revisions of Clojure.\n\n(defn bar [f g h & {:keys [override]}]\n (let [default {:a 1 :b 2 :c 3}\n args (merge default override)]\n (conj '() f g h args)))\n\n(bar 1 2 3 :override {:a 9 :z 5}) ; returns -> ({:z 5, :a 9, :b 2, :c 3} 3 2 1)\n", :_id "55fc6077e4b06a9ffaad4fc1"} {:updated-at 1516276416080, :created-at 1516276416080, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;defn basic examples\n(defn say-hi [name]\n (str \"Hi \" name))\n\n(say-hi \"Jack\")\n;;\"Hi Jack\"\n\n;;the same result using def\n(def say-hello (fn [name]\n (str \"Hello \" name)))\n\n(say-hello \"Bob\")\n;;\"Hello Bob\"\n\n;;the same result using def and an anonymous function\n(def say-bye #(str \"Bye Bye \" %))\n\n(say-bye \"Mark\")\n;;\"Bye Bye Mark\"", :_id "5a608ac0e4b0a08026c48cff"} {:updated-at 1516725425484, :created-at 1516725425484, :author {:login "jakubholynet", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/624958?v=4"}, :body ";;define a function with metadata\n(defn hello {:awesome true} [] nil)\n\n(meta #'hello)\n=>\n{:arglists ([]),\n :awesome true,\n ...\n}\n\n;; define a function with a return value type hint\n(defn hinted ^long [] 42)\n\n(-> #'hinted meta :arglists first meta :tag)\n=> long\n\n;; both metadata on the fn and return type hint (on the argument vector)\n(defn hinted+meta {:awesome true} ^long [] 42)", :_id "5a6764b1e4b09621d9f53a76"} {:updated-at 1547395275348, :created-at 1547395275348, :author {:login "victorb", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/459764?v=4"}, :body ";; Documentation can also be added with `defn`\n=> (defn add \"Adds two numbers\" [x y] (+ x y))\n#'user/add\n\n;; This documentation can be read with the `doc` function\n=> (doc add) \n-------------------------\nuser/add\n([x y])\n Adds two numbers\n\n;; It can also be used when searching for functions with `find-doc`\n=> (find-doc \"two numbers\")\n-------------------------\nuser/add\n([x y])\n Adds two numbers", :_id "5c3b60cbe4b0ca44402ef61a"} {:updated-at 1550694890901, :created-at 1550694890901, :author {:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}, :body ";; prepost-map examples\n\n;; check that exactly one of :a or :b are in the argument map: \n(defn example\n [{:keys [a b]}]\n {:pre [(not (and a b))\n (or a b)]}\n (println a b))\n;; #'user/example\n\n(example {:a 1 :b 2})\n;; Execution error (AssertionError) at user/example (REPL:1).\n;; Assert failed: (not (and a b))\n\n(example {:c 1 :d 2})\n;; Execution error (AssertionError) at user/example (REPL:1).\n;; Assert failed: (or a b)\n\n(example {:a 1 :c 2})\n;; 1 nil\n;; nil\n\n;; check that the error-free average is between the max and min of the arguments:\n(defn avg\n [error & nums]\n {:post [(<= (apply min nums) % (apply max nums))]}\n (/ (apply + error nums)\n (count nums)))\n;; #'user/avg\n\n(avg 0 1 2 3 4 5)\n;; 3\n\n(avg 100 1 2 3 4 5)\n;; Execution error (AssertionError) at user/avg (REPL:1).\n;; Assert failed: (<= (apply min nums) % (apply max nums))\n", :_id "5c6db9eae4b0ca44402ef69c"} {:updated-at 1578771116812, :created-at 1578770937032, :author {:login "boraseoksoon", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/6975179?v=4"}, :body ";; To inverse boolean\n\n(defn ! [bool]\n (if (= bool true)\n false true))\n\n(! true)\n;; => false\n\n(! false)\n;; => true", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/6975179?v=4", :account-source "github", :login "boraseoksoon"}], :_id "5e1a21f9e4b0ca44402ef813"} {:updated-at 1590107719852, :created-at 1590107719852, :author {:login "mdave16", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/15642321?v=4"}, :body "; You can also destructure inside the method\n(defn foo\n \"Will be passed a hash\"\n [{x :bar y :baz}]\n (+ x y))\n\n(foo 1 2)\n; Wrong number of args (2) passed\n\n(foo {:bar 1 :baz 2})\n; 3\n\n(defn potentially-confusing-fn\n \"Will be passed a hash with one key\"\n [{x :match}]\n (* x x))\n\n(potentially-confusing-fn 1)\n; NullPointerException and nil return\n\n(potentially-confusing-fn {:match 2})\n; 4", :_id "5ec71e47e4b087629b5a190d"}], :macro true, :notes nil, :arglists ["name doc-string? attr-map? [params*] prepost-map? body" "name doc-string? attr-map? ([params*] prepost-map? body) + attr-map?"], :doc "Same as (def name (fn [params* ] exprs*)) or (def\n name (fn ([params* ] exprs*)+)) with any doc-string or attrs added\n to the var metadata. prepost-map defines a map with optional keys\n :pre and :post that contain collections of pre or post conditions.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/defn"} {:added "1.0", :ns "clojure.core", :name "ref", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1284616785000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "alter", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d3e"} {:created-at 1284616936000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "ref-set", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d3f"} {:created-at 1323973222000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "add-watch", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d40"} {:created-at 1326521654000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "dosync", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d41"} {:created-at 1349393302000, :author {:login "eric", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2b0c9ae6f1da9716451e7c86bc87230b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "commute", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d42"} {:created-at 1349397556000, :author {:login "eric", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2b0c9ae6f1da9716451e7c86bc87230b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ensure", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d43"} {:created-at 1364770237000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref-history-count", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d44"} {:created-at 1364770253000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref-min-history", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d45"} {:created-at 1364770260000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref-max-history", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d46"} {:created-at 1364873716000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "set-validator!", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d47"}], :line 2262, :examples [{:author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"} {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"} {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"} {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"} {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"} {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}], :body "user=> (ref [])\n#\n\nuser=> (ref 1 :validator pos?)\n#\n\n=> (ref 0 :validator pos?)\nIllegalStateException Invalid reference state clojure.lang.ARef.validate (ARef.java:33)\n\n=> (dosync (ref-set (ref 1 :validator pos?) 0))\nIllegalStateException Invalid reference state clojure.lang.ARef.validate (ARef.java:33)\n\n=> (dosync (ref-set (ref 1 :validator pos?) 2))\n2", :created-at 1280779137000, :updated-at 1360387666000, :_id "542692cac026201cdc326b3a"} {:updated-at 1470997853281, :created-at 1470997853281, :author {:login "Lacty", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7412474?v=3"}, :body "; create(ref)\n(def a (ref '(1 2 3)))\n\n; read(deref)\n(deref a) ; -> (1 2 3)\n\n; rewrite(ref-set)\n; (ref-set a '(3 2 1)) err!\n(dosync (ref-set a '(3 2 1)))\n\n(deref a) ; -> (3 2 1)", :_id "57ada55de4b0bafd3e2a04e7"} {:updated-at 1548668131418, :created-at 1548668131418, :author {:login "Activeghost", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10783037?v=4"}, :body ";; EXAMPLE: Storing an object in a state map to control it's lifecycle\n(def state (ref {}))\n\n(defn start->streams\n []\n (log/info \"[start->streams] enter\")\n\n;; deref state and do something with it (in this case, check if we have created it)\n (when (not (instance? KafkaStreams (:streams @state)))\n (let [config-file (s/conform ::configs/configuration-file (configs/config CONFIG_PATH))\n kafka-config (s/conform ::configs/kafka-configuration (:processor.config/kafka-configuration config-file))\n stream-processing-props {StreamsConfig/APPLICATION_ID_CONFIG (:applicationid kafka-config)\n StreamsConfig/COMMIT_INTERVAL_MS_CONFIG (:auto.commit.interval.ms kafka-config)\n StreamsConfig/BOOTSTRAP_SERVERS_CONFIG (:bootstrap-servers kafka-config)\n StreamsConfig/DEFAULT_KEY_SERDE_CLASS_CONFIG (.getName (.getClass (Serdes/String)))\n StreamsConfig/DEFAULT_VALUE_SERDE_CLASS_CONFIG (.getName (.getClass (Serdes/String)))\n StreamsConfig/PROCESSING_GUARANTEE_CONFIG StreamsConfig/EXACTLY_ONCE}]\n (try \n (log/infof \"[start->streams] creating kafka stream with config: %s\" stream-processing-props)\n\n (dosync \n\n;; update the ref and store an object in the state map\n (alter state conj (-> { :streams (KafkaStreams. (topology) (StreamsConfig. stream-processing-props))})))\n (log/info \"[start->streams] stream created\")\n\n (catch Exception e (log/error e)))))\n\n;; deref the state and call an fn on the contained object\n (.start (:streams @state)))\n", :_id "5c4ecce3e4b0ca44402ef655"} {:updated-at 1553601306531, :created-at 1553601306531, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; Refs automatically deref their content when used as a function:\n(def m (ref {:a 1 :b 2}))\n\n(m :a)\n;; 1\n\n;; Refs natural ordering is by creation time (oldest first), not their content:\n(def z (ref 10))\n(def y (ref 12))\n(def x (ref 1))\n\n(map deref (sort [x y z]))\n;; (10 12 1)", :_id "5c9a131ae4b0ca44402ef6ca"}], :notes nil, :arglists ["x" "x & options"], :doc "Creates and returns a Ref with an initial value of x and zero or\n more options (in any order):\n\n :meta metadata-map\n\n :validator validate-fn\n\n :min-history (default 0)\n :max-history (default 10)\n\n If metadata-map is supplied, it will become the metadata on the\n ref. validate-fn must be nil or a side-effect-free fn of one\n argument, which will be passed the intended new state on any state\n change. If the new state is unacceptable, the validate-fn should\n return false or throw an exception. validate-fn will be called on\n transaction commit, when all refs have their final values.\n\n Normally refs accumulate history dynamically as needed to deal with\n read demands. If you know in advance you will need history you can\n set :min-history to ensure it will be available when first needed (instead\n of after a read fault). History is limited, and the limit can be set\n with :max-history.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ref"} {:added "1.3", :ns "clojure.core", :name "bigint", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1509577775565, :author {:login "chrm", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/448995?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "biginteger", :ns "clojure.core"}, :_id "59fa542fe4b0a08026c48c90"} {:created-at 1567418361421, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bigdec", :ns "clojure.core"}, :_id "5d6ce7f9e4b0ca44402ef7aa"}], :line 3619, :examples [{:author {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"} {:login "rebcabin", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/880b0bb3a4be9237326dd69565444dee?r=PG&default=identicon"}], :body "user=> (bigint 30)\n30\n\n\n;; Actually do something BigInteger-ish... (http://download.oracle.com/javase/6/docs/api/)\n\nuser=> (def x (bigint 97))\n#'user/x\n\nuser=> (.isProbablePrime (.toBigInteger x) 100)\ntrue\n", :created-at 1283817133000, :updated-at 1375568824000, :_id "542692cec026201cdc326d94"} {:author {:login "rebcabin", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/880b0bb3a4be9237326dd69565444dee?r=PG&default=identicon"}, :editors [{:login "rebcabin", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/880b0bb3a4be9237326dd69565444dee?r=PG&default=identicon"} {:avatar-url "https://avatars2.githubusercontent.com/u/31996?v=4", :account-source "github", :login "avelino"}], :body "user> (= (bigint 42) (clojure.lang.BigInt/fromBigInteger (BigInteger. \"42\")))\ntrue\nuser> (= 42N (bigint 42))\ntrue\nuser> (= 42 (bigint 42))\ntrue\nuser> (= 42 (clojure.lang.BigInt/fromBigInteger (BigInteger. \"42\")))\ntrue\n", :created-at 1375568690000, :updated-at 1528931565159, :_id "542692d2c026201cdc326f4f"} {:author {:login "rebcabin", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/880b0bb3a4be9237326dd69565444dee?r=PG&default=identicon"}, :editors [{:login "rebcabin", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/880b0bb3a4be9237326dd69565444dee?r=PG&default=identicon"}], :body "user> (reduce * (repeat 20 1000))\nArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1388)\n\nuser> (reduce * (repeat 20 (bigint 1000)))\n1000000000000000000000000000000000000000000000000000000000000N\n", :created-at 1375569614000, :updated-at 1375569672000, :_id "542692d2c026201cdc326f51"} {:updated-at 1509577762158, :created-at 1509577762158, :author {:login "chrm", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/448995?v=4"}, :body ";; There is a difference between `BigInt` and `BigInteger`. The first is from\n;; Clojure and should be better for performace, because less unboxing is\n;; necessary. The second is from Java and has more functionality.\n;; https://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html\n\n(type 123N)\n;; => clojure.lang.BigInt\n\n(type (bigint 123))\n;; => clojure.lang.BigInt\n\n(type (biginteger 123))\n;; => java.math.BigInteger\n\n(.modInverse (bigint 123) (bigint 4))\n;; IllegalArgumentException No matching method found: modInverse for class\n;; clojure.lang.BigInt\n\n(.modInverse (biginteger 123) (biginteger 4))\n;; => 3", :_id "59fa5422e4b0a08026c48c8f"} {:updated-at 1535909892844, :created-at 1535909892844, :author {:login "cloojure", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/7083783?v=4"}, :body "; It also works for strings\n(bigint \"12345\") => 12345N\n", :_id "5b8c2004e4b00ac801ed9e7e"} {:updated-at 1598220963933, :created-at 1598220963933, :author {:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}, :body ";; Take care with ratios the decimal part is removed not rounded\nuser=> (bigint 5/4) ; 1.25\n;; 1N\n\nuser=> (bigint 5/2) ; 2.5\n;; 2N", :_id "5f42eaa3e4b0b1e3652d73a7"}], :notes [{:updated-at 1375486531000, :body "The last example does not seem to work; there seems to be a missing coercion from Clojure BigInt to Java BigInteger. I get
\r\nIllegalArgumentException No matching method found: isProbablePrime for class clojure.lang.BigInt clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:53)
", :created-at 1375486531000, :author {:login "rebcabin", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/880b0bb3a4be9237326dd69565444dee?r=PG&default=identicon"}, :_id "542692edf6e94c697052200a"}], :tag "clojure.lang.BigInt", :arglists ["x"], :doc "Coerce to BigInt", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bigint"} {:added "1.2", :ns "clojure.core", :name "extends?", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos [{:created-at 1302036433000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defprotocol", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cb6"} {:created-at 1491526670270, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "defrecord", :ns "clojure.core"}, :_id "58e6e40ee4b01f4add58fe84"} {:created-at 1491526677033, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "deftype", :ns "clojure.core"}, :_id "58e6e415e4b01f4add58fe85"} {:created-at 1501651292857, :author {:login "chbrown", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/360279?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "satisfies?", :ns "clojure.core"}, :_id "5981615ce4b0d19c2ce9d705"}], :line 556, :examples [{:author {:login "mstoeckli", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/271f1fe6c39e19db5714ce29b64d3ad5?r=PG&default=identicon"}, :editors [], :body "user=> (defprotocol Area (get-area [this]))\nArea\n\nuser=> (defrecord Rectangle [width height]\n Area\n (get-area [this]\n (* width height)))\nuser.Rectangle\n\n(extends? Area Rectangle)\ntrue\n", :created-at 1337146392000, :updated-at 1337146392000, :_id "542692d3c026201cdc326fa4"}], :notes nil, :arglists ["protocol atype"], :doc "Returns true if atype extends protocol", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/extends_q"} {:added "1.1", :ns "clojure.core", :name "promise", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1343782692000, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "realized?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ed2"} {:created-at 1291473023000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "future", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f35"} {:created-at 1301868450000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "deliver", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f36"}], :line 7096, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "neveu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/197e0539bc06e120eea534aa2a7d3ec0?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "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\n", :created-at 1280748732000, :updated-at 1285488731000, :_id "542692c7c026201cdc3269c8"} {:author {:login "neotyk", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/366ff985977b3aab09510bc335cd44a4?r=PG&default=identicon"}, :editors [], :body ";; 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\n", :created-at 1324962605000, :updated-at 1324962605000, :_id "542692d4c026201cdc32703f"} {:updated-at 1481568139131, :created-at 1474382276273, :author {:login "JoshAaronJones", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19951591?v=3"}, :body ";; 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]", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/19951591?v=3", :account-source "github", :login "JoshAaronJones"} {:login "jamieorc", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2139?v=3"}], :_id "57e149c4e4b0709b524f0502"}], :notes nil, :arglists [""], :doc "Returns a promise object that can be read with deref/@, and set,\n once only, with deliver. Calls to deref/@ prior to delivery will\n block, unless the variant of deref with timeout is used. All\n subsequent derefs will return the same delivered value without\n blocking. See also - realized?.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/promise"} {:added "1.0", :ns "clojure.core", :name "aset-char", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 3981, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; create an array of 10 characters (initially set to blank by default)\n;; and set one of the elements to the character \"a\"\n\nuser=> (def cs (char-array 10))\n#'user/cs\nuser=> (vec cs)\n[\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ ]\nuser=> (aset-char cs 3 \\a)\n\\a\nuser=> (vec cs)\n[\\ \\ \\ \\a \\ \\ \\ \\ \\ \\ ]\nuser=>", :created-at 1313914505000, :updated-at 1313914505000, :_id "542692c9c026201cdc326ad3"}], :notes [{:body "See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax.", :created-at 1432829137215, :updated-at 1432829137215, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :_id "55673cd1e4b01ad59b65f4de"}], :arglists ["array idx val" "array idx idx2 & idxv"], :doc "Sets the value at the index/indices. Works on arrays of char. Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aset-char"} {:added "1.0", :ns "clojure.core", :name "rseq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1293103256000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "reverse", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c2e"}], :line 1581, :examples [{:author {:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "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", :created-at 1282324324000, :updated-at 1285494434000, :_id "542692c8c026201cdc326a58"} {:author {:login "clojureking", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/92625b8a6be91bb8c688d0d07b4e2a32?r=PG&default=identicon"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "(rseq (into (sorted-map) {:a 1 :b 2}))\n;; => ([:b 2] [:a 1])", :created-at 1409352627000, :updated-at 1423095124718, :_id "542692d5c026201cdc327078"} {:updated-at 1613699307202, :created-at 1613698736253, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :body ";; 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\"", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4", :account-source "github", :login "Crowbrammer"}], :_id "602f16b0e4b0b1e3652d7457"} {:updated-at 1680191517830, :created-at 1680191517830, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; 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", :_id "6425b01de4b08cf8563f4b88"}], :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"} {:added "1.10", :ns "clojure.core", :name "ex-cause", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1636723273402, :author {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-info", :ns "clojure.core"}, :_id "618e6a49e4b0b1e3652d756f"} {:created-at 1636723280306, :author {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-data", :ns "clojure.core"}, :_id "618e6a50e4b0b1e3652d7570"} {:created-at 1636723289915, :author {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-message", :ns "clojure.core"}, :_id "618e6a59e4b0b1e3652d7571"}], :line 4808, :examples [{:updated-at 1636723247465, :created-at 1636723247465, :author {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}, :body ";; (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; [...]", :_id "618e6a2fe4b0b1e3652d756e"} {:updated-at 1636972033983, :created-at 1636972033983, :author {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}, :body ";; 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\"", :_id "61923601e4b0b1e3652d7578"}], :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"} {:added "1.0", :ns "clojure.core", :name "construct-proxy", :file "clojure/core_proxy.clj", :type "function", :column 1, :see-alsos [{:created-at 1539823552877, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "get-proxy-class", :ns "clojure.core"}, :_id "5bc7d7c0e4b00ac801ed9edf"} {:created-at 1539823559598, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "proxy", :ns "clojure.core"}, :_id "5bc7d7c7e4b00ac801ed9ee0"}], :line 290, :examples [{:updated-at 1539823495958, :created-at 1539823495958, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; Compared to \"proxy\" you have the option to pick different \n;; constructors on the same proxy class.\n\n(def MyThread (get-proxy-class Thread))\n\n(defn t\n ([clazz f] (construct-proxy clazz f))\n ([clazz id f] (construct-proxy clazz f id)))\n\n(str (t MyThread #()))\n;; \"Thread[Thread-2,5,main]\"\n\n(str (t MyThread \"***MYTHREAD***\" #()))\n;; \"Thread[***MYTHREAD***,5,main]\"\n", :_id "5bc7d787e4b00ac801ed9ede"}], :notes nil, :arglists ["c & ctor-args"], :doc "Takes a proxy class and any arguments for its superclass ctor and\n creates and returns an instance of the proxy.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/construct-proxy"} {:added "1.0", :ns "clojure.core", :name "agent-errors", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 2236, :examples nil, :deprecated "1.2", :notes nil, :arglists ["a"], :doc "DEPRECATED: Use 'agent-error' instead.\n Returns a sequence of the exceptions thrown during asynchronous\n actions of the agent.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/agent-errors"} {:added "1.0", :ns "clojure.core", :name "*compile-files*", :type "var", :see-alsos nil, :examples [{:updated-at 1584381840421, :created-at 1584381840421, :author {:login "devn", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/10421?v=4"}, :body ";; Ensure that the `require` doesn't result in AOT'd class files\n(binding [*compile-files* false]\n (require 'foo.bar))", :_id "5e6fbf90e4b087629b5a18bf"} {:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1613847596666, :updated-at 1614012007913, :_id "60315c2ce4b0b1e3652d745f"}], :notes nil, :arglists [], :doc "Set to true when compiling files, false otherwise.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*compile-files*"} {:added "1.10", :ns "clojure.core", :name "ex-message", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1602605078561, :author {:login "m0smith", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/398808?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-data", :ns "clojure.core"}, :_id "5f85d016e4b0b1e3652d73db"} {:created-at 1602605096620, :author {:login "m0smith", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/398808?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-info", :ns "clojure.core"}, :_id "5f85d028e4b0b1e3652d73dc"}], :line 4800, :examples [{:updated-at 1587607327636, :created-at 1587603158684, :author {:login "thiagorfaria", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/5934045?v=4"}, :body "(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}\"", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/5934045?v=4", :account-source "github", :login "thiagorfaria"}], :_id "5ea0e6d6e4b087629b5a18dc"}], :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"} {:ns "clojure.core", :name "*math-context*", :type "var", :see-alsos [{:created-at 1635281435762, :author {:login "Chouser", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/36110?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "with-precision", :ns "clojure.core"}, :_id "61786a1be4b0b1e3652d755c"}], :examples nil, :notes nil, :tag "java.math.MathContext", :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*math-context*"} {:added "1.0", :ns "clojure.core", :name "float", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1496073295794, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unchecked-float", :ns "clojure.core"}, :_id "592c444fe4b093ada4d4d796"} {:created-at 1593104025671, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1836941?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bigdec", :ns "clojure.core"}, :_id "5ef4d699e4b0b1e3652d730f"}], :line 3486, :examples [{:updated-at 1496073286628, :created-at 1283814444000, :body "(float 1)\n;;=> 1.0\n(float 1.11)\n;;=> 1.11\n(float 1.111111111111111111111111111M)\n;;=> 1.1111112\n\n;;;; Note that (float) range checks its argument and throws an exception\n;;;; if the value is out of range.\n;;;; Use (unchecked-float) instead if you want to skip the range checks.\n\n(float Double/MAX_VALUE)\n;;=> IllegalArgumentException Value out of range for float: 1.7976931348623157E308\n(unchecked-float Double/MAX_VALUE)\n;;=> Infinity\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon", :account-source "clojuredocs", :login "Miles"}, :_id "542692c9c026201cdc326afd"} {:editors [{:login "wdhowe", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4631165?v=4"}], :body ";; Casting a string does not work\n(float \"123.456\")\n;;=> Execution error (ClassCastException) at user/eval193 (REPL:1).\n;;java.lang.String cannot be cast to java.lang.Number\n\n;; Use Java interop instead\n(Float/parseFloat \"123.456\")\n;;=> 123.456\n\n;; Content originally posted by u/didibus on https://clojuredocs.org/clojure.core/num", :author {:avatar-url "https://avatars0.githubusercontent.com/u/4631165?v=4", :account-source "github", :login "wdhowe"}, :created-at 1596590631704, :updated-at 1596590780119, :_id "5f2a0a27e4b0b1e3652d7365"}], :notes nil, :arglists ["x"], :doc "Coerce to float", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/float"} {:added "1.0", :ns "clojure.core", :name "pr-str", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1299623857000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "pr", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b27"} {:created-at 1313054793000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "read-string", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b28"} {:created-at 1360241771000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "prn-str", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b29"} {:created-at 1517964034880, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "str", :ns "clojure.core"}, :_id "5a7a4b02e4b0e2d9c35f7420"}], :line 4736, :examples [{:author {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}, :editors [{:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Kototama", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a54a4dc204925d397ca010b9a332e74d?r=PG&default=identicon"} {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}], :body "user=> (def x [1 2 3 4 5])\n#'user/x\nuser=> x\n[1 2 3 4 5]\n\n\n;; Turn that data into a string...\nuser=> (pr-str x)\n\"[1 2 3 4 5]\"\n\n\n;; ...and turn that string back into data!\nuser=> (read-string (pr-str x))\n[1 2 3 4 5]\n", :created-at 1284257614000, :updated-at 1287792086000, :_id "542692cbc026201cdc326c20"} {:author {:login "dansalmo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"}, :editors [], :body ";; you can think of pr-str as the inverse of read-string\n;; turn string into symbols\nuser=> (read-string \"(a b foo :bar)\")\n(a b foo :bar)\n\n;;turn symbols into a string\nuser=> (pr-str '(a b foo :bar))\n\"(a b foo :bar)\"", :created-at 1346843924000, :updated-at 1346843924000, :_id "542692d4c026201cdc327032"} {:author {:login "GyrosOfWar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8abc292bf5d9e88cfcbcfbe492774a38?r=PG&default=identicon"}, :editors [{:login "GyrosOfWar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8abc292bf5d9e88cfcbcfbe492774a38?r=PG&default=identicon"} {:login "GyrosOfWar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8abc292bf5d9e88cfcbcfbe492774a38?r=PG&default=identicon"} {:login "GyrosOfWar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8abc292bf5d9e88cfcbcfbe492774a38?r=PG&default=identicon"}], :body "(defn write-object\n \"Serializes an object to disk so it can be opened again later.\n Careful: It will overwrite an existing file at file-path.\"\n [obj file-path]\n (with-open [wr (writer file-path)]\n (.write wr (pr-str obj)))))", :created-at 1391924453000, :updated-at 1391924601000, :_id "542692d4c026201cdc327033"} {:updated-at 1516110350763, :created-at 1516110350763, :author {:login "martinklepsch", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/97496?v=4"}, :body ";; Be careful with side-effects that are part of lazy sequences.\n;; Especially printing can yield unexpected results.\nuser=> (->> (range 10)\n (map #(do (println %) %))\n (pr-str))\n\n\"(0\\n1\\n2\\n3\\n4\\n5\\n6\\n7\\n8\\n9\\n0 1 2 3 4 5 6 7 8 9)\"\n", :_id "5a5e020ee4b0a08026c48cf7"} {:editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}], :body ";; sometimes when printing lazy sequences you do not get what you want.\n(str (take 5 (range 10)))\n;=> \"clojure.lang.LazySeq@1b554e1\"\n\n;; in those cases `pr-str` to the rescue.\n(pr-str (take 5 (range 10)))\n;=> \"(0 1 2 3 4)\"", :author {:avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4", :account-source "github", :login "phreed"}, :created-at 1517963998229, :updated-at 1517964057656, :_id "5a7a4adee4b0e2d9c35f741f"} {:editors [{:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}], :body ";; Be aware that pr-str and friends are influenced by a couple global variables\n;; such as *print-length*:\n\n(set! *print-length* 10)\n(pr-str (range 15))\n;=> \"(0 1 2 3 4 5 6 7 8 9 ...)\"\n\n(set! *print-length* -1)\n(pr-str (range 15))\n;=> \"(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14)\"", :author {:avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4", :account-source "github", :login "bfontaine"}, :created-at 1522748816082, :updated-at 1522748961361, :_id "5ac34d90e4b045c27b7fac30"}], :notes nil, :tag "java.lang.String", :arglists ["& xs"], :doc "pr to a string, returning it", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/pr-str"} {:added "1.0", :ns "clojure.core", :name "concat", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1332796328000, :author {:login "Olivenmann", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d5b1703fb08dd81e4cb2f653a3aaf10b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "conj", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521da6"} {:created-at 1343083284000, :author {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "into", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521da7"} {:created-at 1520441797302, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "lazy-cat", :ns "clojure.core"}, :_id "5aa019c5e4b0316c0f44f90f"} {:created-at 1590171359727, :author {:login "themustafabasit", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/24441401?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "quote", :ns "clojure.core"}, :_id "5ec816dfe4b087629b5a190f"} {:created-at 1597428941227, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "mapcat", :ns "clojure.core"}, :_id "5f36d4cde4b0b1e3652d7377"} {:created-at 1597429044495, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "zipmap", :ns "clojure.core"}, :_id "5f36d534e4b0b1e3652d7378"} {:created-at 1685378146800, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "cat", :ns "clojure.core"}, :_id "6474d462e4b08cf8563f4bbf"} {:created-at 1685378175177, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "cat", :ns "clojure.core.reducers"}, :_id "6474d47fe4b08cf8563f4bc0"}], :line 718, :examples [{:updated-at 1473090562851, :created-at 1279026744000, :body "\nuser=> (concat [1 2] [3 4])\n(1 2 3 4)\n\nuser=> (into [] (concat [1 2] [3 4]))\n[1 2 3 4]\n\nuser=> (concat [:a :b] nil [1 [2 3] 4])\n(:a :b 1 [2 3] 4)\n\n=> (concat [1] [2] '(3 4) [5 6 7] #{9 10 8})\n(1 2 3 4 5 6 7 8 9 10)\n;; The last three elements might appear in a different order.\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon", :account-source "clojuredocs", :login "john.r.woodward"} {:avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon", :account-source "clojuredocs", :login "john.r.woodward"} {:avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon", :account-source "clojuredocs", :login "AtKaaZ"} {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon", :account-source "clojuredocs", :login "kotarak"}, :_id "542692c9c026201cdc326a99"} {:author {:login "Bob Jarvis", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5ba4bce40c00d30a3b924cbaaf94c17a?r=PG&default=identicon"}, :editors [], :body "user=> (concat \"abc\" \"def\")\n(\\a \\b \\c \\d \\e \\f)\n", :created-at 1392247889000, :updated-at 1392247889000, :_id "542692d2c026201cdc326f66"} {:body "user=> (apply concat '(([1 2]) ([3 4] [5 6]) ([7 8])))\n([1 2] [3 4] [5 6] [7 8])\n", :author {:login "prabhathk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11288784?v=3"}, :created-at 1430731339291, :updated-at 1430731382642, :editors [{:login "prabhathk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11288784?v=3"}], :_id "55473a4be4b06eaacc9cda88"} {:updated-at 1501863107172, :created-at 1501863107172, :author {:login "RobinNagpal", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/745748?v=4"}, :body "user=> (concat '(1 2 3) '(4 5 6))\n;; (1 2 3 4 5 6)", :_id "59849cc3e4b0d19c2ce9d707"} {:updated-at 1501863170406, :created-at 1501863170406, :author {:login "RobinNagpal", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/745748?v=4"}, :body "user=> (concat [1 2 3] [4 5 6])\n;; (1 2 3 4 5 6)", :_id "59849d02e4b0d19c2ce9d708"} {:editors [{:login "RobinNagpal", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/745748?v=4"}], :body "(concat {:a \"A\" :b \"B\" :c \"C\"} {:d \"D\" :e \"E\"})\n;; ([:a \"A\"] [:b \"B\"] [:c \"C\"] [:d \"D\"] [:e \"E\"])", :author {:avatar-url "https://avatars3.githubusercontent.com/u/745748?v=4", :account-source "github", :login "RobinNagpal"}, :created-at 1501863260134, :updated-at 1501863287333, :_id "59849d5ce4b0d19c2ce9d709"} {:updated-at 1520436404730, :created-at 1520436404730, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body "(defn padding-right [s width pad] \n (apply str (take width (concat s (repeat pad)))))\n\n(padding-right \"Clojure\" 10 \" \")\n;; \"Clojure \"", :_id "5aa004b4e4b0316c0f44f90e"} {:editors [{:login "manojarya", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/2968153?v=4"}], :body ";; beware! concat returns a lazy 'sequence'. \n\n(conj (concat [1 2] [3 4]) 5) ; doesn't return (1 2 3 4 5)\n;;=>(5 1 2 3 4)", :author {:avatar-url "https://avatars0.githubusercontent.com/u/2968153?v=4", :account-source "github", :login "manojarya"}, :created-at 1569483435769, :updated-at 1569512850496, :_id "5d8c6aabe4b0ca44402ef7c1"} {:editors [{:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}], :body ";; Here is a good article by Stuart Sierra in his \"Clojure Dont's\" series\n;; on concat, and how using it in certain ways can lead to surprisingly large\n;; stack usage:\n;; https://stuartsierra.com/2015/04/26/clojure-donts-concat\n\n(first (reduce concat (map next-results (range 1 4000))))\n;; StackOverflowError clojure.core/seq (core.clj:133)\n\n(nth (iterate #(concat % [1 2 3]) [1 2 3]) 4000)\n;; StackOverflowError clojure.core/seq (core.clj:133)", :author {:avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4", :account-source "github", :login "jafingerhut"}, :created-at 1577571723261, :updated-at 1611951560722, :_id "5e07d58be4b0ca44402ef801"} {:updated-at 1590171425117, :created-at 1588243083702, :author {:login "themustafabasit", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/24441401?v=4"}, :body ";; list 1\n(def list1 (list 'let ['x 10]))\n;; => #'user/list1\nlist1\n;; => (let [x 10])\n\n;; list 2\n(def list2 (list '(println \"x:\" x) '(println \"Bye!\")))\n;; => #'user/list2\nlist2\n;; => ((println \"x:\" x) (println \"Bye!\"))\n\n;; ***\n;; concat all the elements of list1 & list2, and return a new list \n;; In this case - let + [x 10] + (println \"x:\" x) + (println \"Bye!\")\n\n(concat list1 list2)\n;; => (let [x 10] (println \"x:\" x) (println \"Bye!\"))\n\n(eval (concat list1 list2))\n;; => x: 10\n;; Bye!\n;; nil\n\n\n;; see also - quote", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/24441401?v=4", :account-source "github", :login "themustafabasit"}], :_id "5eaaaa8be4b087629b5a18ec"} {:editors [{:login "wactbprot", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/113518?v=4"}], :body "(concat [1 2 3] nil)\n;; => (1 2 3)\n\n(concat [1 2 3] [nil])\n;; => (1 2 3 nil)", :author {:avatar-url "https://avatars.githubusercontent.com/u/113518?v=4", :account-source "github", :login "wactbprot"}, :created-at 1612534560315, :updated-at 1612534622108, :_id "601d5320e4b0b1e3652d7449"}], :notes nil, :arglists ["" "x" "x y" "x y & zs"], :doc "Returns a lazy seq representing the concatenation of the elements in the supplied colls.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/concat"} {:added "1.0", :ns "clojure.core", :name "aset-short", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 3971, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; create an array of 10 shorts and set one of the values to 31415\n\nuser=> (def ss (short-array 10))\n#'user/ss\nuser=> (vec ss)\n[0 0 0 0 0 0 0 0 0 0]\nuser=> (aset-short ss 3 31415)\n31415\nuser=> (vec ss)\n[0 0 0 31415 0 0 0 0 0 0]\nuser=>", :created-at 1313915280000, :updated-at 1313915280000, :_id "542692cac026201cdc326b1c"}], :notes [{:body "See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax.", :created-at 1432829129279, :updated-at 1432829129279, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :_id "55673cc9e4b01ad59b65f4dd"}], :arglists ["array idx val" "array idx idx2 & idxv"], :doc "Sets the value at the index/indices. Works on arrays of short. Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aset-short"} {:added "1.5", :ns "clojure.core", :name "set-agent-send-off-executor!", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1553631504676, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "set-agent-send-executor!", :ns "clojure.core"}, :_id "5c9a8910e4b0ca44402ef6d9"} {:created-at 1553631511505, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "send-via", :ns "clojure.core"}, :_id "5c9a8917e4b0ca44402ef6da"} {:created-at 1559240493574, :author {:login "pdbrown", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1607096?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "shutdown-agents", :ns "clojure.core"}, :_id "5cf01f2de4b0ca44402ef73a"}], :line 2095, :examples [{:updated-at 1553631658338, :created-at 1553631497381, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; This permanently change the thread pool used by agents receiving \n;; tasks with \"send-off\". Use this to control thread pools of applications\n;; you don't own.\n\n(import '[java.util.concurrent Executors])\n(def fj-pool (Executors/newWorkStealingPool 20))\n(set-agent-send-off-executor! fj-pool)", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :_id "5c9a8909e4b0ca44402ef6d8"}], :notes nil, :arglists ["executor"], :doc "Sets the ExecutorService to be used by send-off", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/set-agent-send-off-executor!"} {:added "1.0", :ns "clojure.core", :name "ns", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1289000801000, :author {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "use", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f07"} {:created-at 1289000808000, :author {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "require", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f08"} {:created-at 1289000818000, :author {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "refer", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f09"} {:created-at 1291628676000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "import", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f0a"} {:created-at 1312583994000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ns-publics", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f0b"} {:created-at 1340999276000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "in-ns", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f0c"} {:created-at 1355453198000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "remove-ns", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f0d"} {:created-at 1366844150000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ns-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f0e"} {:created-at 1398960898000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "*ns*", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f0f"} {:created-at 1686507880947, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "alias", :ns "clojure.core"}, :_id "64861168e4b08cf8563f4bc9"}], :line 5764, :examples [{:updated-at 1514387836686, :created-at 1279069109000, :body ";; Generate a Java class\n(ns org.clojuredocs.test\n (:gen-class))\n\n(defn -main [] (println \"Hello, World!\"))\n\n\n;; After compilation:\nsh$ java -cp classes org.clojuredocs.test\nHello, World!\n", :editors [{:avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon", :account-source "clojuredocs", :login "devijvers"} {:avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon", :account-source "clojuredocs", :login "devijvers"} {:avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon", :account-source "clojuredocs", :login "devijvers"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:login "jcburley", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/430319?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon", :account-source "clojuredocs", :login "devijvers"}, :_id "542692cac026201cdc326b6e"} {:updated-at 1541261966025, :created-at 1284948992000, :body ";; Let's create a namespace and then assign it as the current namespace\nuser=> (create-ns 'my-new-namespace)\n#namespace[my-new-namespace]\n\nuser=> (ns 'my-new-namespace)\njava.lang.ClassCastException: clojure.lang.PersistentList cannot be cast to\n clojure.lang.Symbol (NO_SOURCE_FILE:26)\n;; oops, this is not the way to do it; if create-ns needs a symbol, ns does not\n\nuser=> (ns my-new-namespace)\nnil\n\nmy-new-namespace=>\n;; it worked as the current namespace is our newly created one\n\n", :editors [{:avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon", :account-source "clojuredocs", :login "belun"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:login "enocom", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1175430?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon", :account-source "clojuredocs", :login "belun"}, :_id "542692cac026201cdc326b73"} {:author {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"}, :editors [{:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; Generating a class so we can call Clojure from Java \n(ns com.domain.tiny\n (:gen-class\n :name com.domain.tiny\n :methods [#^{:static true} [binomial [int int] double]]))\n\n(defn binomial\n \"Calculate the binomial coefficient.\"\n [n k]\n (let [a (inc n)]\n (loop [b 1\n c 1]\n (if (> b k)\n c\n (recur (inc b) (* (/ (- a b) b) c))))))\n\n(defn -binomial\n \"A Java-callable wrapper around the 'binomial' function.\"\n [n k]\n (binomial n k))\n\n(defn -main []\n (println (str \"(binomial 5 3): \" (binomial 5 3)))\n (println (str \"(binomial 10042 111): \" (binomial 10042 111))))\n\n\n;; Calling from Java\nimport com.domain.tiny;\n\npublic class Main {\n\n public static void main(String[] args) {\n System.out.println(\"(binomial 5 3): \" + tiny.binomial(5, 3));\n System.out.println(\"(binomial 10042, 111): \" + tiny.binomial(10042, 111));\n }\n}\n\n\n;; The result was:\n(binomial 5 3): 10.0\n(binomial 10042, 111): 4.9068389575068143E263\n\n\n;; Example was borrowed from clartaq @ Stack Overflow", :created-at 1285031740000, :updated-at 1285486378000, :_id "542692cac026201cdc326b76"} {:author {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"}, :editors [{:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"} {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"} {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"} {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=3"}], :body ";; Create a namespace named demo.namespace.\n(ns demo.namespace)\n\n;; Clojure recommends namespaces be at least \"two segments\" (ie, they should\n;; have at least one '.') otherwise it will create a class in the \"default\n;; package\", which is discouraged.\n\n;; If this declaration appears in a file named \"demo/namespace.clj\" present\n;; in your classpath, it is known as a \"lib\", \"demo/namespace.clj\" is the lib's\n;; \"root resource\". See http://clojure.org/libs\n\n;; From a clean repl you can load the lib using\nuser=>(require 'demo.namespace) \n; or\nuser=>(use 'demo.namespace)", :created-at 1288999353000, :updated-at 1423811574430, :_id "542692cac026201cdc326b79"} {:author {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"}, :editors [{:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"} {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"} {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"} {:login "remleduff", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f14b40211cdc07185c43edf8f4bd7a5b?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=3"}], :body ";; This example will illustrate changing between namespaces at the repl\n\n;; At the repl, the ns macro can be used to create a namespace, but it is\n;; used to change the current namespace (be careful of typos)\nuser=>(ns demo.namespace)\nnil\ndemo.namespace=> ; The prompt at the repl is now \"demo.namespace\" reflecting\n ; that the current namespace is no longer \"user\".\n\n;; Add a new function to demo.namespace\ndemo.namespace=>(defn foo [] (prn \"Hello from demo.namespace\"))\n#'demo.namespace/foo\n\n;; From within \"demo.namespace\" we can use foo without qualifying it\ndemo.namespace=>(foo)\n\"Hello from demo.namespace\"\nnil\n\n;; Switch back to the \"user\" namespace\ndemo.namespace=>(ns user)\nnil\n\n;; We can no longer use \"foo\" without qualification\nuser=> (foo)\njava.lang.Exception: Unable to resolve symbol: foo in this context\n (NO_SOURCE_FILE:4)\n\nuser=> (demo.namespace/foo)\n\"Hello from demo.namespace\"\nnil\n\n;; The public symbols of \"demo.namespace\" can be \"referred into\" the \"user\"\n;; namespace if desired\nuser=> (refer 'demo.namespace)\nnil\n\n;; foo is now an alias in the \"user\" namespace which refers to the\n;; \"demo.namespace/foo\" symbol\nuser=> (foo)\n\"Hello from demo.namespace\"\nnil", :created-at 1289000535000, :updated-at 1423811666025, :_id "542692cac026201cdc326b7e"} {:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [], :body "(ns rosettacode.24game\n (:require [clojure.string :as str])\n (:use clojure.test))\n\n(deftest test\n (is (= \"ABC\" (str/capitalize \"abc\")))", :created-at 1289383303000, :updated-at 1289383303000, :_id "542692cac026201cdc326b83"} {:author {:login "scode", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/87b4fd6e7ac86cbf1f1b683f7856057?r=PG&default=identicon"}, :editors [], :body ";; Multiple required namespaces with aliases\n(ns demo.namespace\n (:require [com.example.httplib :as httplib]\n [com.example.otherlib :as otherlib]))\n", :created-at 1297670267000, :updated-at 1297670267000, :_id "542692cac026201cdc326b84"} {:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body ";; In clojure 1.4 and higher you can use the refer function from within\n;; a require which is equivalent to (:use foo only [...]) but still \n;; allows you to reference the required namespace:\n(ns my.ns.example\n (:require [my.lib :refer [function1 function2]]))\n\n;; And :refer :all is equivalent to :use :\n(ns my.ns.example\n (:require [my.lib :refer :all]))\n", :created-at 1340687963000, :updated-at 1357904913000, :_id "542692d4c026201cdc327014"} {:updated-at 1358656144000, :created-at 1358656144000, :body "(ns foo.bar\n (:refer-clojure :exclude [ancestors printf])\n (:require [clojure.contrib sql sql.tests])\n (:use [my.lib this that])\n (:import [java.util Date Timer Random]\n (java.sql Connection Statement)))", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d4c026201cdc327017"} {:editors [{:login "PetrGlad", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/124476?v=3"}], :body "; Gotchas\n(ns newns1 [:require clojure.string])\n; newns1=> nil ; Success\n; Note use of vector instead of list - ns macro successfuly processes it \n; but some tools that read this code might not recognize this dependency.\n; Always write ns as per documentation.\n\n(in-ns 'newns2)\n; newns2=> #object[clojure.lang.Namespace 0x29a8c1fb \"newns2\"]\n; New namespace was successfully created\n(first [])\n; newns2=> CompilerException java.lang.RuntimeException: \n; Unable to resolve symbol: first in this context, \n; compiling:(NO_SOURCE_PATH:7:1) \n; Although \"first\" is in core library, it's name is not available here. \n; To fix this do\n(clojure.core/refer-clojure)\n; newns2=> nil\n(first [])\n; newns2=> nil ; Success\n\n; \"ns\" macro both switches to a namespace and refers default library, \n; \"in-ns\" just switches to given namespace\n(ns newns3)\n; newns3=> nil\n(first [])\n; newns3=> nil\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/124476?v=3", :account-source "github", :login "PetrGlad"}, :created-at 1473163926788, :updated-at 1473164242037, :_id "57ceb296e4b0709b524f04e4"} {:updated-at 1508739714948, :created-at 1508739714948, :author {:login "thescalaguy", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/24409454?v=4"}, :body ";; Shows how to use an attr-map\n;; These are arbitrary key-value pairs\n(ns cljdocs.example.core\n \"This is a doc string, FYI :D\"\n {:author \"John Doe\"\n :last-update-date \"23-10-2017\"})\n=> nil\n\n;; The keys in the attr-map are merged with the compiler-generated attr-map\n(meta *ns*)\n=> {:doc \"This is a doc string, FYI :D\", :author \"John Doe\", :last-update-date \"23-10-2017\"}\n", :_id "59ed8a82e4b03026fe14ea93"} {:updated-at 1549690956926, :created-at 1549690956926, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1836941?v=4"}, :body ";; If you import a Java class with an unqualified name (perhaps from local\n;; source file), use the bare class name without placing it in a vector or list:\n(ns foo.bar\n (:import MyClass))", :_id "5c5e684ce4b0ca44402ef674"} {:updated-at 1627881643879, :created-at 1604651002536, :author {:login "green-coder", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4"}, :body ";; References to things in a given namespace can be locally renamed.\n(ns foo.bar\n (:require [clojure.string :refer [blank?]\n :rename {blank? contains-only-spaces-likes?}]))\n\n(contains-only-spaces-likes? \" \")\n; => true\n", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4", :account-source "github", :login "green-coder"}], :_id "5fa507fae4b0b1e3652d73ff"}], :macro true, :notes [{:updated-at 1291628686000, :body "Good description of use/require/import here:\r\n\r\nhttp://blog.8thlight.com/articles/2010/12/6/clojure-libs-and-namespaces-require-use-import-and-ns", :created-at 1291628686000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fac"} {:body "[How to `ns` — Stuart Sierra’s Opinionated Style Guide for Clojure Namespace Declarations]( https://stuartsierra.com/2016/clojure-how-to-ns.html)\n> Make it look like this:\n>
", :created-at 1597543297488, :updated-at 1597552862469, :author {:avatar-url "https://avatars3.githubusercontent.com/u/2316604?v=4", :account-source "github", :login "finalfantasia"}, :_id "5f389381e4b0b1e3652d7379"} {:author {:login "matasaru", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1546100?v=4"}, :updated-at 1668983174412, :created-at 1668983174412, :body "The post referred in the first note has moved to:\n\nhttps://8thlight.com/insights/clojure-libs-and-namespaces-require-use-import-and-ns", :_id "637aa986e4b0b1e3652d768c"}], :arglists ["name docstring? attr-map? references*"], :doc "Sets *ns* to the namespace named by name (unevaluated), creating it\n if needed. references can be zero or more of: (:refer-clojure ...)\n (:require ...) (:use ...) (:import ...) (:load ...) (:gen-class)\n with the syntax of refer-clojure/require/use/import/load/gen-class\n respectively, except the arguments are unevaluated and need not be\n quoted. (:gen-class ...), when supplied, defaults to :name\n corresponding to the ns name, :main true, :impl-ns same as ns, and\n :init-impl-ns true. All options of gen-class are\n supported. The :gen-class directive is ignored when not\n compiling. If :gen-class is not supplied, when compiled only an\n nsname__init.class will be generated. If :refer-clojure is not used, a\n default (refer 'clojure.core) is used. Use of ns is preferred to\n individual calls to in-ns/require/use/import:\n\n (ns foo.bar\n (:refer-clojure :exclude [ancestors printf])\n (:require (clojure.contrib sql combinatorics))\n (:use (my.lib this that))\n (:import (java.util Date Timer Random)\n (java.sql Connection Statement)))", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ns"} {:added "1.0", :ns "clojure.core", :name "symbol", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289212889000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "var", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d00"} {:created-at 1289212892000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "var?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d01"} {:created-at 1331269623000, :author {:login "franks42", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "symbol?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d02"} {:created-at 1331269707000, :author {:login "franks42", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "name", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d03"} {:created-at 1331269713000, :author {:login "franks42", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "namespace", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d04"} {:created-at 1350410406000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "keyword", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d05"} {:created-at 1450416041205, :author {:login "blx", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/887504?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "resolve", :ns "clojure.core"}, :_id "567397a9e4b09a2675a0ba79"} {:created-at 1571179415471, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "deref", :ns "clojure.core"}, :_id "5da64b97e4b0ca44402ef7cd"}], :line 589, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; Returns a symbol with the given namespace and name.\n;;\n;; (symbol name): name can be a string or a symbol.\n;;\n;; (symbol ns name): ns and name must both be strings.\n;;\n;; A symbol string begins with a non-numeric character and can contain\n;; alphanumeric characters and *, +, !, -, _, and ?. (see\n;; http://clojure.org/reader for details).\n;;\n;; symbol does not validate input strings for ns and name, and may return\n;; improper symbols with undefined behavior for non-conformant ns and\n;; name.\n\nuser=> (symbol 'foo)\nfoo\n\nuser=> (symbol \"foo\")\nfoo\n\nuser=> (symbol \"clojure.core\" \"foo\")\nclojure.core/foo\n", :created-at 1280546541000, :updated-at 1331646095000, :_id "542692c8c026201cdc326a06"} {:updated-at 1406075648000, :created-at 1331680187000, :body ";; some gotchas to be aware of:\n\nuser=> (symbol \"user\" 'abc)\nClassCastException clojure.lang.Symbol cannot be cast to java.lang.String clojure.core/symbol (core.clj:523)\n\nuser=> (symbol *ns* \"abc\")\nClassCastException clojure.lang.Namespace cannot be cast to java.lang.String clojure.core/symbol (core.clj:523)\n\nuser=> (symbol 'user \"abc\")\nClassCastException clojure.lang.Symbol cannot be cast to java.lang.String clojure.core/symbol (core.clj:523)\n\n\n;; Warning - the following generated symbols are non-conformant and may wreak\n;; serious havoc in the near/far future when least expected...\n\nuser=> (symbol \"abc def\")\nabc def\n\nuser=> (symbol \"123def\")\n123def\n\nuser=> (symbol \"/123/def/ghi\")\n/123/def/ghi\n\nuser=> (symbol \"/abc/def/ghi\")\n/abc/def/ghi", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"}], :author {:avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon", :account-source "clojuredocs", :login "franks42"}, :_id "542692d5c026201cdc3270a0"} {:body ";; but keywords and numbers are not names\n(symbol 3)\n;; Long cannot be cast to String\n\n;; ... and so they cannot be converted to symbols\n(symbol :dog) \n;; Keyword cannot be cast to String", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1412434976752, :updated-at 1412435184005, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}], :_id "54300c20e4b05f4d257a29a3"}], :notes nil, :tag "clojure.lang.Symbol", :arglists ["name" "ns name"], :doc "Returns a Symbol with the given namespace and name. Arity-1 works\n on strings, keywords, and vars.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/symbol"} {:added "1.0", :ns "clojure.core", :name "to-array-2d", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1375613655000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "to-array", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eac"}], :line 4003, :examples [{:author {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user> (def a (to-array-2d [[1 2 3][4 5 6]]))\n#'user/a\nuser> (alength a)\n2\nuser> (alength (aget a 0))\n3\nuser> (aget a 0 0)\n1\nuser> (aget a 0 1)\n2\nuser> (aget a 0 2)\n3\nuser> (aget a 1 0)\n4\nuser> (aget a 2 0)\n→ ERROR\nnil\n\nuser> ", :created-at 1307740341000, :updated-at 1325519043000, :_id "542692cac026201cdc326b5b"} {:updated-at 1486711509639, :created-at 1313976771000, :body ";; quick example of a ragged array where the length of each element of the \n;; 2d array is unique\n\nuser=> (def a (to-array-2d [[0][1 2][3 4 5][6 7 8 9]]))\n#'user/a\nuser=> (map alength [(aget a 0)(aget a 1)(aget a 2)])\n(1 2 3)\nuser=>\nuser=> (aget a 0 2)\nArrayIndexOutOfBoundsException java.lang.reflect.Array.get (Array.java:-2)", :editors [{:login "zezhenyan", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8064559?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon", :account-source "clojuredocs", :login "shockbob"}, :_id "542692cac026201cdc326b5d"}], :notes nil, :tag "[[Ljava.lang.Object;", :arglists ["coll"], :doc "Returns a (potentially-ragged) 2-dimensional array of Objects\n containing the contents of coll, which can be any Collection of any\n Collection.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/to-array-2d"} {:added "1.0", :ns "clojure.core", :name "mod", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1305751254000, :author {:login "Kototama", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a54a4dc204925d397ca010b9a332e74d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rem", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e34"} {:created-at 1414324069552, :author {:login "alilee", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/16739?v=2"}, :to-var {:ns "clojure.core", :name "quot", :library-url "https://github.com/clojure/clojure"}, :_id "544cdf65e4b03d20a102427c"} {:created-at 1468958800877, :author {:login "chrismurrph", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10278575?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "/", :ns "clojure.core"}, :_id "578e8850e4b0bafd3e2a04b3"}], :line 3566, :examples [{:author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :editors [{:login "jeffmad", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c526ef2dcf52b0cf18875fcb5616cee0?r=PG&default=identicon"} {:login "jeffmad", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c526ef2dcf52b0cf18875fcb5616cee0?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "rvlieshout", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/139665?v=2"}], :body "user=> (mod 10 5)\n0\n\nuser=> (mod 10 6)\n4\n\nuser=> (mod 10 10)\n0\n\nuser=> (mod 10 -1)\n0\n\n;; The mod function is defined as the amount by which a number exceeds the\n;; largest integer multiple of the divisor that is not greater than that number.\n;; The largest integer multiple of 5 not greater than -2 is 5 * -1 = -5.\n;; The amount by which -2 exceeds -5 is 3. \n;;\nuser=> (mod -2 5) \n3", :created-at 1279992236000, :updated-at 1415184216966, :_id "542692cec026201cdc326d7d"} {:updated-at 1558287692250, :created-at 1466434631179, :author {:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11434205?v=3"}, :body ";; rem and mod are commonly used to get the remainder.\n;; mod means Knuth's mod, Don't confuse it with ANSI C's %\n;; operator, which despite being pronounced\n;; 'mod' actually implements rem, i.e. -10 % 3 = -1.\n;; mod has sign of divisor.\n;; Absolute value depends on dividend and divisor having \n;; same sign or not.\n\nuser=> (mod -10 3)\n2\n\nuser=> (rem -10 3)\n-1\n\nuser=> (mod 10 -3)\n-2\nuser=> (mod -10 -3)\n-1\nuser=> (mod 10 3)\n1", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/7660326?v=4", :account-source "github", :login "Shinkenjoe"} {:login "vaer-k", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4069456?v=4"}], :_id "57680447e4b0bafd3e2a048a"} {:updated-at 1486561191724, :created-at 1486561191724, :author {:login "betegelse", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6758479?v=3"}, :body ";; It works for float / double numbers, too, where it is defined as\n;; (- n (* (Math/floor (/ n d)) d))\n\nuser=> (mod 1.5 1)\n;;=> 0.5\n\nuser=> (mod 475.095 7)\n;;=> 6.095000000000027\n\nuser=> (mod 1024.8402 5.12)\n;;=> 0.8402000000000953\n\nuser=> (mod -1024.8402 5.12)\n;;=> 4.279799999999905\n\nuser=> (let [n 1024.8402\n d 5.12\n q (Math/floor (/ n d))\n r (mod n d)]\n (->> (* q d) (+ r) (- n)))\n;;=> 0.0\n", :_id "589b1fa7e4b01f4add58fe40"}], :notes [{:updated-at 1314955596000, :body "The difference between **rem** and **mod** can be remembered by noting that **mod** always returns a value between 0 and div.", :created-at 1314955596000, :author {:login "wdkrnls", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/6d08a2f792f289b95fe1d982d4133d71?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fc8"} {:updated-at 1350500565000, :body "I am confused by the comment about the definition on lines 13+ of the example - which is not accurate when invoking mod when 'num' is positive and 'div' negative. Applying the definition to
(mod 10 -3)
we have \r\n
the largest multiple of -3 not exceeding 10 is 9, from using -3 as a multiplier
\r\n
however (mod 10 -3) yields -2, meaning that 10 exceeds the largest multiple not greater than 10 by -2 i.e. 10 - -2 = 12 is the largest multiple <= 10, a contradiction.
\r\n
therefore (mod 10 -3) should yield 1, not -2
\r\n\r\nSo unless I misunderstood, the definition should be changed to something like: \r\n
\"The mod function is defined as the amount by which a number exceeds the largest integer multiple of the divisor that is not greater than that number, except when the number is positive and the divisor negative, in which case the result is the amount by which the number exceeds the smallest multiple that is not smaller than the number.\"
\r\n\r\nOr, change the implementation to something similar to:\r\n\r\n
(defn mod-2\r\n\t [num div]\r\n\t (let [m (rem num div)]\r\n\t (if (or (zero? m) (= (pos? num) (pos? div)))\r\n\t \tm\r\n\t \t(if (pos? div) (+ m div) m)))) \r\n
\r\n\t \t\r\nto fit the current definition.", :created-at 1350430293000, :author {:login "kingcode", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3d7dd4232cb043d2a3efd99e08ff0983?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fef"}], :arglists ["num div"], :doc "Modulus of num and div. Truncates toward negative infinity.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/mod"} {:added "1.0", :ns "clojure.core", :name "amap", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "areduce", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342853671000, :_id "542692ebf6e94c6970521d8d"} {:created-at 1346930905000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d8e"}], :line 5249, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "(def an-array (int-array 25000 (int 0)))\n\nuser=> (time (amap ^ints an-array \n idx \n ret \n (+ (int 1) \n (aget ^ints an-array idx))))\n\n\"Elapsed time: 14.708653 msecs\"\n\n;; Note: without type hinting the performance of would not be good.", :created-at 1281078010000, :updated-at 1285495171000, :_id "542692ccc026201cdc326c51"}], :macro true, :notes nil, :arglists ["a idx ret expr"], :doc "Maps an expression across an array a, using an index named idx, and\n return value named ret, initialized to a clone of a, then setting \n each element of ret to the evaluation of expr, returning the new \n array ret.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/amap"} {:added "1.0", :ns "clojure.core", :name "pop", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1366675885000, :author {:login "jjcomer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ef581bba2f97adb539c67a35465b3e1b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "peek", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e4d"} {:created-at 1399433581000, :author {:login "Yun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f18708f979ad613ab134cb5002558965?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rest", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e4e"} {:created-at 1400493789000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "conj", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e4f"} {:created-at 1580395434633, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "butlast", :ns "clojure.core"}, :_id "5e32ebaae4b0ca44402ef829"}], :line 1467, :examples [{:author {:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (peek [1 2 3])\n3\nuser=> (pop [1 2 3])\n[1 2]\nuser=> (peek '(1 2 3))\n1\nuser=> (pop '(1 2 3))\n(2 3)", :created-at 1282321157000, :updated-at 1332951332000, :_id "542692cec026201cdc326db5"} {:updated-at 1523918116720, :created-at 1486084396464, :author {:login "HomoEfficio", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/17228983?v=3"}, :body "user=> (peek ())\nnil\nuser=> (pop ())\nIllegalStateException Can't pop empty list\n\nuser=> (peek [])\nnil\nuser=> (pop [])\nIllegalStateException Can't pop empty vector\n\nuser=> (peek (clojure.lang.PersistentQueue/EMPTY))\nnil\nuser=> (into [] (pop (clojure.lang.PersistentQueue/EMPTY)))\n[] ;; Can pop empty Queue", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :_id "5893d92ce4b01f4add58fe39"} {:updated-at 1518213815646, :created-at 1518213815646, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; Use a vector as a LIFO stack to check for balanced brackets\n\n(require '[clojure.set :refer [map-invert]])\n\n(defn balance [form]\n (let [brackets {\\[ \\] \\( \\) \\{ \\}}\n scan (fn [q x]\n (cond\n (brackets x) (conj q x)\n ((map-invert brackets) x)\n (if (= (brackets (peek q)) x)\n (pop q)\n (throw\n (ex-info\n (str \"Unmatched delimiter \" x) {})))\n :else q))]\n (reduce scan [] form)))\n\n(balance \"(let [a (inc 1]) (+ a 2))\")\n;; ExceptionInfo Unmatched delimiter ]\n\n(balance \"(let [a (inc 1)] (+ a 2))\")\n;; []\n", :_id "5a7e1ab7e4b0316c0f44f8b4"} {:updated-at 1518707324327, :created-at 1518707324327, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;basic example on vector and list\n\n;;pop on vector returns a new vector removing the last element\n(pop [1 2 3])\n;; [1 2]\n\n;;pop on list returns a new list removing the first element\n(pop '(1 2 3)) ;; (2 3)", :_id "5a85a27ce4b0316c0f44f8be"}], :notes [{:updated-at 1349888752000, :body "Small reminder:\r\n\r\n \r\nDo not work for arbitrary seq but just for persistent types implementing clojure.lang.IPersistentStack (like clojure.lang.Persistent*).\r\n\r\n \r\nExample:\r\n
", :created-at 1506607739129, :updated-at 1506607752839, :author {:avatar-url "https://avatars2.githubusercontent.com/u/76983?v=4", :account-source "github", :login "raszi"}, :_id "59cd027be4b03026fe14ea4c"} {:author {:login "hkjels", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/339547?v=4"}, :updated-at 1508228053028, :created-at 1508228053028, :body "`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.", :_id "59e5bbd5e4b03026fe14ea92"} {:body "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.", :created-at 1571861481277, :updated-at 1571861546570, :author {:avatar-url "https://avatars3.githubusercontent.com/u/601540?v=4", :account-source "github", :login "didibus"}, :_id "5db0b3e9e4b0ca44402ef7d2"}], :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"} {:added "1.0", :ns "clojure.core", :name "bit-and", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1414514292247, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "bit-or", :library-url "https://github.com/clojure/clojure"}, :_id "544fc674e4b03d20a102428f"}], :line 1293, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}], :body ";; 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", :created-at 1280337486000, :updated-at 1414514260267, :_id "542692c8c026201cdc326a70"} {:author {:login "Pierre", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/dc0590890ca22fee047f8e2598c2568d?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}], :body ";; 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\"", :created-at 1332068603000, :updated-at 1414513918522, :_id "542692d2c026201cdc326f57"} {:author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}], :body ";; 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", :created-at 1345828834000, :updated-at 1414513960925, :_id "542692d2c026201cdc326f58"} {:body ";; here is the truth table for AND \n(Integer/toBinaryString (bit-and 2r1100 2r1010) )\n;;=> \"1000\"\n;; or 2r1000", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1414514718289, :updated-at 1414514718289, :_id "544fc81ee4b03d20a1024295"}], :notes nil, :arglists ["x y" "x y & more"], :doc "Bitwise and", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-and"} {:added "1.9", :ns "clojure.core", :name "bounded-count", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1495640661107, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "counted?", :ns "clojure.core"}, :_id "5925aa55e4b093ada4d4d72b"}], :line 7384, :examples [{:updated-at 1495640638447, :created-at 1495640638447, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body ";;;; 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", :_id "5925aa3ee4b093ada4d4d72a"} {:updated-at 1495640775383, :created-at 1495640775383, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body ";;;; This would run forever\n\n(count (range))\n\n;;;; But this doesn't\n\n(bounded-count 10000 (range))\n;;=> 10000\n", :_id "5925aac7e4b093ada4d4d72d"}], :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"} {:added "1.7", :ns "clojure.core", :name "update", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1441163795513, :author {:login "brunchboy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2228869?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "update-in", :ns "clojure.core"}, :_id "55e66a13e4b0efbd681fbb91"} {:created-at 1441163918027, :author {:login "brunchboy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2228869?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "fnil", :ns "clojure.core"}, :_id "55e66a8ee4b072d7f27980f8"} {:created-at 1449608873882, :author {:login "Chort409", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1062637?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "assoc", :ns "clojure.core"}, :_id "566746a9e4b0f47c7ec61146"} {:created-at 1570520722969, :author {:login "xmo-odoo", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/7571158?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "associative?", :ns "clojure.core"}, :_id "5d9c3e92e4b0ca44402ef7cb"}], :line 6188, :examples [{:editors [{:login "hiteki", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2091138?v=3"} {:avatar-url "https://avatars3.githubusercontent.com/u/11671382?v=4", :account-source "github", :login "dominem"} {:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4"}], :body "(def p {:name \"James\" :age 26})\n;;=> #'user/p\n\n(update p :age inc)\n;;=> {:name \"James\", :age 27}\n\n;; remember, the value of p hasn't changed because it is immutable!\np\n;; {:name \"James\", :age 26}\n(update 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 p :age - 10)\n;;=> {:name \"James\", :age 16}\n\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/2091138?v=3", :account-source "github", :login "hiteki"}, :created-at 1437170219147, :updated-at 1587790479572, :_id "55a97a2be4b0080a1b79cda8"} {:updated-at 1448421903787, :created-at 1448421903787, :author {:login "egracer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4086884?v=3"}, :body ";; the map in update can be nil, and f will still be applied to nil and \n;; return a value\n\n(def empty-map nil)\n#'user/empty-map\n\n(update empty-map :some-key #(str \"foo\" %))\n;;=> {:some-key \"foo\"}\n", :_id "56552a0fe4b053844439827b"} {:updated-at 1476877532228, :created-at 1476877532228, :author {:login "G1enY0ung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/15034155?v=3"}, :body ";; can also use in []\n\nuser=> (update [1 2 3] 0 inc)\n;;=> [2 2 3]\n\nuser=> (update [] 0 #(str \"foo\" %))\n;;=> [\"foo\"]", :_id "58075cdce4b001179b66bdcf"} {:updated-at 1524433722089, :created-at 1524433722089, :author {:login "statcompute", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/4590938?v=4"}, :body "(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 x :name #(if (= \"name2\" %) % \"not 2\"))) ds)\n\n;; ({:id 1.0, :name \"not 2\"} {:id 2.0, :name \"name2\"} {:id 3.0, :name \"not 2\"})", :_id "5add033ae4b045c27b7fac4d"} {:editors [{:login "elken", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2872862?v=4"}], :body ";; From string to boolean\n\n(def answer {:answer \"France\" :correct \"true\" :age 11})\n(update answer :correct #(= % \"true\"))\n\n;; {:answer \"France\", :correct true, :age 11}", :author {:avatar-url "https://avatars1.githubusercontent.com/u/226965?v=4", :account-source "github", :login "aarkerio"}, :created-at 1535749324652, :updated-at 1688394857769, :_id "5b89accce4b00ac801ed9e7c"} {:updated-at 1601184024906, :created-at 1601184024906, :author {:login "gloorfindel", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/49351337?v=4"}, :body ";; Applying a function to the same key in a sequence of arrays\n\n(def dates [{:date \"20200430\",:time \"08:35\"}\n {:date \"20200430\",:time \"09:15\"}]\n\n;; Takes the current time value in the array, and reduces it to the hour by \n;; calling the reduce-to-hour function (not included here)\n\n(map #(update % :time (constantly (reduce-to-hour (:time %)))) dates)\n=> ({:date \"20200430\", :time \"08\"} {:date \"20200430\", :time \"09\"})", :_id "5f702118e4b0b1e3652d73c2"} {:editors [{:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=4"}], :body ";; Very common, update a vector inside a map\n(def little-schemer {:authors [{:birth-year 1944, :name \"Daniel Friedman\"}\n {:name \"Matthias Felleisen\"}]\n :title \"The Little Schemer\"})\n\n(update little-schemer :authors conj {:name \"Gerald J. Sussman\"})\n;;=> \n{:authors [{:birth-year 1944, :name \"Daniel Friedman\"}\n {:name \"Matthias Felleisen\"}\n {:name \"Gerald J. Sussman\"}]\n :title \"The Little Schemer\"}", :author {:avatar-url "https://avatars.githubusercontent.com/u/889685?v=4", :account-source "github", :login "huahaiy"}, :created-at 1613242096574, :updated-at 1613242234272, :_id "60281ef0e4b0b1e3652d744f"} {:editors [{:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=4"}], :body ";; For a simple change of value we can use constantly\n(def hm {:banana 1, :apple 2, :orange 3})\n\n(update hm :banana (constantly 6))\n;;=> {:banana 6 :apple 2 :orange 3}\n\n;; Which is equivalent to using \"assoc\"\n(assoc hm :banana 6)\n;;=> {:banana 6 :apple 2 :orange 3}", :author {:avatar-url "https://avatars.githubusercontent.com/u/8339935?v=4", :account-source "github", :login "rogefm"}, :created-at 1614089059545, :updated-at 1614426803060, :_id "60350b63e4b0b1e3652d7466"} {:updated-at 1623859525031, :created-at 1623859525031, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4"}, :body ";; A quirk in use with vectors (tested with 1.10.3)\n;; If you throw away the argument to the function, you can add a value to\n;; the end of the vector: \n\n;; Normal, expected behavior:\n(update [1 2 3] 2 (fn [_] 42))\n;;=> [1 2 42]\n\n;; If the index is just past the end, you can append to the vector:\n(update [1 2 3] 3 (fn [_] 42))\n;;=> [1 2 3 42]\n\n;; More than one past end won't work\n(update [1 2 3] 4 (fn [_] 42))\n;;=> Execution error (IndexOutOfBoundsException) at user/eval2049 (form-init3979469036338260438.clj:1).\n\n;; If you don't throw away the argument, and your index is one past\n;; the end of the vector, you'll still get an error:\n\n;; Normal, expected behavior:\n(update [1 2 3] 2 inc)\n;;=> [1 2 4]\n\n;; Here the trick fails:\n(update [1 2 3] 3 inc)\n;;=> Execution error (NullPointerException) at user/eval1985 (form-init8618353961027343980.clj:1).", :_id "60ca2145e4b0b1e3652d750a"}], :notes [{:author {:login "alper", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/72429?v=4"}, :updated-at 1576842276976, :created-at 1576842276976, :body "But how do you do a pure update idiomatically? So update one value for another?", :_id "5dfcb424e4b0ca44402ef7fc"} {:author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :updated-at 1633061790090, :created-at 1633061790090, :body "To the previous note (alper), you are looking for `assoc`. ", :_id "61568b9ee4b0b1e3652d754d"} {:author {:login "earthfail", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/21296448?v=4"}, :updated-at 1661097969047, :created-at 1661097969047, :body "in clojure 1.11 there is an [update-vals](https://github.com/clojure/clojure/blob/5ffe3833508495ca7c635d47ad7a1c8b820eab76/src/clj/clojure/core.clj#L8061) and [update-keys](https://github.com/clojure/clojure/blob/5ffe3833508495ca7c635d47ad7a1c8b820eab76/src/clj/clojure/core.clj#L8077) to apply function for all values or all keys respectively", :_id "630257f1e4b0b1e3652d7646"}], :arglists ["m k f" "m k f x" "m k f x y" "m k f x y z" "m k f x y z & more"], :doc "'Updates' a value in an associative structure, where k is a\n key 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 structure. If the key does not exist, nil is passed as the old value.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/update"} {:added "1.0", :ns "clojure.core", :name "list*", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 648, :examples [{:author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body ";; `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", :created-at 1280721203000, :updated-at 1306322562000, :_id "542692c6c026201cdc3268d5"} {:updated-at 1474307619700, :created-at 1474307619700, :author {:login "Manishapillai", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20270279?v=3"}, :body ";;Prepend a map to a list\nuser=> (list* {:name \"Anne\"} [{:city \"NJ\"}]) \n({:name \"Anne\"} {:city \"NJ\"})", :_id "57e02623e4b0709b524f0501"} {:updated-at 1541543275442, :created-at 1496358734409, :author {:login "smnplk", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/380618?v=3"}, :body ";; 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", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/380618?v=4", :account-source "github", :login "smnplk"}], :_id "59309f4ee4b06e730307db20"} {:editors [{:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :body ";; `list*` function:\nuser=> (list* 1 '(2 3))\n(1 2 3)\n\nuser=> (list* 1 2 '(3 4))\n(1 2 3 4)", :author {:avatar-url "https://avatars3.githubusercontent.com/u/153773?v=4", :account-source "github", :login "arlicle"}, :created-at 1536069875312, :updated-at 1656675472111, :_id "5b8e90f3e4b00ac801ed9e86"} {:updated-at 1673074886220, :created-at 1673074886220, :author {:login "Chandrama1", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/78619926?v=4"}, :body ";; `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)", :_id "63b918c6e4b08cf8563f4b5d"}], :notes [{:body "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.", :created-at 1425311436162, :updated-at 1425311436162, :author {:login "miner", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/25400?v=3"}, :_id "54f486cce4b0b716de7a652e"}], :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*"} {:added "1.2", :ns "clojure.core", :name "reify", :file "clojure/core_deftype.clj", :type "macro", :column 1, :see-alsos [{:created-at 1323993523000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "proxy", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ef4"}], :line 70, :examples [{:updated-at 1458043116563, :created-at 1315673869000, :body "(ns foo)\n\n;;; This is a library for the shopping result.\n\n(defrecord Banana [qty])\n(defrecord Grape [qty])\n(defrecord Orange [qty])\n\n;;; 'subtotal' differs 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(extend-type Grape\n Fruit\n (subtotal [item]\n (* 178 (:qty item))))\n\n(extend-type Orange\n Fruit\n (subtotal [item]\n (* 98 (:qty item))))\n\n;;; 'coupon' is the function returing a 'reify' of subtotal. This is\n;;; when someone uses a coupon ticket, the price of some fruits is \n;;; taken off 25%.\n\n(defn coupon [item]\n (reify Fruit\n (subtotal [_]\n (int (* 0.75 (subtotal item))))))\n\n;;; Example: To compute the total when someone bought 10 oranges,\n;;; 15 bananas and 10 grapes, using a coupon for the grapes.\n(apply + (map subtotal [(Orange. 10) (Banana. 15) (coupon (Grape. 10))]))\n;;; 4685 ; (apply + '(980 2370 1335))", :editors [{:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"} {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"} {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"} {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"} {:avatar-url "https://avatars.githubusercontent.com/u/138993?v=3", :account-source "github", :login "Dimagog"} {:login "antonaut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/513311?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon", :account-source "clojuredocs", :login "yasuto"}, :_id "542692cdc026201cdc326d5d"} {:author {:login "number23", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/89e8dc9231de751fd558d5784406cc5e?r=PG&default=identicon"}, :editors [], :body ";; Using a reified FileFilter implementation to obtain only directory files\n(.listFiles (java.io.File. \".\")\n (reify\n java.io.FileFilter\n (accept [this f]\n (.isDirectory f))))\n", :created-at 1339172939000, :updated-at 1339172939000, :_id "542692d5c026201cdc32706f"} {:author {:login "puredanger", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/89c8afd032c7b3473f67c9b00d3acd5a?r=PG&default=identicon"}, :editors [], :body ";;;; This example shows how to reify a multi-arity protocol function\n;;;; (note the different style in defprotocol vs reify)\n\n;; define a multi-arity protocol function blah\n(defprotocol Foo\n (blah\n [this x]\n [this x y]))\n\n;; define an anonymous extension via reify\n(def r (reify Foo \n (blah [_ x] x)\n (blah [_ x y] y)))\n\n;; invoke blah via the r instance\n(blah r 1) ;; => 1\n(blah r 1 2) ;; => 2\n\n\n", :created-at 1355788930000, :updated-at 1355788930000, :_id "542692d5c026201cdc327070"} {:body ";; Note that nested class is referred via '$' \n;; and 'this' is always present in parameters (see underscore in parameters list):\n(Thread/setDefaultUncaughtExceptionHandler\n (reify java.lang.Thread$UncaughtExceptionHandler\n (uncaughtException [_ thread throwable]\n (println (str throwable)))))", :author {:login "PetrGlad", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/124476?v=3"}, :created-at 1420462447425, :updated-at 1420462470195, :editors [{:login "PetrGlad", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/124476?v=3"}], :_id "54aa896fe4b04e93c519ffb3"} {:updated-at 1440403056415, :created-at 1440377269300, :author {:login "yubrshen", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2638417?v=3"}, :body ";;; This example is inspired by the above one and simplified\n;;; to highlight reify's returning a value/\"object\" \n;;; with protocol realization for just this one piece of value/\"object\".\n\n(ns foo)\n\n(defrecord Grape [qty])\n\n(defprotocol Fruit\n (subtotal [item]))\n\n(extend-type Grape\n Fruit\n (subtotal [item]\n (* 178 (:qty item))))\n\n;;; 'discounted' is the function returning a 'reify' instance of fruit with modified \n;;; implementation of subtotal (with discount). That is, \n;;; when someone uses a discounted coupon, the price of the fruits is taken off 25%.\n\n(defn discounted [item]\n (reify Fruit\n (subtotal [_]\n (println \"modifying subtotal with discount:\")\n (int (* 0.75 (subtotal item))))))\n\n;;; Example:\n;;; There is 10 pieces of Grape, and the subtotal before discount is\n;;; (subtotal (Grape. 10))\n;;; => 1780\n\n;;; With discount, then\n;;; (subtotal (discounted (Grape. 10)))\n;;; => modifying subtotal with discount:\n;;; => 1335\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/2638417?v=3", :account-source "github", :login "yubrshen"}], :_id "55da69b5e4b0831e02cddf1e"} {:editors [{:login "Aljendro", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/7899307?v=3"}], :body "(comment\n \"reify\n\n verb | re·ify | \\\\ˈrā-ə-ˌfī, ˈrē-\\\\\n\n : to regard (something abstract) as a material or concrete thing\")\n\n(defprotocol shape\n \"A geometric shape.\"\n\n (area [this]\n \"Calculates the area of the shape.\n\n The first argument is required and corresponds to the implicit target\n object ('this' in Java parlance).\"))\n\n\n(defn make-circle\n \"Creates a circle (a geometric shape) object.\"\n [radius]\n\n (reify shape\n (area [_]\n (* Math/PI radius radius))))\n\n(. (make-circle 8) area)\n;;=> 201.06192982974676\n\n(def circle (make-circle 8))\n\n(satisfies? shape circle)\n;;=> true\n\n(. circle area)\n;;=> 201.06192982974676\n\n\n(defn make-triangle\n \"Creates a triangle (a geometric shape) object.\"\n [base height]\n\n (reify shape\n (area [_]\n (* 0.5 base height))))\n\n(def triangle (make-triangle 8 8))\n\n(. triangle area)\n;;=> 32.0\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/19507371?v=3", :account-source "github", :login "clojureling"}, :created-at 1463855829138, :updated-at 1493672301532, :_id "5740aad5e4b00a9b70be566c"} {:updated-at 1613046786005, :created-at 1613046786005, :author {:login "RokLenarcic", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/3322433?v=4"}, :body ";; Attaching metadata to reify object creates a new instance\n;; Reify call itself attaches metadata of (reify ...) form to the object\n;; so effectively it always creates two objects but return one of them.\n\n;; This matters when you use finalize\n\n(defn create []\n (reify Object\n (finalize [this] (println \"GCing\" this) nil)))\n\n(do (create)\n (System/gc))\n\n;;GCing #object[.$create$reify__7691 0x3b287fd2 .$create$reify__7691@3b287fd2]\n;;GCing #object[.$create$reify__7691 0x38249fdc .$create$reify__7691@38249fdc]\n;;=> nil", :_id "60252402e4b0b1e3652d744c"} {:updated-at 1669428148216, :created-at 1669428148216, :author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=4"}, :body "(defprotocol Foo (foo-f [this]))\n(defprotocol Bar (bar-f [this]))\n\n;; It is fine to reify multiple protocol/interfaces\n(def foo-bar\n (reify\n Foo\n (foo-f [_] :foo)\n Bar\n (bar-f [_] :bar)))\n\n(foo-f foo-bar) ;;=>:foo\n(bar-f foo-bar) ;;=>:bar\n", :_id "638173b4e4b0b1e3652d7691"}], :macro true, :notes [{:author {:login "ieugen", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1050920?v=4"}, :updated-at 1680326363601, :created-at 1680326363601, :body "reify can implement multiple interfaces:\n\n```clojure\n(let [a (reify\n java.lang.AutoCloseable\n (close [_this]\n (println \"aaa\"))\n java.lang.Runnable\n (run [_this]\n (println \"Run\")))]\n (.close a)\n (.run a))\n```\n\nNote that methods in reify DO NOT accept docstrings like clojure defn's , although they look very similar. You will get compilation error with method not found if you use a docstring. \n\nSomething like this\n```\n; Evaluating file: java_map.clj\n; Syntax error (IllegalArgumentException) compiling reify* at (src/java_map.clj:27:5).\n; Can't define method not in interfaces: close\n; Evaluation of file java_map.clj failed: class clojure.lang.Compiler$CompilerException\n```", :_id "6427bedbe4b08cf8563f4b8b"} {:author {:login "ieugen", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1050920?v=4"}, :updated-at 1684257603676, :created-at 1684257154747, :body "Sometimes you will need to add type hints.\nThis is mandatory if there are overloaded methods. \n\nOne such case is when implementing `java.util.Collection` `toArray` .\n\nWithout type hints, you will get \n\n```\nMismatched return type: toArray, expected: [Ljava.lang.Object;, had: java.lang.Object\n```\n\nA correct way to handle this is like bellow.\n\nNote: when you add one type hint, you need to add for all methods in reify. \nSee docs above.\n```\n(reify java.util.Collection\n (^boolean containsAll [_this ^java.util.Collection c])\n (^objects toArray [_this]\n (throw (UnsupportedOperationException.)))\n (^objects toArray [_this ^objects objects]\n (throw (UnsupportedOperationException.))))\n```\n\nhttps://github.com/clojure/data.avl/commit/03f32144951ab7b50b8a74ea5e8c22629e7fbde0\n", :_id "6463b982e4b08cf8563f4bbc"}], :arglists ["& opts+specs"], :doc "reify is a macro with the following structure:\n\n (reify options* specs*)\n \n Currently there are no options.\n\n Each spec consists of the 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 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 the first 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 The return type can be indicated by a type hint on the method name,\n and arg types can be indicated by a type hint on arg names. If you\n leave out all hints, reify will try to match on same name/arity\n method in the protocol(s)/interface(s) - this is preferred. If you\n supply any hints at all, no inference is done, so all hints (or\n default of Object) must be correct, for both arguments and return\n type. If a method is overloaded in a protocol/interface, multiple\n independent method definitions must be supplied. If overloaded with\n same arity in an interface you must specify complete hints to\n disambiguate - a missing hint implies Object.\n\n recur works to method heads The method bodies of reify are lexical\n closures, and can refer to the surrounding local scope:\n \n (str (let [f \"foo\"] \n (reify Object \n (toString [this] f))))\n == \"foo\"\n\n (seq (let [f \"foo\"] \n (reify clojure.lang.Seqable \n (seq [this] (seq f)))))\n == (\\f \\o \\o))\n \n reify always implements clojure.lang.IObj and transfers meta\n data of the form to the created object.\n \n (meta ^{:k :v} (reify Object (toString [this] \"foo\")))\n == {:k :v}", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reify"} {:added "1.0", :ns "clojure.core", :name "update-in", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1302248534000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "assoc-in", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c66"} {:created-at 1318010541000, :author {:login "jks", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/de50bee3396570d25f900873303c98f1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "get-in", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c67"} {:created-at 1348895075000, :author {:login "eric", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2b0c9ae6f1da9716451e7c86bc87230b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "fnil", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c68"} {:created-at 1441163870973, :author {:login "brunchboy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2228869?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "update", :ns "clojure.core"}, :_id "55e66a5ee4b072d7f27980f7"} {:created-at 1570520733044, :author {:login "xmo-odoo", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/7571158?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "associative?", :ns "clojure.core"}, :_id "5d9c3e9de4b0ca44402ef7cc"}], :line 6172, :examples [{:updated-at 1565345379991, :created-at 1280322066000, :body "(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", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "dominem", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11671382?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon", :account-source "clojuredocs", :login "gstamp"}, :_id "542692c9c026201cdc326a9e"} {:author {:login "gregg-williams", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/58610a64fc8638eec8d2239d80d4046f?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Jeff N", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7a9dd2ab880632b999aaeff00fc0d8e2?r=PG&default=identicon"} {:login "Jeff N", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7a9dd2ab880632b999aaeff00fc0d8e2?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/2091138?v=3", :account-source "github", :login "hiteki"} {:login "dominem", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11671382?v=4"}], :body "(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}", :created-at 1283780561000, :updated-at 1565345395993, :_id "542692c9c026201cdc326aa0"} {:updated-at 1447712876892, :created-at 1305018966000, :body "(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", :editors [{:avatar-url "https://www.gravatar.com/avatar/d1906fc5df2c8ce5b2d58cc6ea855aab?r=PG&default=identicon", :account-source "clojuredocs", :login "shuaybi"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "ghiden", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/17842?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/d1906fc5df2c8ce5b2d58cc6ea855aab?r=PG&default=identicon", :account-source "clojuredocs", :login "shuaybi"}, :_id "542692c9c026201cdc326aa4"} {:author {:login "jamesqiu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc1268deaa7f2e78fe2b5ea76e6481d8?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; 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}", :created-at 1349714558000, :updated-at 1422566857659, :_id "542692d5c026201cdc3270b1"} {:editors [{:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "clojureman", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1793303?v=3"}], :updated-at 1495693819157, :created-at 1412006537832, :author {:avatar-url "https://avatars.githubusercontent.com/u/453580?v=2", :account-source "github", :login "pmbauer"}, :body ";; 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.", :_id "54298289e4b09282a148f202"} {:editors [{:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}], :body ";;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}}", :author {:avatar-url "https://avatars.githubusercontent.com/u/50778?v=3", :account-source "github", :login "edipofederle"}, :created-at 1442182854368, :updated-at 1460718796470, :_id "55f5f6c6e4b05246bdf20a90"} {:editors [{:login "gnperdue", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1294053?v=3"}], :body ";; 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}}", :author {:avatar-url "https://avatars.githubusercontent.com/u/1294053?v=3", :account-source "github", :login "gnperdue"}, :created-at 1451965282908, :updated-at 1451965612224, :_id "568b3b62e4b0e0706e05bd9b"} {:updated-at 1459182480723, :created-at 1459182480723, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}, :body "user=> (update-in {:a {:b 3}} [:a :b] inc)\n\n;;=> {:a {:b 4}}", :_id "56f95b90e4b09295d75dbf42"} {:updated-at 1476877648099, :created-at 1476877648099, :author {:login "G1enY0ung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/15034155?v=3"}, :body ";; can also use in []\n\nuser=> (update-in [1 2 [1 2 3]] [2 0] inc)\n;;=> [1 2 [2 2 3]]", :_id "58075d50e4b001179b66bdd0"} {:updated-at 1514472378082, :created-at 1514472169736, :author {:login "jcburley", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/430319?v=4"}, :body ";; 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)", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/430319?v=4", :account-source "github", :login "jcburley"}], :_id "5a4502e9e4b0a08026c48ce4"} {:updated-at 1524434442870, :created-at 1524434442870, :author {:login "statcompute", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/4590938?v=4"}, :body "(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", :_id "5add060ae4b045c27b7fac4e"}], :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"} {:added "1.0", :ns "clojure.core", :name "prefer-method", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1337584953000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "prefers", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e0f"} {:created-at 1337584964000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "get-method", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e10"} {:created-at 1337584977000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "methods", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e11"}], :line 1803, :examples [{:editors [{:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}], :body "(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", :author {:avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3", :account-source "github", :login "ertugrulcetin"}, :created-at 1475488456319, :updated-at 1475488811909, :_id "57f22ac8e4b0709b524f0514"}], :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"} {:added "1.0", :ns "clojure.core", :name "aset-int", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 3946, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; 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=>", :created-at 1313915065000, :updated-at 1313915065000, :_id "542692cdc026201cdc326d37"}], :notes [{:body "See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax.", :created-at 1432829144129, :updated-at 1432829144129, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :_id "55673cd8e4b03e2132e7d173"}], :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"} {:added "1.0", :ns "clojure.core", :name "*clojure-version*", :file "clojure/core.clj", :type "var", :column 3, :see-alsos [{:created-at 1328398023000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "clojure-version", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aa6"}], :dynamic true, :line 7069, :examples [{:updated-at 1493242329065, :created-at 1280322760000, :body "user=> *clojure-version*\n{:interim true, :major 1, :minor 2, :incremental 0, :qualifier \"master\"}", :editors [{:login "chbrown", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/360279?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/ee24aacb65359196b0a1bad050f9a62f?r=PG&default=identicon", :account-source "clojuredocs", :login "mattdw"}, :_id "542692cac026201cdc326b62"}], :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*"} {:added "1.7", :ns "clojure.core", :name "ensure-reduced", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1464286337203, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "reduced", :ns "clojure.core"}, :_id "57473c81e4b0af2c9436d1ef"} {:created-at 1464286352101, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "reduced?", :ns "clojure.core"}, :_id "57473c90e4b0bafd3e2a045d"} {:created-at 1464286361977, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unreduced", :ns "clojure.core"}, :_id "57473c99e4b0af2c9436d1f0"} {:created-at 1464286386482, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "reduce", :ns "clojure.core"}, :_id "57473cb2e4b0af2c9436d1f1"}], :line 2849, :examples [{:updated-at 1464286295227, :created-at 1464286295227, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :body "(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}]", :_id "57473c57e4b0bafd3e2a045c"} {:updated-at 1682279619055, :created-at 1682279619055, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; 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", :_id "64458cc3e4b08cf8563f4b95"}], :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"} {:added "1.0", :ns "clojure.core", :name "*'", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1412880795489, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "*", :library-url "https://github.com/clojure/clojure"}, :_id "5436d99be4b0ae7956031574"}], :line 996, :examples [{:body ";; 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", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1412880775853, :updated-at 1412880775853, :_id "5436d987e4b0ae7956031573"}], :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/*'"} {:added "1.0", :ns "clojure.core", :name "instance?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1285513897000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "type", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e9d"} {:created-at 1285513925000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "supers", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e9e"} {:created-at 1341631058000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "doto", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e9f"} {:created-at 1341631065000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "class", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ea0"} {:created-at 1432578737325, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "satisfies?", :library-url "https://github.com/clojure/clojure"}, :_id "55636ab1e4b03e2132e7d16d"} {:created-at 1482897919586, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "isa?", :ns "clojure.core"}, :_id "586339ffe4b0fd5fb1cc9642"}], :line 139, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "john.r.woodward", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/22b6fbc4a386291e45b1cb4449377086?r=PG&default=identicon"} {:login "steloflute", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/fc0969cd0910a427052f0f6281967392?r=PG&default=identicon"} {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"} {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"} {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"} {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"} {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"} {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"}], :body "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", :created-at 1282289726000, :updated-at 1358905451000, :_id "542692c6c026201cdc3268e1"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"} {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"} {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"}], :body "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", :created-at 1313989675000, :updated-at 1358543212000, :_id "542692c6c026201cdc3268eb"} {:author {:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"}, :editors [{:login "Phalphalak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon"}], :body ";; 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", :created-at 1358905444000, :updated-at 1358905610000, :_id "542692d3c026201cdc326fcf"} {:editors [{:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3", :account-source "github", :login "mars0i"}, :created-at 1482898746157, :updated-at 1482898800493, :_id "58633d3ae4b0fd5fb1cc9643"}], :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"} {:added "1.0", :ns "clojure.core", :name "with-open", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1496906064866, :author {:login "fhur", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/6452323?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "slurp", :ns "clojure.core"}, :_id "5938f950e4b06e730307db30"} {:created-at 1507926365257, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "input-stream", :ns "clojure.java.io"}, :_id "59e1215de4b03026fe14ea7f"}], :line 3831, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "benmoss", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/239754?v=3"} {:login "PetrGlad", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/124476?v=3"}], :body ";; 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", :created-at 1281949367000, :updated-at 1420810336807, :_id "542692c7c026201cdc32699a"} {:author {:login "octopusgrabbus", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon"}, :editors [], :body "(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", :created-at 1352321815000, :updated-at 1352321815000, :_id "542692d6c026201cdc3270bb"} {:updated-at 1522741647810, :created-at 1522741647810, :author {:login "jcburley", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/430319?v=4"}, :body ";; 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.", :_id "5ac3318fe4b045c27b7fac2f"} {:editors [{:login "NielsvanKlaveren", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/43436964?v=4"}], :body ";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\"]))", :author {:avatar-url "https://avatars0.githubusercontent.com/u/43436964?v=4", :account-source "github", :login "NielsvanKlaveren"}, :created-at 1544177851915, :updated-at 1544184780984, :_id "5c0a48bbe4b0ca44402ef5e2"}], :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"} {: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"} {:added "1.0", :ns "clojure.core", :name "re-find", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1282039272000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "re-groups", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bfe"} {:created-at 1282039314000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "re-matcher", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bff"} {:created-at 1282039324000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "re-pattern", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c00"} {:created-at 1282039359000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "re-seq", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c01"} {:created-at 1324028214000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "re-matches", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c02"} {:created-at 1379040124000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "subs", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c03"} {:created-at 1412843259867, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.string", :name "replace", :library-url "https://github.com/clojure/clojure"}, :_id "543646fbe4b0ae795603156f"}], :line 4898, :examples [{:author {:login "nipra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/142529?v=3"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jwatki06", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5594302?v=3"}], :body "user=> (def matcher (re-matcher #\"\\d+\" \"abc12345def\"))\n#'user/matcher\n\nuser=> (re-find matcher)\n\"12345\"\n\n;; If you only want the first match, it is shorter to call re-find with the\n;; pattern and the string to search, rather than explicitly creating a matcher\n;; as above.\nuser=> (re-find #\"\\d+\" \"abc12345def\")\n\"12345\"\n\n;; If you want all matches as a sequence, use re-seq. Creating a matcher\n;; explicitly with re-matcher and passing it to re-find is only the best way\n;; if you want to write a loop that iterates through all matches, and do not\n;; want to use re-seq for some reason.\n", :created-at 1279049854000, :updated-at 1465229780990, :_id "542692cac026201cdc326b4c"} {:author {:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"}, :editors [], :body ";; re-find can be used to iterate through re matches in the string\n\nuser=> (def phone-number \"672-345-456-3212\")\n#'user/phone-number\n\nuser=> (def matcher (re-matcher #\"\\d+\" phone-number))\n#'user/matcher\n\nuser=> (re-find matcher)\n\"672\"\n\nuser=> (re-find matcher)\n\"345\"\n\nuser=> (re-find matcher)\n\"456\"\n\nuser=> (re-find matcher)\n\"3212\"\n\n;; when there's no more valid matches, nil is returned\nuser=> (re-find matcher)\nnil", :created-at 1312373129000, :updated-at 1312373129000, :_id "542692cac026201cdc326b4f"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; When there are parenthesized groups in the pattern and re-find\n;; finds a match, it returns a vector. The first item is the part of\n;; the string that matches the entire pattern, and each successive\n;; item are the parts of the string that matched the 1st, 2nd,\n;; etc. parenthesized groups. Groups are numbered by the order in\n;; which their left parenthesis occurs in the string, from left to\n;; right.\nuser=> (def line \" RX packets:1871074138 errors:5 dropped:48 overruns:9\")\n#'user/line\n\nuser=> (re-find #\"(\\S+):(\\d+)\" line)\n[\"packets:1871074138\" \"packets\" \"1871074138\"]\n\n;; groups can nest\nuser=> (re-find #\"(\\S+:(\\d+)) \\S+:\\d+\" line)\n[\"packets:1871074138 errors:5\" \"packets:1871074138\" \"1871074138\"]\n\n;; If there is no match, re-find always returns nil, whether there are\n;; parenthesized groups or not.\nuser=> (re-find #\"(\\S+):(\\d+)\" \":2 numbers but not 1 word-and-colon: before\")\nnil\n\n;; A parenthesized group can have nil as its result if it is part of\n;; an 'or' (separated by | in the regex), and another alternative is\n;; the one that matches.\nuser=> (re-find #\"(\\D+)|(\\d+)\" \"word then number 57\")\n[\"word then number \" \"word then number \" nil]\n\nuser=> (re-find #\"(\\D+)|(\\d+)\" \"57 number then word\")\n[\"57\" nil \"57\"]\n\n;; It is also possible for a group to match the empty string.\nuser=> (re-find #\"(\\d*)(\\S)\\S+\" \"lots o' digits 123456789\")\n[\"lots\" \"\" \"l\"]\n\n;; If you want to use parentheses to group a part of the regex, but\n;; have no interest in capturing the string it matches, you can follow\n;; the left paren with ?: to prevent capturing.\nuser=> (re-find #\"(?:\\S+):(\\d+)\" line)\n[\"packets:1871074138\" \"1871074138\"]\n\n;; re-matches also behaves this way, and re-seq returns a sequence of\n;; matches, where each one can be a vector like re-find returns.\n", :created-at 1324028180000, :updated-at 1324028180000, :_id "542692d4c026201cdc32704a"} {:author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :editors [], :body ";;It's possible to get variables out of your string with regexp\n\nuser=> (re-find #\"(\\d\\d\\d) (USD)\" \"450 USD\")\n[\"450 USD\" \"450\" \"USD\"]\nuser=> (nth *1 1)\n\"450\"\n\n;;thanks kotarak @ stackoverflow.com for this one", :created-at 1326426979000, :updated-at 1326426979000, :_id "542692d4c026201cdc32704b"} {:author {:login "Pete Mancini", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/19c72d50850490b8dea594fe3eb04437?r=PG&default=identicon"}, :editors [{:login "Pete Mancini", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/19c72d50850490b8dea594fe3eb04437?r=PG&default=identicon"}], :body ";; If your input has line delimiters you can switch on multiline with (?m)\n\nuser=> (def testcase \"Line 1\\nLine 2\\nTarget Line\\nLine 4\\nNot a target line\")\nuser=>(re-find #\"(?im)^target.*$\" testcase)\n\"Target Line\"", :created-at 1369872025000, :updated-at 1369872064000, :_id "542692d4c026201cdc32704c"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; 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.", :created-at 1379040119000, :updated-at 1379040119000, :_id "542692d4c026201cdc32704e"} {:updated-at 1598128246429, :created-at 1598128036322, :author {:login "jgomo3", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1125678?v=4"}, :body ";; Use it as a simple predicate based on regexp,\n;; since it returns nil if `re` and `s` do not match.\n\nuser=> (def text-with-blank-lines [\"En un lugar de la Mancha,\"\n \"\"\n \" \"\n \"de cuyo nombre no quiero acordarme\"\n \" \"])\n\n;; Let's count how many non-blank lines are there:\nuser=> (count (filter #(re-find #\"\\S\" %) text-with-blank-lines))\n2\n\n;; Example inspired in 'Programming Clojure 3rd Ed.' 'Seq-in Stream'.", :editors [{:avatar-url "https://avatars0.githubusercontent.com/u/1125678?v=4", :account-source "github", :login "jgomo3"}], :_id "5f417fa4e4b0b1e3652d7386"}], :notes [{:body "the regex can't be a var?\n\n```clojure\n(let [regex \"abc\"] (re-find #a \"abc\"))\n```\nthis will get an error!", :created-at 1419230605090, :updated-at 1419230605090, :author {:login "paomian", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2999156?v=3"}, :_id "5497bd8de4b09260f767ca7d"} {:author {:login "blx", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/887504?v=3"}, :updated-at 1447600673577, :created-at 1447600673577, :body "@paomian: The regex *can* be a variable, but the variable needs to be a regex.\n\nThis works fine:\n
\n\nbecause the **#** reader macro for declaring regexes applies to the string right after it -- without doing any kind of substitution.\n\nYou could also do\n
", :created-at 1338782914000, :author {:login "Iceland_jack", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c889e0a95a3bb07f90ab28ad442f1127?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fe1"} {:author {:login "rauhs", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/11081351?v=3"}, :updated-at 1511875643591, :created-at 1511875643591, :body "Many other programming languages like Kotlin or Haskell define `partition` slightly different. They partition the given collection into two collections, the first containing all truthy values and the second elements all falsy elements. This function does it:\n\n```\n(defn partition-2\n \"Partitions the collection into exactly two [[all-truthy] [all-falsy]]\n collection.\"\n [pred coll]\n (mapv persistent!\n (reduce\n (fn [[t f] x]\n (if (pred x)\n [(conj! t x) f]\n [t (conj! f x)]))\n [(transient []) (transient [])]\n coll)))\n(partition-2 odd? (range 5))\n\n```", :_id "5a1d643be4b0a08026c48cc3"} {:author {:login "jcburley", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/430319?v=4"}, :updated-at 1516207930627, :created-at 1516207930627, :body "I tried this implementation of your Kotlin/Haskell `partition`, which is simpler but somewhat slower (less than 2x):\n\n```\n(defn partition-3\n \"Partitions the collection into exactly two [[all-truthy] [all-falsy]]\n collection.\"\n [pred coll]\n (let [m (group-by pred coll)]\n [(m true) (m false)]))\n```", :_id "5a5f7f3ae4b0a08026c48cf9"} {:body "A third implementation which in my limited testing in cljs is the fastest so far:\n```\n(defn split-by\n \"Effectively though non-lazily splits the `coll`ection using `pred`,\n essentially like `[(filter coll pred) (remove coll pred)]`\"\n [pred coll]\n (let [match (transient [])\n no-match (transient [])]\n (doseq [v coll]\n (if (pred v)\n (conj! match v)\n (conj! no-match v)))\n [(persistent! match) (persistent! no-match)]))\n```\n\nUsing `simple-benchmark` in cljs, these are the results:\n```\n[r (range 1000)], (partition-2 odd? r), 1000 runs, 167 msecs\n[r (range 1000)], (partition-3 odd? r), 1000 runs, 364 msecs\n[r (range 1000)], (split-by odd? r), 1000 runs, 60 msecs\n```\n\nIt's worth noting that all implementations of the java-esque `partition` in this thread are non-lazy.\n\nOn big collections where you don't want to realize the whole list, this is the fastest:\n```\n[(filter odd? r) (filter (complement odd?) r)]\n```\n\nCan also be written as:\n\n```\n((juxt filter remove) odd? r)\n```\n\n(taken from: http://blog.jayfields.com/2011/08/clojure-partition-by-split-with-group.html)", :created-at 1576139342503, :updated-at 1576139618518, :author {:avatar-url "https://avatars0.githubusercontent.com/u/2477927?v=4", :account-source "github", :login "Saikyun"}, :_id "5df1fa4ee4b0ca44402ef7f6"} {:author {:login "zackteo", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/7510179?v=4"}, :updated-at 1620302811324, :created-at 1620302811324, :body "Perhaps this will be of help someone trying to find the regions denoted by partitions\n```\n(defn partition-at\n \"Like partition-by but will start a new run when f returns true\"\n [f coll]\n (lazy-seq\n (when-let [s (seq coll)]\n (let [run (cons (first s) (take-while #(not (f %)) (rest s)))]\n (cons run (partition-at f (drop (count run) s)))))))\n```\n(taken from: http://cninja.blogspot.com/2011/02/clojure-partition-at.html#comments)", :_id "6093dbdbe4b0b1e3652d74f4"}], :arglists ["f" "f coll"], :doc "Applies f to each value in coll, splitting it each time f returns a\n new value. Returns a lazy seq of partitions. Returns a stateful\n transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/partition-by"} {:added "1.2", :ns "clojure.core", :name "numerator", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1314000040000, :author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "denominator", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c62"}], :line 3582, :examples [{:updated-at 1596571068249, :created-at 1313999955000, :body ";; note that the function always returns the numerator of the reduced fraction\n\n(numerator (/ 2 3))\n;;=> 2\n\nuser=> (map numerator [(/ 2 4) (/ 4 6) (/ 6 8)])\n(1 2 3)\n", :editors [{:login "wdhowe", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4631165?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon", :account-source "clojuredocs", :login "shockbob"}, :_id "542692cbc026201cdc326be1"}], :notes nil, :tag "java.math.BigInteger", :arglists ["r"], :doc "Returns the numerator part of a Ratio.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/numerator"} {:added "1.2", :ns "clojure.core", :name "object-array", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 5325, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; create an array of Java Objects using object-array\n;; and demonstrate that it can be used with the Java fill function\n\nuser=> (def os (object-array [nil 23.2 \"abc\" 33]))\n#'user/os\nuser=> (vec os)\n[nil 23.2 \"abc\" 33]\nuser=> (java.util.Arrays/fill os 31415)\nnil\nuser=> (vec os)\n[31415 31415 31415 31415]\nuser=>", :created-at 1313961890000, :updated-at 1313961890000, :_id "542692c6c026201cdc3268d2"}], :notes nil, :arglists ["size-or-seq"], :doc "Creates an array of objects", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/object-array"} {:added "1.0", :ns "clojure.core", :name "with-out-str", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1398723561000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-in-str", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e63"}], :line 4716, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3", :account-source "github", :login "bkovitz"}], :body ";; Instead of printing, the following will place the output normally\n;; sent to stdout into a string.\n\nuser=> (with-out-str (println \"this should return as a string\"))\n\"this should return as a string\\n\"\n", :created-at 1280928491000, :updated-at 1461945233822, :_id "542692c8c026201cdc326a43"} {:editors [{:login "viebel", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/955710?v=3"} {:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}], :body ";; `time` prints the elapsed time. `with-out-str` can put it into a variable.\n\n(def elapsed\n (with-out-str\n (time (last (range 10000)))))\n\nelapsed\n;=> \"\\\"Elapsed time: 49.363055 msecs\\\"\\n\"\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/955710?v=3", :account-source "github", :login "viebel"}, :created-at 1458892903287, :updated-at 1461945165867, :_id "56f4f067e4b07ac9eeceed16"} {:updated-at 1493591261548, :created-at 1493591261548, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/8271291?v=3"}, :body "(defmacro with-out-str-data-map\n [& body]\n `(let [s# (new java.io.StringWriter)]\n (binding [*out* s#]\n (let [r# ~@body]\n {:result r#\n :str (str s#)}))))\n\n(with-out-str-data-map (do\n (println \"Clojure is the best!\")\n 2))\n\n;;=> {:str \"Clojure is the best!\\n\", :result 2}", :_id "590664dde4b01f4add58fe9f"} {:updated-at 1504610437254, :created-at 1504610437254, :author {:login "yogsototh", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/93899?v=4"}, :body "(defn pp-str [x]\n (with-out-str (clojure.pprint/pprint x))\n\n\n(pp-str {:foo \"foo\" :bar \"bar\"})\n;;=> \"{:foo \\\"foo\\\", :bar \\\"bar\\\"}\\n\"\n", :_id "59ae8885e4b09f63b945ac5f"}], :macro true, :notes nil, :arglists ["& body"], :doc "Evaluates exprs in a context in which *out* is bound to a fresh\n StringWriter. Returns the string created by any nested printing\n calls.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/with-out-str"} {:added "1.0", :ns "clojure.core", :name "condp", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1289183336000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "cond", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b46"} {:created-at 1334294023000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "if", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b47"} {:created-at 1470961020992, :author {:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "case", :ns "clojure.core"}, :_id "57ad157ce4b0bafd3e2a04e5"}], :line 6359, :examples [{:author {:login "jneira", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2c8ecc24181d171df85a26458b9cd5f?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"} {:login "kimtg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7685905?v=3"}], :body ";; Taken from the excellent clojure tutorial:\n;; http://java.ociweb.com/mark/clojure/article.html\n\n(print \"Enter a number: \")\n(flush) ; stays in a buffer otherwise\n(let [line (read-line)\n value (try\n (Integer/parseInt line)\n (catch NumberFormatException e line))] ; use string val if not int\n (println\n (condp = value\n 1 \"one\"\n 2 \"two\"\n 3 \"three\"\n (str \"unexpected value, \\\"\" value \\\")))\n (println\n (condp instance? value\n Number (* value 2)\n String (* (count value) 2))))\n", :created-at 1278989834000, :updated-at 1425998195013, :_id "542692cbc026201cdc326be2"} {:updated-at 1494204573950, :created-at 1279027225000, :body ";; (some #{4 5 9} [1 2 3 4]) \n;; is the first matching clause, \n;; the match value is 4 which is decremented\n(condp some [1 2 3 4]\n #{0 6 7} :>> inc\n #{4 5 9} :>> dec\n #{1 2 3} :>> #(+ % 3))\n;;=> 3", :editors [{:avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon", :account-source "clojuredocs", :login "kotarak"} {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "adamdavislee", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/8780347?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon", :account-source "clojuredocs", :login "kotarak"}, :_id "542692cbc026201cdc326be4"} {:author {:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"}, :editors [{:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; in this case there is no matching clause\n;; so an exception is raised.\n(condp some [1 2 3 4]\n #{0 6 7} :>> inc\n #{5 9} :>> dec)\n\n;; java.lang.IllegalArgumentException: No matching clause: [1 2 3 4]", :created-at 1279027251000, :updated-at 1421191702604, :_id "542692cbc026201cdc326be7"} {:author {:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; a composite predicate which parses a string with \"re-seq\" \n;; producing a list which is made into a \"seq\".\n(condp (comp seq re-seq) \"foo=bar\"\n #\"[+](\\w+)\" :>> #(vector (-> % first (nth 1) keyword) true)\n #\"[-](\\w+)\" :>> #(vector (-> % first (nth 1) keyword) false)\n #\"(\\w+)=(\\S+)\" :>> #(let [x (first %)]\n [(keyword (nth x 1)) (nth x 2)]))\n;;=> [:foo \"bar\"]", :created-at 1279027512000, :updated-at 1421192246892, :_id "542692cbc026201cdc326bea"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; See examples for \"if\" explaining Clojure's idea of logical true\n;; and logical false.", :created-at 1334294027000, :updated-at 1334294027000, :_id "542692d2c026201cdc326f69"} {:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [], :body ";;this is with liberator\n;;branching on request method\n(defresource my-resource\n :exists? (fn [{:keys [db] {query-params :query-params \n body :body \n method :request-method} \n :request}]\n \n (condp = method\n :get (my-get-exists-fn)\n :post (my-post-exists-fn))))", :created-at 1367366404000, :updated-at 1367366404000, :_id "542692d2c026201cdc326f6a"} {:author {:login "leesper", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f150e0f851c74d1b9c001b901b29a287?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; a recursive function to calculate length\n;; same as 'count'\n(defn length [lst]\n (condp = lst\n (list) 0 ; if empty list result 0\n (+ 1 (length (rest lst))))) ; default expression\n\n(length '(1 2 3))\n;;=> 3", :created-at 1375971960000, :updated-at 1421192464881, :_id "542692d2c026201cdc326f6b"} {:updated-at 1598097023549, :created-at 1402793361000, :body ";; test arguments against various binary predicates\n(condp apply [2 3]\n = \"eq\"\n < \"lt\"\n > \"gt\")\n;;=> \"lt\"\n\n;; test argument against various unary predicates\n(condp apply [:foo]\n string? \"it's a string\"\n keyword? \"it's a keyword\"\n symbol? \"it's a symbol\"\n fn? \"it's a function\"\n \"something else!\")\n;;=> \"it's a keyword\"", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:avatar-url "https://avatars.githubusercontent.com/u/1195619?v=3", :account-source "github", :login "jeffi"} {:login "titogarcia", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/699549?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/f2fad9c9c81cfdf191f10265371f1d72?r=PG&default=identicon", :account-source "clojuredocs", :login "vee"}, :_id "542692d2c026201cdc326f6c"} {:body "; This function is part of a great solution to the \"fizzbuzz\" interview question.\n; Let's review \n; Players take turns to count incrementally, \n; replacing any number divisible by three with the word \"fizz\", \n; any number divisible by five with the word \"buzz\", and \n; any number divisible by both three and five with the word \"fizzbuzz\".\n(defn fizz-buzz [n]\n (condp #(zero? (mod %2 %1)) n\n 15 \"fizzbuzz\"\n 3 \"fizz\"\n 5 \"buzz\"\n n))\n\n(into [] (map fizz-buzz) (range 1 20))\n;;=> [1 2 \"fizz\" 4 \"buzz\" \"fizz\" 7 8 \"fizz\" \"buzz\" \n;; 11 \"fizz\" 13 14 \"fizzbuzz\" 16 17 \"fizz\" 19]", :author {:login "dfletcher", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/189317?v=3"}, :created-at 1433388096371, :updated-at 1510263672104, :editors [{:login "dfletcher", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/189317?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/200617?v=3", :account-source "github", :login "bsima"} {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}], :_id "556fc440e4b03e2132e7d185"} {:updated-at 1506692074248, :created-at 1506692074248, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :body ";; Test a string against multiple regexps, and do something different\n;; with the match each time. \n(condp re-matches \"17->42\"\n #\"(\\w+)->(\\w+)\" :>> (fn [[_ p1 p2]]\n {:start p1 :end p2})\n\n #\"(\\w+)->$\" :>> (fn [[_ p1]]\n {:start p1})\n\n #\"\\w+\" :>> (fn [[p]]\n {:fixed p})\n\n nil)\n; => {:start \"17\" :end \"42\"}", :_id "59ce4beae4b03026fe14ea4d"} {:updated-at 1534346599711, :created-at 1534346599711, :author {:login "ernstroux", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/20518350?v=4"}, :body ";if you are using the function literal already and can't nest\n\n(#(condp (fn [clause expr] (clojure.string/includes? expr clause)) \"transaction-result-kafka\"\n \"transaction-result\" 1\n \"transaction-failure\" 4\n (do\n (str \"got message with nil topic\")\n nil)))\n;=> 1", :_id "5b744567e4b00ac801ed9e5b"} {:editors [{:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}], :body ";; We can use symbols in the test-expression; this isn't possible with 'case'\n(defn id-resolver\n [id]\n (let [id-a \"a\"\n id-b \"b\"\n\t id-c \"c\"]\n (condp = id\n\t id-a {:response-a \"id-a\"}\n\t id-b {:response-b \"id-b\"}\n\t id-c {:response-c \"id-c\"})))\n\n(id-resolver \"a\")\n;; => {:response-a \"id-a\"}", :author {:avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4", :account-source "github", :login "berczeck"}, :created-at 1598155978713, :updated-at 1598156087855, :_id "5f41eccae4b0b1e3652d738d"} {:editors [{:login "Rovanion", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/632775?v=4"}], :body ";; Want to apply multiple predicates to the same expr? \n;; Not saying you should, but here is how you could.\n\n(def events [{:timestamp \"2021-01-01\" :source nil :destination 1 :litres 1 :price-per-litres 1}\n {:timestamp \"2021-01-02\" :source 1 :destination 2 :litres 0.5 :price-per-litres nil}\n {:timestamp \"2021-01-02\" :source nil :destination 1 :litres 1 :price-per-litres 2}\n {:timestamp \"2021-01-02\" :source 2 :destination nil :litres 0.25 :price-per-litres nil}])\n\n(map (fn [event]\n (condp (fn [preds e] ((apply every-pred preds) e)) event\n [:price-per-litres :destination] :insert\n [:source :destination] :transfer\n [:source (complement :destination)] :withdrawal))\n events)\n;; => (:insert :transfer :insert :withdrawal)\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/632775?v=4", :account-source "github", :login "Rovanion"}, :created-at 1655813285477, :updated-at 1655813318085, :_id "62b1b4a5e4b0b1e3652d760c"}], :macro true, :notes [{:author {:login "bsima", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/200617?v=3"}, :updated-at 1470339463090, :created-at 1470339463090, :body "A lot of these examples show the pattern:\n\n```\n(condp = value\n :a \"a\"\n :b \"b\"\n ...)\n```\n\nWhich is the same as:\n\n```\n(case value\n :a \"a\"\n :b \"b\"\n ...)\n```", :_id "57a39987e4b0bafd3e2a04c7"}], :arglists ["pred expr & clauses"], :doc "Takes a binary predicate, an expression, and a set of clauses.\n Each clause can take the form of either:\n\n test-expr result-expr\n\n test-expr :>> result-fn\n\n Note :>> is an ordinary keyword.\n\n For each clause, (pred test-expr expr) is evaluated. If it returns\n logical true, the clause is a match. If a binary clause matches, the\n result-expr is returned, if a ternary clause matches, its result-fn,\n which must be a unary function, is called with the result of the\n predicate as its argument, the result of that call being the return\n value of condp. A single default expression can follow the clauses,\n and its value will be returned if no clause matches. If no default\n expression is provided and no clause matches, an\n IllegalArgumentException is thrown.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/condp"} {:added "1.0", :ns "clojure.core", :name "derive", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1308310489000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "parents", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c78"} {:created-at 1308310496000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ancestors", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c79"} {:created-at 1308310502000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "descendants", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c7a"} {:created-at 1308310508000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "isa?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c7b"} {:created-at 1332885397000, :author {:login "luskwater", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/f3b2650c3d4aa47c9e22bf9ba5596a9f?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "make-hierarchy", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c7c"} {:created-at 1341101591000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "underive", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c7d"}], :line 5626, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [], :body ";; derive let you build a hierarchy but parents/ancestors/descendants and isa? let you query the hierarchy\n(derive ::rect ::shape)\n(derive ::square ::rect)\n", :created-at 1308310469000, :updated-at 1308310469000, :_id "542692c7c026201cdc3269d0"} {:author {:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"}, :editors [], :body "user=> (derive ::Cat ::Feline)\nnil\n\nuser=> (derive ::Lion ::Feline)\nnil\n\nuser=> (isa? ::Lion ::Feline)\ntrue\n\nuser=> (isa? ::Tuna ::Feline)\nfalse", :created-at 1313009794000, :updated-at 1313009794000, :_id "542692c7c026201cdc3269d1"} {:updated-at 1503164433228, :created-at 1503164433228, :author {:login "mhmdsalem1993", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10787314?v=4"}, :body "(derive java.util.Map ::collection)\n(derive java.util.Collection ::collection)\n\n(isa? java.util.HashMap ::collection)\n-> true", :_id "59987811e4b09f63b945ac51"} {:editors [{:login "timgilbert", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4"}], :body ";; (derive) can be handy in multimethods that switch on field values:\n\n(def data [{:record/type :types/integer :record/number 123}\n {:record/type :types/float :record/number 123.45}\n {:record/type :types/text :record/text \"hello\"}])\n\n(derive :types/float ::number)\n(derive :types/integer ::number)\n(derive :types/text ::text)\n\n(defmulti record-str :record/type)\n\n(defmethod record-str ::number [r] (str \"Number: \" (:record/number r)))\n(defmethod record-str ::text [r] (str \"Text: \" (:record/text r)))\n\n(map record-str data)\n;; => (\"Number: 123\" \"Number: 123.45\" \"Text: hello\")\n", :author {:avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4", :account-source "github", :login "timgilbert"}, :created-at 1551112001815, :updated-at 1551112172422, :_id "5c741741e4b0ca44402ef6a3"}], :notes nil, :arglists ["tag parent" "h tag parent"], :doc "Establishes a parent/child relationship between parent and\n tag. Parent must be a namespace-qualified symbol or keyword and\n child can be either a namespace-qualified symbol or keyword or a\n class. h must be a hierarchy obtained from make-hierarchy, if not\n supplied defaults to, and modifies, the global hierarchy.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/derive"} {:added "1.0", :ns "clojure.core", :name "load-string", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1334883949000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "read-string", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f04"} {:created-at 1519290621337, :author {:login "witek", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/209520?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "load-file", :ns "clojure.core"}, :_id "5a8e88fde4b0316c0f44f8e7"} {:created-at 1519290634633, :author {:login "witek", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/209520?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "load", :ns "clojure.core"}, :_id "5a8e890ae4b0316c0f44f8e8"}], :line 4089, :examples [{:body "(load-string \"(def x 1)\")\n;; => #'user/x\nx\n;; => 1", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423012385897, :updated-at 1423012385897, :_id "54d17221e4b0e2ac61831d00"} {:updated-at 1522768122029, :created-at 1522768122029, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :body ";; Don’t use this function on untrusted input; it can have unpleasant\n;; side-effects.\n(load-string \"(clojure.java.io/delete-file \\\"my-important-file\\\")\")\n;; => true", :_id "5ac398fae4b045c27b7fac35"} {:updated-at 1546454837037, :created-at 1546454837037, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; Differently from the equivalent \"(eval (read-string x))\", \"load-string\" keeps\n;; track of line numbers:\n\n(def s \"\\n\\n\\n(def c :line4)\")\n(:line (meta (load-string s)))\n;; 4\n(:line (meta (eval (read-string s))))\n;; 1", :_id "5c2d0735e4b0ca44402ef60c"}], :notes nil, :arglists ["s"], :doc "Sequentially read and evaluate the set of forms contained in the\n string", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/load-string"} {:added "1.0", :ns "clojure.core", :name "special-symbol?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 4968, :examples [{:author {:login "franks42", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon"}, :editors [{:login "franks42", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon"}], :body "user=> (clojure-version)\n\"1.4.0\"\n;; the set of special symbols for this clojure-version are the following:\nuser=> (keys (. clojure.lang.Compiler specials))\n(deftype* new quote & var set! monitor-enter recur . case* clojure.core/import* reify* do fn* throw monitor-exit letfn* finally let* loop* try catch if def)\n\n;; for example, \"def\" is not a function, not a macro, not even a var, but a special form:\nuser=> (fn? 'def)\nfalse\nuser=> (:macro (meta (find-var 'clojure.core/def)))\nnil\nuser=> (find-var 'clojure.core/def)\nnil\nuser=> (special-symbol? 'def)\ntrue\n\n;; while \"defn\" is not a special form but a macro:\nuser=> (special-symbol? 'defn)\nfalse\nuser=> (:macro (meta (find-var 'clojure.core/defn)))\ntrue\n", :created-at 1353815386000, :updated-at 1353815535000, :_id "542692d5c026201cdc327099"}], :notes nil, :arglists ["s"], :doc "Returns true if s names a special form", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/special-symbol_q"} {:added "1.0", :ns "clojure.core", :name "ancestors", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1341101490000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "parents", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cd2"} {:created-at 1341101493000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "derive", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cd3"} {:created-at 1341101496000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "underive", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cd4"} {:created-at 1341101502000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "descendants", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cd5"} {:created-at 1341101507000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "make-hierarchy", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cd6"} {:created-at 1341101672000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "isa?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cd7"} {:created-at 1374150921000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "supers", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cd8"}], :line 5598, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}], :body ";; 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=>", :created-at 1313896987000, :updated-at 1313968195000, :_id "542692cdc026201cdc326d1b"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; 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=>", :created-at 1313968946000, :updated-at 1313968946000, :_id "542692cdc026201cdc326d1d"} {:updated-at 1598158917882, :created-at 1598158880926, :author {:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}, :body ";; 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}", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4", :account-source "github", :login "berczeck"}], :_id "5f41f820e4b0b1e3652d7398"}], :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"} {:added "1.0", :ns "clojure.core", :name "subseq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1330671591000, :author {:login "Chouser", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7a0192050ed6488670acfd3f59405c10?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rsubseq", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e25"} {:created-at 1330671627000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "sorted-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e26"} {:created-at 1330671638000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "sorted-set", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e27"} {:created-at 1330671646000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "sorted-map-by", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e28"} {:created-at 1330671652000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "sorted-set-by", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e29"} {:created-at 1423278345112, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "subvec", :library-url "https://github.com/clojure/clojure"}, :_id "54d58109e4b0e2ac61831d29"}], :line 5109, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; Note, that collection passed to subseq must implement Sorted. \n;; Just passing a collection that has been sorted is not enough.\n\nuser=> (subseq [1 2 3 4] > 2)\njava.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to clojure.lang.Sorted (NO_SOURCE_FILE:0)\n\nuser=> (subseq (sorted-set 1 2 3 4) > 2)\n(3 4)\n", :created-at 1281618432000, :updated-at 1285494695000, :_id "542692cfc026201cdc326e78"} {:body ";; Example of getting a subsequence of hashmaps sorted by key :a and\n;; secondarily :b.\n\n(defn compare-ab [x y]\n (compare [(get x :a) (get x :b)]\n [(get y :a) (get y :b)]))\n \n(def ss-ab (apply sorted-set-by compare-ab\n [{:a 42 :b 5000}\n {:a 1 :b 2}\n {:a 99 :b -1000}\n {:a -1 :b 7}]))\nuser=> ss-ab\n#{{:a -1, :b 7} {:a 1, :b 2} {:a 42, :b 5000} {:a 99, :b -1000}}\n\n;; Select all maps whose key :a is greater than 5. \nuser=> (subseq ss-ab > {:a 5})\n({:a 42, :b 5000} {:a 99, :b -1000})\n\n\n", :author {:login "thirdreplicator", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/90335?v=2"}, :created-at 1413610885024, :updated-at 1413610885024, :_id "5441fd85e4b049fc676849cd"} {:updated-at 1463327979493, :created-at 1463327979493, :author {:login "TradeIdeasPhilip", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/18409827?v=3"}, :body ";; If you use the 6 input form of this function, start-test should be > or\n;; >= and the end-test should be < or <=. The other forms don't give you\n;; an error, but don't give you what you expect, either. This is all based\n;; on experimentation. I don't see this documented.\n\n;; This suggests that there are no items in my set between 9 and 2.\nuser=> (subseq (sorted-set 1 2 3 4 5 6 7 8 9 0) < 9 > 2)\n;; => ()\n\n;; This correctly lists all items in my set between 2 and 9.\nuser=> (subseq (sorted-set 1 2 3 4 5 6 7 8 9 0) > 2 < 9)\n;; => (3 4 5 6 7 8)\n\n;; Again, this is not just the \"and\" of the two conditions. Lots of items\n;; in my set are #(and (% > 2) (% > 6)) but this returns nothing. \"> 2\"\n;; means skip to the first item that is #(% > 2). So we jump directly to 3.\n;; \"> 6\" means to stop looking as soon as we find an item where #(% > 6) is\n;; false. 3 <= 6, so we get the empty sequence.\nuser=> (subseq (sorted-set 1 2 3 4 5 6 7 8 9 0) > 2 > 6)\n;; => ()\n\n;; This works as expected, returning everything where #(and (% >= 2) (% <= 4)).\n;; That is to say it returns everything between 2 and 4, inclusive.\nuser=> (subseq (sorted-set 1 2 3 4 5 6 7 8 9 0) >= 2 <= 4)\n;; => (2 3 4)\n\n;; Naïvely you might expect this to give you the same results as the previous\n;; statement. Clearly the result is not the same. I'm not sure what's going\n;; on under the hood here. It's jumping directly to 4 as if I'd said \">= 4\"\n;; rather than \"<= 4\". (Looks like a bug in Clojure to me!) Then it\n;; continued to the end because all of the remaining items were #(% >= 2).\nuser=> (subseq (sorted-set 1 2 3 4 5 6 7 8 9 0) <= 4 >= 2)\n;; => (4 5 6 7 8 9)\nuser=> *clojure-version*\n;; => {:major 1, :minor 8, :incremental 0, :qualifier nil}\n\n;; This one at least makes sense. It jumps directly to the first item that\n;; satisfies the first test and continues until the second item is false.\nuser=> (subseq (sorted-set 1 2 3 4 5 6 7 8 9 0) >= 4 >= 2)\n;; => (4 5 6 7 8 9)\n", :_id "57389cebe4b071da7d6cfd0a"} {:updated-at 1522434900617, :created-at 1522434900617, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; Autocomplete using local Unix dictionary.\n(require '[clojure.string :refer [split]])\n\n(def dict\n (into (sorted-set)\n (split (slurp \"/usr/share/dict/words\") #\"\\s+\")))\n\n;; The vector contains a few simulated keystrokes.\n(map #(take 4 (subseq dict >= %)) [\"c\" \"cl\" \"clo\" \"clos\" \"closu\"])\n;; ((\"c\" \"ca\" \"caam\" \"caama\")\n;; (\"clabber\" \"clabbery\" \"clachan\" \"clack\")\n;; (\"cloaca\" \"cloacal\" \"cloacaline\" \"cloacean\")\n;; (\"closable\" \"close\" \"closecross\" \"closed\")\n;; (\"closure\" \"clot\" \"clotbur\" \"clote\"))", :_id "5abe8354e4b045c27b7fac2a"}], :notes nil, :arglists ["sc test key" "sc start-test start-key end-test end-key"], :doc "sc must be a sorted collection, test(s) one of <, <=, > or\n >=. Returns a seq of those entries with keys ek for\n which (test (.. sc comparator (compare ek key)) 0) is true", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/subseq"} {:added "1.2", :ns "clojure.core", :name "error-handler", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1443938208744, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "set-error-handler!", :ns "clojure.core"}, :_id "5610bfa0e4b0686557fcbd54"} {:created-at 1443938218045, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "agent", :ns "clojure.core"}, :_id "5610bfaae4b08e404b6c1ca5"}], :line 2204, :examples [{:editors [{:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}], :body "(def error-atom (atom []))\n\n(def a (agent \"\"\n :validator string?\n :error-handler (fn [agnt ex]\n (swap! error-atom\n conj\n {:agent agnt\n :exception (.getMessage ex)}))))\n\n(send a 1) ;; will fail validation\n\n@error-atom\n[{:agent #,\n :exception \"java.lang.Long cannot be cast to clojure.lang.IFn\"}]\n\n(error-handler a)\n#", :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :created-at 1443938199376, :updated-at 1443938238017, :_id "5610bf97e4b0686557fcbd53"}], :notes nil, :arglists ["a"], :doc "Returns the error-handler of agent a, or nil if there is none.\n See set-error-handler!", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/error-handler"} {:added "1.0", :ns "clojure.core", :name "gensym", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 604, :examples [{:updated-at 1285495689000, :created-at 1280776789000, :body "user=> (gensym \"foo\")\nfoo2020\n\nuser=> (gensym \"foo\")\nfoo2027\n\nuser=> (gensym \"foo\")\n;; ...\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692c6c026201cdc32690b"} {:updated-at 1285495715000, :created-at 1280776909000, :body "user=> (gensym)\nG__2034\n\nuser=> (let [my-unique-sym (gensym)]\n my-unique-sym)\nG__2075\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692c6c026201cdc32690d"} {:author {:login "gdavis", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ae253eacd4cab9fb2580b8192351b641?r=PG&default=identicon"}, :editors [], :body ";; 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", :created-at 1394152357000, :updated-at 1394152357000, :_id "542692d3c026201cdc326fbc"} {:updated-at 1656609206311, :created-at 1656609206311, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; 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]", :_id "62bdd9b6e4b0b1e3652d760f"}], :notes [{:updated-at 1383198787000, :body "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).", :created-at 1383198787000, :author {:login "mlb", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/11104d872c2bae6e0e98b7533818530a?r=PG&default=identicon"}, :_id "542692edf6e94c697052200c"}], :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"} {:added "1.0", :ns "clojure.core", :name "cond", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1289183323000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "condp", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ee8"} {:created-at 1290574959000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "case", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ee9"} {:created-at 1302510857000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "if", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eea"} {:created-at 1459890885195, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "cond->", :ns "clojure.core"}, :_id "57042ac5e4b075f5b2c864ce"}], :line 574, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"} {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"} {:login "bhenry", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4bc423f6653d93f9185a5cdc9f5cd84f?r=PG&default=identicon"} {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "(defn pos-neg-or-zero\n \"Determines whether or not n is positive, negative, or zero\"\n [n]\n (cond\n (< n 0) \"negative\"\n (> n 0) \"positive\"\n :else \"zero\"))\n\nuser=> (pos-neg-or-zero 5)\n\"positive\"\nuser=> (pos-neg-or-zero -1)\n\"negative\"\nuser=> (pos-neg-or-zero 0)\n\"zero\"\n", :created-at 1279070736000, :updated-at 1285501471000, :_id "542692c7c026201cdc326966"} {:author {:login "bhenry", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4bc423f6653d93f9185a5cdc9f5cd84f?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "TheJoe", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2789ff7d993fbf621e86768b3cce19d4?r=PG&default=identicon"}], :body "user=> (let [grade 85]\n (cond\n (>= grade 90) \"A\"\n (>= grade 80) \"B\"\n (>= grade 70) \"C\"\n (>= grade 60) \"D\"\n :else \"F\"))\n\"B\"", :created-at 1279071870000, :updated-at 1365525514000, :_id "542692c7c026201cdc32696c"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; See examples for \"if\" explaining Clojure's idea of logical true\n;; and logical false.", :created-at 1334293315000, :updated-at 1334293315000, :_id "542692d2c026201cdc326f67"} {:author {:login "Omer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/dae0f434afde5246ccb030cdec81fb71?r=PG&default=identicon"}, :editors [], :body ";; Generates a random number compares it to user input\n(let [rnd (rand-int 10)\n guess (Integer/parseInt (read-line))]\n (cond\n (= rnd guess) (println \"You got my guess right!\")\n :else (println \"Sorry... guess again!\")))", :created-at 1338273335000, :updated-at 1338273335000, :_id "542692d2c026201cdc326f68"} {:updated-at 1459931468351, :created-at 1459931468351, :author {:login "mhmdsalem1993", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10787314?v=3"}, :body ";; Simple Condition Example \n\n(defn test-x [x]\n\t(cond\n\t\t(< x 10) \"less than\"\n\t\t(> x 20) \"greater than\"\n\t)\n)\n\n============test============\n(test-x 9)\n\n=> \"less than\"", :_id "5704c94ce4b0fc95a97eab2c"} {:updated-at 1502632735612, :created-at 1502632735612, :author {:login "RobinNagpal", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/745748?v=4"}, :body "(defn print-cond [xx] \n (cond \n (< xx 6) \"less than 6\"\n (< xx 8) \"less than 8\"\n :else \"Greater than 8\"))\n=> #'aurora.system/print-cond\n(print-cond 5)\n=> \"less than 6\"\n(print-cond 7)\n=> \"less than 8\"\n(print-cond 8)\n=> \"Greater than 8\"\n(print-cond 10)\n=> \"Greater than 8\"\n", :_id "59905b1fe4b0d19c2ce9d716"} {:updated-at 1504194292107, :created-at 1504194292107, :author {:login "chrismurrph", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/10278575?v=4"}, :body ";; If a condition is not matched `nil` will be returned\n(cond\n false \"sumfin\")\n;;=> nil", :_id "59a82ef4e4b09f63b945ac5b"} {:updated-at 1598227713206, :created-at 1598227713206, :author {:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}, :body ";; Instead of use the :else keyword as the default path you can use \n;; whatever that gives meaning to the code\n\nuser=> (cond \n :whatever \"You can use any default keyword\")\n;; You can use any default keyword", :_id "5f430501e4b0b1e3652d73a9"} {:updated-at 1613750506091, :created-at 1613750506091, :author {:login "digash", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/30662?v=4"}, :body ";; cond is a macro the easiest way to understand how it works is to macroexpand it\nuser=> (clojure.walk/macroexpand-all\n '(let [n 3] \n (cond\n (odd? n) \"odd\"\n (even? n) \"even\"\n (< n 0) \"negitive\"\n (< 0 n) \"positive\"\n :else \"zero\")))\n\n(let [n 3]\n (if (odd? n)\n \"odd\"\n (if (even? n)\n \"even\"\n (if (< n 0)\n \"negitive\"\n (if (< 0 n)\n \"positive\"\n (if :else\n \"zero\"\n nil))))))", :_id "602fe0eae4b0b1e3652d745e"}], :macro true, :notes [{:updated-at 1288294778000, :body "We should add a comment in the docstring for the final usage of :else.", :created-at 1288294778000, :author {:login "blais", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9142fc3ffa18ebeddbb03fe575199742?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fa0"} {:author {:login "kimtg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7685905?v=3"}, :updated-at 1441172051574, :created-at 1441172051574, :body "`:else` is not special. Any keyword will do.", :_id "55e68a53e4b072d7f27980f9"} {:author {:login "seltzer1717", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1911117?v=3"}, :updated-at 1445308247668, :created-at 1445308247668, :body "Actually any non-nil or true will work. I prefer to use :default. :else implies truthiness in evaluation rather what it really is which is a 'default' value.", :_id "5625a757e4b04b157a6648d7"} {:author {:login "yubrshen", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/2638417?v=3"}, :updated-at 1494713707387, :created-at 1494713707387, :body "It seems the documentation is not accurate. From my experiment, it seems the function decscription should be like the following:\n\nTakes a set of test/expr pairs. It evaluates each test one at a time. \nIf a test returns logical true, cond evaluates the corresponding expr and\ncontinue to evaluate the next test/expr, until a test fails or \nno more pair of test(:else)/expr to evaluate,\nand returns the last evaluation value of the expr \nthat its corresponding test evaluated to truthy.\nIf there is no test evaluated to truthy, \nreturn the evaluation of :else clause.\nIf there is no :else clause return nil.\n\nThe above description can be supported by the following example:\n\n
\n(defn pos-neg-or-zero\n \"Determines whether or not n is positive, negative, or zero\"\n [n]\n (cond\n (odd? n) \"odd\"\n (even? n) \"even\"\n (< n 0) \"negitive\"\n (< 0 n) \"positive\"\n :else \"zero\"))\n\n(odd? 3) ; => true\n(pos-neg-or-zero 3) ;=> \"positive\"\n(even? 0) ; => true\n(pos-neg-or-zero 0) ;=> \"zero\"\n(even? 4) ; => true\n(pos-neg-or-zero 4) ;=> \"positive\"\n>\n", :_id "5917856be4b01920063ee05d"} {:author {:login "maruks", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/433989?v=3"}, :updated-at 1499359558730, :created-at 1499359558730, :body "yubrshen, \n\n(pos-neg-or-zero 3) => \"odd\"", :_id "595e6946e4b06e730307db4f"} {:author {:login "dan-mcdonald", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/8184051?v=4"}, :updated-at 1592425332445, :created-at 1592425332445, :body "`:else` is just a convention. It works because\n\n
\n=> (boolean :else)\ntrue\n
\n\nIn fact anything except for `false` and `nil` will evaluate to `true` (see [boolean](https://clojuredocs.org/clojure.core/boolean)).", :_id "5eea7b74e4b0b1e3652d7306"}], :arglists ["& clauses"], :doc "Takes a set of test/expr pairs. It evaluates each test one at a\n time. If a test returns logical true, cond evaluates and returns\n the value of the corresponding expr and doesn't evaluate any of the\n other tests or exprs. (cond) returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/cond"} {:added "1.0", :ns "clojure.core", :name "ratio?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1691574043389, :author {:login "ferdinand-beyer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/23474334?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "rational?", :ns "clojure.core"}, :_id "64d35f1be4b08cf8563f4bd9"} {:created-at 1691574076933, :author {:login "ferdinand-beyer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/23474334?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "denominator", :ns "clojure.core"}, :_id "64d35f3ce4b08cf8563f4bda"} {:created-at 1691574083991, :author {:login "ferdinand-beyer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/23474334?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "numerator", :ns "clojure.core"}, :_id "64d35f43e4b08cf8563f4bdb"}], :line 3576, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "(ratio? 22/7)\n;; => true\n\n(ratio? 22)\n;; => false\n\n(ratio? 2.2)\n;; => false\n", :created-at 1279074828000, :updated-at 1423040912016, :_id "542692c9c026201cdc326a96"} {:updated-at 1463237750174, :created-at 1463237750174, :author {:login "TradeIdeasPhilip", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/18409827?v=3"}, :body ";; Both True\nuser=> (ratio? 22/7) \n;; => true\nuser=> (rational? 22/7)\n;; => true\n\n;; Different\nuser=> (ratio? 22)\n;; => false\nuser=> (rational? 22)\n;; => true\n\n;; Both False\nuser=> (ratio? 0.5)\n;; => false\nuser=> (rational? 0.5)\n;; => false", :_id "57373c76e4b05449374f52ee"}], :notes nil, :arglists ["n"], :doc "Returns true if n is a Ratio", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ratio_q"} {:added "1.0", :ns "clojure.core", :name "delay?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1325375628000, :author {:login "moumar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8fae5b9c9ffd332a24ff71a339fa6310?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "delay", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ca7"}], :line 755, :examples [{:author {:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}, :editors [{:login "yasuto", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"}], :body "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=> ", :created-at 1308628940000, :updated-at 1308629066000, :_id "542692cec026201cdc326dc1"}], :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"} {:added "1.0", :ns "clojure.core", :name "intern", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1360641943000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "alter-var-root", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b72"} {:created-at 1484214992310, :author {:login "rauhs", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11081351?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ns-unmap", :ns "clojure.core"}, :_id "587752d0e4b09108c8545a56"} {:created-at 1649576842844, :author {:login "jungwookim", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/50188177?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "create-ns", :ns "clojure.core"}, :_id "62528b8ae4b0b1e3652d75cf"}], :line 6317, :examples [{:author {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}], :body "user=> (intern 'user 'x \"Foobar\")\n#'user/x\n\nuser=> x\n\"Foobar\"\n", :created-at 1283820694000, :updated-at 1287791800000, :_id "542692cac026201cdc326b56"} {:updated-at 1649576567141, :created-at 1649576567141, :author {:login "jungwookim", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/50188177?v=4"}, :body ";; being able to define fn as a val\nuser=> (intern 'user 'sum (fn [a b c]\n (+ a b c)))\n#'user/sum\n\nuser=> (sum 1 2 3)\n6", :_id "62528a77e4b0b1e3652d75ce"} {:updated-at 1649578114784, :created-at 1649577871265, :author {:login "jungwookim", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/50188177?v=4"}, :body ";; you can defind defmethod as well by using intern.\n;; firstly, define defmulti so that upper-case can convert string and keyword into upper-case, respectively.\nuser=> (defmulti upper-case [this]\n (type this))\n\n;; defmethods can be created as a var by clojure.core/intern\nuser=> (intern 'user 'upper-case (defmethod upper-case java.lang.String [this]\n (clojure.string/upper-case this)))\n\nuser=> (intern 'user 'upper-case (defmethod upper-case clojure.lang.Keyword [this]\n (-> this name clojure.string/upper-case keyword)))\n\nuser=> (upper-case \"abc\")\n\"ABC\"\n\nuser=> (upper-case :abc)\n:ABC", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/50188177?v=4", :account-source "github", :login "jungwookim"}], :_id "62528f8fe4b0b1e3652d75d0"}], :notes [{:author {:login "phreed", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/211644?v=3"}, :updated-at 1490886217995, :created-at 1490886217995, :body "\"The Namespace system maintains global maps of symbols to Var objects (see Namespaces). If a def expression does not find an interned entry in the current namespace for the symbol being def-ed, it creates one, otherwise it uses the existing Var. This find-or-create process is called interning. This means that, unless they have been unmap-ed, Var objects are stable references and need not be looked up every time. It also means that namespaces constitute a global environment in which, as described in Evaluation, the compiler attempts to resolve all free symbols as Vars.\n\n\"The var special form or the #' reader macro (see Reader) can be used to get an interned Var object instead of its current value.\"\n\n-- [https://clojure.org/reference/vars]", :_id "58dd1e49e4b01f4add58fe81"}], :arglists ["ns name" "ns name val"], :doc "Finds or creates a var named by the symbol name in the namespace\n ns (which can be a symbol or a namespace), setting its root binding\n to val if supplied. The namespace must exist. The var will adopt any\n metadata from the name symbol. Returns the var.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/intern"} {:ns "clojure.core", :name "print-simple", :file "clojure/core_print.clj", :type "function", :column 1, :see-alsos nil, :line 83, :examples [{:updated-at 1656622812157, :created-at 1656622812157, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; where o is an object to be printed, and w is a java.io.Writer\n;; prints metadata if *print-dup* or *print-meta* & *print-readably* are truthy\n;; stringifies and writes the object to the writer\n\n;; We can bind *out* to a writer and return that\n(let [s (java.io.StringWriter.)]\n (binding [*out* s]\n (print \"Hello!\")\n (str s)))\n;; => \"Hello!\"\n\n;; Or we can use print-simple with no binding necessary\n(let [s (java.io.StringWriter.)]\n (print-simple \"Hello!\" s)\n (str s))\n;; => \"Hello!\"\n", :_id "62be0edce4b0b1e3652d7610"}], :notes nil, :arglists ["o w"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/print-simple"} {:added "1.2", :ns "clojure.core", :name "flatten", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1489089374653, :author {:login "miner", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/25400?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "flatten", :ns "clojure.core.reducers"}, :_id "58c1b35ee4b01f4add58fe74"} {:created-at 1519124274538, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "tree-seq", :ns "clojure.core"}, :_id "5a8bff32e4b0316c0f44f8d6"} {:created-at 1550854184577, :author {:login "finalfantasia", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/2316604?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "sequential?", :ns "clojure.core"}, :_id "5c702828e4b0ca44402ef69f"} {:created-at 1580338242571, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "mapcat", :ns "clojure.core"}, :_id "5e320c42e4b0ca44402ef826"}], :line 7136, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [{:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"} {:login "tonsky", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4188c62c28a196e3e82363217c56fca5?r=PG&default=identicon"}], :body "user=> (flatten [1 [2 3]])\n(1 2 3)\n\nuser=> (flatten '(1 2 3))\n(1 2 3)\n\nuser=> (flatten '(1 2 [3 (4 5)])) \n(1 2 3 4 5)\n\nuser=> (flatten nil)\n()\n\n; Attention with stuff which is not a sequence\n\nuser=> (flatten 5)\n()\n\nuser=> (flatten {:name \"Hubert\" :age 23})\n()\n\n; Workaround for maps\n\nuser=> (flatten (seq {:name \"Hubert\" :age 23}))\n(:name \"Hubert\" :age 23)", :created-at 1279274687000, :updated-at 1341327489000, :_id "542692cfc026201cdc326e49"} {:editors [{:login "bsima", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/200617?v=3"}], :body ";; Useful snippet: \"merge\" two or more vectors with `(comp vec flatten vector)`\n(let [a [{:a \"hi\"} {:b \"hey\"}]\n b [{:c \"yo\"} {:d \"hiya\"}]\n c {:e [\"hola\" \"bonjour\"]}]\n ((comp vec flatten vector) a b c))\n;;=> [{:a \"hi\"} {:b \"hey\"} {:c \"yo\"} {:d \"hiya\"} {:e [\"hola\" \"bonjour\"]}]", :author {:avatar-url "https://avatars.githubusercontent.com/u/200617?v=3", :account-source "github", :login "bsima"}, :created-at 1453767790696, :updated-at 1453767826738, :_id "56a6bc6ee4b015010896bd6e"}], :notes [{:updated-at 1335141716000, :body "(flatten nil) actually returns an empty sequence, not nil. The doc string is fixed in 1.4.", :created-at 1335141716000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fde"} {:updated-at 1336946114000, :body "As shown in the example, flatten will return an empty sequence when given any non-sequential thing. That can sometimes hide a bug. \r\n\r\nHere's another version that doesn't have that problem, and is faster as well.\r\n\r\n\r\n (defn flatten2\r\n \"Like `clojure.core/flatten` but better, stronger, faster.\r\n Takes any nested combination of sequential things (lists, vectors,\r\n etc.) and returns their contents as a single, flat, lazy sequence.\r\n If the argument is non-sequential (numbers, maps, strings, nil, \r\n etc.), returns the original argument.\"\r\n {:static true}\r\n [x]\r\n (letfn [(flat [coll] \r\n (lazy-seq \r\n (when-let [c (seq coll)] \r\n (let [x (first c)] \r\n (if (sequential? x) \r\n (concat (flat x) (flat (rest c))) \r\n (cons x (flat (rest c))))))))]\r\n (if (sequential? x) (flat x) x)))\r\n", :created-at 1335142077000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fdf"} {:updated-at 1341327474000, :body "Actually, flatten on a vector returns list, not a collection:\r\n\r\n user=> (flatten [1 [2 3]])\r\n (1 2 3)\r\n", :created-at 1341327474000, :author {:login "tonsky", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4188c62c28a196e3e82363217c56fca5?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fe4"} {:updated-at 1398620003000, :body "lazy version is much slower than this one:\r\n\r\n
(defn my-flatten [l] \r\n \"free of StackOverflow problem, not lazy and much faster version of flatten.\"\r\n(loop [l1 l, l2 `()]\r\n (cond\r\n (sequential? (first l1)) (recur (concat (first l1) (rest l1)) l2)\r\n (empty? l1) (reverse l2)\r\n :else (recur (rest l1) (cons (first l1) l2)))))\r\n
\r\n\r\nfor complicated construction genereted by:\r\n
(defn gen-list-wird [c] (reduce (fn [a b] (list a b)) (map vector (range c) (map str (range c (* 2 c))))))
\r\ntimes are:\r\ncore/flatten (260 msec)\r\nsteveminer/flatten (135 msec)\r\nmy-flatten (2 msec). This version is slower than steveminder`s version for flat and very nested structures with small number of items.", :created-at 1398617756000, :author {:login "slovic", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b39b58f117a52d4f8ef3f388afb4554a?r=PG&default=identicon"}, :_id "542692edf6e94c6970522025"} {:author {:login "miner", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/25400?v=3"}, :updated-at 1442172372482, :created-at 1442172372482, :body "For a much faster implementation, use `clojure.core.reducers/flatten` (introduced in Clojure 1.5).", :_id "55f5cdd4e4b06a9ffaad4fc0"} {:author {:login "afhammad", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147120?v=3"}, :updated-at 1459255941235, :created-at 1459255941235, :body "To only flatten one level, you can use (mapcat identity coll)\n\nWith flatten:\n
\n", :_id "56fa7a85e4b09295d75dbf43"} {:body "afhammad, i think to flatten one level it may be useful
(apply concat coll)
", :created-at 1470329093649, :updated-at 1470329117379, :author {:avatar-url "https://avatars.githubusercontent.com/u/834990?v=3", :account-source "github", :login "moskvo"}, :_id "57a37105e4b0bafd3e2a04c6"} {:author {:login "beluchin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6383047?v=4"}, :updated-at 1613909662567, :created-at 1613909662567, :body "does not flatten sets:\n\n user=> (flatten [#{1}])\n (#{1})", :_id "60324e9ee4b0b1e3652d7460"}], :arglists ["x"], :doc "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.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/flatten"} {:added "1.0", :ns "clojure.core", :name "doubles", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1656679496626, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "double-array", :ns "clojure.core"}, :_id "62beec48e4b0b1e3652d761b"}], :line 5378, :examples [{:updated-at 1656673535693, :created-at 1656673535693, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; 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\"", :_id "62bed4ffe4b0b1e3652d7616"} {:updated-at 1682271447230, :created-at 1682271447230, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; 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", :_id "64456cd7e4b08cf8563f4b92"}], :notes [{:updated-at 1313877730000, :body "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", :created-at 1313877675000, :author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fc6"}], :arglists ["xs"], :doc "Casts to double[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/doubles"} {:added "1.9", :ns "clojure.core", :name "halt-when", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1658332219541, :author {:login "crimeminister", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/29072?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "transduce", :ns "clojure.core"}, :_id "62d8243be4b0b1e3652d762a"}], :line 7631, :examples [{:updated-at 1520773717746, :created-at 1520773717746, :author {:login "glts", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1483271?v=4"}, :body "(def letters (set \"abcdefghijklmnopqrstuvwxyz\"))\n(def vowels (set \"aeiou\"))\n\n;; Remove the vowels from a string.\n(transduce (remove vowels) str \"hello\")\n;;=> \"hll\"\n\n;; Same, but halt when seeing a non-letter (and return that non-letter).\n(transduce (comp (remove vowels) (halt-when (complement letters)))\n str \"hello\")\n;;=> \"hll\"\n(transduce (comp (remove vowels) (halt-when (complement letters)))\n str \"hello world\")\n;;=> \\space\n", :_id "5aa52a55e4b0316c0f44f91c"} {:editors [{:login "seancorfield", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/43875?v=4"}], :body ";; \"halt-when\" can only really be used with \"transduce\", but not with other\n;; functions that support transducers like \"into\" or \"sequence\".\n\n(def v (vec (concat (range 5) [:x])))\n(def xf (comp (take 10) (halt-when keyword?) (map inc)))\n\n(transduce xf conj [] v)\n;;=> :x\n\n(into [] xf v)\n;;=> ClassCastException!\n;; Clojure 1.11.0 Alpha 4 updates \"into\" so that this works and produces:\n;;=> :x\n\n(sequence xf v)\n;;=> (1 2 3 4 5), wrong result!\n", :author {:avatar-url "https://avatars3.githubusercontent.com/u/1483271?v=4", :account-source "github", :login "glts"}, :created-at 1520774510308, :updated-at 1642119482857, :_id "5aa52d6ee4b0316c0f44f91d"} {:editors [{:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :body ";; Using the second argument in halt-when\n\n(transduce\n (comp (halt-when #{30} ;; stop at 30th item\n (fn [acc itm] acc))) ;; return all items so far\n (completing conj #(reduce + %)) ;; sums items on exit\n (range))\n;; 435", :author {:avatar-url "https://avatars.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}, :created-at 1642611299179, :updated-at 1656671302936, :_id "61e84263e4b0b1e3652d75a0"} {:editors [{:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :body ";; Like `take-while`'s complement when we return the completed result so far\n(transduce (take-while #(< % 10)) + (range));; => 45\n(transduce (halt-when #(>= % 10) (fn [acc _] acc)) + (range));; => 45\n\n;; So it's similar to medley's `take-upto` when `retf` = transduce's `f`\n(transduce (medley.core/take-upto #(>= % 10)) conj (range))\n;; => [0 1 2 3 4 5 6 7 8 9 10]\n(transduce (halt-when #(>= % 10) conj) conj (range))\n;; => [0 1 2 3 4 5 6 7 8 9 10]", :author {:avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4", :account-source "github", :login "tomdl89"}, :created-at 1658423818398, :updated-at 1658425450347, :_id "62d98a0ae4b0b1e3652d762b"} {:updated-at 1685471418885, :created-at 1685471418885, :author {:login "holyjak", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/624958?v=4"}, :body ";; Since Clojure 1.11 we can also use this with e.g. into:\n(into {}\n (comp\n (map (juxt :l :n))\n (halt-when (comp (complement number?) second) \n (constantly ::invalid)))\n [{:l \"A\" :n 1}\n {:l \"B\" :n \"not a number!\"}\n {:l \"C\" :n 3}])\n;; => ::invalid\n;; (remove the B entry to get `=> {\"A\" 1, \"C\" 3}`)", :_id "647640bae4b08cf8563f4bc7"}], :notes [{:author {:login "glts", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1483271?v=4"}, :updated-at 1520774998468, :created-at 1520774998468, :body "`halt-when` is an odd transducer in that it is supposed to be used with `transduce`, but not in other transducible contexts like `sequence` or `into`.\n\nSays Alex Miller at https://dev.clojure.org/jira/browse/CLJ-1451: ‘Yeah, halt-when is a little tricky to use in transducible contexts other than transduce.’ Some more discussion at https://groups.google.com/d/msg/clojure/6HvmJIUsXKk/gLqUsfcnAwAJ.\n", :_id "5aa52f56e4b0316c0f44f91e"} {:author {:login "holyjak", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/624958?v=4"}, :updated-at 1685471806059, :created-at 1685471806059, :body "Not anymore, as pointed out above, at least `into` works fine under Clojure 1.11", :_id "6476423ee4b08cf8563f4bc8"}], :arglists ["pred" "pred retf"], :doc "Returns a transducer that ends transduction when pred returns true\n for an input. When retf is supplied it must be a fn of 2 arguments -\n it will be passed the (completed) result so far and the input that\n triggered the predicate, and its return value (if it does not throw\n an exception) will be the return value of the transducer. If retf\n is not supplied, the input that triggered the predicate will be\n returned. If the predicate never returns true the transduction is\n unaffected.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/halt-when"} {:added "1.0", :ns "clojure.core", :name "with-in-str", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1398723552000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-out-str", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f33"}], :line 4727, :examples [{:author {:login "tormaroe", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8bc7bb10bee96efb190053fe92ffd250?r=PG&default=identicon"}, :editors [{:login "tormaroe", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8bc7bb10bee96efb190053fe92ffd250?r=PG&default=identicon"}], :body ";; Given you have a function that will read from *in*\n(defn prompt [question]\n (println question)\n (read-line))\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", :created-at 1289600189000, :updated-at 1289600648000, :_id "542692c7c026201cdc3269d8"}], :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"} {:added "1.0", :ns "clojure.core", :name "remove-watch", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1331136355000, :author {:login "pjlegato", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4ce55cfd8b3ae2f63f5ecbc8fc1c05d4?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "add-watch", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c2f"} {:created-at 1498791146039, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "atom", :ns "clojure.core"}, :_id "5955bceae4b06e730307db49"} {:created-at 1498791163420, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "var", :ns "clojure.core"}, :_id "5955bcfbe4b06e730307db4a"} {:created-at 1498791180171, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/10404?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ref", :ns "clojure.core"}, :_id "5955bd0ce4b06e730307db4b"} {:created-at 1661778678117, :author {:login "wactbprot", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/113518?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "agent", :ns "clojure.core"}, :_id "630cbaf6e4b0b1e3652d765e"}], :line 2162, :examples [{:body "(def a (atom nil))\n\n;; The key of the watch is `:logger`\n(add-watch a :logger #(println %4))\n\n(reset! a [1 2 3])\n\n;; Deactivate the watch by its assigned key\n(remove-watch a :logger)", :author {:login "jkxyz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10171367?v=3"}, :created-at 1434458463428, :updated-at 1434458576224, :editors [{:login "jkxyz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10171367?v=3"}], :_id "5580195fe4b03e2132e7d197"}], :notes nil, :arglists ["reference key"], :doc "Removes a watch (set by add-watch) from a reference", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/remove-watch"} {:added "1.4", :ns "clojure.core", :name "ex-info", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1414982233911, :author {:login "also", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/15624?v=2"}, :to-var {:ns "clojure.core", :name "ex-data", :library-url "https://github.com/clojure/clojure"}, :_id "5456ea59e4b03d20a102429b"} {:created-at 1504289816491, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "throw", :ns "clojure.core"}, :_id "59a9a418e4b09f63b945ac5e"} {:created-at 1517620449117, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "try", :ns "clojure.core"}, :_id "5a750ce1e4b0e2d9c35f7407"} {:created-at 1517620458546, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "catch", :ns "clojure.core"}, :_id "5a750ceae4b0e2d9c35f7408"} {:created-at 1517620910204, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "finally", :ns "clojure.core"}, :_id "5a750eaee4b0e2d9c35f740f"} {:created-at 1518042214699, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "print-stack-trace", :ns "clojure.stacktrace"}, :_id "5a7b7c66e4b0316c0f44f8a4"}], :line 4783, :examples [{:body "(try\n (throw \n (ex-info \"The ice cream has melted!\" \n {:causes #{:fridge-door-open :dangerously-high-temperature} \n :current-temperature {:value 25 :unit :celsius}}))\n (catch Exception e (ex-data e)))\n\n;;=> {:causes #{:fridge-door-open :dangerously-high-temperature} \n;; :current-temperature {:value 25 :unit :celsius}}))\n\n", :author {:login "claj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/353113?v=3"}, :created-at 1424029233597, :updated-at 1457501094130, :editors [{:login "claj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/353113?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/5733420?v=3", :account-source "github", :login "trimtab613"} {:login "snufkon", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/490414?v=3"}], :_id "54e0f631e4b01ed96c93c87a"} {:updated-at 1561362532798, :created-at 1561362532798, :author {:login "humorless", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/3061798?v=4"}, :body ";; From https://stackoverflow.com/questions/25211457/\n;; Catching ExceptionInfo will only catch throwables created with ex-info:\n(try\n (throw (ex-info \"bad\" {:a 1 :b 2}))\n (catch clojure.lang.ExceptionInfo e\n (prn \"caught\" e)))\n;; => \"caught\" #", :_id "5d108064e4b0ca44402ef761"} {:updated-at 1680871851550, :created-at 1580222636013, :author {:login "daemianmack", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/24476?v=4"}, :body ";; The 3-arg arity is for linking exceptions in accordance with Java convention.\n;; For example you could write an exception wrapper:\n\n(ns clojure.example)\n\n(defn exception-wrapper\n \"Wrap exceptions to embed `:event` information from the `request` such\n that we preserve the `Caused by` convention.\"\n [request exception]\n (let [event (:event request)\n exc (ex-info (.getMessage ^Throwable exception)\n {:event event}\n exception)]\n (throw exc)))\n\nclojure.example> (exception-wrapper {:event \"some-event-info\"}\n (ex-info \"Dang.\" {:trilobites :everywhere}))\n\n;; => Execution error (ExceptionInfo) at clojure.example/eval5596 (REPL:26).\n;; => Dang.\n\nclojure.example> (clojure.repl/pst *e)\n;; => ExceptionInfo Dang. {:event \"some-event-info\"}\n;; => \tclojure.example/exception-wrapper (NO_SOURCE_FILE:7)\n;; => [...]\n;; => \tclojure.main/repl (main.clj:458)\n;; => Caused by:\n;; => ExceptionInfo Dang. {:trilobites :everywhere}\n\n\n\n;; Like in Java, you should chain exceptions (ex-cause). \n;; This lets you rank the exception in context.\n;; An exception chain is like an interrogation \n;; -> Who are you? (type e) => clojure.lang.ExceptionInfo\n;; -> What is your meaning? (ex-message e) => Divide by Zero\n;; -> Why did you behave badly? (ex-data e) => :divisor was 0\n;; -> Who else was involved? (ex-cause e) => #ArithmeticException{}\n;; --> Who are you? (-> e ex-cause type) => ArithmeticException\n;; ---> Who are you? (-> e ex-cause ex-cause type) => ...\n(def a 1)\n(def b 0)\n\n(try (/ a b)\n (catch ArithmeticException ae ;; <-- \"defuse\" Throwable\n (throw ;; <-- re-throw exception\n (ex-info ;; <-- contextualize ae\n (ex-message ae) ;; <-- chain exception message\n {:divisor b :dividend a} ;; <-- give your new ex-info context\n ae)))) ;; <-- chain ae as cause\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4", :account-source "github", :login "loeschzwerg"} {:login "daemianmack", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24476?v=4"}], :_id "5e3048ace4b0ca44402ef823"} {:editors [{:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}], :body ";; Be careful that when thrown in a future\n;; exceptions are cast into an ExecutionException\n(ns clojure.example)\n\n(try\n @(future \n (throw \n (ex-info \"This exception is not caught\" \n {:useless :data})))\n (catch clojure.lang.ExceptionInfo e \n (println \"Is not executed\"))\n (catch java.util.concurrent.ExecutionException e \n (println \"This one is executed\")))\n", :author {:avatar-url "https://avatars3.githubusercontent.com/u/11491686?v=4", :account-source "github", :login "caumond"}, :created-at 1590830551261, :updated-at 1636722156357, :_id "5ed225d7e4b087629b5a1920"}], :notes nil, :arglists ["msg map" "msg map cause"], :doc "Create an instance of ExceptionInfo, a RuntimeException subclass\n that carries a map of additional data.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ex-info"} {:added "1.0", :ns "clojure.core", :name "ifn?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1321052090000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "fn?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c09"}], :line 6230, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; An anonymous function is a function as you'd expect\nuser=> (ifn? #(\"my anonymous function\"))\ntrue\n\n;; Is a vector a function?\nuser=> (ifn? [1 2 3])\ntrue\n\n;; Sure is, lets call it.\nuser=> ([1 2 3] 0)\n1\n\n;; Maps and sets are functions, too.\n\n;; a number is definitely not a function\nuser=> (ifn? 1)\nfalse\n\n;; but a symbol is\nuser=> (ifn? 'foo)\ntrue\n\n;; and so is a keyword\nuser=> (ifn? :foo)\ntrue", :created-at 1281077011000, :updated-at 1329991142000, :_id "542692cdc026201cdc326d38"}], :notes nil, :arglists ["x"], :doc "Returns true if x implements IFn. Note that many data structures\n (e.g. sets and maps) implement IFn", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ifn_q"} {:added "1.5", :ns "clojure.core", :name "some->", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1412083935441, :author {:login "jw-00000", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2936?v=2"}, :to-var {:ns "clojure.core", :name "some->>", :library-url "https://github.com/clojure/clojure"}, :_id "542ab0dfe4b0df9bb778a59b"} {:created-at 1412083945874, :author {:login "jw-00000", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2936?v=2"}, :to-var {:ns "clojure.core", :name "->", :library-url "https://github.com/clojure/clojure"}, :_id "542ab0e9e4b0df9bb778a59c"} {:created-at 1412268640070, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "cond->", :library-url "https://github.com/clojure/clojure"}, :_id "542d8260e4b05f4d257a298e"} {:created-at 1412268648681, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "cond->>", :library-url "https://github.com/clojure/clojure"}, :_id "542d8268e4b05f4d257a298f"} {:created-at 1412268658944, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "as->", :library-url "https://github.com/clojure/clojure"}, :_id "542d8272e4b05f4d257a2990"} {:created-at 1412268673788, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "->>", :library-url "https://github.com/clojure/clojure"}, :_id "542d8281e4b05f4d257a2991"}], :line 7584, :examples [{:body "user=> (-> {:a 1} :b inc)\n;; NullPointerException clojure.lang.Numbers.ops (Numbers.java:942)\n\nuser=> (some-> {:a 1} :b inc)\n;; nil\n", :author {:login "boxp", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1819576?v=2"}, :created-at 1412868850592, :updated-at 1412868897594, :editors [{:login "boxp", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1819576?v=2"}], :_id "5436aaf2e4b06dbffbbb00bd"} {:updated-at 1444741522705, :created-at 1444741522705, :author {:login "marick", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/71909?v=3"}, :body ";; Often used to \"short-circuit out\" of a series of steps:\n\n(some-> val\n step1\n step2\n step3)\n\n;; When nil is returned by any step, the further steps are not executed. Thus\n;; the nil case need be handled only once, at the end.", :_id "561d0192e4b084e61c76ecc3"}], :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->"} {:added "1.9", :ns "clojure.core", :name "nat-int?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1495640911419, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "pos-int?", :ns "clojure.core"}, :_id "5925ab4fe4b093ada4d4d72e"} {:created-at 1495640921991, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "neg-int?", :ns "clojure.core"}, :_id "5925ab59e4b093ada4d4d72f"} {:created-at 1495705366734, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "int?", :ns "clojure.core"}, :_id "5926a716e4b093ada4d4d750"}], :line 1420, :examples [{:updated-at 1495030925280, :created-at 1495030925280, :author {:login "larrychristensen", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/2092583?v=3"}, :body "user> (nat-int? 0)\ntrue\nuser> (nat-int? 1)\ntrue\nuser> (nat-int? -1)\nfalse\n;; especially useful for specs\nuser> (require '[clojure.spec :as spec])\nnil\nuser> (spec/def quantity nat-int?)\nuser/quantity\nuser> (spec/def ::quantity nat-int?)\n:user/quantity\nuser> (spec/valid? ::quantity -1)\nfalse", :_id "591c5c8de4b01920063ee060"} {:updated-at 1495703903990, :created-at 1495703903990, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body "(nat-int? 0)\n;;=> true\n(nat-int? 1)\n;;=> true\n(nat-int? 9223372036854775807)\n;;=> true\n\n;;;; false for negative values\n\n(nat-int? -1)\n;;=> false\n\n;;;; false for decimal values\n\n(nat-int? 0.0)\n;;=> false\n(nat-int? 1.0)\n;;=> false\n(nat-int? 1/2)\n;;=> false\n\n;;;; false for BigInt values\n\n(nat-int? 0N)\n;;=> false\n(nat-int? 1N)\n;;=> false\n(nat-int? 9223372036854775808)\n;;=> false", :_id "5926a15fe4b093ada4d4d74d"}], :notes nil, :arglists ["x"], :doc "Return true if x is a non-negative fixed precision integer", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/nat-int_q"} {: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"} {:added "1.0", :ns "clojure.core", :name "ns-interns", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1288055138000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "ns-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ae9"} {:created-at 1298556643000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "ns-publics", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aea"} {:created-at 1348479295000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ns-aliases", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aeb"} {:created-at 1348479323000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ns-refers", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521aec"}], :line 4207, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body "user=> (take 2 (ns-interns `clojure.core))\n([sorted-map #'clojure.core/sorted-map] [read-line #'clojure.core/read-line])\n\nuser=> (take 5 (sort (keys (ns-interns `clojure.java.io))))\n(Coercions IOFactory append? as-file as-relative-path)\n\nuser=> (count (ns-interns `clojure.core)) ; only 621 functions to learn :-)\n621\nuser=>", :created-at 1313988495000, :updated-at 1313988495000, :_id "542692c8c026201cdc3269ea"} {:author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :editors [], :body ";; See also http://clojure.org/namespaces for information on namespaces in Clojure and how to inspect and manipulate them", :created-at 1348479359000, :updated-at 1348479359000, :_id "542692d4c026201cdc327018"}], :notes nil, :arglists ["ns"], :doc "Returns a map of the intern mappings for the namespace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ns-interns"} {:added "1.0", :ns "clojure.core", :name "all-ns", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1516472495588, :author {:login "bkovitz", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/4142015?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ns-name", :ns "clojure.core"}, :_id "5a6388afe4b093a19c35dc09"}], :line 4147, :examples [{:updated-at 1332953063000, :created-at 1281460579000, :body "user=> (all-ns)\n(# # # # # # # # # # # # # # # # # # # # # # # # #)", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692c7c026201cdc326990"} {:updated-at 1516472462629, :created-at 1516472462629, :author {:login "bkovitz", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/4142015?v=4"}, :body ";; The names of all your current namespaces that end in \"-test\":\n\n(->> (all-ns)\n (map ns-name)\n (map name)\n (filter #(clojure.string/ends-with? % \"-test\")))\n;;=> (\"core-test\" \"farg.pmatch-test\")", :_id "5a63888ee4b093a19c35dc08"}], :notes nil, :arglists [""], :doc "Returns a sequence of all namespaces.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/all-ns"} {:ns "clojure.core", :name "find-protocol-method", :file "clojure/core_deftype.clj", :type "function", :column 1, :see-alsos nil, :line 546, :examples nil, :notes nil, :arglists ["protocol methodk x"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/find-protocol-method"} {:added "1.0", :ns "clojure.core", :name "subvec", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1291975197000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vector", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521dee"} {:created-at 1291975205000, :author {:login "alimoeeny", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vector?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521def"}], :line 3818, :examples [{:updated-at 1423278293433, :created-at 1281558954000, :body ";; not supplying 'end' returns vector from 'start' to (count vector)\nuser=> (subvec [1 2 3 4 5 6 7] 2)\n[3 4 5 6 7]\n\n;; supplying 'end' returns vector from 'start' to element (- end 1)\nuser=> (subvec [1 2 3 4 5 6 7] 2 4)\n[3 4]", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"} {:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"} {:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"} {:avatar-url "https://avatars.githubusercontent.com/u/138993?v=3", :account-source "github", :login "Dimagog"}], :author {:avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon", :account-source "clojuredocs", :login "zmila"}, :_id "542692cec026201cdc326d62"} {:editors [{:login "burnall", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1253998?v=3"}], :body ";; Remove one item by index\n\n(let [coll [0 1 2 3 4 5]\n i 3]\n (concat (subvec coll 0 i)\n (subvec coll (inc i))))\n;; => (0 1 2 4 5)", :author {:avatar-url "https://avatars.githubusercontent.com/u/8399149?v=3", :account-source "github", :login "freckletonj"}, :created-at 1476828499701, :updated-at 1485765017826, :_id "58069d53e4b001179b66bdcd"} {:updated-at 1504176183534, :created-at 1503932170688, :author {:login "Sophia-Gold", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/19278114?v=4"}, :body ";; To query the indices of a subvec:\n(def foo (vec (range 10)))\n(def bar (subvec foo 3 7)) \n=> (.start bar)\n3\n=> (.end bar)\n7\n\n;; Increments with repeated slicing:\n(def baz (subvec bar 2))\n=> (.start baz)\n5\n\n;; Return the original vector:\n=> (.v bar)\n[0 1 2 3 4 5 6 7 8 9]\n=> (.v baz)\n[0 1 2 3 4 5 6 7 8 9]", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/19278114?v=4", :account-source "github", :login "Sophia-Gold"}], :_id "59a42f0ae4b09f63b945ac58"} {:updated-at 1573491889014, :created-at 1573491506809, :author {:login "jonathan-chen-tda", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/17070766?v=4"}, :body ";; IndexOutOfBoundsException for bad indices\n=> (subvec [0 1 2 3 4 5] 8 9)\nExecution error (IndexOutOfBoundsException) at ...", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/17070766?v=4", :account-source "github", :login "jonathan-chen-tda"}], :_id "5dc99332e4b0ca44402ef7d7"}], :notes [{:author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :updated-at 1522075347012, :created-at 1522075347012, :body "
\n;; Note that subvec holds a reference to the original vector. If you plan \n;; to split a large vector and never using it again, consider freeing up\n;; the reference.\n\n(let [v1 (subvec (vec (range 1e7)) 0 5)\n v2 (subvec (vec (range 1e7)) 5 10)]\n (into v1 v2))\n;; OutOfMem\n\n(let [v1 (into [] (subvec (vec (range 1e7)) 0 5))\n v2 (into [] (subvec (vec (range 1e7)) 5 10))]\n (into v1 v2))\n;; [0 1 2 3 4 5 6 7 8 9]\n
", :_id "5ab906d3e4b045c27b7fac25"}], :arglists ["v start" "v start end"], :doc "Returns a persistent vector of the items in vector from\n start (inclusive) to end (exclusive). If end is not supplied,\n defaults to (count vector). This operation is O(1) and very fast, as\n the resulting vector shares structure with the original and no\n trimming is done.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/subvec"} {:added "1.0", :ns "clojure.core", :name "for", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1318594692000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "doseq", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c7f"} {:created-at 1338714786000, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "doall", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c80"} {:created-at 1360362825000, :author {:login "ViljamiPeltola", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1535c08820796d57a212a46a6bdd4cca?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "recur", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c81"} {:created-at 1484942509711, :author {:login "bheesham", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/171007?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "range", :ns "clojure.core"}, :_id "58826cade4b09108c8545a5c"} {:created-at 1602104691947, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "let", :ns "clojure.core"}, :_id "5f7e2d73e4b0b1e3652d73cc"} {:created-at 1602104699060, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "when", :ns "clojure.core"}, :_id "5f7e2d7be4b0b1e3652d73cd"}], :line 4624, :examples [{:updated-at 1421257348418, :created-at 1279388402000, :body ";; prepare a seq of the even values \n;; from the first six multiples of three\n(for [x [0 1 2 3 4 5]\n :let [y (* x 3)]\n :when (even? y)]\n y)\n;;=> (0 6 12)\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :_id "542692c7c026201cdc326952"} {:updated-at 1588419699839, :created-at 1279947290000, :body "(def digits [1 2 3])\n\n(for [x1 digits\n x2 digits]\n (* x1 x2))\n;;=> (1 2 3 2 4 6 3 6 9)", :editors [{:avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon", :account-source "clojuredocs", :login "Jacolyte"} {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "YizhePKU", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/42838469?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon", :account-source "clojuredocs", :login "Jacolyte"}, :_id "542692c7c026201cdc326954"} {:updated-at 1588419818008, :created-at 1283713265000, :body ";; produce a seq of all pairs drawn from two vectors\n(for [x ['a 'b 'c] \n y [1 2 3]]\n [x y])\n;;=> ([a 1] [a 2] [a 3] [b 1] [b 2] [b 3] [c 1] [c 2] [c 3])\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "SubhaSingh", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/12873392?v=3"} {:login "YizhePKU", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/42838469?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/4b163432c99a124feee4be046a3f9d66?r=PG&default=identicon", :account-source "clojuredocs", :login "james"}, :_id "542692c7c026201cdc326957"} {:author {:login "james", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4b163432c99a124feee4be046a3f9d66?r=PG&default=identicon"}, :editors [{:login "james", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4b163432c99a124feee4be046a3f9d66?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; produce a seq of the first three powers for a range of integers\n(for [x (range 1 6) \n :let [y (* x x) \n z (* x x x)]] \n [x y z])\n;;=> ([1 1 1] [2 4 8] [3 9 27] [4 16 64] [5 25 125])\n", :created-at 1283713566000, :updated-at 1421257621209, :_id "542692c7c026201cdc326959"} {:updated-at 1588419920709, :created-at 1292101988000, :body ";; produce a seq of squares\n(for [x (range 6)] \n (* x x))\n;;=> (0 1 4 9 16 25)", :editors [{:avatar-url "https://www.gravatar.com/avatar/6ff7e838d2c47adf942be6df4d22b452?r=PG&default=identicon", :account-source "clojuredocs", :login "pashields"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "YizhePKU", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/42838469?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon", :account-source "clojuredocs", :login "alimoeeny"}, :_id "542692c7c026201cdc32695d"} {:author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=2"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; prepare a seq of all keys from entries whose values are 0\n(for [[x y] '([:a 1] [:b 2] [:c 0]) :when (= y 0)] x)\n;;=> (:c)\n", :created-at 1305076075000, :updated-at 1421257745017, :_id "542692c7c026201cdc32695f"} {:author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; Demonstrating performance difference between :when and :while\n\n(time (dorun (for [x (range 1000) y (range 10000) :when (> x y)] [x y])))\n;; \"Elapsed time: 2898.908 msecs\"\n;;=> nil\n\n(time (dorun (for [x (range 1000) y (range 10000) :while (> x y)] [x y])))\n;; \"Elapsed time: 293.677 msecs\"\n;;=> nil\n", :created-at 1338313241000, :updated-at 1421258673026, :_id "542692d3c026201cdc326fa6"} {:author {:login "bzhou", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5ea589e907c3d7da52e3c76924fbe3f7?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body ";; Demonstrating functional difference between :when and :while\n\n(for [x (range 3) y (range 3)] [x y])\n;;=> ([0 0] [0 1] [0 2] \n;; [1 0] [1 1] [1 2]\n;; [2 0] [2 1] [2 2])\n\n(for [x (range 3) y (range 3) :when (not= x y)] [x y])\n;;=> ( [0 1] [0 2] \n;; [1 0] [1 2] \n;; [2 0] [2 1] )\n\n; Here we see the :while applied to the immediately preceding seq\n(for [x (range 3) y (range 3) :while (not= x y)] [x y])\n;;=> ( \n;; [1 0] \n;; [2 0] [2 1] )\n\n;; The placement of the :while is important\n;; :while can cause a halt for a particular sequence\n\n(for [x (range 3) y (range 3) :while (not= x 1)] [x y])\n;;=> ([0 0] [0 1] [0 2] [2 0] [2 1] [2 2])\n\n(for [x (range 3) :while (not= x 1) y (range 3)] [x y])\n;;=> ([0 0] [0 1] [0 2])\n", :created-at 1340260912000, :updated-at 1510266180494, :_id "542692d3c026201cdc326fa7"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; More examples illustrating the difference between :when and :while\n\n;; Simple but inefficient method of checking whether a number is\n;; prime.\nuser=> (defn prime? [n]\n (not-any? zero? (map #(rem n %) (range 2 n))))\n#'user/prime?\n\nuser=> (range 3 33 2)\n(3 5 7 9 11 13 15 17 19 21 23 25 27 29 31)\n\n;; :when continues through the collection even if some have the\n;; condition evaluate to false, like filter\nuser=> (for [x (range 3 33 2) :when (prime? x)]\n x)\n(3 5 7 11 13 17 19 23 29 31)\n\n;; :while stops at the first collection element that evaluates to\n;; false, like take-while\nuser=> (for [x (range 3 33 2) :while (prime? x)]\n x)\n(3 5 7)\n\n;; The examples above can easily be rewritten with filter or\n;; take-while. When you have a for with multiple binding forms, so\n;; that the iteration occurs in a nested fashion, it becomes possible\n;; to write something briefly with 'for' that would be more verbose or\n;; unwieldy with nested filter or take-while expressions.\n\nuser=> (for [x (range 3 17 2) :when (prime? x)\n y (range 3 17 2) :when (prime? y)]\n [x y])\n([ 3 3] [ 3 5] [ 3 7] [ 3 11] [ 3 13]\n [ 5 3] [ 5 5] [ 5 7] [ 5 11] [ 5 13]\n [ 7 3] [ 7 5] [ 7 7] [ 7 11] [ 7 13]\n [11 3] [11 5] [11 7] [11 11] [11 13]\n [13 3] [13 5] [13 7] [13 11] [13 13])\n\nuser=> (for [x (range 3 17 2) :while (prime? x)\n y (range 3 17 2) :while (prime? y)]\n [x y])\n([3 3] [3 5] [3 7]\n [5 3] [5 5] [5 7]\n [7 3] [7 5] [7 7])\n\n;; This example only gives a finite result because of the :while\n;; expressions.\nuser=> (for [x (range) :while (< x 10) \n y (range) :while (<= y x)]\n [x y])\n\n([0 0]\n [1 0] [1 1]\n [2 0] [2 1] [2 2]\n [3 0] [3 1] [3 2] [3 3]\n [4 0] [4 1] [4 2] [4 3] [4 4]\n [5 0] [5 1] [5 2] [5 3] [5 4] [5 5]\n [6 0] [6 1] [6 2] [6 3] [6 4] [6 5] [6 6]\n [7 0] [7 1] [7 2] [7 3] [7 4] [7 5] [7 6] [7 7]\n [8 0] [8 1] [8 2] [8 3] [8 4] [8 5] [8 6] [8 7] [8 8]\n [9 0] [9 1] [9 2] [9 3] [9 4] [9 5] [9 6] [9 7] [9 8] [9 9])\n", :created-at 1345760672000, :updated-at 1345760672000, :_id "542692d3c026201cdc326fa8"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; Here are a couple of examples where the only difference is where\n;; the :while is placed, but it makes a significant difference in the\n;; behavior.\n\n;; When x=2 y=1 is reached, :while (<= x y) evaluates false, so all\n;; further items in the y collection are skipped. When x=3 y=1 is\n;; reached, the same thing happens.\n\nuser=> (for [x [1 2 3]\n y [1 2 3]\n :while (<= x y)\n z [1 2 3]]\n [x y z])\n([1 1 1] [1 1 2] [1 1 3]\n [1 2 1] [1 2 2] [1 2 3]\n [1 3 1] [1 3 2] [1 3 3])\n\n;; This is different. When x=2 y=1 z=1 is reached, :while (<= x y)\n;; evaluates false, but since the :while is after the binding for z,\n;; all further items in the z collection are skipped. Then x=2 y=2\n;; z=1 is tried, where the while expresssion evaluates true.\n\nuser=> (for [x [1 2 3]\n y [1 2 3]\n z [1 2 3]\n :while (<= x y)]\n [x y z])\n([1 1 1] [1 1 2] [1 1 3]\n [1 2 1] [1 2 2] [1 2 3]\n [1 3 1] [1 3 2] [1 3 3]\n [2 2 1] [2 2 2] [2 2 3]\n [2 3 1] [2 3 2] [2 3 3]\n [3 3 1] [3 3 2] [3 3 3])\n", :created-at 1345760698000, :updated-at 1345760698000, :_id "542692d3c026201cdc326fa9"} {:author {:login "octopusgrabbus", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon"}, :editors [], :body "(defn all-files-present?\n\"Takes a list of real file names, and returns a map of files present 1\nand not present 0.\"\n[file-seq]\n(for [fnam file-seq\n :let [stat-map {(keyword fnam) (look-for fnam \"f\")}]]\n stat-map))\n\n(into {} (all-files-present? '(\"Makefile\" \"build.sh\" \"real-estate.csv\")))\n\n{:Makefile 1, :build.sh 1, :real-estate.csv 0}", :created-at 1356651292000, :updated-at 1356651292000, :_id "542692d3c026201cdc326faa"} {:editors [{:login "alvarogarcia7", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4199136?v=3"}], :updated-at 1456570106848, :created-at 1425980108716, :author {:avatar-url "https://avatars.githubusercontent.com/u/6026368?v=3", :account-source "github", :login "m-combinator"}, :body ";; Flattening a seq of pairs using for comprehensions\n\n(def pairs (for [i (range 10)] [i (inc i)]))\n;; ([0 1] [1 2] [2 3] [3 4] [4 5] [5 6] [6 7] [7 8] [8 9] [9 10])\n\n(def flattened (for [pair pairs element pair] element))\n;; (0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10)", :_id "54febacce4b0b716de7a6536"} {:editors [{:login "colorgmi", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/9025191?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/4199136?v=3", :account-source "github", :login "alvarogarcia7"} {:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=3"}], :body ";; Given an array of integers, return indices of the two numbers such that they \n;; add up to a specific target.\n\n;; You may assume that each input would have exactly one solution.\n;; Given nums = [2, 7, 11, 15], target = 9,\n\n;; Because nums[0] + nums[1] = 2 + 7 = 9,\n;; return [0, 1].\n\n(defn two-sum [nums target]\n (let [nums-index (zipmap nums (range))\n indexs (for [[x i] nums-index\n [y j] nums-index\n :when (< i j)\n :when (= (+ x y) target)]\n [i j])]\n (first indexs)))\n\n(two-sum [2 7 11 15] 9)\n;; [0 1]\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/9025191?v=3", :account-source "github", :login "colorgmi"}, :created-at 1455449257369, :updated-at 1460403168325, :_id "56c064a9e4b060004fc217c4"} {:updated-at 1494499956872, :created-at 1494499956872, :author {:login "abhilater", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1904958?v=3"}, :body ";;; Cartesian products of two sets\n\n(#(set\n (for[x %1, y %2]\n [x y])) #{1 2 3} #{4 5})\n\n;=> #{[2 5] [3 4] [1 4] [1 5] [2 4] [3 5]}", :_id "59144274e4b01f4add58feb5"} {:updated-at 1506265801327, :created-at 1506265801327, :author {:login "cuspymd", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/8870299?v=4"}, :body ";; Nested 'for' example to produce indexes of Two-dimensional array\n(for [i (range 3)]\n (for [j (range 3)]\n [i j]))\n\n;=> (([0 0] [0 1] [0 2]) \n; ([1 0] [1 1] [1 2]) \n; ([2 0] [2 1] [2 2]))", :_id "59c7cac9e4b03026fe14ea49"} {:updated-at 1626035981287, :created-at 1626035981287, :author {:login "jr0cket", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/250870?v=4"}, :body ";; Generate the hiccup for a collection of books, each book has unique details defined in each hash-map inside the collection.\n;; Destructure the keys in the hash-map for each book in turn\n\n(def practicalli-book-list\n [{:title \"Practicalli Spacemacs\"\n :url \"https://practical.li/spacemacs\"\n :image \"/practicalli-spacemacs-book-banner.png\"\n :description \"Coding Clojure with Emacs and Vim multi-modal editing\"}\n {:title \"Practicalli Clojure\"\n :url \"https://practical.li/clojure\"\n :image \"/practicalli-clojure-book-banner.png\"\n :description \"Learn the Clojure language through REPL driven development\"}])\n\n(defn books-list\n [books]\n (for [{:keys [title description url image]} books]\n [:div {:class \"column\"}\n [:a {:href url :target \"_blank\"}\n [:img {:src image}]]\n [:p [:a {:href url :target \"_blank\" }\n title]\n description]]))\n\n(book-list practicalli-book-list)\n;; => [:div {:class \"box\"} [:div {:class \"column\"} [:h2 {:class \"title has-text-centered\"} \"Freely available online books\"]] nil ([:div {:class \"column\"} [:div {:class \"columns\"} [:div {:class \"column\"} [:a {:href \"https://practical.li/spacemacs\", :target \"_blank\"} [:figure {:class \"image\"} [:img {:src \"/practicalli-spacemacs-book-banner.png\"}]]]] [:div {:class \"column\"} [:p [:a {:href \"https://practical.li/spacemacs\", :target \"_blank\", :class \"has-text-weight-bold\"} \"Practicalli Spacemacs\"] \"Emacs and Vim multi-modal editing\"]]]] [:div {:class \"column\"} [:div {:class \"columns\"} [:div {:class \"column\"} [:a {:href \"https://practical.li/clojure\", :target \"_blank\"} [:figure {:class \"image\"} [:img {:src \"/practicalli-clojure-book-banner.png\"}]]]] [:div {:class \"column\"} [:p [:a {:href \"https://practical.li/clojure\", :target \"_blank\", :class \"has-text-weight-bold\"} \"Practicalli Clojure\"] \"Learn the Clojure language through REPL driven development\"]]]])]\n", :_id "60eb570de4b0b1e3652d7516"} {:updated-at 1652121747673, :created-at 1652121747673, :author {:login "vipermark7", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/9751748?v=4"}, :body ";; Easy iteration through nested vectors\n\n(def matrix \n [[\"a\" \"b\"] [\"c\" \"d\"]])\n\n(for [row matrix letter row] \n letter)\n\n;; (\"a\" \"b\" \"c\" \"d\")", :_id "62796093e4b0b1e3652d75ed"}], :macro true, :notes [{:updated-at 1279948874000, :body "My English parser was choking on the description of this function.\r\n\r\n[This SO question](http://stackoverflow.com/questions/3322552/how-do-i-multiply-all-elements-in-one-collection-with-all-the-elements-in-another) has helped clarify how this function works.", :created-at 1279948874000, :author {:login "Jacolyte", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f87"} {:updated-at 1279949964000, :body "Example 1 can be rewritten without using the for macro. Pure functional should be preferred if possible:\r\n
", :created-at 1279949964000, :author {:login "juergenhoetzel", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2736dfffc803c704dcf25b45ff63cede?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f88"} {:updated-at 1313975247000, :body "On juergenhoetzel's comment:\r\n\r\nAll the examples could be re-written in some combination of map and filter, but they are still valid examples of using the for comprehension, AFAIK:\r\n\r\nExamples:\r\n
\r\n\r\n", :created-at 1313973784000, :author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fc7"} {:updated-at 1356553692000, :body "Take careful note of the description's wording:\r\n\r\n binding-form/collection-expr pairs, \r\n each followed by zero or more modifiers\r\n\r\nA consequence is that the binding list may *not* begin with a modifier, i.e a `:let`, `:when` or `:while`!\r\n\r\nThe following example is **illegal** syntax:\r\n\r\n (for [:let [a 1] b (range 5)] \r\n {a b})\r\n\r\nWhile it might sometimes be convenient to start a `for` with a `:let` to reduce code clutter, the \"correct\" procedure is to nest the `for` in a \"proper\" `let`, like this:\r\n\r\n (let [a 1]\r\n (for [b (range 5)] \r\n {a b}))\r\n\r\nSimilarly, a `:when` is better represented by nesting in an `if`.\r\n\r\n", :created-at 1356553540000, :author {:login "csmotricz", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/6c620615dfb537dbd5325380bd2eaa07?r=PG&default=identicon"}, :_id "542692edf6e94c6970521ffa"} {:updated-at 1375377539000, :body "The fifth example should probably be shown in first position, it's the most straightforward and readable for a beginner : \r\n\r\n(for [x (range 3 7)] (* x x))", :created-at 1375377539000, :author {:login "Joan Charmant", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/75a5fdba1a164425d43d3b9c4b830287?r=PG&default=identicon"}, :_id "542692edf6e94c6970522009"} {:updated-at 1395006875000, :body "\"**Sequence** comprehension\", not \"list comprehension\". ", :created-at 1395006875000, :author {:login "Thumbnail", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/db68e51797a2382e185b42ce6534b7a4?r=PG&default=identicon"}, :_id "542692edf6e94c6970522021"}], :arglists ["seq-exprs body-expr"], :doc "List comprehension. Takes a vector of one or more\n binding-form/collection-expr pairs, each followed by zero or more\n modifiers, and yields a lazy sequence of evaluations of expr.\n Collections are iterated in a nested fashion, rightmost fastest,\n and nested coll-exprs can refer to bindings created in prior\n binding-forms. Supported modifiers are: :let [binding-form expr ...],\n :while test, :when test.\n\n (take 100 (for [x (range 100000000) y (range 1000000) :while (< y x)] [x y]))", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/for"} {:added "1.0", :ns "clojure.core", :name "binding", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1322088130000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-redefs", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e9a"} {:created-at 1374313487000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-bindings", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e9b"} {:created-at 1374512208000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-local-vars", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e9c"} {:created-at 1425742740372, :author {:login "kimtg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7685905?v=3"}, :to-var {:ns "clojure.core", :name "def", :library-url "https://github.com/clojure/clojure"}, :_id "54fb1b94e4b01ed96c93c886"}], :line 1947, :examples [{:author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :editors [{:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body ";; 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", :created-at 1281546900000, :updated-at 1287628874000, :_id "542692cfc026201cdc326e66"} {:updated-at 1579643060326, :created-at 1321652674000, :body ";; 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", :editors [{:login "dijonkitchen", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/cab456ee2c30d86ce89400390ad812c6?r=PG&default=identicon", :account-source "clojuredocs", :login "onlyafly"}, :_id "542692d2c026201cdc326f54"} {:author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :editors [{:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}], :body ";;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", :created-at 1326330032000, :updated-at 1326330097000, :_id "542692d2c026201cdc326f55"} {:body "; 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...", :author {:login "kimtg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7685905?v=3"}, :created-at 1425741813941, :updated-at 1546186846359, :editors [{:login "kimtg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7685905?v=3"} {:avatar-url "https://avatars2.githubusercontent.com/u/4270240?v=4", :account-source "github", :login "peter-kehl"} {:login "green-coder", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4"}], :_id "54fb17f5e4b01ed96c93c883"} {:body "; 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", :author {:login "kimtg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7685905?v=3"}, :created-at 1425742394706, :updated-at 1425747333974, :editors [{:login "kimtg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7685905?v=3"}], :_id "54fb1a3ae4b0b716de7a6534"} {:editors [{:login "coldnew", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/39703?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3", :account-source "github", :login "bkovitz"}], :body ";; 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]", :author {:avatar-url "https://avatars.githubusercontent.com/u/39703?v=3", :account-source "github", :login "coldnew"}, :created-at 1446002313487, :updated-at 1461711689159, :_id "56303e89e4b0290a56055d15"} {:editors [{:login "tizac", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1741276?v=3"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/1741276?v=3", :account-source "github", :login "tizac"}, :created-at 1463969516607, :updated-at 1463969570676, :_id "574266ece4b0a1a06bdee498"} {:updated-at 1468290506436, :created-at 1468290319127, :author {:login "eyelidlessness", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/199830?v=3"}, :body ";; 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.", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/199830?v=3", :account-source "github", :login "eyelidlessness"}], :_id "5784550fe4b0bafd3e2a049e"} {:updated-at 1556458271939, :created-at 1556458271939, :author {:login "Hindol", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/705227?v=4"}, :body ";; 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", :_id "5cc5ab1fe4b0ca44402ef712"} {:updated-at 1565050473837, :created-at 1565050473837, :author {:login "stribb", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/7216352?v=4"}, :body ";; 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", :_id "5d48c669e4b0ca44402ef791"} {:editors [{:login "PEZ", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/30010?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/30010?v=4", :account-source "github", :login "PEZ"}, :created-at 1618243197010, :updated-at 1618346238324, :_id "60746e7de4b0b1e3652d74c4"}], :macro true, :notes [{:updated-at 1409723156000, :body "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?", :created-at 1409723015000, :author {:login "fordsfords", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ab6989cb3f3a81269d91a003d45dab25?r=PG&default=identicon"}, :_id "542692edf6e94c697052202f"} {:author {:login "NeedMoreDesu", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/3812527?v=4"}, :updated-at 1509569062961, :created-at 1509569062961, :body "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).", :_id "59fa3226e4b0a08026c48c8c"} {:author {:login "finalfantasia", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2316604?v=4"}, :updated-at 1677133081409, :created-at 1677133058906, :body "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`.", :_id "63f70502e4b08cf8563f4b72"}], :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"} {:added "1.0", :ns "clojure.core", :name "partial", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1358904778000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "comp", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ccb"} {:created-at 1358904783000, :author {:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "juxt", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ccc"} {:created-at 1598161159341, :author {:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "apply", :ns "clojure.core"}, :_id "5f420107e4b0b1e3652d739e"}], :line 2614, :examples [{:author {:login "nipra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/142529?v=3"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "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", :created-at 1279053300000, :updated-at 1285501907000, :_id "542692cdc026201cdc326ceb"} {:author {:login "nipra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/142529?v=3"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}], :body "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", :created-at 1279053544000, :updated-at 1310120171000, :_id "542692cdc026201cdc326cee"} {:author {:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"}, :editors [{:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"} {:login "philos99", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1de5617efb013ca7c9cf8e5646818ffa?r=PG&default=identicon"}], :body "(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", :created-at 1317743830000, :updated-at 1318431084000, :_id "542692d4c026201cdc327023"} {:author {:login "mihirmp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a8fd3b9768ad2d1fe09405348276705c?r=PG&default=identicon"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7412474?v=3", :account-source "github", :login "Lacty"} {:login "pbalduino", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/32979?v=4"}], :body "; 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", :created-at 1339255851000, :updated-at 1575656058223, :_id "542692d4c026201cdc327026"} {:updated-at 1440758720254, :created-at 1440758720254, :author {:login "ftravers", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/443507?v=3"}, :body "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", :_id "55e03bc0e4b072d7f27980f2"} {:editors [{:login "liango2", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5696817?v=3"}], :body ";;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=>", :author {:avatar-url "https://avatars.githubusercontent.com/u/5696817?v=3", :account-source "github", :login "liango2"}, :created-at 1451241930491, :updated-at 1451242239728, :_id "568031cae4b0e0706e05bd8c"} {:updated-at 1470796972437, :created-at 1470796972437, :author {:login "gosukiwi", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/161972?v=3"}, :body "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", :_id "57aa94ace4b0bafd3e2a04d7"} {:editors [{:login "Lacty", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7412474?v=3"}], :body "(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", :author {:avatar-url "https://avatars.githubusercontent.com/u/7412474?v=3", :account-source "github", :login "Lacty"}, :created-at 1470811578410, :updated-at 1470811725631, :_id "57aacdbae4b0bafd3e2a04d8"} {:updated-at 1484410971744, :created-at 1484410971744, :author {:login "codxse", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/5813694?v=3"}, :body ";; 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", :_id "587a505be4b09108c8545a5a"} {:updated-at 1494497949851, :created-at 1494497949851, :author {:login "abhilater", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1904958?v=3"}, :body ";; 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]", :_id "59143a9de4b01f4add58feb4"} {:updated-at 1517160889010, :created-at 1517160889010, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;practical example\n\n(def add-domain\n (partial (str \"@clojure.com\")))\n\n(str \"info\" add-domain )\n;;\"info@clojure.com\"", :_id "5a6e09b9e4b0c974fee49d11"} {:updated-at 1518786294793, :created-at 1518786294793, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body "(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\"", :_id "5a86d6f6e4b0316c0f44f8c7"} {:updated-at 1556081366466, :created-at 1556081366466, :author {:login "Hindol", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/705227?v=4"}, :body ";; 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", :_id "5cbfead6e4b0ca44402ef70f"} {:updated-at 1580488372127, :created-at 1580488372127, :author {:login "sulami", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/1843193?v=4"}, :body ";; 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\"", :_id "5e3456b4e4b0ca44402ef82a"} {:editors [{:login "jvw-git", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/3646688?v=4"}], :body ";; 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.", :author {:avatar-url "https://avatars0.githubusercontent.com/u/3646688?v=4", :account-source "github", :login "jvw-git"}, :created-at 1596472064570, :updated-at 1596697721148, :_id "5f283b00e4b0b1e3652d7331"}], :notes [{:updated-at 1385283247000, :body "This function implements the concept of “[currying](http://en.wikipedia.org/wiki/Currying)â€�.", :created-at 1385283247000, :author {:login "roryokane", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5b2b185c814bb25f2f95a1152e58f033?r=PG&default=identicon"}, :_id "542692edf6e94c697052200e"}], :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"} {:ns "clojure.core", :name "chunked-seq?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1443935187252, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk", :ns "clojure.core"}, :_id "5610b3d3e4b08e404b6c1c97"} {:created-at 1443935201452, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk-first", :ns "clojure.core"}, :_id "5610b3e1e4b08e404b6c1c98"} {:created-at 1443935208310, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk-rest", :ns "clojure.core"}, :_id "5610b3e8e4b08e404b6c1c99"} {:created-at 1443935214143, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk-buffer", :ns "clojure.core"}, :_id "5610b3eee4b0686557fcbd46"} {:created-at 1443935221866, :author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "chunk-next", :ns "clojure.core"}, :_id "5610b3f5e4b0686557fcbd47"}], :line 715, :examples [{:updated-at 1335431382000, :created-at 1335431382000, :body "user=> (chunked-seq? (range 1000))\nfalse\n\nuser=> (chunked-seq? (seq (range 1000)))\ntrue\n\nuser=> (chunked-seq? (iterate inc 10))\nfalse\n\nuser=> (chunked-seq? (seq (iterate inc 10)))\nfalse", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d2c026201cdc326f60"}], :notes nil, :arglists ["s"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/chunked-seq_q"} {:added "1.3", :ns "clojure.core", :name "find-keyword", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1430167074779, :author {:login "ljosa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/197881?v=3"}, :to-var {:ns "clojure.core", :name "keyword", :library-url "https://github.com/clojure/clojure"}, :_id "553e9e22e4b01bb732af0a88"} {:created-at 1430167092343, :author {:login "ljosa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/197881?v=3"}, :to-var {:ns "clojure.core", :name "name", :library-url "https://github.com/clojure/clojure"}, :_id "553e9e34e4b01bb732af0a89"} {:created-at 1430167188442, :author {:login "ljosa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/197881?v=3"}, :to-var {:ns "clojure.core", :name "keyword?", :library-url "https://github.com/clojure/clojure"}, :_id "553e9e94e4b06eaacc9cda7d"} {:created-at 1430167194731, :author {:login "ljosa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/197881?v=3"}, :to-var {:ns "clojure.core", :name "symbol", :library-url "https://github.com/clojure/clojure"}, :_id "553e9e9ae4b01bb732af0a8a"} {:created-at 1430167201482, :author {:login "ljosa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/197881?v=3"}, :to-var {:ns "clojure.core", :name "intern", :library-url "https://github.com/clojure/clojure"}, :_id "553e9ea1e4b06eaacc9cda7e"}], :line 625, :examples [{:body "user=> (find-keyword \"a\")\nnil\nuser=> :a\n:a\nuser=> (find-keyword \"a\")\n:a", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1422932628869, :updated-at 1422932628869, :_id "54d03a94e4b081e022073c45"}], :notes nil, :tag "clojure.lang.Keyword", :arglists ["name" "ns name"], :doc "Returns a Keyword with the given namespace and name if one already\n exists. This function will not intern a new keyword. If the keyword\n has not already been interned, it will return nil. Do not use :\n in the keyword strings, it will be added automatically.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/find-keyword"} {:added "1.0", :ns "clojure.core", :name "replicate", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1385848235000, :author {:login "Alexey Tarasevich", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/43e0398b89022d32b43de4c968069312?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "repeat", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d08"}], :line 3006, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (apply str (replicate 7 \\space))\n ; 7 spaces\n\nuser=> (replicate 7 (rand-int 10))\n(3 3 3 3 3 3 3) ; the same number", :created-at 1281549294000, :updated-at 1332950215000, :_id "542692c9c026201cdc326a82"}], :deprecated "1.3", :notes [{:updated-at 1281553461000, :body "Note that `replicate` is obsolete. It's functionality is now available via the two-arg arity form of [`repeat`](http://clojuredocs.org/v/1578).", :created-at 1281553461000, :author {:login "kotarak", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5db30f607f0b5fa70d690311aa3bfd3b?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f94"}], :arglists ["n x"], :doc "DEPRECATED: Use 'repeat' instead.\n Returns a lazy seq of n xs.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/replicate"} {:added "1.0", :ns "clojure.core", :name "min-key", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1371841141000, :author {:login "adereth", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5ad11b4e208a6cdb3bd45fe01dea59b7?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "min", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521df4"} {:created-at 1371841145000, :author {:login "adereth", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5ad11b4e208a6cdb3bd45fe01dea59b7?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "max-key", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521df5"}], :line 5009, :examples [{:updated-at 1672874240930, :created-at 1280009320000, :body ";; we have a list of key colours\n;; We want to find the one closest to a supplied colour\n;; We're storing rgb values as [r g b]\n;; use min-key to find colour that minimizes \n;; the euclidean distance between the supplied colour \n;; and each key colour\n;; thanks to rhudson, raek and mfex on #clojure\n\n(defn distance-squared\n \"Euclidean distance between two collections considered as coordinates\"\n [c1 c2]\n (->> (map - c1 c2) (map #(* % %)) (reduce +)))\n\n(def key-colours\n {[224 41 224] :purple\n [24 180 46] :green\n [12 129 245] :blue\n [254 232 23] :yellow\n [233 233 233] :white\n [245 27 55] :red\n [231 119 41] :orange\n })\n\n(defn rgb-to-key-colour\n \"Find colour in colour map closest to the supplied [r g b] triple\"\n [rgb-triple colour-map]\n (colour-map\n (apply min-key (partial distance-squared rgb-triple) (keys colour-map))))\n\nuser=> (rgb-to-key-colour [255 0 0] key-colours)\n:red\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:login "jimberry1", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/73443103?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/583358786e336bb14a400ca17722ec3b?r=PG&default=identicon", :account-source "clojuredocs", :login "lozh"}, :_id "542692ccc026201cdc326ca7"} {:author {:login "jamesqiu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc1268deaa7f2e78fe2b5ea76e6481d8?r=PG&default=identicon"}, :editors [{:login "jamesqiu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc1268deaa7f2e78fe2b5ea76e6481d8?r=PG&default=identicon"}], :body "; \"min-key\"/\"max-key\" to \"min\"/\"max\" like \"sort-by\" to \"sort\"\n(min-key #(Math/abs %) -3 1 4)\n; 1\n\n(apply min-key #(Math/abs %) [-3 1 4])\n; 1\n", :created-at 1311522786000, :updated-at 1328006403000, :_id "542692ccc026201cdc326ca9"} {:updated-at 1593445838944, :created-at 1593445838944, :author {:login "guillaume", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/368?v=4"}, :body "user=> (min-key second [\"Jon\" 1] [\"Rich\" 6] [\"Nancy\" 3])\n[\"Jon\" 1]", :_id "5efa0dcee4b0b1e3652d731a"}], :notes nil, :arglists ["k x" "k x y" "k x y & more"], :doc "Returns the x for which (k x), a number, is least.\n\n If there are multiple such xs, the last one is returned.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/min-key"} {:added "1.5", :ns "clojure.core", :name "reduced", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1416151548299, :author {:login "ljos", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/585174?v=2"}, :to-var {:ns "clojure.core", :name "reduce", :library-url "https://github.com/clojure/clojure"}, :_id "5468c1fce4b0dc573b892fd4"} {:created-at 1416151556515, :author {:login "ljos", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/585174?v=2"}, :to-var {:ns "clojure.core", :name "reduced?", :library-url "https://github.com/clojure/clojure"}, :_id "5468c204e4b03d20a10242ab"} {:created-at 1456683943617, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unreduced", :ns "clojure.core"}, :_id "56d33ba7e4b02a6769b5a4ba"} {:created-at 1464286469066, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ensure-reduced", :ns "clojure.core"}, :_id "57473d05e4b0af2c9436d1f3"}], :line 2836, :examples [{:body ";; Suppose you want to short-circuit a sum like:\n(reduce (fn [a v] (+ a v)) (range 10))\n;;=> 45\n\n;; So that it returns the sum of the integers if less than 100:\n(reduce (fn [a v] (if (< a 100) (+ a v) (reduced :big))) (range 10))\n;;=> 45\n\n;; But the keyword :big otherwise:\n(reduce (fn [a v] (if (< a 100) (+ a v) (reduced :big))) (range 20))\n;;=> :big\n\n;; The value returned by (reduced :big) short-circuits the reduction so that \n;; it returns the wrapped value without ranging over the entire sequence.\n;; This is useful for infinite lazy sequences:\n(reduce (fn [a v] (if (< a 100) (+ a v) (reduced :big))) (range))\n;;=>:big\n\n;; Which would otherwise not terminate.", :author {:login "silasdavis", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/99715?v=2"}, :created-at 1412246795536, :updated-at 1495285680591, :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/4996067?v=3", :account-source "github", :login "matanster"}], :_id "542d2d0be4b05f4d257a2985"} {:updated-at 1516387837196, :created-at 1447889898907, :author {:login "teymuri", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/13352033?v=3"}, :body ";;re-implementing (some) using (reduce) and (reduced):\n\n(defn resome [pred koll]\n (reduce (fn [_ c] (when-let [x (pred c)] (reduced x)))\n nil koll))\n\n;;user> (resome #{4} [3 4 2 3 2])\n;;>>> 4\n;;user> (resome even? [3 41 25 3 2])\n;;>>> true\n;;user> (resome even? [3 41 25 3 27])\n;;>>> nil", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/13352033?v=3", :account-source "github", :login "teymuri"} {:login "functor-soup", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6382230?v=3"} {:avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4", :account-source "github", :login "bfontaine"} {:login "featheredtoast", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1322534?v=4"}], :_id "564d0beae4b0be225c0c4795"} {:updated-at 1545247173119, :created-at 1545247173119, :author {:login "TravisHeppner", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/9536486?v=4"}, :body ";;note the return from f must be from reduced for reduce to terminate early.\n\n;;no early termination as the return of f is nil\n(reduce (fn f [a b]\n (when (> b 2)\n (reduced \"Done early!\"))\n (println b)) [1 2 3 4 5])\n;;2\n;;3\n;;4\n;;5\n;;=> nil\n\n;;early termination as the return of f is \"Done early!\" wrapped in a reduce object.\n(reduce (fn f [a b]\n (if (> b 2)\n (reduced \"Done early!\")\n (println b))) [1 2 3 4 5])\n;;2\n;;=> \"Done early!\"", :_id "5c1a99c5e4b0ca44402ef5ee"}], :notes nil, :arglists ["x"], :doc "Wraps x in a way such that a reduce will terminate with the value x", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/reduced"} {:added "1.0", :ns "clojure.core", :name "char-escape-string", :file "clojure/core_print.clj", :type "var", :column 1, :see-alsos [{:created-at 1375209851000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "char-name-string", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cd9"} {:created-at 1534950301941, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "escape", :ns "clojure.string"}, :_id "5b7d7b9de4b00ac801ed9e6b"}], :line 200, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; 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=>", :created-at 1313928437000, :updated-at 1313928437000, :_id "542692c7c026201cdc3269b6"} {:updated-at 1534950256834, :created-at 1534950256834, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body "(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'", :_id "5b7d7b70e4b00ac801ed9e6a"}], :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"} {:added "1.0", :ns "clojure.core", :name "re-matches", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1324028223000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "re-find", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d06"} {:created-at 1379040151000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "subs", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d07"} {:created-at 1432238328876, :author {:login "bobpoekert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/45596?v=3"}, :to-var {:ns "clojure.core", :name "re-groups", :library-url "https://github.com/clojure/clojure"}, :_id "555e38f8e4b01ad59b65f4d9"} {:created-at 1521975114344, :author {:login "witek", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/209520?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "re-pattern", :ns "clojure.core"}, :_id "5ab77f4ae4b045c27b7fac24"}], :line 4886, :examples [{:author {:login "ysph", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/eed512f3595f1baa31fd91f3b297ebbf?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body ";; The distinction is that re-find tries to find _any part_ of the string\n;; that matches the pattern, but re-matches only matches if the _entire_\n;; string matches the pattern.\nuser=> (re-matches #\"hello\" \"hello, world\")\nnil\n\nuser=> (re-matches #\"hello.*\" \"hello, world\")\n\"hello, world\"\n\nuser=> (re-matches #\"hello, (.*)\" \"hello, world\")\n[\"hello, world\" \"world\"]\n", :created-at 1294394717000, :updated-at 1324028606000, :_id "542692c8c026201cdc3269eb"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; 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.", :created-at 1379040148000, :updated-at 1379040148000, :_id "542692d4c026201cdc32704f"} {:author {:login "cloojure", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon"}, :editors [{:login "cloojure", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon"} {:login "cloojure", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon"} {:login "cloojure", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ad3de25d00d953de6e8c82f554cdbf5?r=PG&default=identicon"}], :body "; Regex match flags can be embedded in the regex string. So, we can convert the normal case-sensitive matching into case-insensitive matching.\n\nuser=> (re-matches #\"hello\" \"HELLO\") ; case-sensitive\nnil\n\nuser=> (re-matches #\"(?i)hello\" \"hello\") ; case-insensitive\n\"hello\"\nuser=> (re-matches #\"(?i)hello\" \"HELLO\") ; case-insensitive\n\"HELLO\"\nuser=> (re-matches #\"(?i)HELLO\" \"heLLo\") ; case-insensitive\n\"heLLo\"\n", :created-at 1399524098000, :updated-at 1399524286000, :_id "542692d4c026201cdc327050"}], :notes [{:author {:login "caumond", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/11491686?v=4"}, :updated-at 1615713542191, :created-at 1615713542191, :body "Here is the [java official documentation](https://docs.oracle.com/en/java/javase/15/docs/api/java.base/java/util/regex/Pattern.html) for pattern specifications", :_id "604dd506e4b0b1e3652d748e"}], :arglists ["re s"], :doc "Returns the match, if any, of string to pattern, using\n java.util.regex.Matcher.matches(). Uses re-groups to return the\n groups.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/re-matches"} {:added "1.0", :ns "clojure.core", :name "array-map", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1283650361000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "assoc", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c4c"} {:created-at 1397668962000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "hash-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c4d"} {:created-at 1397668975000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "sorted-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c4e"}], :line 4379, :examples [{:author {:login "Jacolyte", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (array-map [1 2] [3 4 5])\n{[1 2] [3 4 5]}", :created-at 1280205415000, :updated-at 1332949878000, :_id "542692cec026201cdc326d8c"} {:author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :editors [{:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"} {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (array-map :a 10)\n{:a 10}\n\nuser=> (array-map :a 10 :b 20)\n{:a 10 :b 20}\n\nuser=> (apply array-map [:a 10 :b 20 :c 30])\n{:a 10 :b 20 :c 30}\n\nuser=> (apply assoc {} [:a 10 :b 20 :c 30]) ;same result using assoc\n{:a 10 :b 20 :c 30}\n", :created-at 1283649638000, :updated-at 1285492106000, :_id "542692cec026201cdc326d8e"} {:updated-at 1463365462869, :created-at 1303524077000, :body "user=> (keys (assoc (array-map :foo 10 :bar 20) :baz 30))\n(:baz :foo :bar)\n; baz is first; :foo and :bar follow the order given to array-map\n\n\n;; My results have consistently been different from what's listed above.\nuser=> (keys (assoc (array-map :foo 10 :bar 20) :baz 30))\n; => (:foo :bar :baz)\nuser=> (assoc (array-map :foo 10 :bar 20) :baz 30)\n; => {:foo 10, :bar 20, :baz 30}\nuser=> *clojure-version*\n; => {:major 1, :minor 8, :incremental 0, :qualifier nil}\n;; As long as I have an array map, new items get added to the end, not\n;; the beginning.", :editors [{:login "TradeIdeasPhilip", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/18409827?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon", :account-source "clojuredocs", :login "steveminer"}, :_id "542692cec026201cdc326d93"} {:updated-at 1463365157869, :created-at 1463365157869, :author {:login "TradeIdeasPhilip", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/18409827?v=3"}, :body ";; Sometimes Clojure will automatically choose between a hash map and\n;; an array map. What's the rule? Let's try a few experiments.\n\n;; Start with a quick way to make a map with N items.\nuser=> (defn make-map [count] (zipmap (range count) (range count)))\n;; => #'user/make-map\nuser=> (make-map 3)\n;; => {0 0, 1 1, 2 2}\n\n;; Try a few maps. The cutoff seems to be 9.5. If you have fewer than\n;; 9.5 items you get an array map. If you have more than 9.5 items you\n;; get a hash map.\nuser=> (type (make-map 8))\n;; => clojure.lang.PersistentArrayMap\nuser=> (type (make-map 9))\n;; => clojure.lang.PersistentArrayMap\nuser=> (type (make-map 10))\n;; => clojure.lang.PersistentHashMap\nuser=> (type (make-map 11))\n;; => clojure.lang.PersistentHashMap\n\n;; Using assoc we get similar results. 9 or fewer items yields an array\n;; map. 10 or more yields a hash map.\nuser=> (type (assoc (make-map 9) :x 1)) ; 10 items -> hash map.\n;; => clojure.lang.PersistentHashMap\nuser=> (type (assoc (make-map 8) :x 1)) ; 9 items -> array map.\n;; => clojure.lang.PersistentArrayMap\nuser=> (type (assoc (make-map 8) :x 1 :y 2)) ; 10 items -> hash map.\n;; => clojure.lang.PersistentHashMap\nuser=> (type (assoc (assoc (make-map 8) :x 1) :y 2)) ; 10 items -> hash map.\n;; => clojure.lang.PersistentHashMap\n\n;; But when we use { and } to create a map, the cutoff seems to move to 8.5.\n;; A map with 9 items created with assoc or zipmap would be an array map,\n;; but a map with 9 items created by { } is a hash map.\nuser=> (type {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7}) ; 8 items -> array map.\n;; => clojure.lang.PersistentArrayMap\nuser=> (type {0 0, 1 1, 2 2, 3 3, 4 4, 5 5, 6 6, 7 7, 8 8}) ; 9 items -> hash\n;; => clojure.lang.PersistentHashMap\n\n;; Calling dissoc on an array map always yields an array map, regardless of\n;; the size of the map.\n;; Let's start by making a large array map then remove a few items. This will\n;; give us array maps larger than you could create with assoc.\nuser=> (def array20 (apply array-map (range 40)))\n;; => #'user/array20\nuser=> (type array20)\n;; => clojure.lang.PersistentArrayMap\nuser=> (type (dissoc array20 6))\n;; => clojure.lang.PersistentArrayMap\nuser=> (count (dissoc array20 6))\n;; => 19\nuser=> (type (dissoc array20 6 2))\n;; => clojure.lang.PersistentArrayMap\nuser=> (count (dissoc array20 6 2))\n;; => 18\n\n;; Calling dissoc on a hash map always yields another hash map, regardless\n;; of the size of the map.\n;; Let's start by making a large hash map then remove a lot of items. This\n;; will give us hash maps smaller than you could create with assoc.\nuser=> (type (make-map 40))\n;; => clojure.lang.PersistentHashMap\nuser=> (type (apply dissoc (make-map 40) (range 1 80)))\n;; => clojure.lang.PersistentHashMap\nuser=> (count (apply dissoc (make-map 40) (range 1 80)))\n;; => 1\nuser=> (apply dissoc (make-map 40) (range 1 80))\n;; => {0 0}\nuser=> (type (apply dissoc (make-map 40) (range 0 80)))\n;; => clojure.lang.PersistentHashMap\nuser=> (count (apply dissoc (make-map 40) (range 0 80)))\n;; => 0\nuser=> (apply dissoc (make-map 40) (range 0 80))\n;; => {}\n", :_id "57392e25e4b071da7d6cfd0c"} {:editors [{:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :body ";; Maybe you generated a sequence of kv pairs\n(def kvs [[:a 1] [:b 2] [:c 3] [:d 4] [:e 5] [:f 6] [:g 7] [:h 8] [:i 9]])\n\n;; A naïve approach to putting into an array-map…\n(into (array-map) kvs)\n;; => {:e 5, :g 7, :c 3, :h 8, :b 2, :d 4, :f 6, :i 9, :a 1}\n;; …loses order\n(type *1)\n;; => clojure.lang.PersistentHashMap\n\n;; This approach…\n(apply array-map (sequence cat kvs))\n;; => {:a 1, :b 2, :c 3, :d 4, :e 5, :f 6, :g 7, :h 8, :i 9}\n;; …preserves order\n(type *1)\n;; => clojure.lang.PersistentArrayMap", :author {:avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4", :account-source "github", :login "tomdl89"}, :created-at 1659043605194, :updated-at 1682634761186, :_id "62e2ff15e4b0b1e3652d7631"}], :notes [{:updated-at 1280205606000, :body "The definition is kind of short, IMO. More descriptively, `array-map` creates a mapping with arrays being the keys and the values. It doesn't seem like `array-map` cares whether or not the keys/values are arrays, although it doesn't seem to like sequences.", :created-at 1280205606000, :author {:login "Jacolyte", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521f8d"} {:updated-at 1303523878000, :body "An array-map maintains the insertion order of the keys. Look up is linear, which is not a problem for small maps (say less than 10 keys). If your map is large, you should use hash-map instead. \r\n\r\nWhen you assoc onto an existing array-map, the result is a new array-map with the new key as the first key. The rest of the keys are in the same order as the original. Functions such as seq and keys will respect the key order. \r\n\r\nNote that assoc will decide to return a hash-map if the result is too big to be efficient.
\r\n", :created-at 1303523878000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fba"}], :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"} {:added "1.3", :ns "clojure.core", :name "unchecked-byte", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1496262162534, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "byte", :ns "clojure.core"}, :_id "592f2612e4b06e730307db1c"}], :line 3516, :examples [{:body "user=> (unchecked-byte 127)\n127\nuser=> (unchecked-byte 128)\n-128\nuser=> (unchecked-byte 255)\n-1\nuser=> (unchecked-byte 256)\n0\nuser=> (unchecked-byte 257)\n1", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423522274775, :updated-at 1423522274775, :_id "54d939e2e4b081e022073c74"} {:updated-at 1496262153952, :created-at 1496262153952, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body "(unchecked-byte 1)\n;;=> 1\n(unchecked-byte 1N)\n;;=> 1\n(unchecked-byte 1.1)\n;;=> 1\n(unchecked-byte 1.9)\n;;=> 1\n(unchecked-byte 5/3)\n;;=> 1\n\n(unchecked-byte -1)\n;;=> -1\n(unchecked-byte -1N)\n;;=> -1\n(unchecked-byte -1.1)\n;;=> -1\n(unchecked-byte -1.9)\n;;=> -1\n(unchecked-byte -5/3)\n;;=> -1\n\n;;;; Note that (unchecked-byte) does not range check its argument\n;;;; so integer overflow or rounding may occur. \n;;;; Use (byte) if you want to throw an exception in such cases.\n\n(unchecked-byte 128)\n;;=> -128\n(unchecked-byte -129)\n;;=> 129\n\n(byte 128)\n;;=> IllegalArgumentException Value out of range for byte: 128\n(byte -129)\n;;=> IllegalArgumentException Value out of range for byte: -129\n\n(unchecked-byte 1.0E2)\n;;=> 100\n(unchecked-byte 1.0E3)\n;;=> -24\n\n(byte 1.0E2)\n;;=> 100\n(byte 1.0E3)\n;;=> IllegalArgumentException Value out of range for byte: 1000.0", :_id "592f2609e4b06e730307db1b"}], :notes nil, :arglists ["x"], :doc "Coerce to byte. Subject to rounding or truncation.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/unchecked-byte"} {:added "1.0", :ns "clojure.core", :name "with-local-vars", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1374310504000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-bindings", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cea"} {:created-at 1423524505831, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "var-set", :library-url "https://github.com/clojure/clojure"}, :_id "54d94299e4b081e022073c7d"} {:created-at 1437143798426, :author {:login "claj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/353113?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "volatile!", :ns "clojure.core"}, :_id "55a912f6e4b06a85937088aa"} {:created-at 1461815729270, :author {:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "var-get", :ns "clojure.core"}, :_id "572189b1e4b0f8c89e75b110"}], :line 4340, :examples [{:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; with-local-vars allows you to write more imperative-style code, for cases\n;; where you really want to. factorial isn't a case where it helps, but\n;; it is short and familiar. Note that (var-get acc) can be abbreviated\n;; as @acc\nuser=> (defn factorial [x]\n (with-local-vars [acc 1, cnt x]\n (while (> @cnt 0)\n (var-set acc (* @acc @cnt))\n (var-set cnt (dec @cnt)))\n @acc))\n#'user/factorial\nuser=> (factorial 7)\n5040\n", :created-at 1331249053000, :updated-at 1331249053000, :_id "542692d6c026201cdc3270b9"} {:updated-at 1492497328392, :created-at 1492497328392, :author {:login "didibus", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/601540?v=3"}, :body "(with-local-vars [a-local-var-variable \"value\"]\n ;; If you use the symbol by itself, you get the Var back\n (println a-local-var-variable)\n ;; So when using local var variables, you must explicitly\n ;; get the value inside the Var\n (println (var-get a-local-var-variable))\n ;; You can also get the value of a Var by using deref\n (println (deref a-local-var-variable))\n ;; Or the @ reader macro\n (println @a-local-var-variable))", :_id "58f5b3b0e4b01f4add58fe96"} {:updated-at 1567623091068, :created-at 1500198345816, :author {:login "char16t", :account-source "github", :avatar-url "https://avatars6.githubusercontent.com/u/5310476?v=4"}, :body ";; with-local-vars allows you to write more imperative-style code, for cases\n;; where you really want to. This example demonstrate how to change variable value\n;; like in for-loop. There used doseq instead of for, because `for` is a macro\n;; that generates lazy sequence that will be realized out of ranges\n;; with-local-vars block \n(with-local-vars [n 0] \n (doseq [x (range 3)]\n (do (var-set n (inc (var-get n)))\n (println (var-get n)))))\n; 1\n; 2\n; 3\n;=> nil\n", :editors [{:avatar-url "https://avatars6.githubusercontent.com/u/5310476?v=4", :account-source "github", :login "char16t"} {:login "cloojure", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/7083783?v=4"}], :_id "596b35c9e4b0d19c2ce9d6fc"}], :macro true, :notes nil, :arglists ["name-vals-vec & body"], :doc "varbinding=> symbol init-expr\n\n Executes the exprs in a context in which the symbols are bound to\n vars with per-thread bindings to the init-exprs. The symbols refer\n to the var objects themselves, and must be accessed with var-get and\n var-set", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/with-local-vars"} {:added "1.0", :ns "clojure.core", :name "ns-imports", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1288055178000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "ns-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e00"}], :line 4200, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [], :body "user> (ns-imports 'clojure.core)\n{ClassVisitor clojure.asm.ClassVisitor, ProcessBuilder java.lang.ProcessBuilder, Enum java.lang.Enum, SuppressWarnings java.lang.SuppressWarnings, Throwable java.lang.Throwable, InterruptedException ...chop...}", :created-at 1288074884000, :updated-at 1288074884000, :_id "542692ccc026201cdc326c68"}], :notes nil, :arglists ["ns"], :doc "Returns a map of the import mappings for the namespace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ns-imports"} {:added "1.0", :ns "clojure.core", :name "send-off", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1282635172000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "send", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e37"} {:created-at 1282635178000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "agent", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e38"} {:created-at 1282635185000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "shutdown-agents", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e39"} {:created-at 1614551206060, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "send-via", :ns "clojure.core"}, :_id "603c18a6e4b0b1e3652d7468"}], :line 2122, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"} {:login "sfreund", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a288ab5288d2c86c37f8ae3aaa133b1a?r=PG&default=identicon"} {:login "sfreund", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a288ab5288d2c86c37f8ae3aaa133b1a?r=PG&default=identicon"} {:login "fordsfords", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7671908?v=3"}], :body "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", :created-at 1285922554000, :updated-at 1417372052900, :_id "542692c8c026201cdc326a5a"} {:editors [{:login "kwladyka", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/3903726?v=3"}], :body ";; 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.", :author {:avatar-url "https://avatars1.githubusercontent.com/u/3903726?v=3", :account-source "github", :login "kwladyka"}, :created-at 1496609297326, :updated-at 1496609746458, :_id "59347211e4b06e730307db22"}], :notes [{:updated-at 1396535611000, :body "The example uses \"send\", this is supposed to be an example for \"send-off\".", :created-at 1396535611000, :author {:login "Benissimo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e580eaf74a5f97c7ea01e0c026221a1d?r=PG&default=identicon"}, :_id "542692edf6e94c6970522022"} {:body "\"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.", :created-at 1417371642071, :updated-at 1417372219777, :author {:login "fordsfords", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7671908?v=3"}, :_id "547b5ffae4b0dc573b892fe6"}], :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"} {:added "1.0", :ns "clojure.core", :name "defmacro", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1336311079000, :author {:login "redraiment", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/33087654dbc710e81f51fda5f8241f28?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "macroexpand", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f7d"} {:created-at 1336311088000, :author {:login "redraiment", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/33087654dbc710e81f51fda5f8241f28?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "macroexpand-1", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f7e"} {:created-at 1336311122000, :author {:login "redraiment", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/33087654dbc710e81f51fda5f8241f28?r=PG&default=identicon"}, :to-var {:ns "clojure.walk", :name "macroexpand-all", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521f7f"}], :line 444, :examples [{:author {:login "Kototama", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a54a4dc204925d397ca010b9a332e74d?r=PG&default=identicon"}, :editors [{:login "Kototama", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a54a4dc204925d397ca010b9a332e74d?r=PG&default=identicon"} {:login "kochb", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1012892?v=3"}], :body "(defmacro with-tree\n \"works on a JTree and restores its expanded paths after executing body\"\n [tree & body]\n `(let [tree# ~tree\n root# (.getRoot (.getModel tree#))\n expanded# (if-let [x# (.getExpandedDescendants\n tree# (TreePath. root#))]\n (enumeration-seq x#)\n ())\n selectionpaths# (. selectionmodel# getSelectionPaths)]\n ~@body\n (doseq [path# expanded#]\n (.expandPath tree# path#))))\n\n;; usage:\n\n(with-tree *one-jtree-instance*\n ;; some code here...\n )", :created-at 1286492372000, :updated-at 1421193676346, :_id "542692ccc026201cdc326c86"} {:author {:login "Clinton", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e460563f35b0b25d8671d6ef83f54ce?r=PG&default=identicon"}, :editors [], :body "(defmacro unless [pred a b]\n `(if (not ~pred) ~a ~b))\n\n;; usage:\n\n(unless false (println \"Will print\") (println \"Will not print\"))", :created-at 1327060274000, :updated-at 1327060274000, :_id "542692d2c026201cdc326f7a"} {:author {:login "octopusgrabbus", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon"}, :editors [], :body "(def dbg 1)\n\n(defmacro chk-flagM\n \"Throws an exception if flag does not resolve; else returns flag's value.\"\n [flag]\n (if (not (resolve flag))\n (throw (Exception. (str 'flag \" is not a valid var.\")))\n flag))\n\n(defn write-csv-file\n \"Writes a csv file using a key and an s-o-s\"\n [out-sos out-file]\n\n (if (>= (chk-flagM dbg) 2)\n (println (first out-sos), \"\\n\", out-file))\n\n (spit out-file \"\" :append false)\n (with-open [out-data (io/writer out-file)]\n (csv/write-csv out-data (map #(concat % [\"\"]) out-sos))))\n\n", :created-at 1361941726000, :updated-at 1361941726000, :_id "542692d2c026201cdc326f7b"} {:updated-at 1592919257677, :created-at 1592919257677, :author {:login "vale981", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/4025991?v=4"}, :body ";; We can implement algebraic infix notation, which is quite handy for\n;; typing in formulas. :-)\n\n(defmacro __\n \"Expands algebraic infix notation to standard clojure forms. Supports\n operator precedence.\"\n [[item op & rst :as lst]]\n (let [item (if (seq? item)\n `(__ ~item)\n item)]\n (if op\n (case op\n (+ -) `(~op ~item (__ ~rst))\n (* /) (let [[next & rst] rst]\n `(__\n ((~op ~item\n ~(if (seq? next)\n `(__ ~next) next)) ~@rst)))\n ;; we already have a clojure form\n lst)\n item)))\n\n(clojure.walk/macroexpand-all '(__ (1 * 2 + 3 * 4 + (1 + 2))))\n;; => (+ (* 1 2) (+ (* 3 4) (+ 1 2)))\n\n;; parens for precedence\n(clojure.walk/macroexpand-all '(__ (1 + 2 * (3 + 4))))\n;; => (+ 1 (* 2 (+ 3 4)))\n\n;; usual clojure notation in the middle of it\n(clojure.walk/macroexpand-all '(__ (1 + 2 * (+ 3 4))))\n;; => (+ 1 (* 2 (+ 3 4)))", :_id "5ef204d9e4b0b1e3652d730e"} {:updated-at 1603447108371, :created-at 1603446989723, :author {:login "jimka2001", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/6414129?v=4"}, :body ";; The meta data notation `^:dynamic` can be used to force a variable to be dynamic.\n\n(def ^:dynamic *my-dynamic-variable* \"my doc string\" the-initial-value)\n\n;; However, using this notation within a macro does not have the same semantics.\n;; For example the following macro *will not* expand to a definition of a dynamic \n;; variable whose value is a function.\n\n\n(defmacro dyn-fun [name lambda-list & body]. ;; WRONG\n `(def ^:dynamic ~name (fn ~lambda-list ~@body)))\n\n\n;; The macro should be written something like the following.\n\n\n(defmacro dyn-fun [name lambda-list & body]\n `(def ~(with-meta name {:dynamic true}) (fn ~lambda-list ~@body)))\n", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/6414129?v=4", :account-source "github", :login "jimka2001"}], :_id "5f92a8cde4b0b1e3652d73e8"}], :macro true, :notes [{:updated-at 1332614198000, :body "The body of a macro has two implicitly bound symbols: &form and &env. They work like two extra unnamed args. The names begin with '&' to avoid name clashes with normal user-defined symbols. The value of &form is the form of the original macro call before macro expansion. There's useful meta-data on &form. The value of &env is the \"environment\", which is basically a map of lexical bindings. The keys of &env are the lexically bound symbols. The values are internal compiler details, and probably aren't useful for user code.\r\n\r\n\r\nSee also:\r\n[http://blog.jayfields.com/2011/02/clojure-and.html](http://blog.jayfields.com/2011/02/clojure-and.html)", :created-at 1332559647000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fdc"} {:updated-at 1348338864000, :body "Due to syntax-quote resolving symbols (see the [Clojure reader docs](http://clojure.org/reader)), you won't be able to include a regular `let` statement inside a macro, i.e.:\r\n\r\n
(defmacro m [] `(let [x 1] x))\r\n(m) ; => CompilerException java.lang.RuntimeException: Can't let qualified name: user/x, compiling:(NO_SOURCE_PATH:1)
\r\nThe syntax-quote has resolved `x` to `user/x`—which can't be `let`. This is a good thing, as it's signalling to us that we should use gensyms by appending `#`:\r\n\r\n
", :created-at 1348338864000, :author {:login "Arlen", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8bfb3a1eb9879049b4886cd3f9f321c4?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fe7"} {:updated-at 1396943327000, :body "@Arlen:\r\nIf you want to capture the local variables, or create a non-locally scoped variable, you can prepend them with ~', allow a namespace capture:\r\n\r\n
\r\nuseful, if you desire it.", :created-at 1396943283000, :author {:login "travis_rodman", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/988e7de687c27107309bebe02aee1984?r=PG&default=identicon"}, :_id "542692edf6e94c6970522024"} {:body "When debugging macros that use &env, beware that
clojure.walk/macroexpand-all
doesn't \"set up\" any symbols. It ignores any symbols from
(let [...] ...)
and similar. To test &env, run the macro directly.", :created-at 1547117881414, :updated-at 1547117901908, :author {:avatar-url "https://avatars2.githubusercontent.com/u/4270240?v=4", :account-source "github", :login "peter-kehl"}, :_id "5c372539e4b0ca44402ef619"}], :arglists ["name doc-string? attr-map? [params*] body" "name doc-string? attr-map? ([params*] body) + attr-map?"], :doc "Like defn, but the resulting function name is declared as a\n macro and will be used as a macro by the compiler when it is\n called.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/defmacro"} {:added "1.3", :ns "clojure.core", :name "every-pred", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1348529552000, :author {:login "hugoduncan", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/80fa2a15219b987664e4d6f5c78b4c27?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "some-fn", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bf2"} {:created-at 1422932166689, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "every?", :library-url "https://github.com/clojure/clojure"}, :_id "54d038c6e4b0e2ac61831cf4"}], :line 7396, :examples [{:updated-at 1335431607000, :created-at 1335431607000, :body "user=> ((every-pred number? odd?) 3 9 11)\ntrue", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d2c026201cdc326fa0"} {:editors [{:login "daveliepmann", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/974443?v=4"}], :body "(filter (every-pred pos? ratio?)\n [0 2/3 -2/3 1/4 -1/10 5 3/3])\n=> (2/3 1/4)", :author {:avatar-url "https://avatars3.githubusercontent.com/u/974443?v=4", :account-source "github", :login "daveliepmann"}, :created-at 1549903494471, :updated-at 1551557625726, :_id "5c61a686e4b0ca44402ef67b"} {:updated-at 1549903552234, :created-at 1549903552234, :author {:login "daveliepmann", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/974443?v=4"}, :body "((every-pred string? (comp (partial > 5) count)) \"abc\")\ntrue\n((every-pred string? (comp (partial > 5) count)) \"abcdef\")\nfalse", :_id "5c61a6c0e4b0ca44402ef67c"}], :notes [{:body "Careful—every predicate with no arguments is considered true:\n
", :created-at 1468616330948, :updated-at 1468616364083, :author {:avatar-url "https://avatars.githubusercontent.com/u/7443?v=3", :account-source "github", :login "harold"}, :_id "57894e8ae4b0bafd3e2a04a3"}], :arglists ["p" "p1 p2" "p1 p2 p3" "p1 p2 p3 & ps"], :doc "Takes a set of predicates and returns a function f that returns true if all of its\n composing predicates return a logical true value against all of its arguments, else it returns\n false. Note that f is short-circuiting in that it will stop execution on the first\n argument that triggers a logical false result against the original predicates.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/every-pred"} {:added "1.0", :ns "clojure.core", :name "keys", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289979132000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "vals", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cef"} {:created-at 1289979143000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "hash-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cf0"} {:created-at 1318592870000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "key", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cf1"} {:created-at 1470842025768, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "select-keys", :ns "clojure.core"}, :_id "57ab44a9e4b0bafd3e2a04db"}], :line 1555, :examples [{:author {:login "pkolloch", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon"}, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "(keys {:keys :and, :some :values})\n;;=> (:keys :some)\n\n(keys {})\n;;=> nil\n\n(keys nil)\n;;=> nil", :created-at 1280458583000, :updated-at 1423522822893, :_id "542692c7c026201cdc326951"} {:updated-at 1477296966414, :created-at 1477296966414, :author {:login "gzmask", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/132936?v=3"}, :body ";; although doc says it only takes a map, this still works:\n(keys (filter (fn [[_ v]] (-> v :t)) {:a {:t true} :b {:t false} :c {:t true}}))\n;;=> (:a :c)", :_id "580dc346e4b001179b66bddb"}], :notes [{:updated-at 1385457055000, :body "Functions keys and vals return sequences such that\r\n
\r\n(= (zipmap (keys m) (vals m)) m)\r\n
", :created-at 1385457055000, :author {:login "akhudek", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/aaf21f137b69cc5154c8afb29b793e18?r=PG&default=identicon"}, :_id "542692edf6e94c6970522010"} {:body "I noticed that the keys are not always returned in the same order. Usually they are, but not always.", :created-at 1443420358374, :updated-at 1443420375336, :author {:avatar-url "https://avatars.githubusercontent.com/u/5528061?v=3", :account-source "github", :login "Jarzka"}, :_id "5608d8c6e4b08e404b6c1c8a"} {:author {:login "ac1dr3d", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10298138?v=4"}, :updated-at 1522928591363, :created-at 1522928591363, :body "Map with 8 or more keys order are unexpected.", :_id "5ac60bcfe4b045c27b7fac36"}], :arglists ["map"], :doc "Returns a sequence of the map's keys, in the same order as (seq map).", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/keys"} {:added "1.0", :ns "clojure.core", :name "rationalize", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos nil, :line 1277, :examples [{:author {:login "Miles", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bbb26d2a5e856c4fba0f72c3f7250f3f?r=PG&default=identicon"}, :editors [], :body "
\r\nuser=> (rationalize 1.5)\r\n3/2\r\n
", :created-at 1283819843000, :updated-at 1283819843000, :_id "542692cbc026201cdc326c27"} {:updated-at 1335430728000, :created-at 1335430728000, :body "user=> (rationalize Math/PI)\n3141592653589793/1000000000000000\n\nuser=> (rationalize (Math/sqrt 2))\n14142135623730951/10000000000000000", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d4c026201cdc327049"} {:body "(rationalize 2/4)\n;; => 1/2\n\n(rationalize 4/2)\n;; => 2\n\n(rationalize 2)\n;; => 2\n\n(rationalize 2.0)\n;; => 2N", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423041167517, :updated-at 1423041167517, :_id "54d1e28fe4b0e2ac61831d0c"} {:updated-at 1495120328324, :created-at 1495120328324, :author {:login "mhmdsalem1993", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/10787314?v=3"}, :body ";; To quickly convert a mixed number to an improper fraction, \n;; multiply the denominator\n;; by the whole number and add to the numerator\n\n(= (+ 20 3/4) (rationalize (/ (+ (* 20 4) 3) 4)))\n;; => true", :_id "591db9c8e4b01920063ee061"}], :notes [{:updated-at 1388083523000, :body "Remember that for irrational numbers, like sqrt 2, this is only an estimate (pretty good one). ", :created-at 1388083523000, :author {:login "wikopl", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ebf7a80146fda866cb2737cbabf79d63?r=PG&default=identicon"}, :_id "542692edf6e94c6970522017"}], :arglists ["num"], :doc "returns the rational value of num", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/rationalize"} {:added "1.0", :ns "clojure.core", :name "load-file", :type "function", :see-alsos [{:created-at 1286271536000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "load", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d3c"} {:created-at 1350073018000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "spit", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d3d"} {:created-at 1519290658085, :author {:login "witek", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/209520?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "load-string", :ns "clojure.core"}, :_id "5a8e8922e4b0316c0f44f8e9"}], :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "shawnmorel", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/4a701b9e9467b6ccee6b83c698ea6b15?r=PG&default=identicon"} {:login "Jeff Terrell", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/658b2643cf2a8192286b5bb1ecb62cf8?r=PG&default=identicon"}], :body ";; Very useful from a REPL\n;; Paths are specified as strings using canonical file path notation \n;; (rather than clojure-style namespaces dependent on the JVM classpath).\n;; The working directory is set to wherever you invoked the JVM from, \n;; likely the project root.\n\n(load-file \"src/mylib/core.clj\")\n\n;; now you can go and evaluate vars defined in that file.", :created-at 1286271505000, :updated-at 1344912514000, :_id "542692cdc026201cdc326d3e"} {:author {:login "lambder", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1c0c20072f52de3a6335cae183b865f6?r=PG&default=identicon"}, :editors [{:login "lambder", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1c0c20072f52de3a6335cae183b865f6?r=PG&default=identicon"}], :body ";; file located at src/address_book/core.clj\n;; current dir is src/..\n\n(load-file \"src/address_book/core.clj\")", :created-at 1307936530000, :updated-at 1307936548000, :_id "542692cdc026201cdc326d41"} {:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4", :account-source "github", :login "bfontaine"} {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/24317401?v=4"}], :body ";; create a clojure file on the fly using spit\n;; then load it into the REPL and use its function\n\nuser=> (spit \"mycode.clj\" \"(defn doub [x] (* x 2))\")\nnil\nuser=> (load-file \"mycode.clj\")\n#'user/doub\nuser=> (doub 23)\n46\n\n;; Note this is similar to using load-string:\nuser=> (load-string \"(defn doub [x] (* x 2))\")\n#'user/doub", :created-at 1313970180000, :updated-at 1666340708697, :_id "542692cdc026201cdc326d43"}], :notes [{:updated-at 1350351731000, :body "
Be aware that this function is intended to load code only. If your data structures or a string in them grow bigger than around 65,535 it crashes.
\r\n\r\n
Exception similar to:
\r\n
java.lang.ClassFormatError: Unknown constant tag 49 in class file parse$eval13
\nuser=> (frequencies [3 6 2 6 8 7 'b 'c 3 5 3 4 7 6 'a])\n{2 1, 3 3, 4 1, 5 1, 6 3, 7 2, 8 1, a 1, c 1, b 1}\nuser=> (frequencies [3 6 2 6 8 7 'b 'c])\n{3 1, 6 2, 2 1, 8 1, 7 1, b 1, c 1}\n;Note that the order of keys need not be in order of vector\n
", :_id "569ceeb7e4b060004fc217ae"} {:author {:login "humorless", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/3061798?v=4"}, :updated-at 1557220455720, :created-at 1557220455720, :body "```\n(defn frequencies-by\n \"a generalized version of frequencies\"\n [f coll]\n (let [gp (group-by f coll)]\n (zipmap (keys gp) (map #(count (second %)) gp))))\n```", :_id "5cd14c67e4b0ca44402ef71b"}], :arglists ["coll"], :doc "Returns a map from distinct items in coll to the number of times\n they appear.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/frequencies"} {:added "1.0", :ns "clojure.core", :name "read-string", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289454685000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "pr-str", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a90"} {:created-at 1289454689000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "str", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a91"} {:created-at 1313054776000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "read", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a92"} {:created-at 1334883935000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "load-string", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a93"} {:created-at 1352963672000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "*read-eval*", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a94"} {:created-at 1422653056995, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10404?v=2"}, :to-var {:ns "clojure.main", :name "load-script", :library-url "https://github.com/clojure/clojure"}, :_id "54cbf680e4b0e2ac61831cef"} {:created-at 1422653083632, :author {:login "delonnewman", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10404?v=2"}, :to-var {:ns "clojure.edn", :name "read-string", :library-url "https://github.com/clojure/clojure"}, :_id "54cbf69be4b0e2ac61831cf0"}], :line 3805, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (read-string \"1.1\") \n1.1\n\nuser=> (read-string \"1.1.1 (+ 1 1)\")\njava.lang.RuntimeException: java.lang.NumberFormatException: Invalid number: 1.1.1 (NO_SOURCE_FILE:0)\n\nuser=> (read-string \"(+ 1 1)\")\n(+ 1 1)\n", :created-at 1282634798000, :updated-at 1285494370000, :_id "542692c9c026201cdc326ad6"} {:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [{:login "tormaroe", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8bc7bb10bee96efb190053fe92ffd250?r=PG&default=identicon"}], :body "user=> (eval (read-string \"(+ 1 1)\"))\n2\n\nuser=> (read-string (prn-str (+ 1 1)))\n2\n", :created-at 1289408002000, :updated-at 1289710230000, :_id "542692c9c026201cdc326ad8"} {:author {:login "benjiiiiii", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/fd1adaf32d9dc6531d6041dbc379efb0?r=PG&default=identicon"}, :editors [], :body "user=> (+ 11 (read-string \"23\"))\n34\n", :created-at 1291246357000, :updated-at 1291246357000, :_id "542692c9c026201cdc326ada"} {:author {:login "devn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10421?v=3"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}], :body "user=> (read-string \"; foo\\n5\")\n5\n\nuser=> (read-string \"#^String x\")\nx\n\nuser=> (read-string \"(1)\")\n(1)\n\nuser=> (read-string \"(+ 1 2) (- 3 2)\")\n(+ 1 2)\n\nuser=> (read-string \"@a\")\n(clojure.core/deref a)\n\nuser=> (read-string \"(+ 1 2))))))\")\n(+ 1 2)\n\nuser=> (read-string \"::whatever-namespace-you-are-in\")\n:user/whatever-namespace-you-are-in", :created-at 1335430367000, :updated-at 1335430553000, :_id "542692d5c026201cdc32705f"} {:author {:login "dansalmo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"}, :editors [{:login "dansalmo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"}], :body ";convert a string representing a sequence,\n;to the sequence that the string represents\nuser=> (read-string \"(\\\\( \\\\x \\\\y \\\\) \\\\z)\")\n(\\( \\x \\y \\) \\z)\n\n;then you can convert to the string that the string-sequence represents\nuser=> (apply str (read-string \"(\\\\( \\\\x \\\\y \\\\) \\\\z)\"))\n\"(xy)z\"\n\n;which is the inverse of\nuser=> (str (first (list (seq \"(xy)z\"))))\n\"(\\\\( \\\\x \\\\y \\\\) \\\\z)\"", :created-at 1345526514000, :updated-at 1345526600000, :_id "542692c9c026201cdc326adb"} {:author {:login "dansalmo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"}, :editors [], :body ";; you can think of read-string as the inverse of pr-str\n;; turn string into symbols\nuser=> (read-string \"(a b foo :bar)\")\n(a b foo :bar)\n\n;;turn symbols into a string\nuser=> (pr-str '(a b foo :bar))\n\"(a b foo :bar)\"", :created-at 1346843994000, :updated-at 1346843994000, :_id "542692d5c026201cdc327061"} {:updated-at 1518357675254, :created-at 1360635743000, :body ";; WARNING: You SHOULD NOT use clojure.core/read-string to read data from\n;; untrusted sources. See the examples for clojure.core/read, because the same\n;; issues exist for both read and read-string.", :editors [{:login "green-coder", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"}, :_id "542692d5c026201cdc327062"} {:updated-at 1455932713195, :created-at 1455932713195, :author {:login "one-finger", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/17347889?v=3"}, :body ";; convert binary number provided in the form of a string to its numerical value.\nuser=> (read-string (str \"2r\" \"1011\"))\n11\n", :_id "56c7c529e4b0b41f39d96ccf"} {:updated-at 1613109472732, :created-at 1557061665574, :author {:login "loeschzwerg", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/24317401?v=4"}, :body ";; be careful with octal values\nuser=> (read-string \"042\")\n34\n\nuser=> (read-string \"08\")\nExecution error (NumberFormatException)\nInvalid number: 08\n\n;; replace leading zeroes with regex\nuser=> (read-string (clojure.string/replace \"042\" #\"^0+(?!$)\" \"\"))\n42\n\nuser=> (read-string (clojure.string/replace \"00\" #\"^0+(?!$)\" \"\"))\n0", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/39972994?v=4", :account-source "github", :login "jocatelo"}], :_id "5ccee021e4b0ca44402ef71a"} {:editors [{:login "adanhawth", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/36526095?v=4"}], :body ";; if someone littered your csv fields with escaped double quotes...\n(def quoted-string \"\\\"1.23\\\"\")\n\n;; and you find yourself in angst, cause this won't work...\n(Double. quoted-string)\n\t;; Execution error (IllegalArgumentException) at user/eval6365 (form-init17453115089215840832.clj:1).\n\t;; No matching ctor found for class java.lang.Double\n\n;; you don't have to hate the player; but you can come prepared for the game\n(Double. (read-string quoted-string))\n\t;; 1.23", :author {:avatar-url "https://avatars2.githubusercontent.com/u/36526095?v=4", :account-source "github", :login "adanhawth"}, :created-at 1582746730566, :updated-at 1582746790901, :_id "5e56cc6ae4b087629b5a18aa"} {:updated-at 1660763271174, :created-at 1660763271174, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=4"}, :body ";;;; Data representation is same as the one produced by (read-string)\n;;;; and (read) when provided with the option to preserve data conditionals\n\n(read-string {:read-cond :preserve} \"#?(:clj (println \\\"Hey World!\\\"))\")\n;;=> #?(:clj (println \"Hey World!\"))\n", :_id "62fd3c87e4b0b1e3652d763d"}], :notes [{:updated-at 1289408055000, :body "read-string is useful for running clojure code from a script or translator.", :created-at 1289408055000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fa2"} {:author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :updated-at 1568111197675, :created-at 1568111197675, :body "Never **EVER** use `read-string` on data from an untrusted source. Prefer `clojure.edn/read-string` to parse EDN. The former can execute arbitrary code, including calling external URLs or reading/writing/erasing files.", :_id "5d777a5de4b0ca44402ef7af"}], :arglists ["s" "opts s"], :doc "Reads one object from the string s. Optionally include reader\n options, as specified in read.\n\n Note that read-string can execute code (controlled by *read-eval*),\n and as such should be used only with trusted sources.\n\n For data structure interop use clojure.edn/read-string", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/read-string"} {:added "1.0", :ns "clojure.core", :name "proxy", :file "clojure/core_proxy.clj", :type "macro", :column 1, :see-alsos [{:created-at 1360270636000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "gen-class", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521c9e"} {:created-at 1360270701000, :author {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "gen-interface", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521c9f"} {:created-at 1361858921000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "reify", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ca0"}], :line 329, :examples [{:author {:login "Kototama", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a54a4dc204925d397ca010b9a332e74d?r=PG&default=identicon"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3", :account-source "github", :login "bkovitz"}], :body ";; adding a mouse-pressed callback to a Swing component:\n\n(defn add-mousepressed-listener\n [component f & args]\n (let [listener (proxy [MouseAdapter] []\n (mousePressed [event]\n (apply f event args)))]\n (.addMouseListener component listener)\n listener))\n", :created-at 1287523639000, :updated-at 1460780025090, :_id "542692cdc026201cdc326d5c"} {:author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :editors [], :body ";; BUG: proxy dispatches *only* on name, not arity:\nuser=> (let [p (proxy [java.io.InputStream] [] (read [] -1))]\n (println (.read p))\n (println (.read p (byte-array 3) 0 3)))\n\n-1\nArityException Wrong number of args (4) passed to: core$eval213$fn clojure.lang.AFn.throwArity (AFn.java:437)\n", :created-at 1336686490000, :updated-at 1336686490000, :_id "542692d4c026201cdc327040"} {:updated-at 1586252027510, :created-at 1363059784000, :body ";; You can, however, provide multiple-arity functions to get some support \n;; for overloading\nuser> (let [p (proxy [java.io.InputStream] []\n (read\n ([] 1)\n ([^bytes bytes] 2)\n ([^bytes bytes off len] 3)))]\n (println (.read p))\n (println (.read p (byte-array 3)))\n (println (.read p (byte-array 3) 0 3)))\n\n1\n2\n3\nnil", :editors [{:login "Hindol", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/705227?v=4"}], :author {:avatar-url "https://www.gravatar.com/avatar/61b4809de147650070a5e209be48fe7f?r=PG&default=identicon", :account-source "clojuredocs", :login "craigandera"}, :_id "542692d4c026201cdc327041"} {:updated-at 1586252042920, :created-at 1542943086091, :author {:login "gluer", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/22495106?v=4"}, :body ";; a simple example\n\n(defn f [& i]\n (proxy [clojure.lang.ISeq][]\n (seq [] (sort i))\n (toString [] (apply str (interpose \"-\" i)))))\n\n(seq (f 4 3 2 1))\n;;=> (1 2 3 4)\n\n\n(str (f 4 3 2 1))\n;;=> \"4-3-2-1\"", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/22495106?v=4", :account-source "github", :login "gluer"} {:login "Hindol", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/705227?v=4"}], :_id "5bf7716ee4b0ca44402ef5c6"} {:updated-at 1587490591311, :created-at 1587490591311, :author {:login "audriu", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/41568862?v=4"}, :body ";; usage of implicit 'this\n(def prx (proxy [java.lang.Runnable] []\n (run \n ([] (println \"We can use this inside here\" this) 1))))\n\n(.run prx)\n;;=>We can use this inside here #object[user.proxy$java.lang.Object$Runnable.....", :_id "5e9f2f1fe4b087629b5a18db"}], :macro true, :notes nil, :arglists ["class-and-interfaces args & fs"], :doc "class-and-interfaces - a vector of class names\n\n args - a (possibly empty) vector of arguments to the superclass\n constructor.\n\n f => (name [params*] body) or\n (name ([params*] body) ([params+] body) ...)\n\n Expands to code which creates a instance of a proxy class that\n implements the named class/interface(s) by calling the supplied\n fns. A single class, if provided, must be first. If not provided it\n defaults to Object.\n\n The interfaces names must be valid interface types. If a method fn\n is not provided for a class method, the superclass method will be\n called. If a method fn is not provided for an interface method, an\n UnsupportedOperationException will be thrown should it be\n called. Method fns are closures and can capture the environment in\n which proxy is called. Each method fn takes an additional implicit\n first arg, which is bound to 'this. Note that while method fns can\n be provided to override protected methods, they have no other access\n to protected members, nor to super, as these capabilities cannot be\n proxied.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/proxy"} {:added "1.0", :ns "clojure.core", :name "rsubseq", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1330671605000, :author {:login "Chouser", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/7a0192050ed6488670acfd3f59405c10?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "subseq", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521efe"}], :line 5126, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [], :body "user> (rsubseq (sorted-set 1 2 3 4 5) < 3)\n(2 1)", :created-at 1286871962000, :updated-at 1286871962000, :_id "542692c9c026201cdc326af4"} {:editors [{:login "TradeIdeasPhilip", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/18409827?v=3"}], :body ";; If you use the longer form, with the end condition, there are some rules.\n;; start-key should be <= end-key. start-test should be \">\" or \">=\".\n;; end-test should be \"<\" or \"<=\". If follow these rules you'll get all the\n;; values between start-key and end-key. If you don't you won't get an error,\n;; but you probably won't get the result you expect. These rules are exactly\n;; the same for subseq.\n\n;; As expected, returns everything between 2 and 4, in reverse order.\nuser=> (rsubseq (sorted-set 1 2 3 4 5) >= 2 <= 4)\n;; => (4 3 2)\n\n;; Probably not what you expected!\nuser=> (rsubseq (sorted-set 1 2 3 4 5) <= 4 >= 2)\n;; => (2 1)\n\n;; As expected, returns everything between 2 and 4, in order.\nuser=> (subseq (sorted-set 1 2 3 4 5) >= 2 <= 4)\n;; => (2 3 4)\n\n;; Probably not what you expected!\nuser=> (subseq (sorted-set 1 2 3 4 5) <= 4 >= 2)\n;; => (4 5)\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/18409827?v=3", :account-source "github", :login "TradeIdeasPhilip"}, :created-at 1463328932267, :updated-at 1463329023275, :_id "5738a0a4e4b071da7d6cfd0b"}], :notes nil, :arglists ["sc test key" "sc start-test start-key end-test end-key"], :doc "sc must be a sorted collection, test(s) one of <, <=, > or\n >=. Returns a reverse seq of those entries with keys ek for\n which (test (.. sc comparator (compare ek key)) 0) is true", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/rsubseq"} {:added "1.2", :ns "clojure.core", :name "inc", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1325850434000, :author {:login "frangio", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/646001f0ba2b7df47a16c0a1d5b62225?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "dec", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d99"} {:created-at 1415177507055, :author {:login "rvlieshout", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/139665?v=2"}, :to-var {:ns "clojure.core", :name "inc'", :library-url "https://github.com/clojure/clojure"}, :_id "5459e523e4b03d20a102429d"} {:created-at 1525271648690, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "unchecked-inc", :ns "clojure.core"}, :_id "5ae9cc60e4b045c27b7fac5b"}], :line 922, :examples [{:author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}], :body "user=> (inc 1)\n2\n\nuser=> (inc 1.0)\n2.0\n\nuser=> (inc 1/2)\n3/2\n\nuser=> (inc -1)\n0", :created-at 1279992305000, :updated-at 1411874902968, :_id "542692cac026201cdc326b45"} {:updated-at 1516199380227, :created-at 1516199380227, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;increment all the element in a collection\n\n(map inc [1 2 3 4 5])\n;;(2 3 4 5 6) return type list\n\n(into [] (map inc [1 2 3 4 5]))\n;;[2 3 4 5 6] return type vector", :_id "5a5f5dd4e4b0a08026c48cf8"} {:updated-at 1524688467780, :created-at 1524688121378, :author {:login "wuleicanada", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/5652075?v=4"}, :body ";; Careful when using ClojureScript\n;; Make sure you're passing a number\n;; because JavaScript + also does string concatenation\ncljs.user=> (inc \"1\")\n\"11\"\ncljs.user=> (inc 1)\n2\n\n;; Although it's not the case with dec\n;; In JavaScript \"1\" - 1 = 0\ncljs.user=> (dec \"1\")\n0\ncljs.user=> (dec 1)\n0\n\n", :editors [{:avatar-url "https://avatars0.githubusercontent.com/u/5652075?v=4", :account-source "github", :login "wuleicanada"}], :_id "5ae0e4f9e4b045c27b7fac53"} {:updated-at 1633068446525, :created-at 1633068446525, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :body ";; You cannot `inc` a `nil` in Clojure, but you\n;; can in ClojureScript\n\n;; Clojure\n(inc nil) ;;=> NullPointerException\n\n;; ClojureScript\n(inc nil) ;;=> 1", :_id "6156a59ee4b0b1e3652d754f"}], :notes [{:updated-at 1316509073000, :body "Is the documentation suppose to be: \"Returns a number one greater than x.\" ? If not what is num?", :created-at 1316509073000, :author {:login "icefox", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/dc848256f8954abd612cbe7e81859f91?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fcc"} {:author {:login "arashgithub", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1148053?v=3"}, :updated-at 1457669616170, :created-at 1457669616170, :body "is code \"(def i (inc i))\" is conflict with the notion of immutable of data in Clojure. ", :_id "56e245f0e4b0119038be0212"} {:author {:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=3"}, :updated-at 1458583922104, :created-at 1458583922104, :body "Nope, quite the opposite. \"def\" defines a var: \n
\nuser=> (type (def i 1))\nclojure.lang.Var\n
\nA var is one of the 4 types dealing with mutable state (it is not an immutable data structure, like maps, vectors, sets and so on) and it does so following a specific semantic (see http://clojure.org/reference/vars).", :_id "56f03972e4b09295d75dbf35"}], :arglists ["x"], :doc "Returns a number one greater than num. Does not auto-promote\n longs, will throw on overflow. See also: inc'", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/inc"} {:added "1.0", :ns "clojure.core", :name "get-method", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1337585046000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "remove-method", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e3c"} {:created-at 1337585052000, :author {:login "abrooks", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/69976?v=2"}, :to-var {:ns "clojure.core", :name "methods", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e3d"}], :line 1817, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [], :body ";; 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=>", :created-at 1313922883000, :updated-at 1313922883000, :_id "542692cfc026201cdc326e6b"}], :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"} {:added "1.3", :ns "clojure.core", :name "with-redefs", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1322088077000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-redefs-fn", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b7b"} {:created-at 1322088155000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "alter-var-root", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b7c"} {:created-at 1365637645000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "with-bindings", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b7d"}], :line 7518, :examples [{:updated-at 1335591486000, :created-at 1335591486000, :body "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]", :editors [], :author {:avatar-url "https://avatars.githubusercontent.com/u/10421?v=3", :account-source "github", :login "devn"}, :_id "542692d6c026201cdc3270bc"} {:author {:login "johnnyluu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ba99f2dc1064733c7badbb16db9254a?r=PG&default=identicon"}, :editors [{:login "johnnyluu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ba99f2dc1064733c7badbb16db9254a?r=PG&default=identicon"} {:login "rebcabin", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/880b0bb3a4be9237326dd69565444dee?r=PG&default=identicon"}], :body "(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", :created-at 1350024154000, :updated-at 1366582892000, :_id "542692d6c026201cdc3270bd"} {:author {:login "w01fe", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e6b62d981155b5945a29d84a2e439663?r=PG&default=identicon"}, :editors [], :body ";; 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", :created-at 1352471112000, :updated-at 1352471112000, :_id "542692d6c026201cdc3270c0"} {:author {:login "nickzam", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/89377?v=2"}, :editors [], :body ";; 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", :created-at 1405030383000, :updated-at 1405030383000, :_id "542692d6c026201cdc3270c1"} {:updated-at 1625736978558, :created-at 1625736978558, :author {:login "deadghost", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1156996?v=4"}, :body ";; 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", :_id "60e6c712e4b0b1e3652d7514"} {:editors [{:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :body ";; 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", :author {:avatar-url "https://avatars.githubusercontent.com/u/8080718?v=4", :account-source "github", :login "owenRiddy"}, :created-at 1658537792859, :updated-at 1659109879089, :_id "62db4740e4b0b1e3652d762f"}], :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"} {:added "1.9", :ns "clojure.core", :name "uuid?", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 6805, :examples [{:updated-at 1495999029126, :created-at 1495999029126, :author {:login "svenschoenung", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10583730?v=3"}, :body "(uuid? (java.util.UUID/randomUUID))\n;;=> true\n(uuid? (read-string \"#uuid \\\"f81d4fae-7dec-11d0-a765-00a0c91e6bf6\\\"\"))\n;;=> true\n\n(uuid? \"f81d4fae-7dec-11d0-a765-00a0c91e6bf6\")\n;;=> false", :_id "592b2235e4b093ada4d4d780"} {:editors [{:login "E-A-Griffin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/53583563?v=4"}], :body ";; If using a version of Clojure >= 1.11 use `parse-uuid`\n(def new-u (parse-uuid \"4fe5d828-6444-11e8-8222-720007e40350\"))\n;;=> #'user/new-u\nnew-u\n;;=> #uuid \"4fe5d828-6444-11e8-8222-720007e40350\"\n(uuid? new-u)\n;;=> true\n\n;; There is no (uuid) function to coerce a string to a UUID prior to Clojure v1.11, but you can \n;; produce one via Java interop:\n\n(def old-u (java.util.UUID/fromString \"4fe5d828-6444-11e8-8222-720007e40350\"))\n;;=> #'user/old-u\nold-u\n;;=> #uuid \"4fe5d828-6444-11e8-8222-720007e40350\"\n(uuid? old-u)\n;;=> true", :author {:avatar-url "https://avatars1.githubusercontent.com/u/94482?v=4", :account-source "github", :login "timgilbert"}, :created-at 1527711361366, :updated-at 1665246163158, :_id "5b0f0681e4b045c27b7fac86"} {:updated-at 1539315353361, :created-at 1539315353361, :author {:login "ashton314", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/2874507?v=4"}, :body ";; Change a UUID to a string:\n\n\n(.toString (java.util.UUID/randomUUID))\n;;=>\"91bb281c-4cdd-4bea-bd9c-27b5f9c75812\"", :_id "5bc01699e4b00ac801ed9ed9"}], :notes [{:author {:login "E-A-Griffin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/53583563?v=4"}, :updated-at 1665246371235, :created-at 1665246331215, :body ";; Docs for added UUID functions in Clojure 1.11\n\n`parse-uuid`: https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/parse-uuid\n\n`random-uuid`: https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/random-uuid", :_id "6341a47be4b0b1e3652d7673"}], :arglists ["x"], :doc "Return true if x is a java.util.UUID", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/uuid_q"} {:added "1.0", :ns "clojure.core", :name "bit-clear", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1527805067810, :author {:login "NealEhardt", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1338977?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "bit-set", :ns "clojure.core"}, :_id "5b10748be4b045c27b7fac8b"}], :line 1331, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"} {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "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", :created-at 1280337817000, :updated-at 1332950801000, :_id "542692cbc026201cdc326bbf"}], :notes nil, :arglists ["x n"], :doc "Clear bit at index n", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/bit-clear"} {:added "1.0", :ns "clojure.core", :name "filter", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1282310761000, :author {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"}, :to-var {:ns "clojure.core", :name "remove", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e17"} {:created-at 1399907449000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "keep", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e19"} {:created-at 1413316825235, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :to-var {:ns "clojure.core", :name "filterv", :library-url "https://github.com/clojure/clojure"}, :_id "543d80d9e4b02688d208b1b6"} {:created-at 1487135971846, :author {:login "chrismurrph", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/10278575?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "group-by", :ns "clojure.core"}, :_id "58a3e4e3e4b01f4add58fe56"}], :line 2793, :examples [{:updated-at 1420743803007, :created-at 1279065921000, :body "(filter even? (range 10))\n;;=> (0 2 4 6 8)\n\n(filter (fn [x]\n (= (count x) 1))\n [\"a\" \"aa\" \"b\" \"n\" \"f\" \"lisp\" \"clojure\" \"q\" \"\"])\n;;=> (\"a\" \"b\" \"n\" \"f\" \"q\")\n\n(filter #(= (count %) 1)\n [\"a\" \"aa\" \"b\" \"n\" \"f\" \"lisp\" \"clojure\" \"q\" \"\"])\n;;=> (\"a\" \"b\" \"n\" \"f\" \"q\")\n\n; When coll is a map, pred is called with key/value pairs.\n(filter #(> (second %) 100)\n {:a 1\n :b 2\n :c 101\n :d 102\n :e -1})\n;;=> ([:c 101] [:d 102])\n\n(into {} *1)\n;;=> {:c 101, :d 102}\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:avatar-url "https://avatars.githubusercontent.com/u/263299?v=2", :account-source "github", :login "zw"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :_id "542692cac026201cdc326b5f"} {:updated-at 1435879726137, :created-at 1435879726137, :author {:login "bsvingen", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1647562?v=3"}, :body ";; Used without a collection, filter will create a transducer:\n(def xf (filter odd?))\n\n;; We can now apply this transducer to a sequence:\n(transduce xf conj (range 10))\n;; => [1 3 5 7 9]\n", :_id "5595c92ee4b00f9508fd66f4"} {:updated-at 1446483945707, :created-at 1446482046531, :author {:login "Art-B", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1143795?v=3"}, :body ";;When filtering a map, the predicate takes a _list_ of length 2\n(filter (fn [[k v]] (even? k))\n {1 \"a\", 2 \"b\", 3 \"c\", 4 \"d\"}\n)\n;;output:: ([2 \"b\"] [4 \"d\"])\n\n;;A function of arity two will cause an error\n(comment will fail!) \n(filter (fn [k v] (even? k))\n {1 \"a\", 2 \"b\", 3 \"c\", 4 \"d\"}\n)\n;;output:: clojure.lang.ArityException: Wrong number of args (1) passed to: ...", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/1143795?v=3", :account-source "github", :login "Art-B"}], :_id "5637907ee4b04b157a6648df"} {:updated-at 1638750543664, :created-at 1446999529588, :author {:login "puppybits", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/140163?v=3"}, :body "; remove empty vectors from the root vector\n(def vector-of-vectors [[1 2 3] [] [1] []])\n\n(def populated-vector? \n (fn \n [item] \n (not= item [])))\n\n(filter populated-vector? vector-of-vectors)\n\n; => ([1 2 3] [1])\n\n; or\n(filter seq vector-of-vectors)", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/140163?v=3", :account-source "github", :login "puppybits"} {:login "KyleErhabor", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/40676441?v=4"}], :_id "563f75e9e4b0290a56055d22"} {:updated-at 1471132372267, :created-at 1471132372267, :author {:login "sleyzerzon", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/528932?v=3"}, :body ";;filter a map on its values\n(filter (comp #{2 3} last) {:x 1 :y 2 :z 3})\n;;=> ([:y 2] [:z 3])", :_id "57afb2d4e4b02d8da95c26fd"} {:updated-at 1471132498612, :created-at 1471132498612, :author {:login "sleyzerzon", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/528932?v=3"}, :body ";;filter a map on its values\n(filter (comp #{2 3} last) {:x 1 :y 2 :z 3})\n;;=> ([:y 2] [:z 3])\n\n;;extract keys for certain values\n(map first (filter (comp #{2 3} last) {:x 1 :y 2 :z 3}))\n=> (:y :z)", :_id "57afb352e4b02d8da95c26fe"} {:editors [{:login "mdubakov", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/465999?v=3"}], :body ";; You can use set as a filter predicate. In this case it is sets intersection\n(filter #{0 1 2 3} #{2 3 4 5})\n=> (3 2) ", :author {:avatar-url "https://avatars2.githubusercontent.com/u/465999?v=3", :account-source "github", :login "mdubakov"}, :created-at 1491555992092, :updated-at 1491556073772, :_id "58e75698e4b01f4add58fe86"} {:updated-at 1494575824785, :created-at 1494575824785, :author {:login "st-keller", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/476463?v=3"}, :body ";; That's how to get everything from a seq that is not nil;\n(filter some? '(1 nil [] :a nil))\n=> (1 [] :a)", :_id "59156ad0e4b01920063ee05a"} {:updated-at 1517054565714, :created-at 1517054565714, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;practical example using an anonymous function \n;;which return a boolean value\n(def entries [{:month 1 :val 12 :s1 true :s2 false}\n {:month 2 :val 3 :s1 false :s2 true}\n {:month 3 :val 32 :s1 true :s2 false}\n {:month 4 :val 18 :s1 true :s2 false}\n {:month 5 :val 32 :s1 false :s2 true}\n {:month 6 :val 62 :s1 false :s2 true}\n {:month 7 :val 12 :s1 false :s2 true}\n {:month 8 :val 142 :s1 true :s2 false}\n {:month 9 :val 52 :s1 true :s2 false}\n {:month 10 :val 18 :s1 true :s2 false}\n {:month 11 :val 23 :s1 false :s2 true}\n {:month 12 :val 56 :s1 false :s2 true}])\n\n(filter #(:s2 %) entries)\n\n(filter #(and (:s2 %) (> (:val %) 30)) entries)\n", :_id "5a6c6a65e4b076dac5a728aa"} {:editors [{:login "ahmadrasyidsalim", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/18344132?v=4"}], :body ";; given users\n;; [\"pinisi\" \"sikad\" \"zenius\" \"teacher\" \"law\" \"calvin\" \"ijul\"]\n;; \n;; kick \"law\" and \"teacher\"\n\n(filter #(not (some (fn [u] (= u %)) \n [\"law\" \"teacher\"])) \n [\"pinisi\" \"sikad\" \"zenius\" \"teacher\" \"law\" \"calvin\" \"ijul\"])", :author {:avatar-url "https://avatars3.githubusercontent.com/u/5813694?v=4", :account-source "github", :login "codxse"}, :created-at 1530620467973, :updated-at 1632120981728, :_id "5b3b6a33e4b00ac801ed9e23"} {:editors [{:login "tmountain", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/135297?v=4"}], :body ";; if you want to apply multiple predicates, use every-pred\n;; in conjunction with filter\n;; output: (2, 4)\n\n(filter\n (apply every-pred [even? #(< % 5)]) [1, 2, 3, 4, 5])\n\n;; if you want to apply any predicate, use some-fn\n;; output: (0 2 4 6 7 8 9)\n\n(filter\n (some-fn even? #(> % 5))\n (range 10))", :author {:avatar-url "https://avatars1.githubusercontent.com/u/135297?v=4", :account-source "github", :login "tmountain"}, :created-at 1539887379558, :updated-at 1539888985733, :_id "5bc8d113e4b00ac801ed9ee4"}], :notes [{:author {:login "brunchboy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2228869?v=3"}, :updated-at 1441227184007, :created-at 1441227184007, :body "Although the documentation states that the predicate must be free of side effects, it would be more accurate to say that you should not rely on filter to induce side effects that may be caused by the predicate, nor on the timing of when the predicate will be evaluated, because of the lazy and chunked nature of filter.", :_id "55e761b0e4b0efbd681fbb93"} {:author {:login "mattiasw2", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1294931?v=3"}, :updated-at 1474933697182, :created-at 1474933697182, :body "Note that filtering a map will not create a map. If you want to do a lookup on the result, you need to surround the call to filter with (into {} (filter ...))", :_id "57e9b3c1e4b0709b524f050e"}], :arglists ["pred" "pred coll"], :doc "Returns a lazy sequence of the items in coll for which\n (pred item) returns logical true. pred must be free of side-effects.\n Returns a transducer when no collection is provided.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/filter"} {:added "1.0", :ns "clojure.core", :name "locking", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1410129605000, :author {:login "SQuest", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/14c2b5159bb6d42d41ab04b1c714bd1b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "future", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c76"}], :line 1647, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "Ljos", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/45b996a79abca465acaf6c0f10b0437?r=PG&default=identicon"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "(def o (Object.))\n(future (locking o \n (Thread/sleep 5000) \n (println \"done1\")))\n\n;; Now run this before 5 seconds is up and you'll \n;; find the second instance waits for the first instance to print done1\n;; and release the lock, and then it waits for 1 second and prints done2\n\n(Thread/sleep 1000) ; give first instance 1 sec to acquire the lock\n(locking o \n (Thread/sleep 1000)\n (println \"done2\"))\n;; => done1\n;; => done2\n;; => nil\n\n;; locking operates like the synchronized keyword in Java.\n", :created-at 1286271996000, :updated-at 1423012941325, :_id "542692cdc026201cdc326d21"} {:updated-at 1563441285293, :created-at 1563441285293, :author {:login "liuchong", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/236058?v=4"}, :body "(def x 1)\n\n;; Reentrant\n\n(locking x (locking x (println \"hehe in\")) (println \"hehe out\"))\n;; => hehe in\n;; => hehe out\n;; => nil", :_id "5d303885e4b0ca44402ef787"}], :macro true, :notes nil, :arglists ["x & body"], :doc "Executes exprs in an implicit do, while holding the monitor of x.\n Will release the monitor of x in all circumstances.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/locking"} {:added "1.0", :ns "clojure.core", :name "list", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 16, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (list 'a 'b 'c 'd 'e 'f 'g)\n(a b c d e f g)\nuser=> (list 1 2 3)\n(1 2 3)", :created-at 1279072062000, :updated-at 1332950370000, :_id "542692cfc026201cdc326e52"} {:author {:login "devijvers", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (let [m {:1 1 :2 2 :3 3 :4 4}] (map list (keys m) (vals m)))\n((:1 1) (:2 2) (:3 3) (:4 4))", :created-at 1279557389000, :updated-at 1332950386000, :_id "542692cfc026201cdc326e54"} {:body ";; Lists can also be constructed literally using quote, but note the difference\n\n;; When using list the arguments are evaluated\n(let [x 1 y 2]\n (list x y))\n;; => (1 2)\n\n;; ... and when using quote ' they are not:\n(let [x 1 y 2]\n '(x y))\n;; => (x y)\n\n;; there is syntax quote ` (back tick) that allows selective evaluation inside it with ~:\n(let [x 1 y 2]\n `(~x ~y))\n;; => (1 2)\n\n;; But syntax quote ` is mostly used in macro definitions where most elements\n;; should not be evaluated and unquoted with ~ and list form above feels\n;; more idiomatic for simple list construction.", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423011991402, :updated-at 1423012027889, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :_id "54d17097e4b0e2ac61831cfe"}], :notes nil, :arglists ["& items"], :doc "Creates a new list containing the items.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/list"} {:added "1.2", :ns "clojure.core", :name "+", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1351919360000, :author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :to-var {:ns "clojure.core", :name "+'", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cb3"} {:created-at 1314343076000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "*", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eaa"} {:created-at 1314343079000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "-", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521eab"} {:created-at 1423526895712, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "unchecked-add", :library-url "https://github.com/clojure/clojure"}, :_id "54d94befe4b081e022073c82"} {:created-at 1525303139502, :author {:login "NealEhardt", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/1338977?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "inc", :ns "clojure.core"}, :_id "5aea4763e4b045c27b7fac5d"}], :line 984, :examples [{:updated-at 1598154469428, :created-at 1279418175000, :body "(+)\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(+ 1/2 1/2)\n;;=> 1N\n\n(apply + (range 10000000000000 10000000001000))\n;; ArithmeticException: integer overflow", :editors [{:login "MrHus", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4"} {:avatar-url "https://www.gravatar.com/avatar/edeae8e7534b3d554e4ec2c35ffc68d?r=PG&default=identicon", :account-source "clojuredocs", :login "semperos"} {:avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon", :account-source "clojuredocs", :login "TimMc"} {:avatar-url "https://www.gravatar.com/avatar/611bdccae60c79419a30df0e2d6adc2b?r=PG&default=identicon", :account-source "clojuredocs", :login "csophys"} {:avatar-url "https://www.gravatar.com/avatar/60838f7abe2eb311a6e00b10597f34c2?r=PG&default=identicon", :account-source "clojuredocs", :login "BenjyCui"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=2", :account-source "github", :login "phreed"} {:login "berczeck", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1321842?v=4"}], :author {:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"}, :_id "542692c8c026201cdc326a18"}], :notes nil, :arglists ["" "x" "x y" "x y & more"], :doc "Returns the sum of nums. (+) returns 0. Does not auto-promote\n longs, will throw on overflow. See also: +'", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/+"} {:added "1.0", :ns "clojure.core", :name "split-with", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1314290648000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "split-at", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c05"} {:created-at 1314291178000, :author {:login "Havvy", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"}, :to-var {:ns "clojure.string", :name "split", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c06"} {:created-at 1347077825000, :author {:login "dansalmo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "take-while", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c07"} {:created-at 1347077831000, :author {:login "dansalmo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "drop-while", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c08"} {:created-at 1659193713800, :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "partition-by", :ns "clojure.core"}, :_id "62e54971e4b0b1e3652d7633"}], :line 2992, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "user=> (split-with (partial >= 3) [1 2 3 4 5])\n[(1 2 3) (4 5)]\n\nuser=> (split-with (partial > 3) [1 2 3 2 1])\n[(1 2) (3 2 1)]\n\nuser=> (split-with (partial > 10) [1 2 3 2 1])\n[(1 2 3 2 1) ()]", :created-at 1281512571000, :updated-at 1423277699986, :_id "542692c8c026201cdc3269ee"} {:editors [{:login "achesnais", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6626105?v=3"} {:avatar-url "https://avatars.githubusercontent.com/u/1200122?v=3", :account-source "github", :login "Bediako"} {:login "v-kolesnikov", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/6506296?v=4"}], :body ";; If your plan is to split based on a certain value, using sets as\n;; predicates here isn't entirely straightforward.\n\nuser=> (split-with #{:c} [:a :b :c :d])\n[() (:a :b :c :d)]\n\n;; This is because the split happens at the first false/nil predicate result.\n;; Your predicate should thus return false upon hitting the desired split value!\n\nuser=> (split-with (complement #{:c}) [:a :b :c :d])\n[(:a :b) (:c :d)]\n\n;; In short, the predicate defines an attribute valid for the whole left\n;; side of the split. There's no such guarantee for the right side!\n\nuser=> (split-with odd? [1 3 5 6 7 9])\n[(1 3 5) (6 7 9)]\n\n;; Except if your predicate never returns false.\nuser=> (split-with (complement #{:e}) [:a :b :c :d])\n[(:a :b :c :d) ()]\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/6626105?v=3", :account-source "github", :login "achesnais"}, :created-at 1470855993350, :updated-at 1511009715200, :_id "57ab7b39e4b0bafd3e2a04dd"} {:updated-at 1623499263951, :created-at 1581787276541, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; The following split-by builds on top of split-with. Instead of \n;; splitting only the first time pred returns false, it splits (lazily)\n;; every time it turns from true to false.\n\n(defn split-by [pred coll]\n (lazy-seq\n (when-let [s (seq coll)]\n (let [[xs ys] (split-with pred s)]\n (if (seq xs)\n (cons xs (split-by pred ys))\n (let [!pred (complement pred)\n skip (take-while !pred s)\n others (drop-while !pred s)\n [xs ys] (split-with pred others)]\n (cons (concat skip xs)\n (split-by pred ys))))))))\n\n(split-by #(zero? (mod % 2)) [1 1 2 3 3 4 5 6 7 9])\n;; => ((1 1 2) (3 3 4) (5 6) (7 9))", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"} {:login "frwdrik", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/13023061?v=4"}], :_id "5e48288ce4b0ca44402ef839"}], :notes nil, :arglists ["pred coll"], :doc "Returns a vector of [(take-while pred coll) (drop-while pred coll)]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/split-with"} {:added "1.0", :ns "clojure.core", :name "aset", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1588281651305, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "aget", :ns "clojure.core"}, :_id "5eab4133e4b087629b5a18ee"} {:created-at 1668707576824, :author {:login "claj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/353113?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "aset-int", :ns "clojure.core"}, :_id "637674f8e4b0b1e3652d7683"} {:created-at 1668707583337, :author {:login "claj", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/353113?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "aset-double", :ns "clojure.core"}, :_id "637674ffe4b0b1e3652d7684"}], :line 3923, :examples [{:author {:login "dakrone", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"}, :editors [], :body "user=> (def my-array (into-array Integer/TYPE [1 2 3]))\n#'user/my-array\n\nuser=> (aset my-array 1 10) ; Set the element with index 1 to 10\n10\n\nuser=> (into [] my-array)\n[1 10 3]", :created-at 1286508598000, :updated-at 1286508598000, :_id "542692cbc026201cdc326ba0"} {:body "; Two dimensional example\n(use 'clojure.pprint)\n(let [the-array (make-array Long/TYPE 2 3) ]\n (dotimes [nn 6]\n (let [ii (quot nn 3)\n jj (rem nn 3) ]\n (aset the-array ii jj nn)\n ))\n (pprint the-array)\n)\n;=> [[0, 1, 2], [3, 4, 5]]\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\n\n", :author {:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=3"}, :created-at 1423782804290, :updated-at 1423783298831, :editors [{:login "cloojure", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7083783?v=3"}], :_id "54dd3394e4b0e88f43c5afa1"} {:body ";; Simple 2D example:\n(def a (to-array-2d [[1 2] [3 4]]))\n;=> #'expt.core/a\n(aset a 0 1 \"foo\")\n;=> \"foo\"\nexpt.core=> (map vec a)\n;=> ([1 \"foo\"] [3 4])", :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :created-at 1432828883628, :updated-at 1432829193467, :editors [{:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}], :_id "55673bd3e4b01ad59b65f4dc"} {:updated-at 1588283235231, :created-at 1588282039336, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4"}, :body ";; transpose a matrix (two-dimensional array of doubles)\n;; using in-place mutation and no additional memory space.\n\n(defn transpose! [^\"[[D\" matrix]\n (dotimes [i (alength matrix)]\n (doseq [j (range (inc i) (alength matrix))]\n (let [copy (aget matrix i j)]\n (aset matrix i j (aget matrix j i))\n (aset matrix j i copy)))))\n\n(def matrix\n (into-array\n (map double-array\n [[1.0 2.0 3.0]\n [4.0 5.0 6.0]\n [7.0 8.0 9.0]])))\n\n(transpose! matrix)\n(mapv vec matrix)\n\n;; [[1.0 4.0 7.0]\n;; [2.0 5.0 8.0]\n;; [3.0 6.0 9.0]]\n", :editors [{:avatar-url "https://avatars1.githubusercontent.com/u/20086?v=4", :account-source "github", :login "reborg"}], :_id "5eab42b7e4b087629b5a18ef"} {:updated-at 1682634188137, :created-at 1682634188137, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; Doubles are converted to floats; longs to ints, and vice versa:\n(aset (int-array [1 2 3]) 0 (long 42))\n;; => 42\n\n(aset (long-array [1 2 3]) 0 (int 42))\n;; => 42\n\n(aset (float-array [1.0 2.0 3.0]) 0 (double 42.0))\n;; => 42.0\n\n(aset (double-array [1.0 2.0 3.0]) 0 (float 42.0))\n;; => 42.0\n\n;; But some other conversions that may seem possible, are not:\n(aset (byte-array [1 2 3]) 0 (int 42))\n;; => Execution error (IllegalArgumentException) at…\n;; No matching method aset found taking 3 args\n\n(aset (short-array [1 2 3]) 0 (long 42))\n;; => Execution error (IllegalArgumentException) at…\n;; No matching method aset found taking 3 args\n\n;; It's best to be explicit:\n(aset (short-array [1 2 3]) 0 (short 42))\n;; => 42\n", :_id "644af5cce4b08cf8563f4b9e"}], :notes nil, :arglists ["array idx val" "array idx idx2 & idxv"], :doc "Sets the value at the index/indices. Works on Java arrays of\n reference types. Returns val.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/aset"} {:ns "clojure.core", :name "->VecNode", :file "clojure/gvec.clj", :type "function", :column 1, :see-alsos nil, :line 17, :examples nil, :notes nil, :arglists ["edit arr"], :doc "Positional factory function for class clojure.core.VecNode.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/->VecNode"} {:added "1.0", :ns "clojure.core", :name "keyword", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1292127515000, :author {:login "bgruber", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3c2dc1a076ff6e60dfb085ecddcc9f6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "name", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cf9"} {:created-at 1318592819000, :author {:login "mmwaikar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "keyword?", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cfa"} {:created-at 1331680528000, :author {:login "franks42", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "namespace", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cfb"} {:created-at 1331680582000, :author {:login "franks42", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "find-keyword", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cfc"} {:created-at 1350410417000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "symbol", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cfd"}], :line 614, :examples [{:updated-at 1406075185000, :created-at 1280546489000, :body ";; (keyword name): name can be string, symbol, or keyword.\n;; \n;; (keyword ns name): ns and name must both be string.\n;; \n;; A keyword string, like a symbol, begins with a non-numeric\n;; character and can contain alphanumeric characters and *, +, !, -,\n;; _, and ?. (see http://clojure.org/reader for details).\n;; \n;; keyword does not validate input strings for ns and name, and may\n;; return improper keywords with undefined behavior for non-conformant\n;; ns and name.\n\nuser=> (keyword 'foo)\n:foo\n\nuser=> (keyword \"foo\") \n:foo\n\nuser=> (keyword \"user\" \"foo\")\n:user/foo\n\n;; keyword in current namespace\nuser=> (keyword (str *ns*) \"foo\")\n:user/foo", :editors [{:avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon", :account-source "clojuredocs", :login "gstamp"} {:avatar-url "https://www.gravatar.com/avatar/7567c12df3f5e8f8ca031d4320b476ba?r=PG&default=identicon", :account-source "clojuredocs", :login "Alan"} {:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"}], :author {:avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon", :account-source "clojuredocs", :login "dakrone"}, :_id "542692cec026201cdc326d70"} {:author {:login "franks42", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/b3ee701dd6c481e5d310467ddfe62c48?r=PG&default=identicon"}, :editors [{:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}], :body ";; some gotchas to be aware of:\n\nuser=> (keyword \"user\" 'abc)\nClassCastException clojure.lang.Symbol cannot be cast to java.lang.String clojure.core/keyword (core.clj:558)\n\nuser=> (keyword *ns* \"abc\")\nClassCastException clojure.lang.Namespace cannot be cast to java.lang.String clojure.core/keyword (core.clj:558)\n\nuser=> (keyword 'user \"abc\")\nClassCastException clojure.lang.Symbol cannot be cast to java.lang.String clojure.core/keyword (core.clj:558)\n\n\n;; Warning - the following generated keywords are non-conformant and may wreak\n;; serious havoc in the near/far future when least expected...\n;; Even if `keyword?` might return true for them and they seem to work with\n;; `name` and `namespace` as well, and they can be used as functions\n;; (e.g. `(:/// {:/// \"x\"})` works), problems usually come at e.g. destructuring... \n\nuser=> (keyword \"abc def\")\n:abc def\n\nuser=> (keyword \"123def\")\n:123def\n\nuser=> (keyword \"/abc/def/ghi\")\n:/abc/def/ghi\n\nuser=> (keyword \":\" \":\")\n::/:\n\nuser=> (keyword \"/\" \"/\")\n:///\n\nuser=> (keyword \"\")\n:\n\nuser=> (keyword \"\" \"/\")\n://\n\nuser=> (keyword \"...\")\n:...", :created-at 1331680488000, :updated-at 1548520687081, :_id "542692d3c026201cdc326fde"} {:updated-at 1406075556000, :created-at 1392677011000, :body ";; You can define namespaced keywords using '::'\nuser=> (def a :foo)\n#'user/a\n\nuser=> (def b ::foo)\n#'user/b\n\nuser=> (ns foo)\nfoo=> user/a\n:foo\n\nfoo=> user/b\n:user/foo\n\nfoo=> ::foo\n:foo/foo\n\nfoo=> (= user/a :foo)\ntrue\n\nfoo=> (= user/b ::foo)\nfalse\n\nfoo=> (= user/b :user/foo)\ntrue", :editors [{:avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon", :account-source "clojuredocs", :login "Phalphalak"} {:avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon", :account-source "clojuredocs", :login "Phalphalak"} {:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"}], :author {:avatar-url "https://www.gravatar.com/avatar/a684c0fd4f27597437de953e92a15d4b?r=PG&default=identicon", :account-source "clojuredocs", :login "Phalphalak"}, :_id "542692d3c026201cdc326fe0"} {:updated-at 1445848617591, :created-at 1445848617591, :author {:login "ShayMatasaro", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1350551?v=3"}, :body ";;only convert strings\nuser=> (keyword 1)\nnil\n\n\nuser=> (keyword '1)\nnil\n", :_id "562de629e4b0290a56055d13"} {:editors [{:login "PetrGlad", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/124476?v=3"}], :body "(keyword \"my.key\")\n;=> :my.key\n(qualified-keyword? :my.key)\n;=> nil ;; \"my.key\" is just name, dot does not count\n(keyword \"my.namespace\" \"my.key\") \n;=> :my.namespace/my.key\n(qualified-keyword? :my.namespace/my.key)\n;=> true \n(namespace :my.namespace/my.key) \n;=> \"my.namespace\"\n(name :my.namespace/my.key) \n;=> \"my.key\"\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/124476?v=3", :account-source "github", :login "PetrGlad"}, :created-at 1482252029047, :updated-at 1482252099977, :_id "58595efde4b004d3a355e2c9"} {:updated-at 1517353605671, :created-at 1517352728207, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}, :body ";; let's make an illustrative namespace\n(create-ns 'my.arbitrary.long.namespace)\n(alias 'maln 'my.arbitrary.long.namespace)\n;; more typically loaded and aliased with require\n;; (require '[my.arbitrary.long.namespace :as maln])\n\n;; Qualified keywords may be specified with the namespace or the alias.\n;; But unlike with symbols where the bare alias is used \n;; you need to prefix the alias with '::' \n:my.arbitrary.long.namespace/foo\n;=> :my.arbitrary.long.namespace/foo\n::maln/bar\n;=> :my.arbitrary.long.namespace/bar", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4", :account-source "github", :login "phreed"}], :_id "5a70f718e4b0c974fee49d14"} {:editors [{:login "jasonisgraham", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/3493406?v=4"} {:avatar-url "https://avatars3.githubusercontent.com/u/11671382?v=4", :account-source "github", :login "dominem"}], :body "\n;; You can use existing keywords (cljs only)\n\n(keyword :namespace :keyword)\n;;=> :namespace/keyword\n\n(keyword \"namespace\" :keyword)\n;;=> :namespace/keyword\n\n(keyword :namespace \"keyword\")\n;;=> :namespace/keyword\n\n(keyword :meta-namespace/namespace :meta-keyword/keyword)\n;;=> :namespace/keyword\n", :author {:avatar-url "https://avatars2.githubusercontent.com/u/10955264?v=4", :account-source "github", :login "troglotit"}, :created-at 1527776571957, :updated-at 1565335543185, :_id "5b10053be4b045c27b7fac89"} {:editors [{:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}], :body ";; different (non-conformant) keywords can have the same printed representation:\n\n(= :a/b/c (keyword \"a\" \"b/c\"))\n;;=> true\n\n(keyword \"a/b\" \"c\")\n;;=> :a/b/c\n\n(= (str (keyword \"a/b\" \"c\")) (str (keyword \"a\" \"b/c\")))\n;;=> true\n\n(= (keyword \"a/b\" \"c\") (keyword \"a\" \"b/c\"))\n;;=> false\n", :author {:avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4", :account-source "github", :login "cljlc"}, :created-at 1548521622644, :updated-at 1548521923629, :_id "5c4c9096e4b0ca44402ef63d"} {:updated-at 1599398418945, :created-at 1599398354277, :author {:login "luiszambon", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/41161270?v=4"}, :body "(defn creating-map\n [key value]\n {(keyword key) value})\n\n(:map-key (creating-map \"map-key\" \"map-value\"))\n;;=>\"map-value\"", :editors [{:avatar-url "https://avatars0.githubusercontent.com/u/41161270?v=4", :account-source "github", :login "luiszambon"}], :_id "5f54e1d2e4b0b1e3652d73b0"} {:updated-at 1641596456686, :created-at 1641596456686, :author {:login "jkndrkn", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/91959?v=4"}, :body ";; Be careful because it is possible to create keywords that contain whitespace\n\n(keyword \"my-keyword\\t\")\n;;=> :my-keyword\n\n(name (keyword \"my-keyword\\t\"))\n;;=> \"my-keyword\\t\"\n\n\n(= (keyword \"my-keyword\") :my-keyword)\n;;=> true\n\n(= (keyword \"my-keyword\\t\") :my-keyword)\n;;=> false\n", :_id "61d8c628e4b0b1e3652d759d"}], :notes nil, :tag "clojure.lang.Keyword", :arglists ["name" "ns name"], :doc "Returns a Keyword with the given namespace and name. Do not use :\n in the keyword strings, it will be added automatically.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/keyword"} {:added "1.0", :ns "clojure.core", :name "*ns*", :type "var", :see-alsos nil, :examples [{:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [], :body "user=> *ns*\n#", :created-at 1289039963000, :updated-at 1289039963000, :_id "542692c7c026201cdc3269c7"} {:author {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"}, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/92894?v=3", :account-source "github", :login "rafmagana"}], :body "user=> (ns foo.bar)\nnil\n\nfoo.bar=> *ns*\n#", :created-at 1406094577000, :updated-at 1406094613000, :_id "542692d1c026201cdc326f35"} {:editors [{:login "Artiavis", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/1834136?v=3"}], :body ";; A (rare) trap which can happen is attempting to dynamically call `in-ns`, due to how\n;; `*ns*` is really an instance of `clojure.lang.Var` with a root binding.\nuser=> (ns my.namespace)\nnil\n\nmy.namespace=> *ns*\n#\n\n;; This will *only* work in the REPL (or REPL-like environments)!!\n;; Tools like Boot and Lein may or may not provide this (read the manual/code)\nmy.namespace=> (defn swap-ns! [ns-name] (in-ns ns-name))\n#'my.namespace/swap-ns!\n\nmy.namespace=> (swap-ns! 'other.ns)\n#namespace[other.ns]\n\n;; Later, at runtime...\n;; Throws IllegalStateException(\"Can't change/establish root binding of: *ns* with set\")\n;; Remember, *ns* is a root var and in-ns calls set!, which only works after\n;; someone somewhere calls the binding macro (or Java equivalent)\n(defn -main\n [& args]\n (println *ns*)\n (swap-ns! 'arbitrary-namespace))\n;; prints #namespace[clojure.core] and then will crash", :author {:avatar-url "https://avatars1.githubusercontent.com/u/1834136?v=3", :account-source "github", :login "Artiavis"}, :created-at 1497795113128, :updated-at 1497795249422, :_id "59468a29e4b06e730307db35"}], :notes [{:updated-at 1310470085000, :body "A trap I fell into was that *ns* seems to get assigned to clojure.core when run as a \"gen-class\" compiled class.", :created-at 1310470085000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fc4"} {:body "To clarify the above point, see my example above. Although within Lein/Boot/REPL/Compiler contexts, `*ns*` is thread-local due to the use of the `binding` machinery, and so `in-ns` works in those situtations, `*ns*` has a root of `clojure.core`. That means that, at runtime, you cannot call `in-ns` within functions until you've first called `binding`. (This could be relevant for e.g. `eval` calls.)", :created-at 1497579558843, :updated-at 1497795316359, :author {:avatar-url "https://avatars1.githubusercontent.com/u/1834136?v=3", :account-source "github", :login "Artiavis"}, :_id "59434026e4b06e730307db34"}], :tag "clojure.lang.Namespace", :arglists [], :doc "A clojure.lang.Namespace object representing the current namespace.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*ns*"} {:ns "clojure.core", :name "destructure", :file "clojure/core.clj", :type "function", :column 1, :see-alsos nil, :line 4389, :examples [{:author {:login "reborg", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5b2768c3c24e6e96d838c4c43038de93?r=PG&default=identicon"}, :editors [], :body "; look ma, no let!\n(map #(intern *ns* (first %) (eval (last %))) (partition 2 (destructure '[[a b] [\"a\" \"b\"]])))\nuser=> a\n\"a\"\nuser=> b\n\"b\"", :created-at 1396388229000, :updated-at 1396388229000, :_id "542692d2c026201cdc326f8d"} {:updated-at 1519692244573, :created-at 1519675914364, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}, :body ";; Based on the previous example...\n\n;; Suppose you want to do some work at the repl.\n;; It would be nice if the def and let had similar syntax but they do not.\n\n(defn def+ [bindings] \n (let [bings (partition 2 (destructure bindings))\n obj (first bings)\n redef (rest bings)]\n \n (intern *ns* (first obj) (eval (second obj))) \n (map #(intern *ns* (first %) (eval (last %))) redef)))\n\n(def+ '[[u s v] [1 5 9]]) \n \n;; def+ is better implemented as a macro.\n;; It does have the drawback of introducing some intermediate gen variables.\n;; But, it prints the names of all variables.\n\n(defmacro def+\n \"binding => binding-form\n internalizes binding-forms as if by def.\"\n {:added \"1.9\", :special-form true, :forms '[(def+ [bindings*])]}\n [& bindings]\n (let [bings (partition 2 (destructure bindings))]\n (sequence cat \n ['(do) \n (map (fn [[var value]] `(def ~var ~value)) bings)\n [(mapv (fn [[var _]] (str var)) bings)]])))\n\n(def+ [u s v] [1 5 9] \n foo \"bar\" \n [a b] [\"abc\" \"bcd\"])\n;=> #'user/b\n\na\n;=> \"abc\"\n\n;; The justification for such a macro is manifest when\n;; debugging at the repl.\n;; Suppose the following is in a function and \n(let [[a b] [\"a\" \"b\"]] \n (str a b) ; is this correct?\n (conj a b) ; how about this?\n (cat a b)) ; or this?\n\n;; Now in this case the problem is clear but in general it may not be.\n;; So you get set up to track down this problem. \n(def+ [a b] [\"a\" \"b\"])\n\n;; Without def+ you would have to do something like the following...\n(def ab [\"a\" \"b\"])\n(def a (nth ab 0))\n(def b (nth ab 1))\n;; ...to get set up in the repl.", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4", :account-source "github", :login "phreed"}], :_id "5a946a0ae4b0316c0f44f8f2"}], :notes [{:author {:login "Ragsboss", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/3869936?v=3"}, :updated-at 1494263800930, :created-at 1494263800930, :body "I found https://clojure.org/guides/destructuring extremely useful", :_id "5910a7f8e4b01f4add58feb1"} {:body "\"[The `destructure` function] implements the destructuring logic and [...] is designed to be invoked in a macro\". For more info about `desctructure` see https://clojure.org/guides/destructuring#_macros.", :created-at 1519164976336, :updated-at 1519165254309, :author {:avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4", :account-source "github", :login "cljlc"}, :_id "5a8c9e30e4b0316c0f44f8d8"}], :arglists ["bindings"], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/destructure"} {:ns "clojure.core", :name "*assert*", :type "var", :see-alsos [{:created-at 1301778092000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "assert", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d09"}], :examples [{:updated-at 1475615278407, :created-at 1475615278407, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}, :body "user=> (set! *assert* true)\n\nuser=> (defn str->int\n [x]\n {:pre [(string? x)]}\n (Integer/valueOf x))\n\nuser=> (str->int 12.2)\n;;=> AssertionError Assert failed: (string? x) user/str->int...", :_id "57f41a2ee4b0709b524f051e"}], :notes [{:updated-at 1406676369000, :body "A little digging through the RT.java code confirms that this is dynamic, and defaults to true.", :created-at 1406676369000, :author {:login "hlship", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cb598cc180c2363c093e92e8e87e0493?r=PG&default=identicon"}, :_id "542692edf6e94c697052202e"}], :arglists [], :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*assert*"} {:added "1.0", :ns "clojure.core", :name "defmulti", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1285162568000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defmethod", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c30"} {:created-at 1341270331000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "remove-method", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c31"} {:created-at 1341270338000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "remove-all-methods", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c32"} {:created-at 1341270344000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "prefers", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c33"} {:created-at 1341270349000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "methods", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c34"} {:created-at 1341270355000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "get-method", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c35"} {:created-at 1351463879000, :author {:login "klauern", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "defprotocol", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521c36"} {:created-at 1413313710551, :author {:login "kgann", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1098962?v=2"}, :to-var {:ns "clojure.core", :name "make-hierarchy", :library-url "https://github.com/clojure/clojure"}, :_id "543d74aee4b02688d208b1b5"} {:created-at 1485980931712, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "multi-spec", :ns "clojure.spec"}, :_id "58924503e4b01f4add58fe38"}], :line 1725, :examples [{:author {:login "Victor", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc41ebab54cc0e0fbe99d753876d45ce?r=PG&default=identicon"}, :editors [{:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:avatar-url "https://avatars.githubusercontent.com/u/200617?v=3", :account-source "github", :login "bsima"} {:avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4", :account-source "github", :login "bfontaine"} {:login "Luke1298", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7078861?v=4"}], :body ";; 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)", :created-at 1290489704000, :updated-at 1643237673567, :_id "542692cdc026201cdc326d58"} {:author {:login "Victor", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc41ebab54cc0e0fbe99d753876d45ce?r=PG&default=identicon"}, :editors [{:login "stand", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d7f9ed2753f8b3517f1539f6129f0a17?r=PG&default=identicon"} {:avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4", :account-source "github", :login "bfontaine"} {:login "blue0513", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/8979468?v=4"}], :body ";this example illustrates that the dispatch type\n;does not have to be a symbol, but can be anything (in this case, it's a string)\n\n(defmulti greeting\n (fn[x] (get x \"language\")))\n\n;params is not used, so we could have used [_]\n(defmethod greeting \"English\" [params]\n \"Hello!\")\n\n(defmethod greeting \"French\" [params]\n \"Bonjour!\")\n\n;;default handling\n(defmethod greeting :default [params]\n (throw (IllegalArgumentException. \n (str \"I don't know the \" (get params \"language\") \" language\"))))\n\n;then can use this like this:\n(def english-map {\"id\" \"1\", \"language\" \"English\"})\n(def french-map {\"id\" \"2\", \"language\" \"French\"})\n(def spanish-map {\"id\" \"3\", \"language\" \"Spanish\"})\n\n=>(greeting english-map)\n\"Hello!\"\n=>(greeting french-map)\n\"Bonjour!\"\n=>(greeting spanish-map)\n java.lang.IllegalArgumentException: I don't know the Spanish language", :created-at 1290492895000, :updated-at 1589637326870, :_id "542692cdc026201cdc326d59"} {:author {:login "OnesimusUnbound", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"}, :editors [{:login "cddr", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/48030?v=3"}], :body ";; Implementing factorial using multimethods Note that factorial-like function \n;; is best implemented using `recur` which enables tail-call optimization to avoid \n;; a stack overflow error. This is a only a demonstration of clojure's multimethod\n\n;; identity form returns the same value passed\n(defmulti factorial identity)\n\n(defmethod factorial 0 [_] 1)\n(defmethod factorial :default [num] \n (* num (factorial (dec num))))\n\n(factorial 0) ; => 1\n(factorial 1) ; => 1\n(factorial 3) ; => 6\n(factorial 7) ; => 5040", :created-at 1313197324000, :updated-at 1433710661793, :_id "542692cdc026201cdc326d5b"} {:body ";; defmulti/defmethods support variadic arguments and dispatch functions.\n\n(defmulti bat \n (fn ([x y & xs] \n (mapv class (into [x y] xs)))))\n(defmethod bat [String String] [x y & xs] \n (str \"str: \" x \" and \" y))\n(defmethod bat [String String String] [x y & xs] \n (str \"str: \" x \", \" y \" and \" (first xs)))\n(defmethod bat [String String String String] [x y & xs] \n (str \"str: \" x \", \" y \", \" (first xs) \" and \" (second xs)))\n(defmethod bat [Number Number] [x y & xs] \n (str \"number: \" x \" and \" y))\n\n;; you call it like this...\n\n(bat \"mink\" \"stoat\")\n;; => \"str: mink and stoat\"\n\n(bat \"bear\" \"skunk\" \"sloth\")\n;; => \"str: bear, skunk and sloth\"\n\n(bat \"dog\" \"cat\" \"cow\" \"horse\")\n;; => \"str: dog, cat, cow and horse\"\n\n(bat 1 2)\n;; => \"number: 1 and 2\"", :author {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}, :created-at 1412178008616, :updated-at 1412178054860, :editors [{:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=2"}], :_id "542c2058e4b05f4d257a2966"} {:body ";; defmulti - custom hierarchy\n\n(def h (-> (make-hierarchy)\n (derive :foo :bar)))\n\n(defmulti f identity :hierarchy #'h) ;; hierarchy must be a reference type\n\n(defmethod f :default [_] \"default\")\n(defmethod f :bar [_] \"bar\")\n\n(f :unknown) ;; \"default\"\n(f :bar) ;; \"bar\"\n(f :foo) ;; \"bar\"\n\n;; Note that any deref'able type is fine. \n;; Using an atom instead of (var h) is preferable in clojurescript \n;; (which adds a lot of meta information to vars)", :author {:login "kgann", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1098962?v=2"}, :created-at 1413313971298, :updated-at 1440343358927, :editors [{:avatar-url "https://avatars.githubusercontent.com/u/671872?v=3", :account-source "github", :login "hura"}], :_id "543d75b3e4b0a3cf052fe476"} {:updated-at 1440343192893, :created-at 1440343192893, :author {:login "hura", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/671872?v=3"}, :body ";; If you're REPLing you might want to re-define the defmulti dispatch function \n;; (which defmulti won't allow you to do). For this you can use `ns-unmap`:\n\n(defmulti x (fn[_] :inc))\n(defmethod x :inc [y] (inc y))\n(defmethod x :dec [y] (dec y))\n(x 0) ;; => 1\n(defmulti x (fn[_] :dec)) ;; Can't redefine :(\n(x 0) ;; => 1 ;; STILL :(\n(ns-unmap *ns* 'x) ;; => unmap the var from the namespace\n(defmulti x (fn[_] :dec))\n(x 0) ;; => Exception, we now need to redefine our defmethods.\n\n;; So in your file while developing you'd put the ns-unmap to the top of the file\n", :_id "55d9e498e4b0831e02cddf1b"} {:updated-at 1444625178263, :created-at 1444625178263, :author {:login "metasoarous", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/88556?v=3"}, :body ";; It's nice for multimethods to have arglists metadata so that calling `doc`\n;; prints the arglist, instead of just the docstring. For example:\n\n(defmulti f \"Great function\" (fn [x] :blah))\n(doc f)\n;; -------------------------\n;; user/f\n;; Great function\n\n;; However, we can add `:arglists` metadata via a third (optional) argument to `defmulti` (`attr-map?` in the docstring for `defmulti`):\n\n(defmulti g \"Better function\" {:arglists '([x])} (fn [x] :blah))\n(doc g)\n;; -------------------------\n;; user/f\n;; ([x])\n;; Better function\n", :_id "561b3b1ae4b0b41dac04c957"} {:updated-at 1452157994440, :created-at 1452156707338, :author {:login "peter", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2008?v=3"}, :body "(defmulti compact map?)\n\n(defmethod compact true [map]\n (into {} (remove (comp nil? second) map)))\n\n(defmethod compact false [col]\n (remove nil? col))\n\n; Usage:\n\n(compact [:foo 1 nil :bar])\n; => (:foo 1 :bar)\n\n(compact {:foo 1 :bar nil :baz \"hello\"})\n; => {:foo 1, :baz \"hello\"}\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/2008?v=3", :account-source "github", :login "peter"}], :_id "568e2723e4b0f37b65a3c27f"} {:updated-at 1465222176322, :created-at 1465221190822, :author {:login "rauhs", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/11081351?v=3"}, :body ";; This show how to do a wildcard match to a dispatch value:\n(defmulti xyz (fn [x y] [x y]))\n\n;; We don't care about the first argument:\n(defmethod xyz [::default :b]\n [x y]\n :d-b)\n\n;; We have to implement this manually:\n(defmethod xyz :default\n [x y]\n (let [recover (get-method xyz [::default y])]\n ;; Prevent infinite loop:\n (if (and recover (not (= (get-method xyz :default) recover)))\n (do\n (println \"Found a default\")\n ;; Add the default to the internal cache:\n ;; Clojurescript will want (-add-method ...)\n (.addMethod ^MultiFn xyz [x y] recover)\n (recover ::default y))\n :default)))\n\n(xyz nil :b) ;; => :d-b\n;; only prints \"Found a default\" once!", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/11081351?v=3", :account-source "github", :login "rauhs"}], :_id "57558046e4b0bafd3e2a0474"} {:updated-at 1484939584615, :created-at 1484939584615, :author {:login "timgilbert", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/94482?v=3"}, :body ";; Extremely simple example, dispatching on a single field of the input map.\n;; Here we have a polymorphic map that looks like one of these two examples:\n\n;; {:name/type :split :name/first \"Bob\" :name/last \"Dobbs\"}\n;; {:name/type :full :name/full \"Bob Dobbs\"}\n\n(defmulti full-name :name/type)\n\n(defmethod full-name :full [name-data] \n (:name/full name-data))\n\n(defmethod full-name :split [name-data] \n (str (:name/first name-data) \" \" (:name/last name-data)))\n\n(defmethod full-name :default [_] \"???\")\n\n(full-name {:name/type :full :name/full \"Bob Dobbs\"})\n;; => \"Bob Dobbs\"\n\n(full-name {:name/type :split :name/first \"Bob\" :name/last \"Dobbs\"})\n;; => \"Bob Dobbs\"\n\n(full-name {:name/type :oops :name/full \"Bob Dobbs\"})\n;; => \"???\"\n", :_id "58826140e4b09108c8545a5b"} {:editors [{:login "green-coder", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4"}], :body ";;polymorphism classic example\n\n;;defmulti\n(defmulti draw :shape)\n\n;;defmethod\n(defmethod draw :square [geo-obj] (str \"Drawing a \" (:clr geo-obj) \" square\"))\n(defmethod draw :triangle [geo-obj] (str \"Drawing a \" (:clr geo-obj) \" triangle\"))\n\n(defn square [color] {:shape :square :clr color})\n(defn triangle [color] {:shape :triangle :clr color})\n\n(draw (square \"red\"))\n(draw (triangle \"green\"))", :author {:avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4", :account-source "github", :login "ibercode"}, :created-at 1510785469752, :updated-at 1531155016694, :_id "5a0cc1bde4b0a08026c48cb9"} {:updated-at 1510845199326, :created-at 1510845199326, :author {:login "ibercode", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31028993?v=4"}, :body ";;defmulti with dispatch function\n(defmulti salary (fn[amount] (amount :t)))\n\n;;defmethod provides a function implementation for a particular value\n(defmethod salary \"com\" [amount] (+ (:b amount) (/ (:b amount) 2)))\n(defmethod salary \"bon\" [amount] (+ (:b amount) 99))\n\n(salary {:t \"com\" :b 1000}) ;;1500\n(salary {:t \"bon\" :b 1000}) ;;1099 ", :_id "5a0dab0fe4b0a08026c48cba"} {:updated-at 1568297637555, :created-at 1568297637555, :author {:login "the-frey", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/2385077?v=4"}, :body ";; dispatch on the first argument\n(defmulti example-multimethod\n (fn [arg-one opts] arg-one))\n\n;; the opts are available in the defmethods\n(defmethod example-multimethod :path-one [_ opts]\n (println (:first-opt opts)))\n\n(defmethod example-multimethod :path-two [_ opts]\n (println (:second-opt opts)))\n\n(example-multimethod :path-one {:first-opt 1\n :second-opt 2})\n;; 1\n;; => nil", :_id "5d7a52a5e4b0ca44402ef7b3"} {:updated-at 1598457058014, :created-at 1598457058014, :author {:login "Gavlooth", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/10321050?v=4"}, :body ";; You can use multiarity in multimethods \n(defmulti foo (fn [x & _] x))\n\n(defmethod foo :default [_ & _] \"DEFAULT VALUE DISPACHED\")\n\n;; Like a standar multi-arity function\n(defmethod foo :bar \n ([_ _] \"ONE ARGUMENT\")\n ([_ _ _] \"TWO ARGUMENTs\")\n ([_ _ _ _] \"THREE ARGUMENTs\")\n ([_ _ _ _ & more] (cl-format nil \"~d ARGUMENTS\" (+ 3 (count more)))))\n \n(foo :baz 1)\n;; => \"DEFAULT VALUE DISPACHED\"\n\n(foo :bar 1)\n;; => \"ONE ARGUMENT\"\n\n(foo :bar 1 2)\n;; => \"TWO ARGUMENTs\"\n\n(foo :bar 1 2 3)\n;; => \"THREE ARGUMENTs\"\n\n(foo :bar 1 2 3 4 )\n;; => \"4 ARGUMENTS\"\n\n(foo :bar 1 2 3 4 5)\n;; => \"5 ARGUMENTS\"\n\n(foo :baz 1)\n;; => \"DEFAULT VALUE DISPACHED\"\n\n(foo :bar)\n; eval (current-form): (foo :bar)\n; (err) Execution error (ArityException) at user/eval22248 \n; (err) Wrong number of args (1) passed to: user/eval22204/fn--22205\n\n", :_id "5f4684e2e4b0b1e3652d73ad"} {:editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/109629?v=4"}], :body ";; To call the dispatch function without dispatching to a method, \n;; just to examine the dispatch key\n(defmulti xyzzy (fn [x y] (+ x y)))\n((.dispatchFn xyzzy) 3 7)\n;; => 10\n\n;; The above is specific to Clojure on the JVM. In ClojureScript it is\n;; slightly different:\n((.-dispatch-fn xyzzy) 3 7)\n;; => 10", :author {:avatar-url "https://avatars1.githubusercontent.com/u/6414129?v=4", :account-source "github", :login "jimka2001"}, :created-at 1601239335909, :updated-at 1601314098960, :_id "5f70f927e4b0b1e3652d73c3"}], :macro true, :notes [{:updated-at 1290493285000, :body "See also\r\n\r\nhttp://clojure.org/runtime_polymorphism\r\n\r\nhttp://clojure.org/multimethods\r\n\r\n", :created-at 1290493285000, :author {:login "Victor", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bc41ebab54cc0e0fbe99d753876d45ce?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fa5"}], :arglists ["name docstring? attr-map? dispatch-fn & options"], :doc "Creates a new multimethod with the associated dispatch function.\n The docstring and attr-map are optional.\n\n Options are key-value pairs and may be one of:\n\n :default\n\n The default dispatch value, defaults to :default\n\n :hierarchy\n\n The value used for hierarchical dispatch (e.g. ::square is-a ::shape)\n\n Hierarchies are type-like relationships that do not depend upon type\n inheritance. By default Clojure's multimethods dispatch off of a\n global hierarchy map. However, a hierarchy relationship can be\n created with the derive function used to augment the root ancestor\n created with make-hierarchy.\n\n Multimethods expect the value of the hierarchy option to be supplied as\n a reference type e.g. a var (i.e. via the Var-quote dispatch macro #'\n or the var special form).", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/defmulti"} {:added "1.1", :ns "clojure.core", :name "chars", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:to-var {:library-url "https://github.com/clojure/clojure", :name "char-array", :ns "clojure.core"}, :author {:avatar-url "https://avatars.githubusercontent.com/u/528360?v=3", :account-source "github", :login "BertrandDechoux"}, :created-at 1342917427000, :_id "542692eaf6e94c6970521bcf"}], :line 5358, :examples [{:updated-at 1486713986324, :created-at 1486713986324, :author {:login "zezhenyan", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8064559?v=3"}, :body "user=> (seq (chars (char-array \"this is a good one\")))\n(\\t \\h \\i \\s \\space \\i \\s \\space \\a \\space \\g \\o \\o \\d \\space \\o \\n \\e)", :_id "589d7482e4b01f4add58fe44"} {:editors [{:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}], :body ";; char-array will convert where possible\n(char-array \"foo\");; => [\\f, \\o, \\o]\n\n;; chars will not\n(try (chars \"foo\")\n (catch ClassCastException e (ex-message e)))\n;; => \"java.lang.String cannot be cast to [C\"\n", :author {:avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4", :account-source "github", :login "tomdl89"}, :created-at 1656673310214, :updated-at 1656673548489, :_id "62bed41ee4b0b1e3652d7615"} {:updated-at 1682278412171, :created-at 1682278412171, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; Casting avoids expensive reflection, so to see the benefit, enable warning:\n(set! *warn-on-reflection* true)\n\n;; We'll def a char-array but won't type-hint the var:\n(def my-array (char-array [\\f \\g \\h \\i \\j]))\n\n;; and try to amap over it without using `chars` or type hinting:\n(amap my-array i _ (-> my-array (aget i) clojure.string/capitalize first unchecked-char))\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, char).\n;; => [\\F, \\G, \\H, \\I, \\J]\n\n;; We can use `chars` to avoid reflection:\n(amap (chars my-array) i _ (-> (chars my-array) (aget i) clojure.string/capitalize first unchecked-char))\n;; => [\\F, \\G, \\H, \\I, \\J]\n\n;; Just as we can type hint in place:\n(amap ^chars my-array i _ (-> ^chars my-array (aget i) clojure.string/capitalize first unchecked-char))\n;; => [\\F, \\G, \\H, \\I, \\J]\n\n;; Or type hint the var:\n(def ^\"[C\" my-array (char-array [\\f \\g \\h \\i \\j]))\n(amap my-array i _ (-> my-array (aget i) clojure.string/capitalize first unchecked-char))\n;; => [\\F, \\G, \\H, \\I, \\J]\n", :_id "6445880ce4b08cf8563f4b94"}], :notes nil, :arglists ["xs"], :doc "Casts to chars[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/chars"} {:added "1.0", :ns "clojure.core", :name "str", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1347870090000, :author {:login "JR0cket", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ff5786158c0be54051ef8e5c544555d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "pr", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e5e"} {:created-at 1347870109000, :author {:login "JR0cket", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/1ff5786158c0be54051ef8e5c544555d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "prn", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521e5f"} {:created-at 1423277783809, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "pr-str", :library-url "https://github.com/clojure/clojure"}, :_id "54d57ed7e4b0e2ac61831d22"} {:created-at 1423277796681, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "prn-str", :library-url "https://github.com/clojure/clojure"}, :_id "54d57ee4e4b0e2ac61831d23"} {:created-at 1423277811434, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "print-str", :library-url "https://github.com/clojure/clojure"}, :_id "54d57ef3e4b0e2ac61831d24"} {:created-at 1423277823482, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "println-str", :library-url "https://github.com/clojure/clojure"}, :_id "54d57effe4b0e2ac61831d25"}], :line 544, :examples [{:author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:avatar-url "https://avatars2.githubusercontent.com/u/24441401?v=4", :account-source "github", :login "themustafabasit"}], :body "user=> \"some string\"\n\"some string\"\n\nuser=> (str)\n\"\"\n\nuser=> (str nil)\n\"\"\n\nuser=> (str 1)\n\"1\"\n\nuser=> (str 1 2 3)\n\"123\"\n\nuser=> (str 1 'symbol :keyword)\n\"1symbol:keyword\"\n\n;; A very common usage of str is to apply it to an existing collection:\nuser=> (apply str [1 2 3])\n\"123\"\n\n;; compare it with:\nuser=> (str [1 2 3])\n\"[1 2 3]\"\n\n", :created-at 1279191631000, :updated-at 1599671667197, :_id "542692ccc026201cdc326c5f"} {:author {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"}, :editors [{:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"}], :body ";; Destructuring with a string, getting just a few characters from it\nuser=> (let [[first-char second-char] \"abcde\"] \n (prn 'first= first-char) \n (prn 'second= second-char))\nfirst= \\a\nsecond= \\b\nnil\n\n;; More destructuring with a string\nuser=> (let [[first-char second-char & rest-of-chars] \"abcde\"] \n (prn 'first= first-char) \n (prn 'second= second-char) \n (prn 'rest= rest-of-chars))\nfirst= \\a\nsecond= \\b\nrest= (\\c \\d \\e)\nnil\n\n;; Destructuring, getting the first character of a string\n;; and then a reference to the entire string\nuser=> (let [[first-char :as all-the-string] \"abcde\"] \n (prn 'first= first-char) \n (prn 'all= all-the-string))\nfirst= \\a\nall= \"abcde\"\nnil", :created-at 1285683003000, :updated-at 1285683237000, :_id "542692ccc026201cdc326c64"} {:updated-at 1471001180731, :created-at 1471001180731, :author {:login "Lacty", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7412474?v=3"}, :body "user=> (str \"L\" \"a\")\n\"La\"\n\nuser=> (str \"L\" 5 \"a\")\n\"L5a\"", :_id "57adb25ce4b0bafd3e2a04ef"} {:updated-at 1517964096633, :created-at 1517964096633, :author {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}, :body ";; sometimes when printing lazy sequences you do not get what you want.\n(str (take 5 (range 10)))\n;=> \"clojure.lang.LazySeq@1b554e1\"\n\n;; in those cases `pr-str` to the rescue.\n(pr-str (take 5 (range 10)))\n;=> \"(0 1 2 3 4)\"", :_id "5a7a4b40e4b0e2d9c35f7422"} {:updated-at 1527025723311, :created-at 1527025723311, :author {:login "operasfantom", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/31903947?v=4"}, :body ";; be careful with java.lang.Double to java.lang.String conversion\n(str -128004972.0)\n;=> \"-1.28004972E8\"\n", :_id "5b04903be4b045c27b7fac74"} {:updated-at 1547468102218, :created-at 1547468102218, :author {:login "RayceeM", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/28865179?v=4"}, :body ";; Using str in maps\n(def user-map {:fname \"Jane\" :sname \"Doe\"})\n\n;;getting the value of the first key \n(:fname user-map)\n;=> \"Jane\"\n\n(str (:fname user-map) \" \" (:sname user-map))\n;=> \"Jane Doe\"", :_id "5c3c7d46e4b0ca44402ef61b"} {:updated-at 1599671842283, :created-at 1599671842283, :author {:login "themustafabasit", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/24441401?v=4"}, :body "(str nil)\n;; => \"\"\n\n(str true)\n;; => \"true\"\n\n(str false)\n;; => \"false\"\n", :_id "5f590e22e4b0b1e3652d73b6"}], :notes nil, :tag "java.lang.String", :arglists ["" "x" "x & ys"], :doc "With no args, returns the empty string. With one arg x, returns\n x.toString(). (str nil) returns the empty string. With more than\n one arg, returns the concatenation of the str values of the args.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/str"} {:added "1.0", :ns "clojure.core", :name "next", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1289038123000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "rest", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cc7"} {:created-at 1289038131000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "first", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cc8"} {:created-at 1344490440000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "fnext", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521cc9"} {:created-at 1505013547909, :author {:login "didibus", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/601540?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "nthrest", :ns "clojure.core"}, :_id "59b4af2be4b09f63b945ac6c"} {:created-at 1505013554008, :author {:login "didibus", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/601540?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "nthnext", :ns "clojure.core"}, :_id "59b4af32e4b09f63b945ac6d"}], :line 57, :examples [{:author {:login "dpritchett", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/147981?v=3"}, :editors [{:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}], :body "user=> (next '(:alpha :bravo :charlie))\n(:bravo :charlie)\n\nuser=> (next (next '(:one :two :three)))\n(:three)\n\nuser=> (next (next (next '(:one :two :three))))\nnil", :created-at 1279071284000, :updated-at 1289038286000, :_id "542692c8c026201cdc3269fb"} {:author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :editors [{:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"} {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"} {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}], :body ";; next is used in the recursive call. (This is a naive implementation for illustration only. Using `rest` is usually preferred over `next`.)\n\n(defn my-map [func a-list]\n (when a-list\n (cons (func (first a-list))\n (my-map func (next a-list)))))", :created-at 1289038112000, :updated-at 1306984795000, :_id "542692c8c026201cdc3269fd"} {:body ";; Difference between next and rest:\n\n(next [:a])\n;; => nil\n(rest [:a])\n;; => ()\n\n(next [])\n;; => nil\n(rest [])\n;; => ()\n\n(next nil)\n;; => nil\n(rest nil)\n;; => ()", :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :created-at 1423016858063, :updated-at 1423094962892, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :_id "54d1839ae4b0e2ac61831d05"}], :notes [{:updated-at 1306987897000, :body "
(next aseq) === (seq (rest aseq))
\r\n\r\nWhen writing lazy sequence functions, you should use [rest](../clojure.core/rest), not next.", :created-at 1306984569000, :author {:login "steveminer", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/d28543d134185d12d4006a74738d233e?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fc0"}], :tag "clojure.lang.ISeq", :arglists ["coll"], :doc "Returns a seq of the items after the first. Calls seq on its\n argument. If there are no more items, returns nil.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/next"} {:added "1.0", :ns "clojure.core", :name "hash-map", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1317787775000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "merge", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b50"} {:created-at 1320356522000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "assoc", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b51"} {:created-at 1320356532000, :author {:login "boxie", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "dissoc", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b52"} {:created-at 1397669031000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "array-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b53"} {:created-at 1397669038000, :author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "sorted-map", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521b54"} {:created-at 1437362390089, :author {:login "ljosa", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/197881?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "into", :ns "clojure.core"}, :_id "55ac68d6e4b06a85937088b2"} {:created-at 1474932016523, :author {:login "olivergeorge", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/99447?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "zipmap", :ns "clojure.core"}, :_id "57e9ad30e4b0709b524f050d"} {:created-at 1517623031883, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "keys", :ns "clojure.core"}, :_id "5a7516f7e4b0e2d9c35f7413"} {:created-at 1517623038263, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "vals", :ns "clojure.core"}, :_id "5a7516fee4b0e2d9c35f7414"}], :line 379, :examples [{:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "belun", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon"} {:login "rafmagana", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/92894?v=3"} {:login "AtKaaZ", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"} {:login "pilku", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/2970556?v=4"}], :body ";; create hash map the long way\nuser=> (hash-map)\n{}\n\n;; create array map the short way\nuser=> {}\n{}\n\n;; sending a key more times, will remap it to the last value\nuser=> (hash-map :key1 1, :key1 2) \n{:key1 2} \n\nuser=> {:key1 1, :key1 2}\nIllegalArgumentException Duplicate key: :key1 clojure.lang.PersistentArrayMap.createWithCheck (PersistentArrayMap.java:70)\n\n\nuser=> (hash-map :key1 'val1, 'key2 :val2, [:compound :key] nil)\n{[:compound :key] nil, :key1 val1, key2 :val2} \n\n", :created-at 1280353272000, :updated-at 1591472591014, :_id "542692cfc026201cdc326e1f"} {:author {:login "zmila", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "user=> (map #(hash-map % 0) (seq \"abcdefgh\"))\n({\\a 0} {\\b 0} {\\c 0} {\\d 0} {\\e 0} {\\f 0} {\\g 0} {\\h 0}) \n\nuser=> (apply hash-map (.split \"a 1 b 2 c 3\" \" \"))\n{\"a\" \"1\", \"b\" \"2\", \"c\" \"3\"}", :created-at 1280353365000, :updated-at 1332950168000, :_id "542692cfc026201cdc326e23"} {:author {:login "dipto_sarkar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c1d3141a40d240f0918260201aaa0b01?r=PG&default=identicon"}, :editors [{:login "dipto_sarkar", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/c1d3141a40d240f0918260201aaa0b01?r=PG&default=identicon"} {:login "roryokane", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5b2b185c814bb25f2f95a1152e58f033?r=PG&default=identicon"}], :body "; a hash map can be stored in a var by using `def`\nuser=> (def person {:name \"Steve\" :age 24 :salary 7886 :company \"Acme\"})\n#'user/person\nuser=> person\n{:age 24, :name \"Steve\", :salary 7886, :company \"Acme\"}", :created-at 1341478710000, :updated-at 1388572400000, :_id "542692d3c026201cdc326fc4"} {:updated-at 1463334174783, :created-at 1342846621000, :body ";; Take a sequence of sequences (vector of vectors), and create a map\n;; using date as the map key.\n(def csv1 [[\"01/01/2012\" 1 2 3 4][\"06/15/2012\" 38 24 101]])\n\n(map #(hash-map (keyword (first %1)) (vec (rest %1))) csv1)\n;;=> ({:01/01/2012 [1 2 3 4]} {:06/15/2012 [38 24 101]})\n\n;; merge the list of maps into a single map\n(apply merge '({\"01/01/2012\" [1 2 3 4]} {\"06/15/2012\" [38 24 101]}))\n;;=> {\"06/15/2012\" [38 24 101], \"01/01/2012\" [1 2 3 4]}\n\n", :editors [{:avatar-url "https://www.gravatar.com/avatar/b11cdeef90d84ff8af2a2c5012402939?r=PG&default=identicon", :account-source "clojuredocs", :login "Deadron"} {:avatar-url "https://www.gravatar.com/avatar/b11cdeef90d84ff8af2a2c5012402939?r=PG&default=identicon", :account-source "clojuredocs", :login "Deadron"} {:avatar-url "https://avatars.githubusercontent.com/u/211644?v=3", :account-source "github", :login "phreed"} {:login "TradeIdeasPhilip", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/18409827?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon", :account-source "clojuredocs", :login "octopusgrabbus"}, :_id "542692d3c026201cdc326fc7"} {:updated-at 1459028606947, :created-at 1459028606947, :author {:login "smnplk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/380618?v=3"}, :body "(apply hash-map [:a 1 :b 2])\n;;=> {:b 2 :a 1}\n\n;;is the same as\n(def build-map (partial assoc {}))\n(apply build-map [:a 1 :b 2])\n;;=> {:b 2 :a 1}", :_id "56f7027ee4b0103e9c7d9d26"} {:editors [{:login "rebcabin", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/207047?v=4"} {:avatar-url "https://avatars3.githubusercontent.com/u/11434205?v=4", :account-source "github", :login "dijonkitchen"}], :body ";; A hash map acts like a lookup function taking a key as first argument:\n({:a 1, :b 2} :a)\n;;=> 1\n\n;; If the key is not present, nil is returned...\n({:a 1, :b 2} :qwerty)\n;;=> nil\n\n;; ... unless there is a second argument, which becomes the default value to\n;; return when the lookup key is not found:\n({:a 1, :b 2} :qwerty :uiop)\n;;=> :uiop\n\n;; That behavior can lead to surprises:\n(let [map-example {:a 1, :b 2}]\n (map-example #(* % %) (range 10)))\n;;=> (0 1 2 3 4 5 6 7 8 9) \n;; since (range 10) is the default and #(* % %) is an anonymous function that isn't a key in map-example\n\n;; It may be more explicit to use get instead\n(get {:a 1, :b 2} :qwerty :uiop)\n;;=> :uiop", :author {:avatar-url "https://avatars1.githubusercontent.com/u/207047?v=4", :account-source "github", :login "rebcabin"}, :created-at 1563554106051, :updated-at 1587741064160, :_id "5d31f13ae4b0ca44402ef788"}], :notes [{:author {:login "er2", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4515131?v=4"}, :updated-at 1670789233819, :created-at 1670789233819, :body "If you want to create a map from a sequence of pairs, e.g. `[[k1 v1] [k2 v2]]`, see [`into`](https://clojuredocs.org/clojure.core/into).", :_id "63963871e4b0b1e3652d7698"}], :arglists ["" "& keyvals"], :doc "keyval => key val\n Returns a new hash map with supplied mappings. If any keys are\n equal, they are handled as if by repeated uses of assoc.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/hash-map"} {:added "1.0", :ns "clojure.core", :name "if-let", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1293436184000, :author {:login "0x89", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/56bc4acd59315ed4dc1cb99c3be71102?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "when-let", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d88"} {:created-at 1315004464000, :author {:login "srid", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/bd3a68d670372cd09876c26270a4299a?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "if", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d89"} {:created-at 1440455843468, :author {:login "brunchboy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2228869?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "if-some", :ns "clojure.core"}, :_id "55db9ca3e4b072d7f27980f0"}], :line 1841, :examples [{:updated-at 1285499963000, :created-at 1279379785000, :body "user=> (defn sum-even-numbers [nums]\n (if-let [nums (seq (filter even? nums))]\n (reduce + nums)\n \"No even numbers found.\"))\n#'user/sum-even-numbers\n\nuser=> (sum-even-numbers [1 3 5 7 9])\n\"No even numbers found.\"\n\nuser=> (sum-even-numbers [1 3 5 7 9 10 12])\n22\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"}], :author {:avatar-url "https://avatars.githubusercontent.com/u/142529?v=3", :account-source "github", :login "nipra"}, :_id "542692cdc026201cdc326cf5"} {:author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :editors [{:login "nipra", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/142529?v=3"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "phreed", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/211644?v=4"}], :body " (if-let [x false y true]\n \"then\"\n \"else\")\n;; java.lang.IllegalArgumentException: if-let requires exactly 2 forms in binding vector (NO_SOURCE_FILE:1)\n;; see if-let* below\n\n(defn if-let-demo [arg]\n (if-let [x arg]\n \"then\"\n \"else\"))\n\n(if-let-demo 1) ; anything except nil/false\n;;=> \"then\"\n(if-let-demo nil)\n;;=> \"else\"\n(if-let-demo false)\n;;=> \"else\"\n", :created-at 1279489140000, :updated-at 1508883080013, :_id "542692cdc026201cdc326cf7"} {:updated-at 1529851111869, :created-at 1305844049000, :body ";; This macro is nice when you need to calculate something big. And you need \n;; to use the result but only when it's true:\n\n(if-let [life (meaning-of-life 12)]\n life\n (if-let [origin (origin-of-life 1)]\n origin\n (if-let [shooter (who-shot-jr 5)]\n shooter\n\t 42)))\n\n;; As you can see in the above example it will return the answer \n;; to the question only if the answer is not nil. If the answer\n;; is nil it will move to the next question. Until finally it\n;; gives up and returns 42.", :editors [{:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"} {:avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4", :account-source "github", :login "MrHus"} {:avatar-url "https://avatars.githubusercontent.com/u/7194?v=2", :account-source "github", :login "zk"} {:login "green-coder", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/598193?v=4"}], :author {:login "MrHus", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/22608?v=4"}, :_id "542692cdc026201cdc326cfa"} {:author {:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}, :editors [], :body ";; See examples for \"if\" explaining Clojure's idea of logical true\n;; and logical false.", :created-at 1334293326000, :updated-at 1334293326000, :_id "542692d3c026201cdc326fcb"} {:author {:login "ryo", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"}, :editors [{:login "schmee", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/3405586?v=3"}], :body ";;; with destructuring binding\n\n;; successful case\n(if-let [[w n] (re-find #\"a(\\d+)x\" \"aaa123xxx\")]\n [w n]\n :not-found) ;=> [\"a123x\" \"123\"]\n\n;; unsuccessful case\n(if-let [[w n] (re-find #\"a(\\d+)x\" \"bbb123yyy\")]\n [w n]\n :not-found) ;=> :not-found\n\n;; same as above\n(if-let [[w n] nil]\n [w n]\n :not-found) ;=> :not-found\n\n;; on Map\n(if-let [{:keys [a b]} nil]\n [a b]\n :not-found) ;=> :not-found\n", :created-at 1399644384000, :updated-at 1420673793910, :_id "542692d3c026201cdc326fcc"} {:body ";; Note that the binding only extends to the then form, not to the else:\nuser=> (if-let [x nil] \"then\" x)\nCompilerException java.lang.RuntimeException: Unable to resolve symbol:\nx in this context, compiling: ...", :author {:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}, :created-at 1418536023963, :updated-at 1418536080362, :editors [{:login "mars0i", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1836941?v=3"}], :_id "548d2457e4b04e93c519ffa7"} {:editors [{:avatar-url "https://avatars.githubusercontent.com/u/367789?v=3", :account-source "github", :login "mattvvhat"} {:login "antonmos", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/2713?v=3"}], :updated-at 1472595205961, :created-at 1428550556244, :author {:avatar-url "https://avatars.githubusercontent.com/u/367789?v=3", :account-source "github", :login "mattvvhat"}, :body ";; Works well with collections\n\n=> (def x {:whatever 1})\n\n=> (if-let [value (:whatever x)] value \"Not found\")\n1\n\n=> (if-let [value (:no-match x)] value \"Not found\")\n\"Not found\"", :_id "5525f39ce4b033f34014b76a"} {:updated-at 1587464733428, :created-at 1469577276189, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3"}, :body ";; if-let multiple bindings version\n;; Edited: Else branch did not work with expressions.\n\n(defmacro if-let*\n ([bindings then]\n `(if-let* ~bindings ~then nil))\n ([bindings then else]\n (if (seq bindings)\n `(if-let [~(first bindings) ~(second bindings)]\n (if-let* ~(drop 2 bindings) ~then ~else)\n ~else)\n then)))\n\n(if-let* [a 1\n b (+ a 1) ]\n b)\n;;=> 2\n\n(if-let* [a 1\n b (+ a 1)\n c false] ;;false or nil - does not matter\n b\n a)\n;;=> 1\n\n;; Note that this implementation short-curcuits on false so that the prn form \n;; is _not_ evaluated in the below form.\n(if-let* [a false\n b (prn \"Do we evaluate this?\")]\n true\n false)\n;;=> false", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/8271291?v=3", :account-source "github", :login "ertugrulcetin"} {:login "LukasRychtecky", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/585068?v=3"} {:avatar-url "https://avatars2.githubusercontent.com/u/632775?v=4", :account-source "github", :login "Rovanion"}], :_id "5797f83ce4b0bafd3e2a04b9"} {:updated-at 1499190178133, :created-at 1499190178133, :author {:login "claresudbery", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/8990232?v=3"}, :body ";; (if-let [definition condition] then else):\n;; if the value of condition is truthy, then that value is assigned to the definition, \n;; and \"then\" is evaluated.\n;; Otherwise the value is NOT assigned to the definition, and \"else\" is evaluated.\n\n;; Although you can use this structure with booleans, \n;; there's not much point unless you only want to\n;; use the resulting boolean if it's true - as evidenced in the first example below.\n;; if-let is mostly useful when checking for nil.\n\n;; In this first example if Clare is old, it outputs \"Clare is old\".\n;; (the let part of the statement is rather pointless, \n;; as the definition old-clare-age is never used).\n\n(def clare-age 47)\n(if-let [old-clare-age (> clare-age 100)] \n \"Clare is old\" \n \"Clare is not old\")\n;;=> Clare is not old\n\n;; In the next two examples, it only outputs Clare's age if it is valid (ie not nil)\n\n(def clare-age nil)\n(if-let [valid-clare-age clare-age] \n (str \"Clare has a valid age: \" valid-clare-age) \n \"Clare's age is invalid\")\n;;=> Clare's age is invalid\n\n(def clare-age 47)\n(if-let [valid-clare-age clare-age] \n (str \"Clare has a valid age: \" valid-clare-age) \n \"Clare's age is invalid\")\n;;=> Clare has a valid age: 47", :_id "595bd3a2e4b06e730307db4d"} {:updated-at 1534962715587, :created-at 1534962715587, :author {:login "midnio", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/36359066?v=4"}, :body "(if-let [value true]\n \"The expression is true!\"\n \"Sorry, it's not true.\")", :_id "5b7dac1be4b00ac801ed9e6c"} {:updated-at 1535296034148, :created-at 1535296034148, :author {:login "cuspymd", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/8870299?v=4"}, :body ";; Destructuring maps\n(def x {:it 1 :that 2})\n(def y {:that 2}\n(if-let [{value :it} x] value \"Not found\") ;;=> 1\n(if-let [{value :it} nil] value \"Not found\") ;;=> \"Not found\"\n(if-let [{value :it} false] value \"Not found\") ;;=> \"Not found\"\n(if-let [{value :it} y] value \"Not found\") ;;=> nil\n(if-let [{value :it} {}] value \"Not found\") ;;=> nil\n(if-let [{value :it} 1] value \"Not found\") ;;=> nil", :_id "5b82c222e4b00ac801ed9e78"} {:editors [{:login "arlicle", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/153773?v=4"} {:avatar-url "https://avatars2.githubusercontent.com/u/632775?v=4", :account-source "github", :login "Rovanion"}], :body ";; if-let multiple bindings version\n(defmacro if-let*\n ([bindings-vec then] `(if-let* ~bindings-vec ~then nil))\n ([bindings-vec then else]\n (if (seq bindings-vec)\n `(let ~bindings-vec\n (if (and ~@(take-nth 2 bindings-vec))\n ~then\n ~else)))))\n\n\n(if-let* [a 1\n b (+ a 1) ]\n b)\n;;=> 2\n\n(if-let* [a 1\n b (+ a 1)\n c false] ;;false or nil - does not matter\n b\n a)\n;;=> 1 \n\n;; Note that this implementation does _not_ short-circuit on falsey forms.\n(if-let* [a false\n b (prn \"Do we evaluate this?\")]\n true\n false)\n;; \"Do we evaluate this?\"\n;;=> false\n", :author {:avatar-url "https://avatars3.githubusercontent.com/u/153773?v=4", :account-source "github", :login "arlicle"}, :created-at 1536027516561, :updated-at 1587464633192, :_id "5b8deb7ce4b00ac801ed9e81"} {:updated-at 1565305899936, :created-at 1565305899936, :author {:login "metacritical", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/760429?v=4"}, :body ";; Check if the value is true print it otherwise not.\n\n(def log-output \"\") \n\n;; Assume log-output could be the result of another operation like\n;; (def log-output (Gl/ShaderInfoLog shader))\n;; The Following will only print, when logout is not empty.\n\n(if-let [out (not-empty logout)]\n (println out))\n", :_id "5d4cac2be4b0ca44402ef794"} {:updated-at 1590171632153, :created-at 1590171632153, :author {:login "themustafabasit", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/24441401?v=4"}, :body ";; fun of if-let \n(defn some-condition\n [data]\n true)\n\n(let [result (some-condition \"ABC\")]\n (if (true? result)\n \"Success\"\n \"Failure\"))\n;; => \"success\"\n\n;; if-let in Action\n(if-let [result (some-condition \"ABC\")]\n \"Success\"\n \"Failure\")\n;; => \"success\"\n", :_id "5ec817f0e4b087629b5a1911"}], :macro true, :notes [{:updated-at 1299054285000, :body "The difference between when-let and if-let is that when-let doesn't have an else clause and and also accepts multiple forms so you don't need to use a (do...).", :created-at 1299054285000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fb5"} {:updated-at 1326335082000, :body "I wonder what motivates the restriction of only one binding, e.g. many Schemes implement an `and-let*` form which allows multiple bindings, evaluating them in order and breaking out on the first binding that evaluates to false. Can somebody shed some light on this?", :created-at 1326335082000, :author {:login "DerGuteMoritz", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/66bba784787f4f725b1568ec69a616cc?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fd6"}], :arglists ["bindings then" "bindings then else & oldform"], :doc "bindings => binding-form test\n\n If test is true, evaluates then with binding-form bound to the value of \n test, if not, yields else", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/if-let"} {:added "1.0", :ns "clojure.core", :name "underive", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1524236415414, :author {:login "bfontaine", :account-source "github", :avatar-url "https://avatars2.githubusercontent.com/u/1334295?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "derive", :ns "clojure.core"}, :_id "5ada007fe4b045c27b7fac49"}], :line 5664, :examples [{:author {:login "shockbob", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body ";; create a simple hierarchy using the global hierarchy\n;; and demonstrate how underive is used\n\nuser=> (derive ::dog ::animal)\nnil\nuser=> (derive ::spaniel ::dog)\nnil\nuser=> (derive ::tabby ::dog)\nnil\nuser=> (ancestors ::tabby)\n#{:user/dog :user/animal}\nuser=> (underive ::tabby ::dog)\nnil\nuser=> (ancestors ::tabby)\nnil", :created-at 1313962237000, :updated-at 1423522531628, :_id "542692cdc026201cdc326d0f"}], :notes nil, :arglists ["tag parent" "h tag parent"], :doc "Removes a parent/child relationship between parent and\n tag. h must be a hierarchy obtained from make-hierarchy, if not\n supplied defaults to, and modifies, the global hierarchy.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/underive"} {:added "1.1", :ns "clojure.core", :name "ref-max-history", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1323973069000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ecf"} {:created-at 1364770314000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref-min-history", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ed0"} {:created-at 1364770319000, :author {:login "kumarshantanu", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "ref-history-count", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ed1"}], :line 2479, :examples nil, :notes nil, :arglists ["ref" "ref n"], :doc "Gets the max-history of a ref, or sets it and returns the ref", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ref-max-history"} {:added "1.7", :ns "clojure.core", :name "Throwable->map", :file "clojure/core_print.clj", :type "function", :column 1, :see-alsos [{:created-at 1538988481625, :author {:login "cljlc", :account-source "github", :avatar-url "https://avatars0.githubusercontent.com/u/36645452?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "ex-data", :ns "clojure.core"}, :_id "5bbb19c1e4b00ac801ed9eb7"}], :line 471, :examples [{:updated-at 1450285594446, :created-at 1450285594446, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=3"}, :body "(def trace (try (/ 1 0) (catch Throwable t (Throwable->map t))))\n(keys trace)\n;; (:cause :via :trace)\n(:cause trace)\n;; \"Divide by zero\"\n(count (:trace trace))\n;; 33 (this stack trace is 33 invocations deep) ", :_id "56719a1ae4b08a391679537c"}], :notes nil, :arglists ["o"], :doc "Constructs a data representation for a Throwable with keys:\n :cause - root cause message\n :phase - error phase\n :via - cause chain, with cause keys:\n :type - exception class symbol\n :message - exception message\n :data - ex-data\n :at - top stack element\n :trace - root cause stack elements", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/Throwable->map"} {:added "1.0", :ns "clojure.core", :name "false?", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1375213349000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "not", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521efc"}], :line 505, :examples [{:author {:login "samaaron", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/ee3512261f38df2541b9adca77f025cb?r=PG&default=identicon"}, :editors [{:login "jafingerhut", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/109629?v=3"}], :body "(false? false) ;=> true\n(false? true) ;=> false\n(false? nil) ;=> false\n(false? \"foo\") ;=> false", :created-at 1278738764000, :updated-at 1332950044000, :_id "542692c7c026201cdc32699d"}], :notes nil, :tag "java.lang.Boolean", :arglists ["x"], :doc "Returns true if x is the value false, false otherwise.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/false_q"} {:added "1.0", :ns "clojure.core", :name "*print-readably*", :type "var", :see-alsos nil, :examples [{:updated-at 1620478814999, :created-at 1620478814999, :author {:login "reborg", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/20086?v=4"}, :body ";; Showing how *print-readably* is used internally to escape/unescape control\n;; characters:\n\n(binding [*print-readably* false]\n (pr \"a\\nb\\nc\"))\n;; a\n;; b\n;; cnil\n\n;; Only use to change behaviour of code you don't control.\n;; Otherwise, it's equivalent to `print`:\n(print \"a\\nb\\nc\")\n;; a\n;; b\n;; cnil\n", :_id "60968b5ee4b0b1e3652d74f6"}], :notes nil, :arglists [], :doc "When set to logical false, strings and characters will be printed with\n non-alphanumeric characters converted to the appropriate escape sequences.\n\n Defaults to true", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*print-readably*"} {:added "1.0", :ns "clojure.core", :name "ints", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1299221089000, :author {:login "TimMc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "int-array", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521bc6"}], :line 5373, :examples [{:updated-at 1656672965213, :created-at 1656672965213, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body "(def my-floats (float-array [1.1 2.2 3.3]));; => #'user/my-floats\n\n;; int-array will convert where possible\n(int-array my-floats);; => [1, 2, 3]\n\n;; ints will not\n(try (ints my-floats)\n (catch ClassCastException e (ex-message e)));; => \"[F cannot be cast to [I\"\n", :_id "62bed2c5e4b0b1e3652d7613"} {:updated-at 1682268162146, :created-at 1682268162146, :author {:login "tomdl89", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/33435574?v=4"}, :body ";; Casting avoids expensive reflection, so to see the benefit, enable warning:\n(set! *warn-on-reflection* true)\n\n;; We'll def an int-array but won't type-hint the var:\n(def my-array (int-array [10 20 30 40 50 60]))\n\n;; and try to amap over it without using `ints` or type hinting:\n(amap my-array i _ (unchecked-inc-int (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, int).\n;; => [11, 21, 31, 41, 51, 61]\n\n;; We can use `ints` to avoid reflection:\n(amap (ints my-array) i _ (unchecked-inc-int (aget (ints my-array) i)))\n;; => [11, 21, 31, 41, 51, 61]\n\n;; Just as we can type hint in place:\n(amap ^ints my-array i _ (unchecked-inc-int (aget ^ints my-array i)))\n;; => [11, 21, 31, 41, 51, 61]\n\n;; Or type hint the var:\n(def ^\"[I\" my-array (int-array [10 20 30 40 50 60]))\n(amap my-array i _ (unchecked-inc-int (aget my-array i)))\n;; => [11, 21, 31, 41, 51, 61]\n", :_id "64456002e4b08cf8563f4b8e"}], :notes nil, :arglists ["xs"], :doc "Casts to int[]", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/ints"} {:added "1.0", :ns "clojure.core", :name "class", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1281949437000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "type", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a95"} {:created-at 1325041755000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "class?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a96"} {:created-at 1357883208000, :author {:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}, :to-var {:ns "clojure.core", :name "instance?", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521a97"}], :line 3460, :examples [{:updated-at 1451352065851, :created-at 1280546296000, :body "user=> (class 1)\njava.lang.Long\n\nuser=> (class [1 2 3])\nclojure.lang.PersistentVector\n\nuser=> (class (String. \"foo\"))\njava.lang.String", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/109629?v=3", :account-source "github", :login "jafingerhut"} {:login "rtoal", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/538615?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon", :account-source "clojuredocs", :login "dakrone"}, :_id "542692cac026201cdc326b68"} {:editors [{:login "rtoal", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/538615?v=3"}], :body "user=> (class class)\nclojure.core$class", :author {:avatar-url "https://avatars.githubusercontent.com/u/538615?v=3", :account-source "github", :login "rtoal"}, :created-at 1451352054083, :updated-at 1451352297752, :_id "5681dff6e4b01f598e267e93"} {:updated-at 1474629795271, :created-at 1474629795271, :author {:login "jfacorro", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/1522569?v=3"}, :body "user=> (class nil)\nnil", :_id "57e510a3e4b0709b524f0509"}], :notes nil, :arglists ["x"], :doc "Returns the Class of x", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/class"} {:added "1.3", :ns "clojure.core", :name "some-fn", :file "clojure/core.clj", :type "function", :column 1, :see-alsos [{:created-at 1348529537000, :author {:login "hugoduncan", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/80fa2a15219b987664e4d6f5c78b4c27?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "every-pred", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ecd"} {:created-at 1374512408000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "some", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521ece"} {:created-at 1461817364964, :author {:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "some->", :ns "clojure.core"}, :_id "57219014e4b0fc95a97eab5f"} {:created-at 1461817376595, :author {:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "some->>", :ns "clojure.core"}, :_id "57219020e4b0fc95a97eab60"} {:created-at 1582756004670, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "or", :ns "clojure.core"}, :_id "5e56f0a4e4b087629b5a18ac"} {:created-at 1609357926155, :author {:login "MicahElliott", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/159047?v=4"}, :to-var {:library-url "https://github.com/clojure/clojure", :name "fnil", :ns "clojure.core"}, :_id "5fecda66e4b0b1e3652d7425"}], :line 7436, :examples [{:updated-at 1462556528065, :created-at 1321364478000, :body "\nuser=> ((some-fn even?) 1)\nfalse\nuser=> ((some-fn even?) 2)\ntrue\nuser=> ((some-fn even?) 1 2)\ntrue\n", :editors [{:login "huahaiy", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/889685?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/e7869fe1a48cb1814c657eaca6bea3eb?r=PG&default=identicon", :account-source "clojuredocs", :login "replore"}, :_id "542692d5c026201cdc32708b"} {:author {:login "uvtc", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/34f159f89cbd1d9beac0276f5a7af552?r=PG&default=identicon"}, :editors [], :body ";; `some-fn` is useful for when you'd use `some` (to find out if any\n;; values in a given coll satisfy some predicate), but have more than\n;; one predicate. For example, to check if any values in a coll are\n;; either even or less than 10:\n\n(or (some even? [1 2 3])\n (some #(< % 10) [1 2 3]))\n\n;; but `some-fn` can save you some duplication here:\n\n((some-fn even? #(< % 10)) 1 2 3)\n\n;; Minor note: the former returns nil if it doesn't find\n;; what it's looking for. The latter returns false.", :created-at 1343775095000, :updated-at 1343775095000, :_id "542692d5c026201cdc32708c"} {:updated-at 1477665180894, :created-at 1399749753000, :body ";;; http://en.wikipedia.org/wiki/Fizz_buzz\n(def fizzbuzz\n (some-fn #(and (= (mod % 3) 0) (= (mod % 5) 0) \"FizzBuzz\")\n #(and (= (mod % 3) 0) \"Fizz\")\n #(and (= (mod % 5) 0) \"Buzz\")\n str))\n\n(run! println (map fizzbuzz (range 1 18)))\n\n1\n2\nFizz\n4\nBuzz\nFizz\n7\n8\nFizz\nBuzz\n11\nFizz\n13\n14\nFizzBuzz\n16\n17", :editors [{:login "GordonGustafson", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/6244646?v=3"}], :author {:avatar-url "https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon", :account-source "clojuredocs", :login "ryo"}, :_id "542692d5c026201cdc32708d"} {:updated-at 1461825756902, :created-at 1461820011453, :author {:login "bkovitz", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3"}, :body ";; Here's an easy way to apply several functions in succession to the same\n;; value and get the first true result. Note the double parentheses at the\n;; beginning: because some-fn returns a function, you have to apply it.\n\n((some-fn :a :b :c :d) {:c 3 :d 4})\n;=> 3\n\n;; Here's how to do the same thing but with a vector of functions. Note\n;; the 'apply' as well as the double parentheses, since you have to make\n;; some-fn take its arguments from the vector.\n\n(def parsers\n [parse-custom-command\n parse-basic-command\n parse-weird-command\n reject-command])\n\n((apply some-fn parsers) text-from-user)\n\n;; Each element of parsers is a function that returns a data structure if\n;; it successfully parses its argument or nil if it fails. reject-command\n;; always succeeds, returning a representation of an error.\n\n;; Note the technique of putting a catch-all function for errors last.\n", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/4142015?v=3", :account-source "github", :login "bkovitz"}], :_id "57219a6be4b0f8c89e75b111"}], :notes nil, :arglists ["p" "p1 p2" "p1 p2 p3" "p1 p2 p3 & ps"], :doc "Takes a set of predicates and returns a function f that returns the first logical true value\n returned by one of its composing predicates against any of its arguments, else it returns\n logical false. Note that f is short-circuiting in that it will stop execution on the first\n argument that triggers a logical true result against the original predicates.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/some-fn"} {:added "1.2", :ns "clojure.core", :name "case", :file "clojure/core.clj", :type "macro", :column 1, :see-alsos [{:created-at 1294148893000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "cond", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d1e"} {:created-at 1294148897000, :author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "condp", :library-url "https://github.com/clojure/clojure"}, :_id "542692ebf6e94c6970521d1f"}], :line 6697, :examples [{:author {:login "jneira", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2c8ecc24181d171df85a26458b9cd5f?r=PG&default=identicon"}, :editors [{:login "jneira", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2c8ecc24181d171df85a26458b9cd5f?r=PG&default=identicon"} {:login "zk", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/7194?v=2"} {:login "dale", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a7a1eca257c6cea943fea41e5cc3e9a3?r=PG&default=identicon"} {:login "dale", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a7a1eca257c6cea943fea41e5cc3e9a3?r=PG&default=identicon"} {:login "phreed", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/211644?v=3"}], :body "(let [mystr \"hello\"]\n (case mystr\n \"\" 0\n \"hello\" (count mystr)))\n;;=> 5\n\n(let [mystr \"no match\"]\n (case mystr\n \"\" 0\n \"hello\" (count mystr)))\n;; No matching clause: no match\n;; [Thrown class java.lang.IllegalArgumentException]\n\n(let [mystr \"no match\"]\n (case mystr\n \"\" 0\n \"hello\" (count mystr)\n \"default\"))\n;;=> \"default\"\n\n;; You can give multiple values for the same condition by putting\n;; those values in a list.\n(case 'y\n (x y z) \"x, y, or z\"\n \"default\")\n;;=> \"x, y, or z\"\n\n(let [myseq '(1 2)]\n (case myseq\n (()) \"empty seq\"\n ((1 2)) \"my seq\"\n \"default\"))\n;;=> \"my seq\"\n\n;; \"The test-constants are not evaluated.They must be compile-time\n;; literals, and need not be quoted.\" \n(let [myvec [1 2]]\n (case myvec\n [] \"empty vec\"\n (vec '(1 2)) \"my vec\"\n \"default\"))\n;;=> \"default\"\n", :created-at 1278987914000, :updated-at 1422376846462, :_id "542692ccc026201cdc326c89"} {:editors [{:login "rmprescott", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/224805?v=4"}], :body ";; From: The Clojure Style Guide \n;; https://github.com/bbatsov/clojure-style-guide#case\n;; License: Creative Commons Attribution 3.0 Unported License\n;;\n;; Prefer case instead of cond or condp when test expressions are compile-time constants.\n\n;; good\n(cond\n (= x 10) :ten\n (= x 20) :twenty\n (= x 30) :forty\n :else :dunno)\n\n;; better\n(condp = x\n 10 :ten\n 20 :twenty\n 30 :forty\n :dunno)\n\n;; best\n(case x\n 10 :ten\n 20 :twenty\n 30 :forty\n :dunno)", :author {:avatar-url "https://avatars1.githubusercontent.com/u/224805?v=4", :account-source "github", :login "rmprescott"}, :created-at 1539061331613, :updated-at 1539061466913, :_id "5bbc3653e4b00ac801ed9ecc"} {:updated-at 1575502428174, :created-at 1575502355101, :author {:login "huahaiy", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4"}, :body ";; test-constants are not evaluated, so the symbols should NOT be quoted\n(let [x 'a-symbol] ; quoted\n (case x \n a-symbol :a ; not quoted\n b-symbol :b)) ; not quoted\n;;=> :a", :editors [{:avatar-url "https://avatars3.githubusercontent.com/u/889685?v=4", :account-source "github", :login "huahaiy"}], :_id "5de84213e4b0ca44402ef7f1"} {:updated-at 1582540498084, :created-at 1582540498084, :author {:login "bnii", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/22633514?v=4"}, :body ";; Other example on\n;; \"The test-constants are not evaluated. They must be compile-time\n;; literals, and need not be quoted.\" \n\n(def one 1)\n;;=> #'user/one\n(case 1 \n one :one \n :not-one)\n;;=> :not-one", :_id "5e53a6d2e4b087629b5a18a1"} {:updated-at 1587638962866, :created-at 1587638962866, :author {:login "uosl", :account-source "github", :avatar-url "https://avatars3.githubusercontent.com/u/3865590?v=4"}, :body ";; You can use a macro to inline test-constants you wish to define separately.\n\n(def ops-single '(\"=\" \"!=\" \"<\" \"<=\" \">\" \">=\"))\n\n(def ops-multi '(\"ONE OF\" \"NONE OF\"))\n\n(defmacro ops-type [op]\n `(case ~op\n ~ops-single :single\n ~ops-multi :multi))", :_id "5ea172b2e4b087629b5a18df"} {:updated-at 1587918490021, :created-at 1587918490021, :author {:login "ertugrulcetin", :account-source "github", :avatar-url "https://avatars1.githubusercontent.com/u/8271291?v=4"}, :body "(case :blocking\n (:blocking :compute) :block-or-compute\n :async :async)\n\n;;=> :block-or-compute\n\n\n(case :async\n (:blocking :compute) :block-or-compute\n :async :async)\n\n;;=> :async", :_id "5ea5b69ae4b087629b5a18e9"} {:updated-at 1629037974768, :created-at 1615140525278, :author {:login "Crowbrammer", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4"}, :body ";; I timed rmprescott's example:\n\n(let [x 30] \n ;; \"good\"\n (time (cond\n (= x 10) :ten\n (= x 20) :twenty\n (= x 30) :thirty\n :else :dunno)) ;;=> \"Elapsed time: 0.0666 msecs\"\n\n ;; \"better\"\n (time (condp = x\n 10 :ten\n 20 :twenty\n 30 :thirty\n :dunno)) ;;=> \"Elapsed time: 0.4197 msecs\"\n\n ;; best in performance if else statement is executed (not shown)\n ;; best in readability\n (time (case x\n 10 :ten\n 20 :twenty\n 30 :thirty\n :dunno)) ;;=> \"Elapsed time: 0.0032 msecs\"\n \n ;; best in performance if known branches are executed\n ;; worst in readability\n (time (if (= x 10)\n :ten\n (if (= x 20)\n :twenty\n (if (= x 30)\n :thirty\n :dunno)))))) ;;=> \"Elapsed time: 0.0021 msecs\" \n\n;;=> :thirty", :editors [{:avatar-url "https://avatars.githubusercontent.com/u/19522656?v=4", :account-source "github", :login "Crowbrammer"}], :_id "604516ade4b0b1e3652d746d"} {:updated-at 1643907667427, :created-at 1643907667427, :author {:login "fdhenard", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/884972?v=4"}, :body ";; demonstrates inclusion on the test\n;; ... could be one of \"what\" or \"why\"\n\n(case \"what\"\n (\"what\" \"why\") :question\n :something-else)\n\n;;=> :question", :_id "61fc0a53e4b0b1e3652d75a6"}], :macro true, :notes [{:updated-at 1290270646000, :body "the third example describing myseq may be incorrect. I think we have to use vectors for comparing list of compile time constants.\r\n
\r\n\r\nThe parenthesized test conditions are used when multiple test conditions give the same output (output expression). In my case , since both [true, true] and [false, false] return true, i have put them within parenthesis.\r\n\r\n
", :created-at 1290269788000, :author {:login "dpani", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/3229d0eee8f780b9baa64657ff561fd3?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fa4"} {:updated-at 1290655074000, :body "I updated that example with myseq to reflect behavior of Clojure 1.2.0 on my machine. I also added an additional example to explicitly demonstrate multiple values for the same condition.", :created-at 1290655074000, :author {:login "dale", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/a7a1eca257c6cea943fea41e5cc3e9a3?r=PG&default=identicon"}, :_id "542692ecf6e94c6970521fa6"} {:body "Java enums are not compile-time literals.", :created-at 1613272178203, :updated-at 1613272197403, :author {:avatar-url "https://avatars.githubusercontent.com/u/6383047?v=4", :account-source "github", :login "beluchin"}, :_id "60289472e4b0b1e3652d7455"} {:body "Keep in mind this is not quite like pattern matching.\n\n```\n(case [:a :b]\n [:a :b] \"a b combo\"\n [_ :b] \"at least b\" \n)\n```\n\nWill not work. Instead install and use core.match:\n\n```\n(clojure.core.match/match [:a :b]\n [:a :b] \"a b combo\"\n [_ :b] \"at least b\")\n```\n(Thanks to potetm and Martin Půda on Clojurians Slack)", :created-at 1648411010714, :updated-at 1648411421228, :author {:avatar-url "https://avatars.githubusercontent.com/u/590297?v=4", :account-source "github", :login "eccentric-j"}, :_id "6240c182e4b0b1e3652d75c3"} {:author {:login "KingMob", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/946421?v=4"}, :updated-at 1680176304321, :created-at 1680176304321, :body "Reminder: compile-time *literals* are not the same thing as compile-time *constants*. The Clojure macro/compiler is not smart enough to work with things like Java constants or `^:const` vars.\n\nE.g.: \n\n```\n(case Math/PI\n Math/PI :pi\n Math/E :e\n :default)\n=> :default\n\n\n\n(def ^:const pi Math/PI)\n=> #'user/pi\n(case Math/PI\n pi :pi\n Math/E :e\n :default)\n=> :default\n```\n\nwill not work.", :_id "642574b0e4b08cf8563f4b87"}], :arglists ["e & clauses"], :doc "Takes an expression, and a set of clauses.\n\n Each clause can take the form of either:\n\n test-constant result-expr\n\n (test-constant1 ... test-constantN) result-expr\n\n The test-constants are not evaluated. They must be compile-time\n literals, and need not be quoted. If the expression is equal to a\n test-constant, the corresponding result-expr is returned. A single\n default expression can follow the clauses, and its value will be\n returned if no clause matches. If no default expression is provided\n and no clause matches, an IllegalArgumentException is thrown.\n\n Unlike cond and condp, case does a constant-time dispatch, the\n clauses are not considered sequentially. All manner of constant\n expressions are acceptable in case, including numbers, strings,\n symbols, keywords, and (Clojure) composites thereof. Note that since\n lists are used to group multiple constants that map to the same\n expression, a vector can be used to match a list if needed. The\n test-constants need not be all of the same type.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/case"} {:added "1.0", :ns "clojure.core", :name "*flush-on-newline*", :type "var", :see-alsos nil, :examples nil, :notes nil, :arglists [], :doc "When set to true, output will be flushed whenever a newline is printed.\n\n Defaults to true.", :library-url "https://github.com/clojure/clojure", :href "/clojure.core/*flush-on-newline*"} {:added "1.0", :ns "clojure.core", :name "to-array", :file "clojure/core.clj", :static true, :type "function", :column 1, :see-alsos [{:created-at 1329377518000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "alength", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ba2"} {:created-at 1329377602000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "char-array", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ba3"} {:created-at 1329377609000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "int-array", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ba4"} {:created-at 1329377615000, :author {:login "Claj", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "long-array", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ba5"} {:created-at 1374150114000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "into-array", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ba6"} {:created-at 1374150319000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "make-array", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ba7"} {:created-at 1375613635000, :author {:login "alilee", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"}, :to-var {:ns "clojure.core", :name "to-array-2d", :library-url "https://github.com/clojure/clojure"}, :_id "542692eaf6e94c6970521ba8"}], :line 338, :examples [{:author {:login "gstamp", :account-source "clojuredocs", :avatar-url "https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"}, :editors [{:login "Dimagog", :account-source "github", :avatar-url "https://avatars.githubusercontent.com/u/138993?v=3"}], :body "user=> (to-array [1 2 3])\n#