{"created-at":1781050155961,"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"},{"updated-at":1712575657726,"created-at":1712575657726,"author":{"login":"siddharthjain-in","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/6537820?v=4"},"body":"; add a doc-string to your def variable\n(def my-var \"this is doc string for my var\" \"hello\")\n\n; add a doc-string using meta key `:doc` \n(def ^{:doc \"this is doc string for my var\"} my-var \"hello\") ","_id":"6613d4a969fbcc0c226174b9"}],"notes":null,"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 \"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.\"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"},{"author":{"login":"kumarshantanu","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109792?v=4"},"updated-at":1713439935723,"created-at":1713439935723,"body":"The blog-post linked above has moved to https://8thlight.com/insights/quoting-without-confusion","_id":"662104bf69fbcc0c226174be"}],"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(->> coll\n (eduction (map #(quot % 5))\n (filter odd?))\n frequencies)\n
\n\nSo `eduction` turns out to be quite powerful in that it brings the benefits of transducers to all collection-processing functions, even those that predate transducers: `first`, `last`, `group-by`, `run!`, `str/join`, …\n","_id":"5aa308b5e4b0316c0f44f917"},{"author":{"login":"glts","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/1483271?v=4"},"updated-at":1520634630501,"created-at":1520634630501,"body":"Interesting background about `sequence` versus `eduction`: https://groups.google.com/d/msg/clojure/9I6MtgOTD0w/NiG5PimBCP8J","_id":"5aa30b06e4b0316c0f44f919"},{"body":"`eduction` does not cache the result while `sequence` does. `eduction` is intended to be used when you are eventually going to `reduce` over the sequence.\n\nhttps://groups.google.com/d/msg/clojure/9I6MtgOTD0w/NiG5PimBCP8J","created-at":1577794782807,"updated-at":1577824559009,"author":{"avatar-url":"https://avatars0.githubusercontent.com/u/705227?v=4","account-source":"github","login":"Hindol"},"_id":"5e0b3cdee4b0ca44402ef803"}],"arglists":["xform* coll"],"doc":"Returns a reducible/iterable application of the transducers\n to the items in coll. Transducers are applied in order as if\n combined with comp. Note that these applications will be\n performed every time reduce/iterator is called.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/eduction"},{"added":"1.0","ns":"clojure.core","name":"tree-seq","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1454531860990,"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":"walk","ns":"clojure.walk"},"_id":"56b26514e4b060004fc217bb"},{"created-at":1519124143092,"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":"file-seq","ns":"clojure.core"},"_id":"5a8bfeafe4b0316c0f44f8d5"}],"line":4984,"examples":[{"updated-at":1454531766626,"created-at":1280776531000,"body":";; Each node is a number or a seq, \n;; so branch?==seq? and children==identity\n;; \n;; .\n;; / \\\n;; . .\n;; /|\\ |\n;; 1 2 . 4\n;; | \n;; 3\n;;\n;; ... each sub-tree is serialized in depth-first order\n(tree-seq seq? identity '((1 2 (3)) (4)))\n\n;;=> (((1 2 (3)) (4)) \n;; (1 2 (3)) \n;; 1 \n;; 2 \n;; (3) \n;; 3 \n;; (4) \n;; 4)\n","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2","account-source":"github","login":"zk"},{"avatar-url":"https://www.gravatar.com/avatar/4b71cdf53bc76edd1a2ab66c446954b5?r=PG&default=identicon","account-source":"clojuredocs","login":"algal"},{"avatar-url":"https://www.gravatar.com/avatar/4b71cdf53bc76edd1a2ab66c446954b5?r=PG&default=identicon","account-source":"clojuredocs","login":"algal"},{"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":"542692ccc026201cdc326c82"},{"updated-at":1454531340455,"created-at":1321413864000,"body":"(tree-seq map? #(interleave (keys %) (vals %)) {:a 1 :b {:c 3 :d 4 :e {:f 6 :g 7}}})\n;;=> ({:a 1, :b {:c 3, :d 4, :e {:f 6, :g 7}}} \n;; :a 1 :b {:c 3, :d 4, :e {:f 6, :g 7}} \n;; :c 3 :d 4 :e {:f 6, :g 7} \n;; :f 6 :g 7)","editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/d790f5851d80da498e475ece4487e92?r=PG&default=identicon","account-source":"clojuredocs","login":"patazj"},"_id":"542692d5c026201cdc3270aa"},{"updated-at":1454530812433,"created-at":1321841153000,"body":";; Each node is a (node-root child1 child2 ...),\n;; so branch?==next and children==rest\n;;\n;; A\n;; / \\\n;; B C\n;; / \\ |\n;; D E F\n;;\n(map first (tree-seq next rest '(:A (:B (:D) (:E)) (:C (:F)))))\n;;=> (:A :B :D :E :C :F)","editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/4b71cdf53bc76edd1a2ab66c446954b5?r=PG&default=identicon","account-source":"clojuredocs","login":"algal"},"_id":"542692d5c026201cdc3270ab"},{"author":{"login":"gregginca","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bad5f5cb177b0968d4288596691ec3cd?r=PG&default=identicon"},"editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"}],"body":";; The previous example seems to be a flatten function,\n;; where every node's value is added to the returned sequence\n;; as it is visited in a depth first search.\n;; That is not the case as the following example illustrates: \n;; *\n;; / \\\n;; * 4\n;; /|\\\n;; 1 2 *\n;; |\n;; 3\n(map first (tree-seq next rest '((1 2 (3)) (4))))\n;;=> ((1 2 (3)) 4)\n\n;; For a proper 'flatten' function see below.","created-at":1334020823000,"updated-at":1454531099621,"_id":"542692d5c026201cdc3270ac"},{"updated-at":1471103831802,"created-at":1335429840000,"body":";; The nodes are filtered based on their collection type, \n;; here they must be a list.\n(tree-seq seq? seq [[1 2 [3]] [4]])\n;;=> ([[1 2 [3]] [4]])\n\n;; notice the difference between seq? and sequential?\n(tree-seq sequential? seq [[1 2 [3]] [4]])\n;;=> ([[1 2 [3]] [4]] [1 2 [3]] 1 2 [3] 3 [4] 4)\n\n;; If the nodes in the tree are a specific type of collection...\n;; a vector\n(tree-seq vector? seq [[1 2 [3]] [4]])\n([[1 2 [3]] [4]] [1 2 [3]] 1 2 [3] 3 [4] 4)\n\n;; ... or a list\n(tree-seq seq? seq '((1 2 (3)) (4)))\n(((1 2 (3)) (4)) (1 2 (3)) 1 2 (3) 3 (4) 4)\n","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},{"login":"bbakersmith","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1828358?v=3"}],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/10421?v=3","account-source":"github","login":"devn"},"_id":"542692d5c026201cdc3270ad"},{"editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/89076?v=3","account-source":"github","login":"shark8me"},{"login":"reborg","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4"}],"updated-at":1519124120018,"created-at":1423128977650,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/89076?v=3","account-source":"github","login":"shark8me"},"body":";; Use tree-seq to recursively find all files \n;; given a root directory (here for didactic purposes. See file-seq)\n(let [directory (clojure.java.io/file \"/path/to/directory/\")\n dir? #(.isDirectory %)]\n ;we want only files, therefore filter items that are not directories.\n (filter (comp not dir?) \n (tree-seq dir? #(.listFiles %) directory)))","_id":"54d33991e4b0e2ac61831d15"},{"editors":[{"login":"zackteo","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/7510179?v=4"}],"body":"\n(def t '((1 2 (3)) (4)))\n;;=> #'user/t\n\n;; Here the tree-seq uses 'sequential?' as the 'branch?' predicate.\n;; This causes the 'children' function to run for any collection.\n;; The 'seq' ('children') function recurses on all items in the collection.\n;; This results in a sequence of sub-trees, rooted at each node.\n(tree-seq sequential? seq t)\n;;=> (((1 2 (3)) (4))\n;; (1 2 (3)) 1 2 \n;; (3) 3 (4) 4)\n\n;; (The following example is from 4Clojure)\n;; It returns the leaves of a tree as a sequence.\n;; \n(defn flatten [x]\n (filter (complement sequential?)\n (rest (tree-seq sequential? seq x))))\n(flatten t)\n;;=> (1 2 3 4)\n","author":{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},"created-at":1454529390718,"updated-at":1603927166586,"_id":"56b25b6ee4b060004fc217b6"},{"updated-at":1503909100023,"created-at":1503908769269,"author":{"login":"MokkeMeguru","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/30849444?v=4"},"body":"(tree-seq seq? identity '(1 2 (3 (4))))\n;; ((1 2 (3 (4))) 1 2 (3 (4)) 3 (4) 4)\n\n;; It's same as ...\n(tree-seq seq? seq '(1 2 (3 (4))))\n(tree-seq sequential? seq '(1 2 (3 (4))))\n;; ((1 2 (3 (4))) 1 2 (3 (4)) 3 (4) 4)\n\n;; This processing ...\n(sequential? '(1 2 (3 (4)))) ;; returns true ... -> (1 2 (3 (4))) <--- !!!\n(sequential? 1) ;; returns false ... -> 1\n(sequential? 2) ;; returns false ... -> 2\n(sequential? '(3 (4)) ;; returns true ... -> (3 (4)) <--- !!! \n(sequential? 3) ;; returns false ... -> 3\n(sequential? '(4)) ;; returns true ... -> (4) <--- !!!\n(sequential? 4) ;; return false ... -> 4\n\n;; so, #tree-seq returns...\n;; ((1 2 (3 (4))) 1 2 (3 (4)) 3 (4) 4)","editors":[{"avatar-url":"https://avatars2.githubusercontent.com/u/30849444?v=4","account-source":"github","login":"MokkeMeguru"}],"_id":"59a3d3a1e4b09f63b945ac54"},{"editors":[{"login":"kovasap","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8763010?v=4"}],"body":";; When traversing a map tree, it's sometimes useful to have a back-reference\n;; to the parent. This tree-seq variant provides that.\n\n(defn tree-seq-adding-parent\n \"Like tree-seq, but takes in a tree of maps and a unique :parent key to each map.\"\n [branch? children root]\n (let [walk (fn walk [parent node]\n (lazy-seq\n (cons (assoc node :parent parent)\n (when (branch? node)\n (mapcat (partial walk node) (children node))))))]\n (walk nil root)))\n\n(def map-tree\n {:name \"root\"\n :children [{:name \"child1\"\n :children [{:name \"grandchild1\"}\n {:name \"grandchild2\"}]}\n {:name \"child2\"}]})\n\n(tree-seq-adding-parent associative? :children map-tree)\n;; =>\n;; ({:name \"root\",\n;; :children\n;; [{:name \"child1\",\n;; :children [{:name \"grandchild1\"} {:name \"grandchild2\"}]}\n;; {:name \"child2\"}],\n;; :parent nil\n;; {:name \"child1\",\n;; :children [{:name \"grandchild1\"} {:name \"grandchild2\"}],\n;; :parent\n;; {:name \"root\",\n;; :children\n;; [{:name \"child1\",\n;; :children [{:name \"grandchild1\"} {:name \"grandchild2\"}]}\n;; {:name \"child2\"}]}}\n;; {:name \"grandchild1\",\n;; :parent\n;; {:name \"child1\",\n;; :children [{:name \"grandchild1\"} {:name \"grandchild2\"}]}}\n;; {:name \"grandchild2\",\n;; :parent\n;; {:name \"child1\",\n;; :children [{:name \"grandchild1\"} {:name \"grandchild2\"}]}}\n;; {:name \"child2\",\n;; :parent\n;; {:name \"root\",\n;; :children\n;; [{:name \"child1\",\n;; :children [{:name \"grandchild1\"} {:name \"grandchild2\"}]}\n;; {:name \"child2\"}]}})\n\n","author":{"avatar-url":"https://avatars.githubusercontent.com/u/8763010?v=4","account-source":"github","login":"kovasap"},"created-at":1652035527222,"updated-at":1652035548192,"_id":"62780fc7e4b0b1e3652d75ea"},{"updated-at":1698404778459,"created-at":1698404778459,"author":{"login":"jacobmendoza","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/2363912?v=4"},"body":";; Tree-seq uses depth-first search (DFS), pre-order traversal, to explore the \n;; tree. \n;;\n;; 1\n;; / \\\n;; 2 3\n;; | \n;; 4\n;; |\n;; 5\n\n(let [tree {:value 1 \n :children [{:value 2\n :children [{:value 4\n :children [{:value 5}]}]}\n {:value 3}]}]\n (map :value\n (tree-seq\n #(contains? % :children) ;branch?\n #(get % :children) ;children\n tree)))\n\n=> (1 2 4 5 3)\n","_id":"653b99aa69fbcc0c226173f4"}],"notes":[{"body":"The 'branch?' and 'children' functions perform different types of filtering.\nThe 'branch?' function examines a node and determines whether there are children that need to be included in the processing.\nThe 'children' function selects (or generates) the children to be included in the returned sequence.","created-at":1454529614571,"updated-at":1508445428109,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},"_id":"56b25c4ee4b0ceed88ce8d21"},{"author":{"login":"lostdiaspora","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/4893998?v=3"},"updated-at":1462851110244,"created-at":1462851110244,"body":"Example 5 has for the second example \n(tree-seq seq? seq [[1 2 [3]] [4]])\nwhen it should be \n(tree-seq sequential? seq [[1 2 [3]] [4]])","_id":"57315626e4b012fa59bdb2ed"}],"arglists":["branch? children root"],"doc":"Returns a lazy sequence of the nodes in a tree, via a depth-first walk.\n branch? must be a fn of one arg that returns true if passed a node\n that can have children (but may not). children must be a fn of one\n arg that returns a sequence of the children. Will only be called on\n nodes for which branch? returns true. Root is the root node of the\n tree.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/tree-seq"},{"added":"1.0","ns":"clojure.core","name":"unchecked-remainder-int","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":1254,"examples":null,"notes":null,"arglists":["x y"],"doc":"Returns the remainder of division of x by y, both int.\n Note - uses a primitive operator subject to truncation.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/unchecked-remainder-int"},{"added":"1.0","ns":"clojure.core","name":"seq","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1323104884000,"author":{"login":"mmwaikar","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"seq?","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521f01"},{"created-at":1350272113000,"author":{"login":"dansalmo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"empty?","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521f02"},{"created-at":1398980077000,"author":{"login":"ryo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"iterator-seq","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521f03"},{"created-at":1495638720841,"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":"5925a2c0e4b093ada4d4d727"},{"created-at":1550706027921,"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":"sequential?","ns":"clojure.core"},"_id":"5c6de56be4b0ca44402ef69d"},{"created-at":1550706149555,"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":"sequence","ns":"clojure.core"},"_id":"5c6de5e5e4b0ca44402ef69e"}],"line":128,"examples":[{"updated-at":1552553839711,"created-at":1280777400000,"body":"(seq '(1)) ;;=> (1)\n(seq [1 2]) ;;=> (1 2)\n(seq \"abc\") ;;=> (\\a \\b \\c)\n\n;; Corner cases\n(seq nil) ;;=> nil\n(seq '()) ;;=> nil\n(seq []) ;;=> nil\n(seq \"\") ;;=> nil","editors":[{"login":"devn","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/10421?v=3"},{"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"},{"avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3","account-source":"github","login":"Dimagog"},{"login":"notake","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/17588518?v=4"}],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/10421?v=3","account-source":"github","login":"devn"},"_id":"542692cac026201cdc326b53"},{"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"},{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"body":";; (seq x) is the recommended idiom for testing if a collection is not empty\n(every? seq [\"1\" [1] '(1) {:1 1} #{1}])\n;;=> true","created-at":1350272074000,"updated-at":1422038529310,"_id":"542692d5c026201cdc327079"},{"author":{"login":"rafmagana","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/92894?v=3"},"editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"},{"login":"osipaandr","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/14186734?v=4"}],"body":";; 'seq' can be used to turn a map into a list of vectors.\n;; Notice how the list is built adding elements to the beginning \n;; of the seq (list) not to the end, as with vectors.\n;; (Of course, the order that items are \n;; taken from a map should not be relied upon\n;; unless a deterministic 'sorted-map' is used.)\n(seq {:key1 \"value1\" :key2 \"value2\"})\n;;=> ([:key2 \"value2\"] [:key1 \"value1\"])","created-at":1380601368000,"updated-at":1616180554494,"_id":"542692d5c026201cdc32707b"},{"updated-at":1585288063944,"created-at":1470910164741,"author":{"login":"ertugrulcetin","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8271291?v=3"},"body":";; Here is the difference between seq and sequence\n\n(seq nil)\n;;=> nil\n\n(seq ())\n;;=> nil\n\n(sequence ())\n;;=> ()\n\n(sequence nil)\n;;=> ()","editors":[{"avatar-url":"https://avatars1.githubusercontent.com/u/598193?v=4","account-source":"github","login":"green-coder"}],"_id":"57ac4ed4e4b0bafd3e2a04e1"},{"editors":[{"login":"bfontaine","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/1334295?v=4"},{"login":"osipaandr","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/14186734?v=4"}],"body":";; seq is very similar to not-empty:\n\n(every? seq [\"1\" [1] '(1) {:1 1} #{1}])\n;;=> true\n(every? not-empty [\"1\" [1] '(1) {:1 1} #{1}])\n;;=> true\n\n(seq '(1)) ;;=> (1)\n(not-empty '(1)) ;;=> (1)\n\n(seq [1 2]) ;;=> (1 2)\n(not-empty [1 2]) ;;=> [1 2]\n\n\n(seq \"abc\") ;;=> (\\a \\b \\c)\n(not-empty \"abc\") ;;=> \"abc\"\n\n(map seq [nil '() [] \"\" {}])\n;;=> (nil nil nil nil nil)\n\n(map not-empty [nil '() [] \"\" {}])\n;;=> (nil nil nil nil nil)","author":{"avatar-url":"https://avatars2.githubusercontent.com/u/1334295?v=4","account-source":"github","login":"bfontaine"},"created-at":1602257369027,"updated-at":1616180682337,"_id":"5f8081d9e4b0b1e3652d73d1"}],"notes":null,"tag":"clojure.lang.ISeq","arglists":["coll"],"doc":"Returns a seq on the collection. If the collection is\n empty, returns nil. (seq nil) returns nil. seq also works on\n Strings, native Java arrays (of reference types) and any objects\n that implement Iterable. Note that seqs cache values, thus seq\n should not be used on any Iterable whose iterator repeatedly\n returns the same mutable object.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/seq"},{"added":"1.0","ns":"clojure.core","name":"reduce","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1289800599000,"author":{"login":"kumarshantanu","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"reductions","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521e01"},{"created-at":1289816968000,"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"apply","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521e02"},{"created-at":1289816979000,"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"frequencies","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521e03"},{"created-at":1416151510249,"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":"5468c1d6e4b0dc573b892fd2"},{"created-at":1416151518003,"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":"5468c1dee4b03d20a10242aa"},{"created-at":1461185368746,"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":"reduce-kv","ns":"clojure.core"},"_id":"5717eb58e4b0fc95a97eab4f"},{"created-at":1514410007011,"author":{"login":"jcburley","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/430319?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"fold","ns":"clojure.core.reducers"},"_id":"5a441017e4b0a08026c48cdf"},{"created-at":1550086607808,"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-by","ns":"clojure.core"},"_id":"5c6471cfe4b0ca44402ef683"}],"line":6947,"examples":[{"updated-at":1453975469787,"created-at":1278185820000,"body":"(reduce + [1 2 3 4 5]) ;;=> 15\n(reduce + []) ;;=> 0\n(reduce + [1]) ;;=> 1\n(reduce + [1 2]) ;;=> 3\n(reduce + 1 []) ;;=> 1\n(reduce + 1 [2 3]) ;;=> 6","editors":[{"avatar-url":"https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon","account-source":"clojuredocs","login":"dakrone"},{"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":"mobyte","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/207296?v=3"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/43db6edb2c82a7c76cb5b5911391f02a?r=PG&default=identicon","account-source":"clojuredocs","login":"cody"},"_id":"542692ccc026201cdc326c36"},{"updated-at":1561377314389,"created-at":1278632532000,"body":";; Converting a vector to a set:\n\n(reduce conj #{} [:a :b :c])\n;; => #{:a :c :b}\n","editors":[{"avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon","account-source":"clojuredocs","login":"boxie"},{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/693b9bfd287e55741c2a4af6f7de0d72?r=PG&default=identicon","account-source":"clojuredocs","login":"jkkramer"},"_id":"542692ccc026201cdc326c39"},{"updated-at":1343775932000,"created-at":1279060391000,"body":";; Create a word frequency map out of a large string s.\n\n;; `s` is a long string containing a lot of words :)\n(reduce #(assoc %1 %2 (inc (%1 %2 0)))\n {}\n (re-seq #\"\\w+\" s))\n\n; (This can also be done using the `frequencies` function.)\n","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2","account-source":"github","login":"zk"},{"avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon","account-source":"clojuredocs","login":"boxie"},{"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"}],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/1453?v=4","account-source":"github","login":"ghoseb"},"_id":"542692ccc026201cdc326c3b"},{"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":"goodmike","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/42e0998c3077ba0ac435423941a3978e?r=PG&default=identicon"},{"login":"goodmike","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/42e0998c3077ba0ac435423941a3978e?r=PG&default=identicon"},{"login":"goodmike","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/42e0998c3077ba0ac435423941a3978e?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":";; Calculate primes until 1000\n\n(reduce\n (fn [primes number]\n (if (some zero? (map (partial mod number) primes))\n primes\n (conj primes number)))\n [2]\n (take 1000 (iterate inc 3)))\n\n;;=> [2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 \n;; 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 \n;; 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 \n;; 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 \n;; 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 \n;; 449 457 461 463 467 479 487 491 499 503 509 521 523 541 547 557 \n;; 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 \n;; 653 659 661 673 677 683 691 701 709 719 727 733 739 743 751 757 \n;; 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 \n;; 877 881 883 887 907 911 919 929 937 941 947 953 967 971 977 983 \n;; 991 997]","created-at":1279066766000,"updated-at":1420654061502,"_id":"542692ccc026201cdc326c40"},{"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":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"body":";; Add one collection to another (combining sequences is done with cons):\n(reduce conj [1 2 3] [4 5 6])\n;;=> [1 2 3 4 5 6]\n\n(reduce #(cons %2 %1) [1 2 3] [4 5 6])\n;;=> '(6 5 4 1 2 3)","created-at":1279163552000,"updated-at":1420654295036,"_id":"542692ccc026201cdc326c46"},{"author":{"login":"gradysw","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/a2d549191f2863bf87489949edebb548?r=PG&default=identicon"},"editors":[{"login":"gradysw","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/a2d549191f2863bf87489949edebb548?r=PG&default=identicon"},{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"body":";; Combine a vector of collections into a single collection \n;; of the type of the first collection in the vector.\n(reduce into [[1 2 3] [:a :b :c] '([4 5] 6)])\n;;=> [1 2 3 :a :b :c [4 5] 6]\n\n;; The flatten function can be used to completely fuse \n;; all of the items of a nested tree into a single sequence.\n;; Sometimes all that is needed is to fuse the first level\n;; of a tree. This can be done with 'reduce' and 'into'.\n(reduce into [] '([] [[10 18]] [[8 18]] [[10 12]] [[0 -6]] [[2 6]]))\n;;=> [[10 18] [8 18] [10 12] [0 -6] [2 6]]\n","created-at":1325573490000,"updated-at":1426023239324,"_id":"542692d5c026201cdc327064"},{"author":{"login":"octopusgrabbus","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon"},"editors":[],"body":"(defn key-pres?\n \"This function accepts a value (cmp-val) and a vector of vectors\n (parsed output from clojure-csv) and returns the match value\n back if found and nil if not found. \n\n Using reduce, the function searches every vector row to see \n if cmp-val is at the col-idx location in the vector.\"\n\n [cmp-val cmp-idx csv-data]\n (reduce\n (fn [ret-rc csv-row]\n (if (= cmp-val (nth csv-row col-idx nil))\n (conj ret-rc cmp-val)))\n [] \n csv-data))","created-at":1334260928000,"updated-at":1334260928000,"_id":"542692d5c026201cdc327066"},{"author":{"login":"octopusgrabbus","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon"},"editors":[{"login":"octopusgrabbus","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/fd31b8bcea99fa7b0711fbc424587774?r=PG&default=identicon"}],"body":"(defn reduce-csv-row\n \"Accepts a csv-row (a vector) a list of columns to extract, \n and reduces (and returns) a csv-row to a subset based on \n selection using the values in col-nums (a vector of integer \n vector positions.)\"\n\n [csv-row col-nums]\n\n (reduce\n (fn [out-csv-row col-num]\n ; Don't consider short vectors containing junk.\n (if-not (<= (count csv-row) 1)\n (conj out-csv-row (nth csv-row col-num nil))))\n []\n col-nums))\n\n","created-at":1334261221000,"updated-at":1334261450000,"_id":"542692d5c026201cdc327067"},{"editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"updated-at":1561323174151,"created-at":1426023157581,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},"body":";; Some functions update a collection with a single item.\n;; A number of functions have a 'more' argument which lets\n;; them work over collections.\n;; These functions can benefit 'reduce' which lets them work \n;; a collection of items...\n(into {} {:dog :food})\n\n(reduce into {} [{:dog :food} {:cat :chow}])\n;;=> {:dog :food, :cat :chow}","_id":"54ff62f5e4b0b716de7a6539"},{"updated-at":1561377338656,"created-at":1441139931232,"author":{"login":"lwm","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1991377?v=3"},"body":";; The reduction will terminate early if an intermediate result uses the \n;; `reduced` function.\n\n(defn limit [x y] \n (let [sum (+ x y)] \n (if (> sum 10) (reduced sum) sum)))\n\n(reduce + 0 (range 10))\n;; => 45\n\n(reduce limit 0 (range 10))\n;; => 15","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/25400?v=3","account-source":"github","login":"miner"},{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"_id":"55e60cdbe4b072d7f27980f5"},{"editors":[{"login":"teymuri","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/13352033?v=3"},{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"body":";; This will generate the first 100 Fibonacci numbers\n;; (size of (range) + 2):\n\n(reduce \n (fn [a b] (conj a (+' (last a) (last (butlast a))))) \n [0 1] \n (range 98))\n\n;; [0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269 2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986 102334155 165580141 267914296 433494437 701408733 1134903170 1836311903 2971215073 4807526976 7778742049 12586269025 20365011074 32951280099 53316291173 86267571272 139583862445 225851433717 365435296162 591286729879 956722026041 1548008755920 2504730781961 4052739537881 6557470319842 10610209857723 17167680177565 27777890035288 44945570212853 72723460248141 117669030460994 190392490709135 308061521170129 498454011879264 806515533049393 1304969544928657 2111485077978050 3416454622906707 5527939700884757 8944394323791464 14472334024676221 23416728348467685 37889062373143906 61305790721611591 99194853094755497 160500643816367088 259695496911122585 420196140727489673 679891637638612258 1100087778366101931 1779979416004714189 2880067194370816120 4660046610375530309 7540113804746346429 12200160415121876738N 19740274219868223167N 31940434634990099905N 51680708854858323072N 83621143489848422977N 135301852344706746049N 218922995834555169026N]","author":{"avatar-url":"https://avatars.githubusercontent.com/u/13352033?v=3","account-source":"github","login":"teymuri"},"created-at":1443219853505,"updated-at":1561377380394,"_id":"5605c98de4b08e404b6c1c85"},{"editors":[{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"body":";; Reduce can be used to reimplement a map function:\n\n(defn map* [f & c]\n (let [c* (partition (count c)\n (apply interleave c))]\n (reduce (fn [s k] (conj s (apply f k))) [] c*)))\n\n;; user=> (map* * [0.5 0.5 0.5] (range))\n;; [0.0 0.5 1.0]\n;; user=> (map* str \"clojure\" (range))\n;; [\"c0\" \"l1\" \"o2\" \"j3\" \"u4\" \"r5\" \"e6\"]\n","author":{"avatar-url":"https://avatars.githubusercontent.com/u/13352033?v=3","account-source":"github","login":"teymuri"},"created-at":1447891132480,"updated-at":1561323290402,"_id":"564d10bce4b0538444398272"},{"editors":[{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"body":";; Update map entries:\n(defn update-map-entries [m e]\n (reduce #(update-in %1 [(first %2)] (fn [_] (last %2))) m e))\n\n;; => (update-map-entries {:a 1 :b 2 :c 3} {:a 5 :b 9})\n;; {:a 5, :b 9, :c 3}\n;; => (update-map-entries {:a 1 :b 2 :c 3} {:a 5 :b 9 :d 8})\n;; {:a 5, :b 9, :c 3, :d 8}","author":{"avatar-url":"https://avatars.githubusercontent.com/u/1223207?v=3","account-source":"github","login":"hadielmougy"},"created-at":1470237574017,"updated-at":1561377421060,"_id":"57a20b86e4b0bafd3e2a04c5"},{"editors":[{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"body":";; Flatten values in a map.\n(reduce\n (fn [flattened [k v]]\n (clojure.set/union flattened v))\n #{}\n {:e #{:m :f}, :c #{:f}, :b #{:c :f}, :d #{:m :f}, :a #{:c :f}})\n\n;; => #{:m :c :f}","author":{"avatar-url":"https://avatars.githubusercontent.com/u/528932?v=3","account-source":"github","login":"sleyzerzon"},"created-at":1471131155930,"updated-at":1561323131079,"_id":"57afae13e4b02d8da95c26fa"},{"editors":[{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"body":";; A simple factorial function using reduce:\n\n(defn fact\n [x] \n (reduce * (range 1 (inc x))))","author":{"avatar-url":"https://avatars.githubusercontent.com/u/2006175?v=3","account-source":"github","login":"cloxure"},"created-at":1479851336416,"updated-at":1561377519723,"_id":"5834bd48e4b0782b632278c7"},{"updated-at":1561377553253,"created-at":1485475889351,"author":{"login":"mahonbaldwin","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/2431381?v=3"},"body":";; Reduce over maps by destructuring keys:\n(def x {:a 1 :b 2})\n\n(reduce (fn [p [k v]]\n (into p {k (+ 1 v)}))\n {} ; First value for p\n x)\n\n;; => {:a 2, :b 3}","editors":[{"avatar-url":"https://avatars0.githubusercontent.com/u/838526?v=3","account-source":"github","login":"isaacm"},{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"_id":"588a9031e4b01f4add58fe32"},{"editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/211644?v=4"}],"body":";; conj! over transient array for speed.\n;; This example flattens over one level.\n;; To do so uses reduce twice.\n(persistent!\n (reduce\n (fn [acc0 item-vector]\n (reduce \n (fn [acc1 item]\n (conj! acc1 item))\n acc0 item-vector))\n (transient [])\n [[:foo :bar :baz] [] [:fred :barney]]))\n ;;=> [:foo :bar :baz :fred :barney] ","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/211644?v=4","account-source":"github","login":"phreed"},"created-at":1508890297162,"updated-at":1508890336628,"_id":"59efd6b9e4b0a08026c48c76"},{"updated-at":1516050550051,"created-at":1516050550051,"author":{"login":"ibercode","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/31028993?v=4"},"body":";;reduce with side effects\n;;given a collection return a new collection\n\n(def initial-coll [1 2 3 4 5])\n\n(defn byten\n [coll]\n (reduce (fn [new-coll unit]\n (into new-coll [(* 10 unit)]))\n []\n coll))\n\n(byten initial-coll)\n;;[10 20 30 40 50]\n\n\n","_id":"5a5d1876e4b0a08026c48cf5"},{"editors":[{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"body":";; Reduce with side effects using an anonymous function\n;; given a collection return a new collection:\n\n(def initial-coll [1 2 3 4 5])\n\n(defn byten\n [coll]\n (reduce #(into %1 [(* 10 %2)])\n []\n coll))\n\n(byten initial-coll)\n;; => [10 20 30 40 50]","author":{"avatar-url":"https://avatars0.githubusercontent.com/u/31028993?v=4","account-source":"github","login":"ibercode"},"created-at":1516050752043,"updated-at":1561377738301,"_id":"5a5d1940e4b0a08026c48cf6"},{"editors":[{"login":"IwoHerka","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/9204550?v=4"}],"body":";; A practical example of mapping over values\n;; in a hash-map with the `upper-case` function:\n\n(reduce\n (fn [acc [k v]]\n (assoc acc k (clojure.string/upper-case v)))\n {}\n {:a \"aaaaaaa\" :b \"bbbbbbb\"})\n\n;; => {:a \"AAAAAAA\", :b \"BBBBBBB\"}","author":{"avatar-url":"https://avatars0.githubusercontent.com/u/31028993?v=4","account-source":"github","login":"ibercode"},"created-at":1517738937897,"updated-at":1561377698196,"_id":"5a76dbb9e4b0e2d9c35f7418"},{"editors":[{"login":"ftravers","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/443507?v=4"}],"body":"(reduce\n (fn [accumulator current-item] ; <-- accumulator is FIRST argument to function\n ...) ; <-- your fn definition goes here\n [] ; <-- initial value for your accumulator \n [:a :b]) ; <-- collection to operate on\n","author":{"avatar-url":"https://avatars1.githubusercontent.com/u/443507?v=4","account-source":"github","login":"ftravers"},"created-at":1555521629477,"updated-at":1555521659756,"_id":"5cb7605de4b0ca44402ef70b"},{"editors":[{"login":"tanrax","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/4553672?v=4"}],"body":"(reduce #(str %1 %2) \"\" [\"Woody\" \"Potato\" \"Buzz\"])\n;;=> \"WoodyPotatoBuzz\"\n\n;; or\n\n(reduce (fn [accumulator current-item] (str accumulator current-item)) \"\" [\"Woody\" \"Potato\" \"Buzz\"])\n;;=> \"WoodyPotatoBuzz\"\n\n","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/4553672?v=4","account-source":"github","login":"tanrax"},"created-at":1583079460917,"updated-at":1584265812224,"_id":"5e5be024e4b087629b5a18b0"},{"updated-at":1693707759326,"created-at":1693707759326,"author":{"login":"burinc","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/19825136?v=4"},"body":"; Nice use of reduce from some version of medley library \n; https://github.com/weavejester/medley\n\n(defn assoc-some\n \"Associates a key k, with a value v in a map m, if and only if v is not nil.\"\n ([m k v]\n (if (nil? v) m (assoc m k v)))\n ([m k v & kvs]\n (reduce (fn [m [k v]] (assoc-some m k v))\n (assoc-some m k v)\n (partition 2 kvs))))\n\n(assoc-some {} :a 1)\n;;=> {:a 1}\n\n(assoc-some {} :a nil :b 2)\n;;=> {:b 2}\n\n(assoc-some {:a 1 :b 2} :a 10 :c 3)\n;;=> {:a 10, :b 2, :c 3}\n\n","_id":"64f3edefe4b08cf8563f4be7"},{"updated-at":1694309383597,"created-at":1694309383597,"author":{"login":"burinc","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/19825136?v=4"},"body":";; Transform key/value pairs\n(reduce (fn [acc [k v]]\n (assoc acc (str (name k)) v))\n {}\n [[:a 1] [:b 2] [:c 3]])\n;;=> {\"a\" 1, \"b\" 2, \"c\" 3}\n\n(reduce (fn [acc [k v]]\n (assoc acc (str \"k\" k) (* v 2)))\n {}\n (partition 2 (range 10)))\n;;=> {\"k0\" 2, \"k2\" 6, \"k4\" 10, \"k6\" 14, \"k8\" 18}","_id":"64fd1c07e4b08cf8563f4bf7"},{"updated-at":1736155857640,"created-at":1736155857640,"author":{"login":"vasanth53","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/95751113?v=4"},"body":";; Function to generate permutations using reduce\n(defn permutations [coll]\n (reduce\n (fn [acc x]\n (for [perm acc\n i (range (inc (count perm)))]\n (concat (take i perm) [x] (drop i perm))))\n [[]] ; Start with an empty permutation\n coll))\n\n;; Example usage\n(permutations [1 2 3])\n\n;; => ((3 2 1) (2 3 1) (2 1 3) (3 1 2) (1 3 2) (1 2 3))\n","_id":"677ba2d1cd84df5de54e2068"}],"notes":[{"updated-at":1278794710000,"body":"clojure.core/reduce seems to be a special case of a function that's defined twice in core.clj, and the first definition (at the line cited above: 773) is just a temporary definition; the real definition is later at line 5323, which contains the docstring.","created-at":1278794710000,"author":{"login":"JoshuaEckroth","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/ef8bb10e14b41f71f8ea9ed9d66d07b7?r=PG&default=identicon"},"_id":"542692ebf6e94c6970521f80"},{"author":{"login":"didibus","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/601540?v=3"},"updated-at":1505006701520,"created-at":1505006701520,"body":"The reducing function f is of shape:\n\n(f [accumulator next-element] ...)","_id":"59b4946de4b09f63b945ac67"},{"author":{"login":"iljaf","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/35742698?v=4"},"updated-at":1598124872512,"created-at":1598124872512,"body":"The 4th example (generating prime numbers) is kind of nice conceptually, but running it for the first 1m integers is taking 2 min on i7 2.7GHz machine, so it seems to be a very inefficient way of generating prime numbers. ","_id":"5f417348e4b0b1e3652d7385"}],"arglists":["f coll","f val coll"],"doc":"f should be a function of 2 arguments. If val is not supplied,\n returns the result of applying f to the first 2 items in coll, then\n applying f to that result and the 3rd item, etc. If coll contains no\n items, f must accept no arguments as well, and reduce returns the\n result of calling f with no arguments. If coll has only 1 item, it\n is returned and f is not called. If val is supplied, returns the\n result of applying f to val and the first item in coll, then\n applying f to that result and the 2nd item, etc. If coll contains no\n items, returns val and f is not called.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/reduce"},{"added":"1.0","ns":"clojure.core","name":"when-first","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1405367822000,"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-let","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521b77"},{"created-at":1713010008086,"author":{"login":"MicahElliott","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/159047?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"when","ns":"clojure.core"},"_id":"661a755869fbcc0c226174bd"}],"line":4649,"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":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"}],"body":"user=> (when-first [a [1 2 3]] a)\n1\nuser=> (when-first [a []] :x)\nnil\nuser=> (when-first [a nil] :x)\nnil","created-at":1280737783000,"updated-at":1423524033466,"_id":"542692cac026201cdc326b30"},{"editors":[{"login":"totorigolo","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/1183296?v=4"}],"body":";; Note that the 'when' switches on the truthiness of the sequence, not the\n;; truthiness of the elements within the sequence.\n\nuser=> (when-first [a [nil 2 3]] \n (print (str \"Picked: \" (prn-str a))))\nPicked: nil\nnil","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/1634344?v=3","account-source":"github","login":"peterwestmacott"},"created-at":1490868547686,"updated-at":1542136234692,"_id":"58dcd943e4b01f4add58fe80"},{"updated-at":1522689850199,"created-at":1522689850199,"author":{"login":"reborg","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4"},"body":";; A concise way to write the basic lazy loop.\n\n(defn dechunk [xs]\n (lazy-seq\n (when-first [x xs]\n (cons x\n (dechunk (rest xs))))))\n\n;; would print 32 dots otherwise:\n(first (map #(do (print \".\") %) (dechunk (range 100))))\n;; .0","_id":"5ac2673ae4b045c27b7fac2e"}],"macro":true,"notes":null,"arglists":["bindings & body"],"doc":"bindings => x xs\n\n Roughly the same as (when (seq xs) (let [x (first xs)] body)) but xs is evaluated only once","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/when-first"},{"added":"1.0","ns":"clojure.core","name":"find-ns","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1284970272000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"create-ns","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521bd5"},{"created-at":1284970279000,"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":"542692eaf6e94c6970521bd6"},{"created-at":1489760484301,"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":"ns-map","ns":"clojure.core"},"_id":"58cbf0e4e4b01f4add58fe76"}],"line":4152,"examples":[{"author":{"login":"teyc","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bd6e62afb4881ab0f617611b8b65d003?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":"(find-ns 'clojure.string)\n;;=> nil\n\n(require 'clojure.string)\n;;=> nil\n\n(find-ns 'clojure.string)\n;;=> #\r\n(contains (1 2 3) 1)\r\n
\r\nI used:\r\n\r\n(some #(= 1 %) (1 2 3))\r\n
\r\n\r\nHope that helps.","created-at":1279546429000,"author":{"login":"robertpostill","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/16aae57aa6b16e96fa81089bea6acad8?r=PG&default=identicon"},"_id":"542692ebf6e94c6970521f81"},{"updated-at":1279552212000,"body":"For collections I use the `java.util.Collection#contains()` method:\r\n\r\n\r\nuser=> (.contains [1 2 3] 1)\r\ntrue\r\nuser=> (.contains [1 2 3] 4)\r\nfalse\r\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 (defn seq-contains? [coll target] (some #(= target %) coll))\r\n(seq-contains? [true false true] false) ; = true
","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\nLet's do some investigation to find the answer. First we start by finding out the type of
\n;=> true\n[1 1 1 1 1]:\n\n(class [1 1 1 1 1])\n\nSo when the statement
\n;=> clojure.lang.PersistentVector\n(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\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(.containsKey [1 1 1 1 1 1] 4) ; true\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":2689,"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":null,"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":[{"created-at":1708775042567,"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":"proxy","ns":"clojure.core"},"_id":"65d9d68269fbcc0c226174a9"}],"line":328,"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":null,"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":7538,"examples":[{"updated-at":1718839142351,"created-at":1282318865000,"body":"user=> (keep-indexed #(when (odd? %1) %2) [:a :b :c :d :e])\n(:b :d)","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3","account-source":"github","login":"jafingerhut"},{"avatar-url":"https://www.gravatar.com/avatar/56a007a4b2c47b141bd39790278f88a7?r=PG&default=identicon","account-source":"clojuredocs","login":"SoniaH"},{"login":"arcanjoaq","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1619912?v=4"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/10b2fd3c0a4cc46dc241a48468dc551?r=PG&default=identicon","account-source":"clojuredocs","login":"pkolloch"},"_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":null,"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":7747,"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":null,"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":5034,"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"},{"updated-at":1767193509472,"created-at":1767193509472,"author":{"login":"wdhowe","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/4631165?v=4"},"body":";; Remove the last character in a string\n(def s \"/my/dir/path/\")\n\n(subs s 0 (dec (count s)))\n\n;=> \"/my/dir/path\"","_id":"69553ba5b7956e24e4cb4ec7"}],"notes":null,"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":2487,"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":null,"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":4131,"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":2964,"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"},{"editors":[{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"}],"body":";; take-last is rarely what you want from a pure performance perspective,\n;; although for small collections, it's not worth worrying about\n;; unless it's on a hot path.\n\n;; let's make an alternative version, using drop:\n(defn my-take-last [n coll]\n (drop (- (count coll) n) coll))\n\n(require '[criterium.core :as c])\n;; For lazy-sequences, where we are taking a small number of elements,\n;; take-last can be faster:\n(->> (c/benchmark-round-robin [(dorun (take-last 2 (map inc (range 100))))\n (dorun (my-take-last 2 (map inc (range 100))))]\n c/*default-benchmark-opts*)\n (map (comp first :mean)))\n;; => (1.968E-6 2.613E-6)\n;; So, they both take a few microseconds. Rarely important.\n;; But take-last is ~25% faster\n\n;; For lazy-sequences where we are taking a large number of elemnts,\n;; the advantage disappears:\n(->> (c/benchmark-round-robin [(dorun (take-last 92 (map inc (range 100))))\n (dorun (my-take-last 92 (map inc (range 100))))]\n c/*default-benchmark-opts*)\n (map (comp first :mean)))\n;; => (2.517E-6 2.150E-6)\n;; take-last is ~17% slower here. But we're still on microsecond scales.\n\n;; For counted collections, take-last is noticeably slower:\n(->> (c/benchmark-round-robin [(dorun (take-last 2 (mapv inc (range 100))))\n (dorun (my-take-last 2 (mapv inc (range 100))))]\n c/*default-benchmark-opts*)\n (map (comp first :mean)))\n;; => (2.183E-6 1.230E-6)\n;; take-last is ~77% slower here, and it only gets worse the larger collections get\n\n;; For vectors specifically, subvec can be even faster:\n(defn my-vec-take-last [n v]\n (subvec v (- (count v) n)))\n\n(->> (c/benchmark-round-robin [(dorun (take-last 2 (mapv inc (range 100))))\n (dorun (my-vec-take-last 2 (mapv inc (range 100))))]\n c/*default-benchmark-opts*)\n (map (comp first :mean)))\n;; => (2.075E-6 1.133E-6)\n;; take-last is ~83% slower here\n\n;; For readability, take-last communicates intent well, but for hot-paths,\n;; it's worth knowing it's (sometimes significantly) slower than alternatives\n","author":{"avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4","account-source":"github","login":"tomdl89"},"created-at":1765584527875,"updated-at":1765589793404,"_id":"693cae8fb7956e24e4cb4ec0"}],"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":1351,"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":null,"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":7976,"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":null,"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":518,"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(gen-class :name clj.TestAppender :extends org.apache.log4j.AppenderSkeleton)\r\n\r\n(defn -append [this event]\r\n (println (.getMessage event)))\r\n
\r\n\r\n\r\nNeed to implement close and requireLayout. These are not in AppenderSkeleton but are required by the interface Appender.\r\n(gen-class :name TstAppender :extends org.apache.log4j.AppenderSkeleton)\r\n\r\n(defn -append [this event]\r\n (println (.getMessage event)))\r\n\r\n(defn -close [this]) ;nothing to clean up\r\n\r\n(defn -requireLayout [this] false)\r\n\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.) ;;=> #
\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":1219,"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":null,"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":null,"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":4314,"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"},{"created-at":1775094196090,"author":{"login":"wlkr","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/5406568?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"peek","ns":"clojure.core"},"_id":"69cdc9b47955605a202df29f"}],"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":null,"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":4911,"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 #\"(?\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"},{"body":"```\n(defn slurp-norm\n \"When the file is incoming with \\r\\n newlines\"\n [file]\n (with-open [rdr (io/reader file)]\n (str/join \"\\n\" (line-seq rdr))))\n```","created-at":1738166701645,"updated-at":1738166712945,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/6553?v=4","account-source":"github","login":"piranha"},"_id":"679a51adcd84df5de54e2075"}],"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":[{"created-at":1721397185771,"author":{"login":"Kaspazza","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/36607370?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"println","ns":"clojure.core"},"_id":"669a6fc169fbcc0c226174dd"}],"line":3723,"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":null,"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":5362,"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":null,"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":6293,"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":3156,"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":1841,"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":null,"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":null,"line":5784,"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":null,"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":7847,"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":null,"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"},{"created-at":1696605582468,"author":{"login":"maria-silvia","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/57308135?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"update-in","ns":"clojure.core"},"_id":"6520258ee4b08cf8563f4bfc"},{"created-at":1713480532424,"author":{"login":"MicahElliott","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/159047?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"remove","ns":"clojure.core"},"_id":"6621a35469fbcc0c226174c0"}],"line":1519,"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"},{"editors":[{"login":"TuggyNE","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/218900?v=4"}],"body":";; dissoc keys in a coll\nuser=> (reduce dissoc {:a 1 :b 2 :c 3} [:b :c])\n{:a 1}\n;; Can also use apply, a bit slower; any seqable works for either of these\nuser=> (apply dissoc {:a 1 :b 2 :c 3} #{:b :c})\n{:a 1}","author":{"avatar-url":"https://avatars0.githubusercontent.com/u/1518393?v=4","account-source":"github","login":"Em-AK"},"created-at":1608027071533,"updated-at":1736267760815,"_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"},{"created-at":1712651107449,"author":{"login":"ghoseb","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1453?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"ref-set","ns":"clojure.core"},"_id":"6614fb6369fbcc0c226174ba"}],"line":2344,"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":null,"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":3451,"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.12","ns":"clojure.core","name":"splitv-at","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":7422,"examples":null,"notes":null,"arglists":["n coll"],"doc":"Returns a vector of [(into [] (take n) coll) (drop n coll)]","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/splitv-at"},{"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":1376,"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\n06:08 < mikera> (defn >>> [v bits] (bit-shift-right (bit-and 0xFFFFFFFF v) bits))
\r\n\r\nThere's also an open ticket for a [built-in version](http://dev.clojure.org/jira/browse/CLJ-827).","created-at":1326786313000,"author":{"login":"TimMc","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"},"_id":"542692ecf6e94c6970521fd7"},{"body":"unsigned-bit-shift-right was added in Clojure 1.6.0. Click the link in the See Also section above.","created-at":1415350996576,"updated-at":1415350996576,"author":{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=2"},"_id":"545c8ad4e4b03d20a102429f"}],"arglists":["x n"],"doc":"Bitwise shift right","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/bit-shift-right"},{"ns":"clojure.core","name":"print-method","file":"clojure/core.clj","type":"var","column":1,"see-alsos":[{"created-at":1340861043000,"author":{"login":"abrooks","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/69976?v=2"},"to-var":{"ns":"clojure.core","name":"print-dup","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521dda"}],"line":3689,"examples":[{"author":{"login":"pangloss","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/1202c95dec14eee416717e8c0add0f0c?r=PG&default=identicon"},"editors":[],"body":"(deftype XYZ [])\n\n; without custom print-method defined:\nuser=> (prn (XYZ.))\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\nuser> (peek (cons 1 '()))\r\n; Evaluation aborted.\r\n
\r\ndo not work because type is clojure.lang.Cons but\r\n\r\nuser> (peek (conj '() 1))\r\n1\r\n
\r\nworks because type is clojure.lang.PersistentList.","created-at":1349884718000,"author":{"login":"tomby42","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/305033855efb82d6041586b874b5bb24?r=PG&default=identicon"},"_id":"542692ecf6e94c6970521fea"}],"arglists":["coll"],"doc":"For a list or queue, same as first, for a vector, same as, but much\n more efficient than, last. If the collection is empty, returns nil.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/peek"},{"added":"1.0","ns":"clojure.core","name":"aget","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1359687973000,"author":{"login":"mmwaikar","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"aclone","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521af2"},{"created-at":1389744326000,"author":{"login":"jw0","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/ca45063da41a9f3aa9028295d8b66d89?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"get","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521af3"},{"created-at":1389744330000,"author":{"login":"jw0","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/ca45063da41a9f3aa9028295d8b66d89?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"nth","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521af4"},{"created-at":1454023320808,"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":"contains?","ns":"clojure.core"},"_id":"56aaa298e4b060004fc217b3"},{"created-at":1593147984636,"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":"aset","ns":"clojure.core"},"_id":"5ef58250e4b0b1e3652d7310"}],"line":3938,"examples":[{"updated-at":1454082671521,"created-at":1284178036000,"body":"\n;; create two arrays\n(def a1 (double-array '(1.0 2.0 3.0 4.0)))\n;;=> #'user/a1\n(def a2 (int-array '(9 8 7 6)))\n;;=> #'user/a2\n\n;; get an item by index\n(aget a1 2)\n;;=> 3.0\n(aget a2 3)\n;;=> 6\n\n;; 2d array and 2 indicies\n(def a3 (make-array Integer/TYPE 100 100))\n;;=> #'user/a3\n(aget a3 23 42)\n;;=> 0","editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/363fd6c774471e207b327fda11b246c7?r=PG&default=identicon","account-source":"clojuredocs","login":"dermatthias"},"_id":"542692cec026201cdc326da0"},{"editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"body":";; aget can be used to check the existence of an element\n;; this approach works with documents in ClojureScript where core/contains? does not\n(aget js/document \"getElementById\")\n;;=> #object[getElementById \"function getElementById() { [native code] }\"]\n(contains? js/document \"getElementById\")\n;;=> false","author":{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},"created-at":1454022947998,"updated-at":1454082875581,"_id":"56aaa123e4b0ceed88ce8d19"}],"notes":null,"arglists":["array idx","array idx & idxs"],"doc":"Returns the value at the index/indices. Works on Java arrays of all\n types.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/aget"},{"added":"1.0","ns":"clojure.core","name":"pvalues","file":"clojure/core.clj","static":true,"type":"macro","column":1,"see-alsos":[{"created-at":1329792245000,"author":{"login":"cmccoy","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cf46d3ffedb153a97fe69cb4719e0fd?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"pmap","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521e7d"},{"created-at":1336537825000,"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":"542692ebf6e94c6970521e7e"},{"created-at":1423019380983,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"pcalls","library-url":"https://github.com/clojure/clojure"},"_id":"54d18d74e4b0e2ac61831d0a"}],"line":7191,"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":";; expressions are calculated in parallel\n\nuser=> (pvalues (expensive-calc-1) (expensive-calc-2))\n(2330 122)\n","created-at":1280322280000,"updated-at":1285496725000,"_id":"542692cac026201cdc326b59"},{"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":";; pvalues is implemented using Clojure futures. See examples for 'future'\n;; for discussion of an undesirable 1-minute wait that can occur before\n;; your standalone Clojure program exits if you do not use shutdown-agents.","created-at":1336537820000,"updated-at":1406853126000,"_id":"542692d4c026201cdc327046"}],"macro":true,"notes":null,"arglists":["& exprs"],"doc":"Returns a lazy sequence of the values of the exprs, which are\n evaluated in parallel","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/pvalues"},{"added":"1.1","ns":"clojure.core","name":"bound-fn","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1331766568000,"author":{"login":"metajack","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/194d8437f5baed192c90be27369c4922?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"bound-fn*","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d55"}],"line":2023,"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":1331769907000,"updated-at":1331769907000,"_id":"542692d2c026201cdc326f5c"}],"macro":true,"notes":null,"arglists":["& fntail"],"doc":"Returns a function defined by the given fntail, which will install the\n same bindings in effect as in the thread at the time bound-fn was called.\n This may be used to define a helper function which runs on a different\n thread, but needs the same bindings in place.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/bound-fn"},{"added":"1.7","ns":"clojure.core","name":"vswap!","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1469617377040,"author":{"login":"kumarshantanu","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109792?v=3"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"volatile!","ns":"clojure.core"},"_id":"579894e1e4b0bafd3e2a04bf"},{"created-at":1492398573657,"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":"58f431ede4b01f4add58fe91"},{"created-at":1492398581193,"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":"volatile?","ns":"clojure.core"},"_id":"58f431f5e4b01f4add58fe92"},{"created-at":1492398620716,"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":"swap!","ns":"clojure.core"},"_id":"58f4321ce4b01f4add58fe93"}],"line":2556,"examples":[{"updated-at":1492398484318,"created-at":1492398484318,"author":{"login":"didibus","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/601540?v=3"},"body":"(let [interrupt (volatile! false)\n f1 (future (Thread/sleep 1000)\n (vswap! interrupt not))\n f2 (future (while (not @interrupt)\n (println \"Another cycle!\")\n (Thread/sleep 100)))]\n @f1\n @f2)","_id":"58f43194e4b01f4add58fe90"}],"macro":true,"notes":null,"arglists":["vol f & args"],"doc":"Non-atomically swaps the value of the volatile as if:\n (apply f current-value-of-vol args). Returns the value that\n was swapped in.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/vswap!"},{"added":"1.0","ns":"clojure.core","name":"last","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1289038378000,"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":"542692ebf6e94c6970521e58"},{"created-at":1289038381000,"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":"542692ebf6e94c6970521e59"},{"created-at":1289038385000,"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":"542692ebf6e94c6970521e5a"},{"created-at":1289038414000,"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"butlast","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521e5b"},{"created-at":1306817792000,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"take-last","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521e5c"},{"created-at":1436712121100,"author":{"login":"sindux","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1397898?v=3"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"peek","ns":"clojure.core"},"_id":"55a27cb9e4b020189d740550"}],"line":264,"examples":[{"updated-at":1473264230717,"created-at":1279416204000,"body":"user=> (last [1 2 3 4 5])\n5\nuser=> (last [\"a\" \"b\" \"c\" \"d\" \"e\"])\n\"e\"\nuser=> (last {:one 1 :two 2 :three 3})\n[:three 3]\nuser=> (last [])\nnil\n\n;; but be careful with what you expect from a map (or set):\nuser=> (last {:a 1 :b 2 :c 3 :d 4 :e 5 :f 6 :g 7 :h 8 :i 9})\n[:a 1]","editors":[{"avatar-url":"https://avatars2.githubusercontent.com/u/22608?v=4","account-source":"github","login":"MrHus"},{"avatar-url":"https://www.gravatar.com/avatar/69ad2af1f028b1b7e76c14f83bdf26cb?r=PG&default=identicon","account-source":"clojuredocs","login":"jszakmeister"},{"avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3","account-source":"github","login":"Dimagog"},{"login":"reborg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/20086?v=3"}],"author":{"login":"MrHus","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/22608?v=4"},"_id":"542692c8c026201cdc326a2c"},{"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"editors":[],"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\n ([a-list]\n (cond (= a-list nil) nil\n :else (cons (last a-list)\n (my-reverse (butlast a-list))))))","created-at":1289038818000,"updated-at":1289038818000,"_id":"542692c8c026201cdc326a2f"},{"updated-at":1499968174976,"created-at":1499966780539,"author":{"login":"webappzero","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/1661060?v=3"},"body":";; Prefer clojure.core/peek over `last` for potentially large vectors.\n\nuser=> (def v (into [] (take 900900 (range))))\n#'user/v\n\nuser=> (time (last v))\n\"Elapsed time: 24.460958 msecs\"\n900899\n\nuser=> (def v2 (into [] (take 900900 (range))))\n#'user/v2\n\nuser=> (time (peek v2))\n\"Elapsed time: 0.020498 msecs\"\n900899\n\n;; For a deep dive into why Rich Hickey chose not to make `last` performant\n;; for large vectors, please see:\n;; https://gist.github.com/reborg/dc8b0c96c397a56668905e2767fd697f\n\n","editors":[{"avatar-url":"https://avatars2.githubusercontent.com/u/1661060?v=3","account-source":"github","login":"webappzero"}],"_id":"5967ad3ce4b0d19c2ce9d6f9"},{"editors":[{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"}],"body":";; last is also inefficient for sorted-sets and sorted-maps, and\n;; peek doesn't work for these, so we can combine `first` with `rseq`\n;; to efficiently get the last element on large sorted- collections instead\n\n(def sm (into (sorted-map)\n (map vector (range 1e6) (repeatedly #(rand-int 100)))))\n\n(time (last sm))\n\"Elapsed time: 144.298867 msecs\"\n;; => [999999 42]\n\n(time (first (rseq sm)))\n\"Elapsed time: 0.024408 msecs\"\n;; => [999999 42]","author":{"avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4","account-source":"github","login":"tomdl89"},"created-at":1680193851632,"updated-at":1680196828207,"_id":"6425b93be4b08cf8563f4b89"},{"updated-at":1728637092443,"created-at":1728637092443,"author":{"login":"sanel","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/213914?v=4"},"body":";; Beside using clojure.core/peek for fast access to the last element in\n;; a large vector, you can also use (first (rseq)) which is performant as well\n\n(def v (into [] (take 900900 (range))))\n(time (last v))\n\"Elapsed time: 24.825208 msecs\"\n900899\n\n(def v2 (into [] (take 900900 (range))))\n(time (peek v2))\n\"Elapsed time: 0.02343 msecs\"\n900899\n\n(def v3 (into [] (take 900900 (range))))\n(time (first (rseq v3)))\n\"Elapsed time: 0.02581 msecs\"\n900899","_id":"6708e8a469fbcc0c22617505"}],"notes":null,"arglists":["coll"],"doc":"Return the last item in coll, in linear time","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/last"},{"added":"1.0","ns":"clojure.core","name":"pr","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1290689171000,"author":{"login":"dale","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/a7a1eca257c6cea943fea41e5cc3e9a3?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"print","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521bd2"},{"created-at":1299623874000,"author":{"login":"TimMc","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"prn","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521bd3"},{"created-at":1299623879000,"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-str","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521bd4"},{"created-at":1470508478634,"author":{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"read","ns":"clojure.edn"},"_id":"57a62dbee4b0bafd3e2a04ca"}],"dynamic":true,"line":3703,"examples":[{"author":{"login":"srid","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bd3a68d670372cd09876c26270a4299a?r=PG&default=identicon"},"editors":[],"body":"user=> (pr \"foo\")\n\"foo\"nil","created-at":1315392482000,"updated-at":1315392482000,"_id":"542692cec026201cdc326da1"},{"author":{"login":"srid","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bd3a68d670372cd09876c26270a4299a?r=PG&default=identicon"},"editors":[],"body":"user=> (pr {:foo \"hello\" :bar 34.5})\n{:foo \"hello\", :bar 34.5}nil","created-at":1315392515000,"updated-at":1315392515000,"_id":"542692cec026201cdc326da2"},{"body":";; Difference between pr and print\n\nuser=> (pr ['a :b \"\\n\" \\space \"c\"])\n[a :b \"\\n\" \\space \"c\"]nil\n\nuser=> (print ['a :b \"\\n\" \\space \"c\"])\n[a :b\n c]nil\n","author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"created-at":1423019089923,"updated-at":1423019089923,"_id":"54d18c51e4b0e2ac61831d09"},{"updated-at":1470507649207,"created-at":1470507649207,"author":{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"},"body":";; WARNING: Clojure's keyword and symbol functions allow you to create\n;; values that cannot be printed then later read and recreate those same\n;; values.\n\n;; For most common symbols and keywords, they round-trip through pr\n;; then read-string, as this example shows.\nuser=> (read-string (with-out-str (pr {:a 1, :b 2})))\n{:a 1, :b 2}\n\n;; But these values do not round-trip through the same steps:\nuser=> (def kw1 (keyword \"foo bar\"))\n#'user/kw1\nuser=> kw1\n:foo bar\nuser=> (def s2 (with-out-str (pr {kw1 1, :b 2})))\n#'user/s2\nuser=> s2\n\"{:foo bar 1, :b 2}\"\nuser=> (read-string s2)\n\nRuntimeException Map literal must contain an even number of forms clojure.lang.Util.runtimeException (Util.java:221)\n\n;; Similarly for a symbol like (symbol \"a;b\")\nuser=> (def sym1 (symbol \"a;b\"))\n#'user/sym1\nuser=> sym1\na;b\nuser=> (def s3 (with-out-str (pr sym1)))\n#'user/s3\nuser=> s3\n\"a;b\"\nuser=> (read-string s3)\na\n\n;; If you wish to transmit data that may contain such values, one suggestion\n;; is to use the transit library: https://github.com/cognitect/transit-format\n\n;; It is much faster and formally specified.","_id":"57a62a81e4b0bafd3e2a04c9"}],"notes":[{"author":{"login":"jcburley","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/430319?v=4"},"updated-at":1514410889866,"created-at":1514410889866,"body":"\"Readable by the reader\" means, for example, that a string is printed with surrounding double quotes and with quotes, backslashes, and nonprinting characters being escaped via a backslash prefix.","_id":"5a441389e4b0a08026c48ce2"}],"arglists":["","x","x & more"],"doc":"Prints the object(s) to the output stream that is the current value\n of *out*. Prints the object(s), separated by spaces if there is\n more than one. By default, pr and prn print in a way that objects\n can be read by the reader","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/pr"},{"added":"1.0","ns":"clojure.core","name":"namespace","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1366844136000,"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","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d8a"},{"created-at":1385200446000,"author":{"login":"abrooks","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/69976?v=2"},"to-var":{"ns":"clojure.core","name":"name","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d8b"},{"created-at":1523484084873,"author":{"login":"delonnewman","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/10404?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"def","ns":"clojure.core"},"_id":"5ace85b4e4b045c27b7fac3d"}],"line":1612,"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=> (def x \"Foobar\")\n#'user/x\n\nuser=> (namespace 'user/x)\n\"user\"\n","created-at":1284256918000,"updated-at":1287791961000,"_id":"542692cbc026201cdc326c1d"},{"editors":[{"login":"dominem","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/11671382?v=4"}],"body":"(namespace :admin/live-playlist-details)\n;;=> \"admin\"\n\n(namespace :about)\n;;=> nil","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/11671382?v=4","account-source":"github","login":"dominem"},"created-at":1565335391711,"updated-at":1565335408498,"_id":"5d4d1f5fe4b0ca44402ef795"}],"notes":[{"body":"Note this does not try to be \"smart\"\n\n```\nuser=>(namespace 'no-such-name/no-such-var)\n\"no-such-name\"\n\nuser=>(def a-var)\n#'user-a-var\n\nuser=>(namespace 'a-var)\nnil\n```","created-at":1443303990722,"updated-at":1443304019556,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/159998?v=3","account-source":"github","login":"merriam"},"_id":"56071236e4b08e404b6c1c89"}],"tag":"java.lang.String","arglists":["x"],"doc":"Returns the namespace String of a symbol or keyword, or nil if not present.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/namespace"},{"added":"1.1","ns":"clojure.core","name":"push-thread-bindings","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1374313643000,"author":{"login":"alilee","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"pop-thread-bindings","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d2b"},{"created-at":1374313651000,"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":"542692ebf6e94c6970521d2c"},{"created-at":1374313699000,"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":"542692ebf6e94c6970521d2d"}],"line":1930,"examples":null,"notes":null,"arglists":["bindings"],"doc":"WARNING: This is a low-level function. Prefer high-level macros like\n binding where ever possible.\n\n Takes a map of Var/value pairs. Binds each Var to the associated value for\n the current thread. Each call *MUST* be accompanied by a matching call to\n pop-thread-bindings wrapped in a try-finally!\n \n (push-thread-bindings bindings)\n (try\n ...\n (finally\n (pop-thread-bindings)))","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/push-thread-bindings"},{"added":"1.0","ns":"clojure.core","name":"bases","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1519504605797,"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":"supers","ns":"clojure.core"},"_id":"5a91ccdde4b0316c0f44f8ee"},{"created-at":1519504691579,"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":"type","ns":"clojure.core"},"_id":"5a91cd33e4b0316c0f44f8ef"}],"line":5596,"examples":[{"author":{"login":"teyc","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bd6e62afb4881ab0f617611b8b65d003?r=PG&default=identicon"},"editors":[],"body":"user=> (import 'java.io.File)\r\n\r\nuser=> (bases java.io.File)\r\n(java.lang.Object java.io.Serializable java.lang.Comparable)
","created-at":1283977099000,"updated-at":1283977099000,"_id":"542692c9c026201cdc326ac4"},{"body":";; what is a hash-map?\n(bases (class {}))\n;;=> (clojure.lang.APersistentMap \n;;+> clojure.lang.IObj \n;;+> clojure.lang.IEditableCollection)\n\n;; what is a set?\n(bases (class #{}))\n;;=> (clojure.lang.APersistentSet \n;;+> clojure.lang.IObj \n;;+> clojure.lang.IEditableCollection)\n\n;; what is a vector?\n(bases (class []))\n;;=> (clojure.lang.APersistentVector \n;;+> clojure.lang.IObj \n;;+> clojure.lang.IEditableCollection)\n\n;; what is a list? \n(bases (class ()))\n;;=> (clojure.lang.Obj \n;;+> clojure.lang.IPersistentList \n;;+> java.util.List \n;;+> clojure.lang.ISeq \n;;+> clojure.lang.Counted \n;;+> clojure.lang.IHashEq)","author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=2"},"created-at":1414510940403,"updated-at":1414510965758,"editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=2"}],"_id":"544fb95ce4b03d20a102428b"},{"updated-at":1598220307317,"created-at":1598220307317,"author":{"login":"berczeck","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/1321842?v=4"},"body":";; what is a defrecord\n\nuser=> (defprotocol Fly\n (fly [this]))\n\nuser=> (defrecord Bird [name] Fly\n (fly [this] (str (:name this) \" flies....\")))\n\nuser=> (ancestors Bird)\n;; (java.lang.Object \n;; user.Fly \n;; clojure.lang.IRecord \n;; clojure.lang.IHashEq \n;; clojure.lang.IObj \n;; clojure.lang.ILookup \n;; clojure.lang.IKeywordLookup \n;; clojure.lang.IPersistentMap \n;; java.util.Map \n;; java.io.Serializable)\n","_id":"5f42e813e4b0b1e3652d73a5"}],"notes":null,"arglists":["c"],"doc":"Returns the immediate superclass and direct interfaces of c, if any","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/bases"},{"added":"1.0","ns":"clojure.core","name":"=","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1287469623000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"==","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521f25"},{"created-at":1291975060000,"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":"542692ebf6e94c6970521f26"},{"created-at":1298162787000,"author":{"login":"TimMc","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"identical?","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521f27"}],"line":785,"examples":[{"updated-at":1474477801279,"created-at":1280470020000,"body":"user=> (= 1)\ntrue\nuser=> (= 1 1)\ntrue\nuser=> (= 1 2)\nfalse\nuser=> (= 1 1 1)\ntrue\nuser=> (= 1 1 2)\nfalse\nuser=> (= '(1 2) [1 2])\ntrue\nuser=> (= nil nil)\ntrue\nuser=> (= (sorted-set 2 1) (sorted-set 1 2))\ntrue\n\n;; It should be noted that equality is not defined for Java arrays.\n;; Instead you can convert them into sequences and compare them that way.\n;; (= (seq array1) (seq array2))\n","editors":[{"avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon","account-source":"clojuredocs","login":"gstamp"},{"avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2","account-source":"github","login":"zk"},{"login":"reborg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/20086?v=3"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/b3881a28fe402dd2d1de44717486cae8?r=PG&default=identicon","account-source":"clojuredocs","login":"citizen428"},"_id":"542692ccc026201cdc326c72"},{"editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=2","account-source":"github","login":"phreed"},{"login":"iammegatron","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/406013?v=3"}],"updated-at":1450298371193,"created-at":1412883142742,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=2","account-source":"github","login":"phreed"},"body":";; There are functional differences between = and == \n;; = may introduce java autoboxing \n\n;; true:\n(= 1)\n(= 1 1) \n(= 1/1, 2/2, 3/3, 4/4) \n(= :foo)\n(= nil anything) ; anything = nil\n\n\n;; false:\n(= 1, 1.0, 1/1) ; differs from ==\n(= 1 2)\n(= 1 \\1) ; differs from ==\n(= 1 \"1\") ; differs from ==\n\n","_id":"5436e2c6e4b06dbffbbb00c7"},{"body":";; If passed a single value (= x) the result is always true.\n(= 1)\n(= nil)\n(= false)\n(= true)\n(= {:a 1 :b2})\n(= 'false)\n;;=> true \n","author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"},"created-at":1418923922664,"updated-at":1418923922664,"_id":"54930f92e4b04e93c519ffa9"},{"updated-at":1543388969936,"created-at":1543388779355,"author":{"login":"huahaiy","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/889685?v=4"},"body":";; = can be used to compare the equality of nested Clojure data structures\n(= {:a [1 {1 2}] :b 'ok :c \"string\"} \n {:b 'ok :c \"string\" :a '(1 {1 2})})\n;;=> true","editors":[{"avatar-url":"https://avatars3.githubusercontent.com/u/889685?v=4","account-source":"github","login":"huahaiy"}],"_id":"5bfe3e6be4b0ca44402ef5cc"},{"editors":[{"login":"huahaiy","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/889685?v=4"},{"avatar-url":"https://avatars2.githubusercontent.com/u/109629?v=4","account-source":"github","login":"jafingerhut"}],"body":";; See the Clojure Equality guide for more details:\n;; https://clojure.org/guides/equality\n\n;; One perhaps surprising case is comparing regular expressions.\n;; In Clojure, regular expressions only equal one another if they are\n;; the same object in memory, i.e. if (identical? x y) is also true.\n;; Therefore, any data structure containing regular expression will \n;; only be equal to one another if the corresponding regular expressions are\n;; identical.\n;; See https://dev.clojure.org/jira/browse/CLJ-1182\n(= #\"fav*\" #\"fav*\")\n;;=> false\n\n;; Another exception is the special floating point value ##NaN for \"Not a Number\".\n;; In Clojure on Java, this value is never equal to itself, and any collections\n;; containing such \"values\" are never equal to any other collections, either:\n(= ##NaN ##NaN)\n;;=> false\n\n(= [1 2 3 ##NaN] [1 2 3 ##NaN])\n;;=> false\n\n;; There are a few other minor exceptions where clojure.core/= might behave in\n;; ways that surprise you. You can find an article describing the known cases\n;; for Clojure on Java here: https://clojure.org/guides/equality","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/889685?v=4","account-source":"github","login":"huahaiy"},"created-at":1543389091657,"updated-at":1565641554721,"_id":"5bfe3fa3e4b0ca44402ef5cf"},{"updated-at":1645209415531,"created-at":1645209415531,"author":{"login":"mars0i","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1836941?v=4"},"body":";; You can test for a Java infinity, but there are quirks to know about. \n\n;; Note particularly that Double/POSITIVE_INFINITY and Float/POSITIVE_INFINITY\n;; are = and ==, but they are neither identical? nor .equals. However, the\n;; value these Java objects return has the same representation, ##Inf, in\n;; Clojure. Further, the literal ##Inf is parsed as something that is\n;; .equals to Double/POSITIVE_INFINITY but not identical? to it. Similar\n;; points hold for the Java NEGATIVE_INFINITY's and their Clojure\n;; representation, ##-Inf.\n\nuser=> Double/POSITIVE_INFINITY\n;;=> ##Inf\nuser=> Float/POSITIVE_INFINITY\n;;=> ##Inf\nuser=> (= Double/POSITIVE_INFINITY Float/POSITIVE_INFINITY)\n;;=> true\nuser=> (= ##Inf ##Inf)\n;;=> true\nuser=> (== Double/POSITIVE_INFINITY Float/POSITIVE_INFINITY)\n;;=> true\nuser=> (== ##Inf ##Inf)\n;;=> true\nuser=> (identical? Double/POSITIVE_INFINITY Float/POSITIVE_INFINITY)\n;;=> false\nuser=> (identical? ##Inf ##Inf)\n;;=> true\nuser=> (.equals Double/POSITIVE_INFINITY Float/POSITIVE_INFINITY)\n;;=> false\nuser=> (.equals ##Inf ##Inf)\n;;=> true\nuser=> (identical? ##Inf Double/POSITIVE_INFINITY)\n;;=> false\nuser=> (identical? ##Inf Float/POSITIVE_INFINITY)\n;;=> false\nuser=> (.equals ##Inf Double/POSITIVE_INFINITY)\n;;=> true\nuser=> (.equals ##Inf Float/POSITIVE_INFINITY)\n;;=> false\n\n;; (Tested with Clojure 1.10.3.)","_id":"620fe747e4b0b1e3652d75a8"},{"updated-at":1655019041411,"created-at":1655019041411,"author":{"login":"clojer","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/107184681?v=4"},"body":"user=> (= + +)\ntrue\nuser=> (= = =)\ntrue\nuser=> (= inc inc)\ntrue\nuser=> (= #() #())\nfalse","_id":"62a59621e4b0b1e3652d75fd"}],"notes":[{"updated-at":1287470783000,"body":"There is a difference between \"=\" and \"==\". For primitives you definitely want to use \"==\" as \"=\" will result in a cast to the wrapped types for it's arguments. \r\n\r\nThis may not be the case come Clojure 1.3 (see [1])\r\n\r\n[1] http://github.com/clojure/clojure/commit/df8c65a286e90e93972bb69392bc106128427dde","created-at":1287470783000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"_id":"542692ecf6e94c6970521f9b"},{"author":{"login":"domokato","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/2388832?v=4"},"updated-at":1674772771853,"created-at":1674772771853,"body":"`=` compares collections in a type-independent manner but not numbers, despite what the docs say. See examples above.","_id":"63d30123e4b08cf8563f4b6c"}],"arglists":["x","x y","x y & more"],"doc":"Equality. Returns true if x equals y, false if not. Same as\n Java x.equals(y) except it also works for nil, and compares\n numbers and collections in a type-independent manner. Clojure's immutable data\n structures define equals() (and thus =) as a value, not an identity,\n comparison.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/="},{"added":"1.10","ns":"clojure.core","name":"read+string","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":3796,"examples":[{"updated-at":1638567988480,"created-at":1638567988480,"author":{"login":"earthfail","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/21296448?v=4"},"body":";; read from *in*\n;; notice that whitespace is trimmed\nuser=> (read+string)\n :a\n[:a \":a\"]\nuser=> (read+string)\n 1234 56 7\n[1234 \"1234\"]\nuser=> (read+string)\n[56 \"56\"]\nuser=> (read+string)\n[7 \"7\"]\n\n;; if there is a comment it is included in the string read\nuser=> (read+string)\n;comment\n:value\n[:value \";comment\\n:value\"] ","_id":"61aa9034e4b0b1e3652d757f"}],"notes":null,"arglists":["","stream","stream eof-error? eof-value","stream eof-error? eof-value recursive?","opts stream"],"doc":"Like read, and taking the same args. stream must be a LineNumberingPushbackReader.\n Returns a vector containing the object read and the (whitespace-trimmed) string read.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/read+string"},{"added":"1.0","ns":"clojure.core","name":"dosync","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1285922303000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"sync","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521cdf"},{"created-at":1326521625000,"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":"542692ebf6e94c6970521ce0"},{"created-at":1343102755000,"author":{"login":"TimMc","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"locking","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ce1"}],"line":5129,"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":"zk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2"}],"body":";; Keep dosync body free of side-effects:\n(defn my-thread-unsafe-fn [important-ref]\n (let [start-work (ref false)]\n (dosync\n (when (not @important-ref)\n ;\"If a conflict occurs between 2 transactions \n ;trying to modify the same reference, \n ;one of them will be retried.\"\n ;http://clojure.org/concurrent_programming\n (ref-set important-ref true)\n (ref-set start-work true)))\n (when @start-work \n ;launch side-effects here\n )))\n","created-at":1279380650000,"updated-at":1285500150000,"_id":"542692c7c026201cdc32698d"},{"body":";; Create 2 bank accounts\n(def acc1 (ref 100))\n(def acc2 (ref 200))\n\n;; How much money is there?\n(println @acc1 @acc2)\n;; => 100 200\n\n;; Either both accounts will be changed or none\n(defn transfer-money [a1 a2 amount]\n (dosync\n (alter a1 - amount)\n (alter a2 + amount)\n amount)) ; return amount from dosync block and function (just for fun)\n\n;; Now transfer $20\n(transfer-money acc1 acc2 20)\n;; => 20\n\n;; Check account balances again\n(println @acc1 @acc2)\n;; => 80 220\n\n;; => We can see that transfer was successful","author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"created-at":1423044726004,"updated-at":1423044726004,"_id":"54d1f076e4b081e022073c5b"}],"macro":true,"notes":null,"arglists":["& exprs"],"doc":"Runs the exprs (in an implicit do) in a transaction that encompasses\n exprs and any nested calls. Starts a transaction if none is already\n running on this thread. Any uncaught exception will abort the\n transaction and flow out of dosync. The exprs may be run more than\n once, but any effects on Refs will be atomic.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/dosync"},{"added":"1.0","ns":"clojure.core","name":"remove-ns","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1284970244000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"create-ns","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521b5c"},{"created-at":1284970256000,"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":"542692eaf6e94c6970521b5d"}],"line":4166,"examples":[{"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":"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":"sillitor","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/c6e7b175eb48c8e3db32f3ff7c2a205d?r=PG&default=identicon"}],"body":";; Let's create a namespace and then remove it\n\nuser=> (create-ns 'my-new-namespace)\n#\n(def my-keep (comp (partial remove nil?) map))\n
\nor, perhaps more traditionally:\n\n\n(defn my-keep [& args]\n (remove nil? (apply map args)))\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":3536,"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":null,"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":2800,"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":3566,"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":null,"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":null,"line":3977,"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":533,"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"},{"updated-at":1719752674225,"created-at":1719752674225,"author":{"login":"surferHalo","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/11332464?v=4"},"body":";; good companion with \"some\" if you want boolean return\n\n(some #{1 2 3} [4])\n;; => nil\n(some? (some #{1 2 3} [4]))\n;; => false\n\n(some #{1 2 3} [1])\n;; => 1\n(some? (some #{1 2 3} [1]))\n;; => true","_id":"668157e269fbcc0c226174da"},{"updated-at":1722802000534,"created-at":1722802000534,"author":{"login":"jacoobes","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/76754747?v=4"},"body":"(some? 0)\n;; => true","_id":"66afdf5069fbcc0c226174e7"}],"notes":null,"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":1198,"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":null,"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":8117,"examples":null,"notes":null,"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":700,"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":null,"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":null,"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":949,"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":6922,"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":null,"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":3043,"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":null,"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":3110,"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":null,"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":null,"line":577,"examples":null,"notes":null,"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"},{"created-at":1721984960738,"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-inc","ns":"clojure.core"},"_id":"66a367c069fbcc0c226174e0"}],"line":1163,"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":null,"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":7475,"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":null,"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":2003,"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":null,"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":7379,"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":null,"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":2574,"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":null,"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":3292,"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;;=> (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(defn inc-ref [ref type & [init-value]]\r\n (if init-value\r\n (dosync\r\n (alter ref assoc type init-value)\r\n (type @ref))\r\n (dosync\r\n (alter ref assoc type (inc (name @ref)))\r\n (type @ref))))\r\n\r\nuser> (inc-ref counts :articles)\r\n=>1\r\nuser> (inc-ref counts :magazines 1)\r\n=>1\r\nuser> (:magazines @counts)\r\n=>1
","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":1033,"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":null,"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":1893,"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":3384,"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":null,"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":5196,"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":6660,"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":[{"created-at":1722240797007,"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":"swap-vals!","ns":"clojure.core"},"_id":"66a74f1d69fbcc0c226174e4"}],"line":2400,"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":null,"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":5558,"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":null,"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":3659,"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":null,"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"},{"created-at":1713480509845,"author":{"login":"MicahElliott","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/159047?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"dissoc","ns":"clojure.core"},"_id":"6621a33d69fbcc0c226174bf"}],"line":2843,"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":null,"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":1010,"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":[{"author":{"login":"ClemRz","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1130946?v=4"},"updated-at":1721779674549,"created-at":1721779674549,"body":"Beware of floating-point related issues:\n\n```\n=> (* 155.39 100)\n15538.999999999998\n```","_id":"66a045da69fbcc0c226174df"}],"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":4892,"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":1127,"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":null,"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":3418,"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#
\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":[{"created-at":1767373745216,"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":"*print-level*","ns":"clojure.core"},"_id":"6957fbb1b7956e24e4cb4ecb"}],"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":null,"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":2385,"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":null,"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":null,"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":3309,"examples":null,"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":4523,"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"},{"updated-at":1692349135324,"created-at":1692179180792,"author":{"login":"jimka2001","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/6414129?v=4"},"body":";; There is some confusion in various lisps about the scope of variables in the\n;; bindings of let variables. It works as follows in Clojure.\n(let [y 'OUTER]\n (let [y 'INNER\n x y] ;; binds x to 'INNER, not to 'OUTER\n x))\n;; => inner\n\n;; Note that both Common Lisp and emacs lisp would bind x to 'OUTER not 'INNER\n;; in the corresponding code.\n\n;; But this is because `let` in Common Lisp and emacs lisp does not bind sequentially.\n;; The correct analogue of Clojure's `let` is in fact `let*` in these other lisps,\n;; in which case the behaviour does match.","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/6414129?v=4","account-source":"github","login":"jimka2001"},{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"}],"_id":"64dc9aece4b08cf8563f4be2"}],"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 binding-form => name, or destructuring-form\n destructuring-form => map-destructure-form, or seq-destructure-form\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.\n\n See https://clojure.org/reference/special_forms#binding-forms for\n more information about destructuring.","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":2472,"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":null,"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":1948,"examples":null,"notes":null,"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":4335,"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":5799,"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":null,"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":169,"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":null,"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":1694,"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":4071,"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":null,"examples":[{"updated-at":1705869820104,"created-at":1705869734840,"author":{"login":"teodorlu","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/5285452?v=4"},"body":";; All functions that normally write to *out* can write to *err* by binding\n;; *out* to *err*:\n\nuser> (binding [*out* *err*]\n (prn \"prn can be used\")\n (println \"println can also be used\"))\n\"prn can be used\"\nprintln can also be used\n;; => nil","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/5285452?v=4","account-source":"github","login":"teodorlu"}],"_id":"65ad81a669fbcc0c22617484"}],"notes":null,"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":1508,"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\n in associative collection, set, string, array, or ILookup instance.","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":3878,"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;;=> #(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"},{"created-at":1714062792131,"author":{"login":"MicahElliott","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/159047?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"assoc","ns":"clojure.core"},"_id":"662a85c869fbcc0c226174c1"}],"line":7029,"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"},{"updated-at":1733862000838,"created-at":1733862000838,"author":{"login":"jacoobes","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/76754747?v=4"},"body":"; I like adding commas to encourage readability\n(def nums #{ 1 2 3 4 5})\n(into nums, [5 6 7]) ;=> #{1 2 3 4 5 6 7}\n; commas are treated as whitespace\n(into nums [5 6 7]) ;=> #{1 2 3 4 5 6 7}\n","_id":"6758a27069fbcc0c22617523"}],"notes":null,"arglists":["","to","to from","to xform from"],"doc":"Returns a new coll consisting of to with all of the items of\n from conjoined. A transducer may be supplied.\n (into x) returns x. (into) returns [].","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":5318,"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":[{"author":{"login":"KingMob","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/946421?v=4"},"updated-at":1698778125243,"created-at":1698778125243,"body":"Unlike `reduce`, `areduce` cannot be short-circuited with `(reduced)`. It's essentially a little macro that constructs a loop over all elements of an array. ","_id":"65414c0d69fbcc0c2261741e"}],"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"},{"created-at":1734339241198,"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":"parse-long","ns":"clojure.core"},"_id":"675feaa969fbcc0c22617525"}],"line":3506,"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"},{"editors":[{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?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 parse-long instead\n(parse-long \"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":1596590278008,"updated-at":1734339282707,"_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"},{"created-at":1734339323390,"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":"parse-double","ns":"clojure.core"},"_id":"675feafb69fbcc0c22617527"}],"line":3518,"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"},{"editors":[{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?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 parse-double instead\n(parse-double \"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":1596590762065,"updated-at":1734339339867,"_id":"5f2a0aaae4b0b1e3652d7366"}],"notes":null,"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":2565,"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":null,"arglists":["x"],"doc":"Returns true if x is a volatile.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/volatile_q"},{"added":"1.11","ns":"clojure.core","name":"update-vals","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1698251679030,"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":"update-keys","ns":"clojure.core"},"_id":"6539439f69fbcc0c226173d0"}],"line":8132,"examples":[{"updated-at":1698251589460,"created-at":1698251589460,"author":{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"},"body":"(update-vals {:a 1, :b 2} inc)\n;; => {:a 2, :b 3}\n\n;; To replace each map with its value for a specific key…\n(update-vals {:a {:x 7, :y 100}, :b {:x 8, :y 150}, :c {:x 9, :y 200}} :x)\n;; => {:a 7, :b 8, :c 9}\n\n;; To dissoc a kv pair from each map…\n(update-vals {:a {:x 7, :y 100}, :b {:x 8, :y 150}, :c {:x 9, :y 200}}\n #(dissoc % :x))\n;; => {:a {:y 100}, :b {:y 150}, :c {:y 200}}\n\n;; To update a value for a key in each map…\n(update-vals {:a {:x 7, :y 100}, :b {:x 8, :y 150}, :c {:x 9, :y 200}}\n #(update % :x inc))\n;; => {:a {:x 8, :y 100}, :b {:x 9, :y 150}, :c {:x 10, :y 200}}\n","_id":"6539434569fbcc0c226173cf"}],"notes":null,"arglists":["m f"],"doc":"m f => {k (f v) ...}\n\n Given a map m and a function f of 1-argument, returns a new map where the keys of m\n are mapped to result of applying f to the corresponding values of m.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/update-vals"},{"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":5282,"examples":null,"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\nuser=> (definline bad-sqr [x] `(* ~x ~x))\r\n#'user/bad-sqr\r\nuser=> (bad-sqr (do (println \"x\") 5))\r\nx\r\nx\r\n25\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":107,"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":null,"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":204,"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 #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":7764,"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":null,"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":3982,"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":6370,"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 \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":558,"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":null,"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":7244,"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#(ns com.example.my-application.server\n \"Example application HTTP server and routing.\"\n (:refer-clojure :exclude [send])\n (:require\n [clojure.core.async :as async :refer [! >!!]]\n [com.example.my-application.base]\n [com.example.my-application.server.sse :as server.sse]\n [io.pedestal.http :as http]\n [io.pedestal.http.sse :as http.sse]\n [ring.util.response :as response])\n (:import\n (java.nio.file Files LinkOption)\n (org.apache.commons.io FileUtils)))
","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":591,"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":null,"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":4029,"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":null,"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":3592,"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
\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":5302,"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":null,"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"},{"created-at":1699735252549,"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":"pop!","ns":"clojure.core"},"_id":"654fe6d469fbcc0c2261744b"}],"line":1481,"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\nuser> (pop (cons 1 '()))\r\n; Evaluation aborted.\r\n
\r\ndo not work because type is clojure.lang.Cons but\r\n\r\nuser> (pop (conj '() 1))\r\n()\r\n
\r\nworks because type is clojure.lang.PersistentList.","created-at":1349885055000,"author":{"login":"tomby42","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/305033855efb82d6041586b874b5bb24?r=PG&default=identicon"},"_id":"542692ecf6e94c6970521feb"}],"arglists":["coll"],"doc":"For a list or queue, returns a new list/queue without the first\n item, for a vector, returns a new vector without the last item. If\n the collection is empty, throws an exception. Note - not the same\n as next/butlast.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/pop"},{"added":"1.0","ns":"clojure.core","name":"use","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1284770251000,"author":{"login":"rbolkey","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/d537f88b794c220d6ce447add22c12a7?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"refer","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521dd2"},{"created-at":1284770260000,"author":{"login":"rbolkey","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/d537f88b794c220d6ce447add22c12a7?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"require","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521dd3"},{"created-at":1289380610000,"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","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521dd4"},{"created-at":1291628646000,"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":"542692ebf6e94c6970521dd5"}],"line":6156,"examples":[{"author":{"login":"scode","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/87b4fd6e7ac86cbf1f1b683f7856057?r=PG&default=identicon"},"editors":[{"login":"zk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2"}],"body":";; Use the namespace clojure.java.io:\nuser=> (use '(clojure.java io))\n\n","created-at":1279160083000,"updated-at":1285497782000,"_id":"542692cfc026201cdc326e03"},{"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":"clizzin","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/555813697e5dc358bb27d5efd3ffa23?r=PG&default=identicon"}],"body":";; Imports only the split function from clojure.string.\nuser=> (use '[clojure.string :only (split)])\nnil\n\n;; split is now available without a namespace qualification.\nuser=> (split \"hello world\" #\" \")\n[\"hello\" \"world\"]\n\n;; You can also add the :as keyword to import the rest of clojure.string\n;; with a namespace qualification.\nuser=> (use '[clojure.string :as s :only (split)])\nnil\n\n;; Now we can access any function in clojure.string using s.\nuser=> (s/replace \"foobar\" \"foo\" \"squirrel\")\n\"squirrelbar\"\n\n;; And we can still call split with or without the s qualification.\nuser=> (split \"hello world\" #\" \")\n[\"hello\" \"world\"]\nuser=> (s/split \"hello world\" #\" \")\n[\"hello\" \"world\"]","created-at":1279596076000,"updated-at":1294233809000,"_id":"542692cfc026201cdc326e05"},{"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"editors":[{"login":"klauern","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"}],"body":"(ns some.namespace\n (:require [clojure.contrib.json :as json])\n (:use [clojure.string :only [trim lower-case split]]\n [clojure.contrib.shell-out]\n [clojure.pprint]\n [clojure.test]))\n","created-at":1291021620000,"updated-at":1338424818000,"_id":"542692cfc026201cdc326e08"},{"updated-at":1474049969039,"created-at":1474049969039,"author":{"login":"mars0i","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1836941?v=3"},"body":";; use accepts other keywords from require that aren't listed in the docstring.\n\n;; If you try to load a namespace, and it fails to load due to an error in\n;; the source code, when you load it again after fixing the problem, you\n;; can get a \"namespace not found\" exception. Use :reload to avoid this:\n(use '[my.namespace] :reload)\n\n;; However, if the error was in source for a namespace required or used\n;; from my.namespace, you'll get the \"namespace not found\" exception\n;; after fixing the problem, even using :reload. Use :reload-all to avoid this:\n(use '[my.namespace] :reload-all)\n\n;; You can also use :verbose, which does what you would think it would do:\n(use '[my.namespace] :verbose)","_id":"57dc37b1e4b0709b524f04fb"},{"updated-at":1648959694945,"created-at":1648959694945,"author":{"login":"mars0i","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1836941?v=4"},"body":";; As the docstring says,\n;;\n;; The arguments and semantics for :exclude, :only, and :rename are the same\n;; as those documented for clojure.core/refer\n;;\n;; but the syntax for these options is derived from require, not refer.\n;; Here is an example using Clojure 1.11, in which the abs function was\n;; introduced into clojure.core.\n\n;; First let's try it with require and refer separately:\nuser=> (require 'clojure.math.numeric-tower)\nnil\nuser=> (refer 'clojure.math.numeric-tower :exclude '[abs])\nnil\nuser=> abs\n#object[clojure.core$abs 0x36fdf831 \"clojure.core$abs@36fdf831\"]\n;; The last line shows that we've correctly excluded the version of\n;; abs that numeric-tower defines, and instead are using the version of abs\n;; that's now in clojure.core.\n\n;; Now let's try it with use. The refer-style syntax doesn't work:\nuser=> (use 'clojure.math.numeric-tower :exclude '[abs])\nSyntax error compiling at (/private/var/folders/68/d0l7z7p906l07fj6s7j5_ygm0000gq/T/form-init6849217183418449171.clj:1:1).\nUnsupported option(s) supplied: :exclude\n;; Instead :exclude must be wrapped up with the namespace in a sequence,\n;; as with options for require:\nuser=> (use '[clojure.math.numeric-tower :exclude [abs]])\nnil\nuser=> abs\n#object[clojure.core$abs 0x13abd924 \"clojure.core$abs@13abd924\"]\n","_id":"624920cee4b0b1e3652d75ca"}],"notes":[{"updated-at":1291628658000,"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":1291628658000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"_id":"542692ecf6e94c6970521fab"},{"updated-at":1318868130000,"body":"http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html","created-at":1318868130000,"author":{"login":"vikbehal","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/b773242b82712096e51f5f6aed5f9abd?r=PG&default=identicon"},"_id":"542692ecf6e94c6970521fd0"},{"author":{"login":"rafaroca","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/609454?v=4"},"updated-at":1667422305527,"created-at":1667422305527,"body":"The blog post from 8thlight is not available under the above URL anymore. The Wayback Machine has a snapshot of it.\n\nhttps://web.archive.org/web/20220323035057/https://8thlight.com/blog/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html","_id":"6362d861e4b0b1e3652d7680"}],"arglists":["& args"],"doc":"Like 'require, but also refers to each lib's namespace using\n clojure.core/refer. Use :use in the ns macro in preference to calling\n this directly.\n\n 'use accepts additional options in libspecs: :exclude, :only, :rename.\n The arguments and semantics for :exclude, :only, and :rename are the same\n as those documented for clojure.core/refer.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/use"},{"ns":"clojure.core","name":"unquote","file":"clojure/core.clj","type":"var","column":1,"see-alsos":[{"created-at":1319196053000,"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-splicing","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d5d"},{"created-at":1537911869941,"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":"quote","ns":"clojure.core"},"_id":"5baaac3de4b00ac801ed9ea6"}],"line":13,"examples":[{"author":{"login":"huahaiy","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/889685?v=2"},"editors":[{"login":"huahaiy","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/889685?v=2"}],"body":"user=> (let [x 2]\n `(1 x 3))\n(1 user/x 3)\n\nuser=> (let [x 2]\n `(1 ~x 3))\n(1 2 3)\n","created-at":1305077398000,"updated-at":1305077465000,"_id":"542692cec026201cdc326d76"},{"author":{"login":"klauern","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"},"editors":[],"body":"user=> `(1 (dec 3) 3)\n\n(1 (clojure.core/dec 3) 3)\n\nuser => `(1 ~(dec 3) 3)\n\n(1 2 3)","created-at":1319196729000,"updated-at":1319196729000,"_id":"542692d5c026201cdc3270af"}],"notes":null,"arglists":[],"library-url":"https://github.com/clojure/clojure","href":"/clojure.core/unquote"},{"added":"1.0","ns":"clojure.core","name":"declare","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1336168390000,"author":{"login":"gavilancomun","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/f4b1f93f88e052f9eb412a8791b6ddf1?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"def","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521c7e"},{"created-at":1763765247119,"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":"letfn","ns":"clojure.core"},"_id":"6920ebff848d032713abce4a"}],"line":2793,"examples":[{"updated-at":1285500741000,"created-at":1279161281000,"body":"user=> (defn foo []\n (undefined-func))\n; Evaluation aborted. Unable to resolve symbol: undefined-func in this context\nnil\n\nuser=> (declare undefined-func)\n#'user/undefined-func\n\nuser=> (defn foo []\n (undefined-func))\n#'user/foo\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"}],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/142529?v=3","account-source":"github","login":"nipra"},"_id":"542692cdc026201cdc326d18"},{"author":{"login":"lu4nx","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4acdafde2cbf672ee0389cf8016378?r=PG&default=identicon"},"editors":[{"login":"lu4nx","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4acdafde2cbf672ee0389cf8016378?r=PG&default=identicon"}],"body":"user=> (declare show)\n#'user/show\nuser=> (defn welcome [user-name] (prn (show) user-name))\n#'user/welcome\nuser=> (defn show [] (prn \"welcome \"))\n#'user/show\nuser=> (welcome \"lu4nx\")\n\"welcome \"\nnil \"lu4nx\"\nnil\nuser=> ","created-at":1385992546000,"updated-at":1385992606000,"_id":"542692d2c026201cdc326f78"},{"body":"; def will do too.\nuser=> (def show)\n#'user/show\nuser=> (defn welcome [user-name] (prn (show) user-name))\n#'user/welcome\nuser=> (defn show [] (prn \"welcome\"))\n#'user/show\nuser=> (welcome \"lu4nx\")\n\"welcome\"\nnil \"lu4nx\"\nnil","author":{"login":"kimtg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7685905?v=3"},"created-at":1425741679616,"updated-at":1425741679616,"_id":"54fb176fe4b0b716de7a6533"},{"editors":[{"login":"owenRiddy","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/8080718?v=4"}],"body":";;Declare (like \"def\") has a natural partner in \"var\".\n;;Consider trying to embed a to-be-defined function in a data structure:\n\n(declare foo)\n(def bar {:handy-fn foo})\n(defn foo [] 42)\n((:handy-fn bar))\n;;IllegalStateException Attempting to call unbound fn: #'user/foo clojure.lang.Var$Unbound.throwArity (Var.java:43)\n\n;;:handy-fn in bar is now permanently linked to the unbound var\n;; present when the def was evaluated. This can be avoided\n;; by not evaluating foo when creating bar.\n\n(declare foo)\n;;(def bar {:handy-fn (var foo)})\n(def bar {:handy-fn #'foo})\n(defn foo [] 42)\n((:handy-fn bar))\n;; 42","author":{"avatar-url":"https://avatars0.githubusercontent.com/u/8080718?v=4","account-source":"github","login":"owenRiddy"},"created-at":1502501725640,"updated-at":1502501762521,"_id":"598e5b5de4b0d19c2ce9d714"}],"macro":true,"notes":null,"arglists":["& names"],"doc":"defs the supplied var names with no bindings, useful for making forward declarations.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/declare"},{"added":"1.1","ns":"clojure.core","name":"dissoc!","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1329969087000,"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":"542692ebf6e94c6970521ea9"},{"created-at":1577916166729,"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":"5e0d1706e4b0ca44402ef80b"}],"line":3407,"examples":[{"author":{"avatar-url":"https://avatars.githubusercontent.com/u/1453?v=4","account-source":"github","login":"ghoseb"},"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":";; dissoc! works on a transient map\n\n;; WARNING: Below is an example of what is called \"bashing in place\" of\n;; a transient, and is _NOT_ the correct way to use transients. See assoc!\n;; examples for some discussion of the reason.\n;; Also see one example for conj! that contains a detailed example\n;; of a wrong result that can occur if you do not use its return value.\n\n(let [my-map (transient {:x 1 :y 2 :z 3})]\n (dissoc! my-map :x) ; mistake is to use my-map below, not dissoc! return val\n (persistent! my-map)) ; returns persistent map {:y 2 :z 3}\n\n\n;; Here is a correct way to do the operation described above:\n\n(let [my-map (transient {:x 1 :y 2 :z 3})\n x (dissoc! my-map :x)] ; after this, don't use my-map again, only x\n (persistent! x)) ; returns persistent map {:y 2 :z 3}","created-at":1293728413000,"updated-at":1577916082525,"_id":"542692cbc026201cdc326c15"}],"notes":null,"arglists":["map key","map key & ks"],"doc":"Returns a transient map that doesn't contain a mapping for key(s).","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/dissoc!"},{"added":"1.2","ns":"clojure.core","name":"reductions","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1289800579000,"author":{"login":"kumarshantanu","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"reduce","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521b07"},{"created-at":1423043837477,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"reduced","library-url":"https://github.com/clojure/clojure"},"_id":"54d1ecfde4b081e022073c59"}],"line":7362,"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=> (reductions + [1 1 1 1])\n(1 2 3 4)\nuser=> (reductions + [1 2 3])\n(1 3 6)\n\n;; This is just like reduce except that the calculation is collected during the reduce.\nuser=> (assert (= (reduce + [1 2 3]) \n (last (reductions + [1 2 3]))))\nnil\n","created-at":1281363432000,"updated-at":1285494988000,"_id":"542692cbc026201cdc326baa"},{"body":"user=> (reductions conj [] '(1 2 3))\n([] [1] [1 2] [1 2 3])","author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"created-at":1423043905622,"updated-at":1423043905622,"_id":"54d1ed41e4b081e022073c5a"},{"body":"user=> (reductions + [1 2 3 4 5])\n(1 3 6 10 15)\n\n;;defining the function to perform the same reductions\nuser=> (reductions (fn [sum num] (+ sum num)) [1 2 3 4 5])\n;;(1 3 6 10 15)\n\n;;reductions using a init value 100\nuser=> (reductions (fn [sum num] (+ sum num)) 100 [1 2 3 4 5])\n;;(100 101 103 106 110 115)\n\n;;defining a function for the same reductions\nuser=>(defn add [sum num] \n #_=>(+ sum num))\n;;#'user/add\n\nuser=>(reductions add [1 2 3 4 5])\n;;(1 3 6 10 15)","author":{"login":"pavanred","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/60858?v=3"},"created-at":1427434749175,"updated-at":1427476229157,"editors":[{"login":"pavanred","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/60858?v=3"}],"_id":"5514ecfde4b08eb9aa0a8d3a"},{"updated-at":1488836230529,"created-at":1488836230529,"author":{"login":"matrix10657","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/1264071?v=3"},"body":";; useful for performing lazy calculations which rely on \n;; previous calculations\n\n;; e.g. Taking an infinite list of posts with some height and \n;; adding an offset to each, which is the sum of all previous \n;; heights\n\nuser=> (def posts (repeat {:height 50}))\n#'user/posts\n\nuser=> (take 3 posts)\n({:height 50} {:height 50} {:height 50})\n\nuser=> (def posts-with-offsets\n #_=> (map #(assoc %1 :offset %2)\n #_=> posts\n #_=> (reductions + 0 (map :height posts))))\n#'user/posts-with-offsets\n\nuser=> (take 3 posts-with-offsets)\n({:height 50, :offset 0} {:height 50, :offset 50} {:height 50, :offset 100})\n\n","_id":"58bdd686e4b01f4add58fe6b"}],"notes":[{"author":{"login":"betegelse","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/6758479?v=3"},"updated-at":1486825461877,"created-at":1486825461877,"body":"I think the description above would be clearer if it stated that the result of reductions is equivalent to the sequence of results of applying reduce to `(take n coll)`, with `n` starting with 1, that is, equivalent to\n```clojure\n(defn my-reduce [op coll] (for [n (range (count coll))] (reduce op (take (inc n) coll)))\n```\n","_id":"589f27f5e4b01f4add58fe4a"},{"author":{"login":"jayzawrotny","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/590297?v=4"},"updated-at":1523454828509,"created-at":1523454828509,"body":"In other libraries and languages this function may be referred to as \"scan\". ","_id":"5ace136ce4b045c27b7fac3c"}],"arglists":["f coll","f init coll"],"doc":"Returns a lazy seq of the intermediate values of the reduction (as\n per reduce) of coll by f, starting with init.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/reductions"},{"added":"1.0","ns":"clojure.core","name":"aset-byte","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":4002,"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 bytes and set one of the values to 127\n\nuser=> (def bs (byte-array 10))\n#'user/bs\nuser=> (vec bs)\n[0 0 0 0 0 0 0 0 0 0]\nuser=> (aset-byte bs 2 127)\n127\nuser=> (vec bs)\n[0 0 127 0 0 0 0 0 0 0]\nuser=>","created-at":1313914294000,"updated-at":1313914294000,"_id":"542692c6c026201cdc32692c"}],"notes":[{"body":"See [aset](http://clojuredocs.org/clojure.core/aset) for illustrations of multi-dimensional syntax.","created-at":1432829120788,"updated-at":1432829120788,"author":{"login":"mars0i","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1836941?v=3"},"_id":"55673cc0e4b03e2132e7d172"}],"arglists":["array idx val","array idx idx2 & idxv"],"doc":"Sets the value at the index/indices. Works on arrays of byte. Returns val.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/aset-byte"},{"added":"1.9","ns":"clojure.core","name":"indexed?","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":6340,"examples":[{"updated-at":1611630046254,"created-at":1611630046254,"author":{"login":"Crowbrammer","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/19522656?v=4"},"body":"(indexed? '(1 2 3)) ;;=> false\n\n(indexed? [1 2 3]) ;;=> true\n\n(indexed? {:a \"Hi\" :hello \"Why\"}) ;;=> false\n\n(indexed? (sorted-set 1 2 3)) ;;=> false\n\n(indexed? #{1 2 3}) ;;=> false","_id":"600f85dee4b0b1e3652d743d"}],"notes":null,"arglists":["coll"],"doc":"Return true if coll implements Indexed, indicating efficient lookup by index","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/indexed_q"},{"added":"1.1","ns":"clojure.core","name":"ref-history-count","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1329984882000,"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-min-history","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521eb6"},{"created-at":1329984893000,"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-max-history","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521eb7"},{"created-at":1364770223000,"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":"542692ebf6e94c6970521eb8"}],"line":2480,"examples":[{"author":{"login":"Claj","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5fd658a8d2ef549071cb5286b1b874aa?r=PG&default=identicon"},"editors":[],"body":"user=> (def store (ref {}))\n#'user/store\nuser=> (ref-history-count store)\n0\nuser=> (ref-max-history store)\n10\nuser=> (ref-min-history store)\n0","created-at":1329984988000,"updated-at":1329984988000,"_id":"542692d5c026201cdc327069"},{"updated-at":1656667547237,"created-at":1656667547237,"author":{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"},"body":";; ref must have a :min-history of >0 to use the history queue\n\n(def r (ref 42 :min-history 2));; => #'user/r\n(ref-history-count r);; => 0\n(dosync (alter r inc));; => 43\n(ref-history-count r);; => 1\n(dosync (alter r inc));; => 44\n(ref-history-count r);; => 2","_id":"62bebd9be4b0b1e3652d7611"}],"notes":null,"arglists":["ref"],"doc":"Returns the history count of a ref","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/ref-history-count"},{"added":"1.2","ns":"clojure.core","name":"-","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1351919398000,"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":"542692ebf6e94c6970521d20"},{"created-at":1423527267534,"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":"54d94d63e4b0e2ac61831d44"},{"created-at":1423527580571,"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":"54d94e9ce4b081e022073c85"},{"created-at":1525302779122,"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":"dec","ns":"clojure.core"},"_id":"5aea45fbe4b045c27b7fac5c"}],"line":1045,"examples":[{"author":{"login":"MrHus","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/22608?v=4"},"editors":[{"avatar-url":"https://avatars2.githubusercontent.com/u/22608?v=4","account-source":"github","login":"MrHus"},{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"}],"body":"user=> (- 1)\n-1 \nuser=> (- 6 3) \n3\nuser=> (- 10 3 2) \n5","created-at":1279418306000,"updated-at":1332950680000,"_id":"542692c8c026201cdc326a4f"},{"body":"\n(- 0 9000000000000000000 1000000000000000000)\n;; ArithmeticException: integer overflow\n\n(-' 0 9000000000000000000 1000000000000000000)\n;;=> 10000000000000000000N \n\n\n","author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=2"},"created-at":1412882447241,"updated-at":1412882447241,"_id":"5436e00fe4b0ae7956031579"}],"notes":null,"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. Does not auto-promote\n longs, will throw on overflow. See also: -'","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/-"},{"added":"1.1","ns":"clojure.core","name":"assoc!","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1324959540000,"author":{"login":"kumarshantanu","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"dissoc!","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521a8d"},{"created-at":1324959556000,"author":{"login":"kumarshantanu","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"transient","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521a8e"},{"to-var":{"library-url":"https://github.com/clojure/clojure","name":"conj!","ns":"clojure.core"},"author":{"avatar-url":"https://avatars.githubusercontent.com/u/1453?v=4","account-source":"github","login":"ghoseb"},"created-at":1327875049000,"_id":"542692eaf6e94c6970521a8f"},{"created-at":1417201150839,"author":{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"},"to-var":{"ns":"clojure.core","name":"pop!","library-url":"https://github.com/clojure/clojure"},"_id":"5478c5fee4b03d20a10242b6"},{"created-at":1417201158048,"author":{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"},"to-var":{"ns":"clojure.core","name":"disj!","library-url":"https://github.com/clojure/clojure"},"_id":"5478c606e4b03d20a10242b7"},{"created-at":1417201185853,"author":{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"},"to-var":{"ns":"clojure.core","name":"persistent!","library-url":"https://github.com/clojure/clojure"},"_id":"5478c621e4b0dc573b892fe2"}],"line":3394,"examples":[{"author":{"login":"yasuto","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"},"editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/1453?v=4","account-source":"github","login":"ghoseb"},{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"}],"body":";; The key concept to understand here is that transients are \n;; not meant to be `bashed in place`; always use the value \n;; returned by either assoc! or other functions that operate\n;; on transients.\n\n(defn merge2\n \"An example implementation of `merge` using transients.\"\n [x y]\n (persistent! (reduce\n (fn [res [k v]] (assoc! res k v))\n (transient x)\n y)))\n\n;; Why always use the return value, and not the original? Because the return\n;; value might be a different object than the original. The implementation\n;; of Clojure transients in some cases changes the internal representation\n;; of a transient collection (e.g. when it reaches a certain size). In such\n;; cases, if you continue to try modifying the original object, the results\n;; will be incorrect. See one example for conj! that contains a detailed\n;; example of a wrong result that can occur if you do not use its return value.\n\n;; Think of transients like persistent collections in how you write code to\n;; update them, except unlike persistent collections, the original collection\n;; you passed in should be treated as having an undefined value. Only the return\n;; value is predictable.","created-at":1307739385000,"updated-at":1577916047949,"_id":"542692c8c026201cdc326a21"},{"updated-at":1482997682425,"created-at":1482997682425,"author":{"login":"dalzony","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/562341?v=3"},"body":"(def m (assoc! (transient {}) :x 1 :y 2))\n\n(:x m)\n;; 1\n\n(:y m)\n;; 2\n\n(count m)\n;; 2","_id":"5864bfb2e4b0fd5fb1cc9649"}],"notes":null,"arglists":["coll key val","coll key val & kvs"],"doc":"When applied to a transient map, adds mapping of key(s) to\n val(s). When applied to a transient vector, sets the val at index.\n Note - index must be <= (count vector). Returns coll.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/assoc!"},{"added":"1.0","ns":"clojure.core","name":"hash-set","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1471555426806,"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":"sorted-set","ns":"clojure.core"},"_id":"57b62762e4b0b5e6d7a4fa5a"},{"created-at":1532623831801,"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","ns":"clojure.core"},"_id":"5b59fbd7e4b00ac801ed9e2d"}],"line":391,"examples":[{"author":{"login":"zmila","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/68dd6f50915854aa04fefcf4d6fa5c8e?r=PG&default=identicon"},"editors":[{"login":"rafael","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/7adbf4434f63cedd463196b652fa7a44?r=PG&default=identicon"},{"login":"zk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2"},{"login":"clojureking","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/92625b8a6be91bb8c688d0d07b4e2a32?r=PG&default=identicon"},{"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"},{"avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4","account-source":"github","login":"reborg"}],"body":";; Any duplicates are squashed (no error)\n(hash-set 1 2 1 3 1 4 1 5)\n;;=> #{1 4 3 2 5}\n\n;; There is an equivalent reader macro '#{...}'\n(= (hash-set :c :a :b) #{:b :a :c})\n;;=> true \n\n;; A string can be treated as a sequence to produce\n;; a set of the characters found in the string.\n(apply hash-set (seq \"Lorem ipsum dolor sit amet\"))\n;;=> #{\\space \\a \\d \\e \\i \\L \\l \\m \\o \\p \\r \\s \\t \\u}\n\n;; or simply (see \"set\")\n(set \"Lorem ipsum dolor sit amet\")\n;;=> #{\\space \\a \\d \\e \\i \\L \\l \\m \\o \\p \\r \\s \\t \\u}","created-at":1280503618000,"updated-at":1532623811799,"_id":"542692c6c026201cdc326931"},{"updated-at":1643941642045,"created-at":1643941642045,"author":{"login":"jlb0170","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/4674635?v=4"},"body":";; The \"equivalent\" reader macro throws an error when receiving duplicates, however:\n#{ 1 2 1 }\n;;=> Duplicate key: 1","_id":"61fc8f0ae4b0b1e3652d75a7"}],"notes":null,"arglists":["","& keys"],"doc":"Returns a new hash set with supplied keys. Any equal keys are\n handled as if by repeated uses of conj.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/hash-set"},{"added":"1.4","ns":"clojure.core","name":"reduce-kv","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1413271598814,"author":{"login":"viksit","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/198669?v=2"},"to-var":{"ns":"clojure.core","name":"reduce","library-url":"https://github.com/clojure/clojure"},"_id":"543cd02ee4b0a3cf052fe475"},{"created-at":1423043757434,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"reduced","library-url":"https://github.com/clojure/clojure"},"_id":"54d1ecade4b081e022073c58"}],"line":6989,"examples":[{"body":"Let's assume you want to apply a function to a vector of maps,\n\nInput: [{:a 1 :b 2} {:a 3 :b 4}]\n\nsuch that all vals are incremented by 1.\n\nResult: [{:a 2 :b 3} {:a 4 :b 5}]\n\nAn easy way to do so is using reduce-kv,\n\n(def vector-of-maps [{:a 1 :b 2} {:a 3 :b 4}])\n\n(defn update-map [m f] \n (reduce-kv (fn [m k v] \n (assoc m k (f v))) {} m))\n\n(map #(update-map % inc) vector-of-maps)\n\n=> ({:b 3, :a 2} {:b 5, :a 4})","author":{"login":"viksit","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/198669?v=2"},"created-at":1413271555020,"updated-at":1413271555020,"_id":"543cd003e4b02688d208b1b4"},{"body":";; Swap keys and values in a map\nuser=> (reduce-kv #(assoc %1 %3 %2) {} {:a 1 :b 2 :c 3})\n{1 :a, 2 :b, 3 :c}","author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"created-at":1423043718645,"updated-at":1423043718645,"_id":"54d1ec86e4b0e2ac61831d0f"},{"updated-at":1445117098242,"created-at":1445117098242,"author":{"login":"Luckvery","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1178168?v=3"},"body":";; Swap keys with values, only if values are not empty,\n;; while turning values into proper keys\n\n(def someMap { :foo \"food\", :bar \"barista\", :baz \"bazaar\"})\n\n(defn swap [someMap]\n (reduce-kv (fn [m k v]\n (if (empty? v) m (assoc m (keyword v) (name k)))) {} someMap))\n\n(swap someMap)\n\n=> {:food \"foo\", :barista \"bar\", :bazaar \"baz\"}\n","_id":"5622bcaae4b04b157a6648d6"},{"editors":[{"login":"bpetri","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8858685?v=3"}],"body":";; Calculate total wins and winning streaks\n(def all-games \n [{:game 1 :won true} \n {:game 2 :won false} \n {:game 3 :won true} \n {:game 4 :won true}])\n\n(reduce-kv\n (fn [result index game]\n (let [last-game (last result)\n wins (if (:won game) \n (inc (:total last-game 0)) \n (:total last-game))\n streak (if (:won game) \n (inc (:streak last-game 0)) \n 0)]\n (println (assoc game :total wins :streak streak))\n (conj result (assoc game :total wins :streak streak))))\n []\n all-games)\n\n;; Output\n;; {:game 1, :won true, :total 1, :streak 1}\n;; {:game 2, :won false, :total 1, :streak 0}\n;; {:game 3, :won true, :total 2, :streak 1}\n;; {:game 4, :won true, :total 3, :streak 2}\n\n;; [{:game 1, :won true, :total 1, :streak 1} {:game 2, :won false, :total 1, :streak 0} {:game 3, :won true, :total 2, :streak 1} {:game 4, :won true, :total 3, :streak 2}]","author":{"avatar-url":"https://avatars.githubusercontent.com/u/140163?v=3","account-source":"github","login":"puppybits"},"created-at":1446938119194,"updated-at":1461160135892,"_id":"563e8607e4b0290a56055d1f"},{"editors":[{"login":"jvanderhyde","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/6516608?v=3"}],"body":";; You can define map-kv using reduce-kv, \n;; to do something to every value in a map.\n\n(defn map-kv [f coll]\n (reduce-kv (fn [m k v] (assoc m k (f v))) (empty coll) coll))\n\n(map-kv inc {:a 12, :b 19, :c 2})\n;;=> {:c 3, :b 20, :a 13}\n\n;; It works on vectors, too.\n(map-kv inc [1 1 2 3 5])\n;;=> [2 2 3 4 6]","author":{"avatar-url":"https://avatars.githubusercontent.com/u/6516608?v=3","account-source":"github","login":"jvanderhyde"},"created-at":1473374682272,"updated-at":1473374856199,"_id":"57d1e9dae4b0709b524f04eb"},{"updated-at":1486417959138,"created-at":1486417959138,"author":{"login":"overset","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/34342?v=3"},"body":";; It works with indexes on vectors as well\n\n(reduce-kv (fn [res idx itm] (assoc res idx itm)) {} [\"one\" \"two\" \"three\"])\n\n;;=> {2 \"three\", 1 \"two\", 0 \"one\"}","_id":"5898f027e4b01f4add58fe3c"},{"updated-at":1486833406498,"created-at":1486833406498,"author":{"login":"bsifou","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8908139?v=3"},"body":"\n(defn update-map-entries[m e]\n (reduce-kv (fn [r k v] (assoc r k v)) m e))\n\n;;user=> (update-map-entries {:a 1 :b 2 :c 3} {:a 5 :b 9})\n;;{:a 5, :b 9, :c 3}\n;;user=> (update-map-entries {:a 1 :b 2 :c 3} {:a 5 :b 9 :d 8})\n;;{:a 5, :b 9, :c 3, :d 8}\n\n\n","_id":"589f46fee4b01f4add58fe4b"},{"updated-at":1596611537211,"created-at":1596611537211,"author":{"login":"themustafabasit","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/24441401?v=4"},"body":";; increment map values \n(def abc-map {:a 1\n :b 2\n :c 3})\n(seq abc-map)\n;; => ([:a 1] [:b 2] [:c 3])\n\n;; via reduce \n(reduce (fn [new-map [k v]]\n (assoc new-map k (inc v)))\n {}\n abc-map)\n;; => {:a 2, :b 3, :c 4}\n\n\n;; via reduce-kv\n(reduce-kv (fn [new-map k v]\n (assoc new-map k (inc v)))\n {}\n abc-map)\n;; => {:a 2, :b 3, :c 4}\n","_id":"5f2a5bd1e4b0b1e3652d7372"},{"updated-at":1602494138585,"created-at":1602494138585,"author":{"login":"cdol","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/47477903?v=4"},"body":";; filter a coll of maps with arbitrary # of preds\n\n;; setup coll\n(def people '(\t{:gender \"male\", :age-group \"child\", :origin \"Germany\", :prename \"Hans\"}\n\t\t{:gender \"male\", :age-group \"adult\", :origin \"France\", :prename \"Jacques\"}\n\t\t{:gender \"male\", :age-group \"senior\", :origin \"Estonia\", :prename \"Rasmus\"}\n\t\t{:gender \"male\", :age-group \"adult\", :origin \"Poland\", :prename \"Jakub\"}\n\t\t{:gender \"male\", :age-group \"senior\", :origin \"Germany\", :prename \"Uwe\"}\n\t\t{:gender \"female\", :age-group \"adult\", :origin \"France\", :prename \"Amélie\"}\n\t\t{:gender \"female\", :age-group \"child\", :origin \"Estonia\", :prename \"Sofia\"}\n\t\t{:gender \"female\", :age-group \"child\", :origin \"Germany\", :prename \"Emma\"}\n\t\t{:gender \"female\", :age-group \"child\", :origin \"Estonia\", :prename \"Alisa\"}\n\t\t{:gender \"female\", :age-group \"senior\", :origin \"Poland\", :prename \"Anna\"}))\n\n;; select elements using reduce-kv & filter\n(defn multi-pred [coll m] \n (reduce-kv \n (fn [erg k v] (filter #(= v (k %)) erg)) coll m) )\n\n;; two \"preds\"\n(multi-pred people {:gender \"male\", :age-group \"senior\"})\n;; => ({:gender \"male\", :age-group \"senior\", :origin \"Estonia\", :prename \"Rasmus\"} {:gender \"male\", :age-group \"senior\", :origin \"Germany\", :prename \"Uwe\"})\n\n;; three \"preds\"\n(multi-pred people {:gender \"female\", :age-group \"child\", :origin \"Estonia\"})\n;; => ({:gender \"female\", :age-group \"child\", :origin \"Estonia\", :prename \"Sofia\"} {:gender \"female\", :age-group \"child\", :origin \"Estonia\", :prename \"Alisa\"})","_id":"5f841ebae4b0b1e3652d73d6"},{"updated-at":1639378520202,"created-at":1639378520202,"author":{"login":"cloudbuck3t","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/90472507?v=4"},"body":";; an example to show how to add a new key to nested maps.\n\n;; consider a map with submaps\n{:a {:b 1} :c {:d 2} :e {:f 3}}\n\n\n;; reduce-kv keeps an accumulator that \n;; starts with the value provided in init, \n;; in this case an empty map.\n\n\n;; you can return the original collection via reduce-kv this way\n(reduce-kv\n (fn [acc k v]\n (assoc acc k v))\n {}\n {:a {:b 1} :c {:d 2} :e {:f 3}}))\n\n;; the output is identical to the input.\n=> {:a {:b 1} :c {:d 2} :e {:f 3}}\n\n;; you can insert a new key-value pair into each submap \n;; by using this instead, generalized as a function\n;; that takes a map and a new-key and its new-key-value as inputs:\n\n(defn add-submap [m new-key new-keys-value]\n (reduce-kv\n (fn [acc k v]\n (assoc acc k (assoc v new-key new-keys-value)))\n {}\n m))\n\n;; notice how the value \"v\" of the key \"k\" is actually the submap on each key,\n;; when we visit :a we are looking at the first k-v pair,\n;; the key is :a, \n;; and the value is {:b 1}\n;; \n;; so we assoc a new key into that submap (the value) \n;; for each key-and-submap pairing.\n\n;; so when you run this function \n=> (add-submap {:a {:b 1} \n :c {:d 2} \n :e {:f 3}} :email-verified nil)\n\n;; the result is the original data with the new key and its val in each submap.\n=> {:a {:b 1, :email-verified nil}, \n :c {:d 2, :email-verified nil}, \n :e {:f 3, :email-verified nil}}","_id":"61b6ee58e4b0b1e3652d7588"}],"notes":[{"author":{"login":"KingMob","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/946421?v=4"},"updated-at":1610241088036,"created-at":1610241088036,"body":"Currently broken for subvectors: [CLJ-2065](https://clojure.atlassian.net/browse/CLJ-2065)","_id":"5ffa5440e4b0b1e3652d7428"},{"author":{"login":"diegonayalazo","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/11781279?v=4"},"updated-at":1649396094971,"created-at":1649396032294,"body":"Seems to be fixed for subvectors as of release 1.11. https://clojure.atlassian.net/browse/CLJ-2065","_id":"624fc940e4b0b1e3652d75cd"}],"arglists":["f init coll"],"doc":"Reduces an associative collection. f should be a function of 3\n arguments. Returns the result of applying f to init, the first key\n and the first value in coll, then applying f to that result and the\n 2nd key and value, etc. If coll contains no entries, returns init\n and f is not called. Note that reduce-kv is supported on vectors,\n where the keys will be the ordinals.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/reduce-kv"},{"added":"1.0","ns":"clojure.core","name":"or","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1300530940000,"author":{"login":"j1n3l0","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/6db7c6ecdbe97a1e844c88ecf587f61f?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"and","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521c42"},{"created-at":1334293978000,"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":"542692eaf6e94c6970521c43"},{"created-at":1582756022836,"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":"5e56f0b6e4b087629b5a18ad"}],"line":856,"examples":[{"author":{"login":"dakrone","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"},"editors":[{"login":"purplejacket","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/214093?v=3"}],"body":"user> (or true false false)\ntrue\n\nuser> (or true true true)\ntrue\n\nuser> (or false false false)\nfalse\n\nuser> (or nil nil)\nnil\n\nuser> (or false nil)\nnil\n\nuser> (or true nil)\ntrue\n\n;; or doesn't evaluate if the first value is true\nuser> (or true (println \"foo\"))\ntrue\n\n;; order matters\nuser> (or (println \"foo\") true)\nfoo\ntrue\n\n;; does not coerce a given value to a boolean true, returns the value\nuser> (or false 42)\n42\n\nuser> (or false 42 9999)\n42\n\nuser> (or 42 9999)\n42","created-at":1293673853000,"updated-at":1429754329073,"_id":"542692cbc026201cdc326bc3"},{"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":1334293981000,"updated-at":1334293981000,"_id":"542692d4c026201cdc327022"},{"updated-at":1454687827177,"created-at":1454687827177,"author":{"login":"ertugrulcetin","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8271291?v=3"},"body":";;evaluates last expression for this case\nuser> (or nil false)\nfalse\n\nuser> (or false nil)\nnil","_id":"56b4c653e4b060004fc217bc"},{"updated-at":1581256939913,"created-at":1581256939913,"author":{"login":"caumond","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/11491686?v=4"},"body":";; Defaulted value\nuser> (or nil \"crazy default value\")\ncrazy default value\n\nuser> (or \"value\" \"not useful default value\")\nvalue","_id":"5e4010ebe4b0ca44402ef82d"},{"updated-at":1596145782717,"created-at":1596145383310,"author":{"login":"luiszambon","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/41161270?v=4"},"body":";; It cares about function's return. Example:\n;; println returns 'nil', so the next param will be evaluated.\n(or (println \"Clojure\") true \"Code\" false)\nClojure\n;;=>true\n","editors":[{"avatar-url":"https://avatars0.githubusercontent.com/u/41161270?v=4","account-source":"github","login":"luiszambon"}],"_id":"5f233ee7e4b0b1e3652d732b"},{"editors":[{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"}],"body":";; `or` is a macro, so can't be given where a fn is expected\n(map or [true false] [false false])\n;; => Syntax error compiling at…\n;; => Can't take value of a macro: #'clojure.core/or\n\n;; wrap in a fn instead\n(map #(or %1 %2) [true false] [false false])\n;; => (true false)","author":{"avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4","account-source":"github","login":"tomdl89"},"created-at":1658141645967,"updated-at":1682634667591,"_id":"62d53bcde4b0b1e3652d7627"}],"macro":true,"notes":null,"arglists":["","x","x & next"],"doc":"Evaluates exprs one at a time, from left to right. If a form\n returns a logical true value, or returns that value and doesn't\n evaluate any of the other expressions, otherwise it returns the\n value of the last expression. (or) returns nil.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/or"},{"added":"1.0","ns":"clojure.core","name":"cast","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1434488356659,"author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"},"to-var":{"ns":"clojure.core","name":"type","library-url":"https://github.com/clojure/clojure"},"_id":"55808e24e4b01ad59b65f4fe"}],"line":348,"examples":[{"updated-at":1463934422291,"created-at":1289541716000,"body":";; Cast doesn't change the type of the input - it just throws an exception if it's the wrong type\n;; Since Long is a subclass of Number\nuser=> (cast Number 1) \n1\nuser=> (type (cast Number 1))\njava.lang.Long\n","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},{"login":"tirkarthi","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/3972343?v=3"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/bc41ebab54cc0e0fbe99d753876d45ce?r=PG&default=identicon","account-source":"clojuredocs","login":"Victor"},"_id":"542692cdc026201cdc326ccd"}],"notes":null,"arglists":["c x"],"doc":"Throws a ClassCastException if x is not a c, else returns x.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/cast"},{"added":"1.0","ns":"clojure.core","name":"reset!","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1324098243000,"author":{"login":"TimMc","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"swap!","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ee4"},{"created-at":1360265917000,"author":{"login":"AtKaaZ","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"compare-and-set!","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ee5"},{"created-at":1360265926000,"author":{"login":"AtKaaZ","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"atom","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ee6"},{"created-at":1527705044232,"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":"5b0eedd4e4b045c27b7fac7e"},{"created-at":1527705380123,"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":"5b0eef24e4b045c27b7fac85"}],"line":2393,"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":"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"},{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"}],"body":"user=> (def x (atom 10))\n#'user/x\n\nuser=> @x\n10\n\nuser=> (reset! x 20)\n20\n\nuser=> @x\n20","created-at":1281850260000,"updated-at":1416077324639,"_id":"542692ccc026201cdc326cb0"}],"notes":null,"arglists":["atom newval"],"doc":"Sets the value of atom to newval without regard for the\n current value. Returns newval.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/reset!"},{"added":"1.0","ns":"clojure.core","name":"name","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1385200415000,"author":{"login":"abrooks","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/69976?v=2"},"to-var":{"ns":"clojure.core","name":"namespace","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ca3"}],"line":1604,"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":"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=3"},{"login":"egracer","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/4086884?v=3"}],"body":";; the name of the keyword is without the ':'\n;; \"str\" will retain the ':'.\n(name :x)\n;;=> \"x\"\n\n(name \"x\")\n;;=> \"x\"\n\n;; returns the symbol name as a string without the namespace.\n(name 'x)\n;;=> \"x\"\n\n(name 'user/x)\n;;=> \"x\"\n\n;; throws an error for invalid types, no nil punning\n(name nil)\n;;=> Error: Doesn't support name:\n\n(name 2)\n;;=> Error: Doesn't support name: 2","created-at":1280319438000,"updated-at":1455058375466,"_id":"542692cbc026201cdc326b9a"},{"updated-at":1548517573974,"created-at":1467226948210,"author":{"login":"timgilbert","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/94482?v=3"},"body":";; Note that for namespaced keywords, `name` only returns the name part.\n(name :my-ns/my-name)\n;;=> \"my-name\"\n\n(name :ns/deep/key)\n;;=> \"deep/key\"\n;; For more info see: `keyword` and `keyword?`...\n(name :'//-,)\n;;=> \"/-\"\n(name :/)\n;;=> \"/\"\n(name ://)\n;;=> RuntimeException Invalid token: :// clojure.lang.Util.runtimeException (Util.java:221)\n;;=> RuntimeException Unmatched delimiter: ) clojure.lang.Util.runtimeException (Util.java:221)\n(name :///)\n;;=> \"//\"\n(namespace :///)\n;;=> \"\"\n\n;; If you want the namespace part, you can use (namespace):\n(namespace :my-ns/my-key)\n;;=> \"my-ns\"\n\n;; Using (str) will give you both parts, but also includes the leading colon.\n(str :my-ns/my-key)\n;;=> \":my-ns/my-key\"","editors":[{"avatar-url":"https://avatars0.githubusercontent.com/u/36645452?v=4","account-source":"github","login":"cljlc"}],"_id":"57741b44e4b0bafd3e2a0499"},{"updated-at":1548513828805,"created-at":1478905733257,"author":{"login":"souenzzo","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/3241703?v=3"},"body":";; To get full key\n(defn keyname [key] (str (namespace key) \"/\" (name key)))\n\n(keyname :ns/key)\n=> \"ns/key\"\n\n(keyname :ns/deep/key)\n=> \"ns/deep/key\"\n\n;; Just for fun\n(string/replace :key/val #\"^:\" \"\")\n=> \"key/val\"","editors":[{"avatar-url":"https://avatars0.githubusercontent.com/u/36645452?v=4","account-source":"github","login":"cljlc"}],"_id":"58264f85e4b0782b632278bf"},{"updated-at":1548517913344,"created-at":1548517913344,"author":{"login":"cljlc","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/36645452?v=4"},"body":";; `name` (and `namespace`) \"knows\" how a keyword was built:\n\n(name (keyword \"a/b\" \"c\"))\n;;=> \"c\"\n\n(name (keyword \"a\" \"b/c\"))\n;;=> \"b/c\"\n","_id":"5c4c8219e4b0ca44402ef636"},{"editors":[{"login":"green-coder","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/598193?v=4"}],"body":";; To get the fully qualified name of the keyword, we can use symbol.\n\n(str (symbol :a/b))\n;;=> \"a/b\"\n","author":{"avatar-url":"https://avatars1.githubusercontent.com/u/598193?v=4","account-source":"github","login":"green-coder"},"created-at":1577551007249,"updated-at":1577551119811,"_id":"5e07849fe4b0ca44402ef7ff"},{"updated-at":1635440614807,"created-at":1635440614807,"author":{"login":"naxels","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/3195443?v=4"},"body":"; Preserves capitals\n\n(name :pageQuery)\n; => \"pageQuery\"","_id":"617ad7e6e4b0b1e3652d7560"}],"notes":null,"tag":"java.lang.String","arglists":["x"],"doc":"Returns the name String of a string, symbol or keyword.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/name"},{"added":"1.0","ns":"clojure.core","name":"ffirst","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1343067219000,"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":"first","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521a7f"},{"created-at":1348637462000,"author":{"login":"dansalmo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"fnext","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521a80"},{"created-at":1348637521000,"author":{"login":"dansalmo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"nfirst","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521a81"},{"created-at":1482183756311,"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":"5858544ce4b004d3a355e2bf"},{"created-at":1482183947394,"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":"next","ns":"clojure.core"},"_id":"5858550be4b004d3a355e2c2"}],"line":100,"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=> (ffirst '([]))\nnil \n\nuser=> (ffirst ['(a b c) '(b a c)])\na \n\nuser=> (ffirst '([a b c] [b a c]))\na","created-at":1280345631000,"updated-at":1332951869000,"_id":"542692cbc026201cdc326bba"},{"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=> (first {:b 2 :a 1 :c 3})\n[:b 2] \n\nuser=> (ffirst {:b 2 :a 1 :c 3})\n:b","created-at":1280345657000,"updated-at":1332951883000,"_id":"542692cbc026201cdc326bbd"},{"body":"user=> (first [1])\n1\n\nuser=> (ffirst [[1]])\n1","author":{"login":"divyashravanthi","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/6253335?v=3"},"created-at":1432113125180,"updated-at":1432113125180,"_id":"555c4fe5e4b03e2132e7d163"}],"notes":null,"arglists":["x"],"doc":"Same as (first (first x))","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/ffirst"},{"added":"1.0","ns":"clojure.core","name":"sorted-set","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1317095643000,"author":{"login":"pauldoo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5cb916d3c8abc9f45a093209e72489fb?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"sorted-set-by","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521c6b"},{"created-at":1330671694000,"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":"542692eaf6e94c6970521c6c"},{"created-at":1330671698000,"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":"542692eaf6e94c6970521c6d"},{"created-at":1330671734000,"author":{"login":"Chouser","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/7a0192050ed6488670acfd3f59405c10?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"sorted-map","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521c6e"},{"created-at":1419807368932,"author":{"login":"zk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7194?v=3"},"to-var":{"ns":"clojure.core","name":"into","library-url":"https://github.com/clojure/clojure"},"_id":"54a08a88e4b09260f767ca80"},{"created-at":1423277153400,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"hash-set","library-url":"https://github.com/clojure/clojure"},"_id":"54d57c61e4b0e2ac61831d1f"},{"created-at":1548553242467,"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":"5c4d0c1ae4b0ca44402ef646"}],"line":419,"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=3"},{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"}],"body":"user=> (sorted-set 3 2 1)\n#{1 2 3}\n\nuser=> (sorted-set 3 2 1 1)\n#{1 2 3}\n\nuser=> #{2 1 3}\n#{1 3 2}\n\nuser=> (apply sorted-set #{2 1 3})\n#{1 2 3}","created-at":1280319522000,"updated-at":1423277124415,"_id":"542692cfc026201cdc326e6f"},{"editors":[{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/109629?v=4"}],"body":"(sorted-set :a \"A\" 1)\n\n;;Exception\n;;unable to implement java.lang.String.compareTo\n\n;; This exception occurs because the default comparator, a Clojure function\n;; named `compare`, throws an exception when asked to compare two values of\n;; very dissimilar tpyes, like a keyword and a string, or a keyword and a number.\n;; If you really want a sorted set containing such dissimilar types, you will\n;; need to create your own custom comparator and use sorted-set-by.\n;; See this article for advice on creating custom comparators:\n;; https://clojure.org/guides/comparators","author":{"avatar-url":"https://avatars0.githubusercontent.com/u/31028993?v=4","account-source":"github","login":"ibercode"},"created-at":1518777459431,"updated-at":1548624108584,"_id":"5a86b473e4b0316c0f44f8c5"},{"editors":[{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/109629?v=4"}],"body":";; (sorted-set ...) is equivalent in behavior to (sorted-set-by compare ...)\n;; where compare is Clojure's default comparator function clojure.core/compare\n;; See the documentation of compare for more details on its behavior.\n\n;; For a set sorted by the order that elements were added,\n;; see ordered-set: https://github.com/clj-commons/ordered\n\n;; If you deal with many large sets of integers, and want a more memory-efficient\n;; data structure for those, see int-set and dense-int-set:\n;; https://github.com/clojure/data.int-map","author":{"avatar-url":"https://avatars2.githubusercontent.com/u/109629?v=4","account-source":"github","login":"jafingerhut"},"created-at":1548553235377,"updated-at":1548618903382,"_id":"5c4d0c13e4b0ca44402ef645"}],"notes":null,"arglists":["& keys"],"doc":"Returns a new sorted set with supplied keys. Any equal keys are\n handled as if by repeated uses of conj.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/sorted-set"},{"added":"1.0","ns":"clojure.core","name":"counted?","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1495640676349,"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":"bounded-count","ns":"clojure.core"},"_id":"5925aa64e4b093ada4d4d72c"}],"line":6318,"examples":[{"author":{"login":"dakrone","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"},"editors":[],"body":"user=> (counted? [:a :b :c])\ntrue\n\nuser=> (counted? '(:a :b :c))\ntrue\n\nuser=> (counted? {:a 1 :b 2 :c 3})\ntrue\n\nuser=> (counted? #{:a :b :c})\ntrue\n\nuser=> (counted? \"asdf\")\nfalse\n\nuser=> (counted? (into-array Integer/TYPE [1 2 3]))\nfalse","created-at":1286508818000,"updated-at":1286508818000,"_id":"542692cac026201cdc326b0c"},{"updated-at":1467307667667,"created-at":1467307667667,"author":{"login":"miner","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/25400?v=3"},"body":";; Lazy sequences are not counted?\n(counted? (map inc (range 5)))\n;;=> false","_id":"57755693e4b0bafd3e2a049c"}],"notes":null,"arglists":["coll"],"doc":"Returns true if coll implements count in constant time","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/counted_q"},{"added":"1.1","ns":"clojure.core","name":"byte-array","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1451898302123,"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":"bytes","ns":"clojure.core"},"_id":"568a35bee4b0f37b65a3c27d"},{"created-at":1455883026411,"author":{"login":"guruma","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/534540?v=3"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"byte","ns":"clojure.core"},"_id":"56c70312e4b0b41f39d96ccc"}],"line":5346,"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 bytes\n;; and demonstrate that you can use it in the standard Java fill function\n;; note the needed byte coercion in the fill function call\n\nuser=> (def bees (byte-array 10))\n#'user/bees\n\nuser=> (for [i (range 10)](aset-byte bees i (* i i)))\n(0 1 4 9 16 25 36 49 64 81)\n\nuser=> (vec bees)\n[0 1 4 9 16 25 36 49 64 81]\n\nuser=> (java.util.Arrays/fill bees (byte 122))\nnil\nuser=> (vec bees)\n[122 122 122 122 122 122 122 122 122 122]\nuser=>","created-at":1313959908000,"updated-at":1313962959000,"_id":"542692cec026201cdc326d67"},{"editors":[{"login":"guruma","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/534540?v=3"}],"body":";; copied from the example in clojure.core/byte\nuser=> (def x (byte-array [(byte 0x43) \n (byte 0x6c)\n (byte 0x6f)\n (byte 0x6a)\n (byte 0x75)\n (byte 0x72)\n (byte 0x65)\n (byte 0x21)]))\n#'user/x\n\nuser=> (String. x)\n\"Clojure!\"","author":{"avatar-url":"https://avatars.githubusercontent.com/u/534540?v=3","account-source":"github","login":"guruma"},"created-at":1455883152605,"updated-at":1455883201637,"_id":"56c70390e4b0b41f39d96ccd"},{"editors":[{"login":"nivekuil","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/4633048?v=4"}],"body":";; NOTE: equality uses identity, not value semantics.\nuser=> (= (byte-array 10) (byte-array 10))\nfalse\nuser=> (java.util.Arrays/equals (byte-array 10) (byte-array 10))\ntrue\n\nuser=> (def a (byte-array [(byte 0x43)]))\n#'user/a\nuser=> (def b (byte-array [(byte 0x43)]))\n#'user/b\nuser=> (= a b)\nfalse\nuser=> (java.util.Arrays/equals a b)\ntrue","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/4633048?v=4","account-source":"github","login":"nivekuil"},"created-at":1606705309670,"updated-at":1606705382806,"_id":"5fc4609de4b0b1e3652d7412"}],"notes":[{"body":"The maximum size of a byte-array is Integer/MAX_VALUE, as arrays are int-indexed in Java. However, it is possible to pass a value that is larger than this, resulting in a cast that will wrap around. This incorrect usage will not give any indication of error.","created-at":1625076336154,"updated-at":1625076620437,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/1780598?v=4","account-source":"github","login":"dspearson"},"_id":"60dcb270e4b0b1e3652d7510"},{"author":{"login":"luposlip","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/763627?v=4"},"updated-at":1631709838369,"created-at":1631709678505,"body":"To type hint a byte array, use this non-obvious syntax:\n\n(.write ^OutputStream output-stream ^\"[B\" bytearray)
","_id":"6141e9eee4b0b1e3652d753b"},{"author":{"login":"brunchboy","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/2228869?v=4"},"updated-at":1731011533745,"created-at":1731011533745,"body":"You can also use `^bytes` to type hint a byte array, and as of Clojure 1.12, `^byte/1` for a one-dimensional byte array, `^byte/2` for two dimensions, etc.","_id":"672d23cd69fbcc0c2261750e"}],"arglists":["size-or-seq","size init-val-or-seq"],"doc":"Creates an array of bytes","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/byte-array"},{"added":"1.11","ns":"clojure.core","name":"parse-double","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1775529746545,"author":{"login":"wlkr","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/5406568?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"parse-long","ns":"clojure.core"},"_id":"69d46f127955605a202df2a1"}],"line":8179,"examples":[{"updated-at":1698255818548,"created-at":1698255818548,"author":{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"},"body":"(parse-double \"4.2\")\n;; => 4.2\n\n(parse-double \"-4.2e4\")\n;; => -42000.0\n\n(parse-double \"4\")\n;; => 4.0\n\n(parse-double \"NaN\")\n;; => ##NaN\n\n(parse-double \"Infinity\")\n;; => ##Inf\n\n(parse-double \"four\")\n;; => nil\n(parse-double \"\")\n;; => nil","_id":"653953ca69fbcc0c226173db"}],"notes":null,"arglists":["s"],"doc":"Parse string with floating point components and return a Double value,\n or nil if parse fails.\n\n Grammar: https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#valueOf-java.lang.String-","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/parse-double"},{"added":"1.7","ns":"clojure.core","name":"tagged-literal","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1661550936046,"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":"read-string","ns":"clojure.edn"},"_id":"63094158e4b0b1e3652d7656"},{"created-at":1757184352247,"author":{"login":"daveliepmann","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/974443?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"tagged-literal?","ns":"clojure.core"},"_id":"68bc8160cd84df5de54e2094"}],"line":7963,"examples":[{"updated-at":1661545330654,"created-at":1661545330654,"author":{"login":"Quezion","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1403153?v=4"},"body":"(def x (tagged-literal 'user {:name \"Foo\"}))\n\n(:form x) ;; Get the actual codeform\n;; => {:name \"Foo\"}\n\n(:tag x) ;; Get the tagged symbol\n;; => user","_id":"63092b72e4b0b1e3652d7654"},{"updated-at":1661546360936,"created-at":1661546360936,"author":{"login":"djblue","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1986211?v=4"},"body":"(require '[clojure.edn :as edn])\n(edn/read-string {:default tagged-literal} \"#js [1 2 3]\")\n;; => #js [1 2 3]\n","_id":"63092f78e4b0b1e3652d7655"}],"notes":[{"author":{"login":"miner","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/25400?v=4"},"updated-at":1610656712993,"created-at":1610656712993,"body":"`tagged-literal` is useful as a value fo `clojure.core/*default-data-reader-fn*`","_id":"6000abc8e4b0b1e3652d7431"}],"arglists":["tag form"],"doc":"Construct a data representation of a tagged literal from a\n tag symbol and a form.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/tagged-literal"},{"added":"1.0","ns":"clojure.core","name":"println","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1290672953000,"author":{"login":"dale","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/a7a1eca257c6cea943fea41e5cc3e9a3?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"prn","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521ae2"},{"created-at":1302236980000,"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","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521ae3"},{"created-at":1374264342000,"author":{"login":"lbeschastny","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/416170465e4045f810f09a9300dda4dd?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"println-str","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521ae4"},{"created-at":1518042813319,"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":"pprint","ns":"clojure.pprint"},"_id":"5a7b7ebde4b0316c0f44f8ac"}],"line":3759,"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":"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":"user=> (println \"Hello world.\")\nHello world.\nnil\n\nuser=> (def items [ \"hello\" :a 1 (list :b 2) \\c {:d 4} #{5 6 7} ])\n#'user/items\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; 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; 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; Calling println w/o args outputs a newline and nothing else.\nuser=> (println)\n\nnil\n; The newline function does the same.\nuser=> (newline)\n\nnil\nuser=>","created-at":1280776981000,"updated-at":1402400141000,"_id":"542692cec026201cdc326d9a"},{"body":"; be careful when using println in functions like map\n; println has nil as its return value\n\nuser=> (map #(println %) (range 1 4))\n\n(1 2 3 nil nil nil)\n\n","author":{"login":"rsachdeva","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/232903?v=2"},"created-at":1413839939176,"updated-at":1413839939176,"_id":"54457c43e4b0dc573b892fa1"}],"notes":null,"arglists":["& more"],"doc":"Same as print followed by (newline)","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/println"},{"added":"1.2","ns":"clojure.core","name":"extend-type","file":"clojure/core_deftype.clj","type":"macro","column":1,"see-alsos":[{"created-at":1336757561000,"author":{"login":"Cosmi","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/10f2eae92de67116fa98d06ec55fcf29?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"extend","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521be8"},{"created-at":1351471424000,"author":{"login":"klauern","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/76c55292df5e9df9042eaf89ac35954b?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"extend-protocol","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521be9"},{"created-at":1351471431000,"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":"542692eaf6e94c6970521bea"}],"line":848,"examples":[{"author":{"login":"yasuto","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cacfb7ecf08cb6461767e514c93b7bf9?r=PG&default=identicon"},"editors":[],"body":";;; This is a library for the shopping result.\n\n(defrecord Banana [qty])\n\n;;; 'subtotal' differ from each fruit.\n\n(defprotocol Fruit\n (subtotal [item]))\n\n(extend-type Banana\n Fruit\n (subtotal [item]\n (* 158 (:qty item))))\n\n;;; Please see the term of 'reify'.","created-at":1315674061000,"updated-at":1315674061000,"_id":"542692cbc026201cdc326bc2"}],"macro":true,"notes":null,"arglists":["t & specs"],"doc":"A macro that expands into an extend call. Useful when you are\n supplying the definitions explicitly inline, extend-type\n automatically creates the maps required by extend. Propagates the\n class as a type hint on the first argument of all fns.\n\n (extend-type MyType \n Countable\n (cnt [c] ...)\n Foo\n (bar [x y] ...)\n (baz ([x] ...) ([x y & zs] ...)))\n\n expands into:\n\n (extend MyType\n Countable\n {:cnt (fn [c] ...)}\n Foo\n {:baz (fn ([x] ...) ([x y & zs] ...))\n :bar (fn [x y] ...)})","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/extend-type"},{"added":"1.0","ns":"clojure.core","name":"macroexpand-1","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1284957759000,"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","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521b13"},{"created-at":1289586228000,"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"to-var":{"ns":"clojure.walk","name":"macroexpand-all","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521b14"}],"line":4044,"examples":[{"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"editors":[],"body":"user=> (macroexpand-1 '(defstruct mystruct[a b]))\n(def mystruct (clojure.core/create-struct [a b]))\n","created-at":1286272779000,"updated-at":1286272779000,"_id":"542692cbc026201cdc326ba7"},{"updated-at":1339248839000,"created-at":1339248839000,"body":"user=> (macroexpand-1 '(-> c (+ 3) (* 2)))\n(clojure.core/-> (clojure.core/-> c (+ 3)) (* 2))","editors":[],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/528360?v=3","account-source":"github","login":"BertrandDechoux"},"_id":"542692d4c026201cdc326ffa"},{"editors":[{"login":"lourkeur","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/15657735?v=4"}],"body":"; When testing macro expansion in a file instead of at the REPL, \n; please note that it may be necessary to use a backquote\n; instead of a straight quote.\n\n(defmacro iiinc [x]\n `(+ 3 ~x))\n\n(deftest t-stuff\n ; This doesn't work.\n (println (macroexpand-1 '(iiinc 2))) ;=> (iiinc 2)\n\n ; Oddly, we can use the macro itself fine in our tests...\n (println (iiinc 2)) ;=> 5\n (is (= 5 (iiinc 2))) ;=> unit test passes\n\n ; This fixes it by resolving the symbol iiinc at compile-time.\n (println (macroexpand-1 `(iiinc 2)))) ;=> (+ 3 2)\n\n; Also, as the previous examples show, please remember that \n; you must quote the form you are providing to `macroexpand-1`.\n","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/7083783?v=3","account-source":"github","login":"cloojure"},"created-at":1494031935843,"updated-at":1522520280321,"_id":"590d1e3fe4b01f4add58feaf"}],"notes":null,"arglists":["form"],"doc":"If form represents a macro form, returns its expansion,\n else returns form.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/macroexpand-1"},{"added":"1.0","ns":"clojure.core","name":"assoc-in","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1291975376000,"author":{"login":"alimoeeny","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/9e8dd06976ead4082d2181f3807117e1?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"assoc","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521ac6"},{"created-at":1302248543000,"author":{"login":"zk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2"},"to-var":{"ns":"clojure.core","name":"update-in","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521ac7"},{"created-at":1318010528000,"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":"542692eaf6e94c6970521ac9"},{"created-at":1570520711353,"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":"5d9c3e87e4b0ca44402ef7ca"}],"line":6224,"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":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"body":"(def users [{:name \"James\" :age 26} {:name \"John\" :age 43}])\n\n;; update the age of the second (index 1) user \n(assoc-in users [1 :age] 44)\n;;=> [{:name \"James\", :age 26} {:name \"John\", :age 44}]\n\n;; insert the password of the second (index 1) user\n(assoc-in users [1 :password] \"nhoJ\")\n;;=> [{:name \"James\", :age 26} {:password \"nhoJ\", :name \"John\", :age 43}]\n\n;; create a third (index 2) user\n;; Also (assoc m 2 {...}) or (conj m {...})\n(assoc-in users [2] {:name \"Jack\" :age 19}) \n;;=> [{:name \"James\", :age 26} {:name \"John\", :age 43} {:name \"Jack\", :age 19}]\n\n;; From http://clojure-examples.appspot.com/clojure.core/assoc-in","created-at":1278953901000,"updated-at":1422565766316,"_id":"542692cac026201cdc326b38"},{"author":{"login":"devth","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/70c7535cbb9fea0353250a4edda155be?r=PG&default=identicon"},"editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"},{"avatar-url":"https://avatars.githubusercontent.com/u/200617?v=3","account-source":"github","login":"bsima"},{"login":"elias94","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8095533?v=4"}],"body":";; can be used to update a mutable item.\n(def ppl (atom {\"persons\" {\"joe\" {:age 1}}}))\n(swap! ppl assoc-in [\"persons\" \"bob\"] {:age 2})\n\n@ppl\n;;=> {\"persons\" {\"joe\" {:age 1}, \"bob\" {:age 2}}}","created-at":1378880124000,"updated-at":1625799501437,"_id":"542692d2c026201cdc326f4c"},{"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":1495693228091,"created-at":1412006606316,"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(assoc-in {} [] {:k :v})\n;;=> {nil {:k :v}}\n\n;; In general, you find that for a non-empty path\n;; (get-in (assoc-in m path v) path) \n;; is equal to v.\n;; Surprisingly this does not hold true in case of an empty path.","_id":"542982cee4b09282a148f203"},{"body":";; another example of updating a mutable item.\n;; this time the first key is to a map and the second to a vector.\n(def foo (atom {:users [{:a \"a\"} {:b \"b\"}]}))\n(swap! foo assoc-in [:users 2] {:c \"c\"})\n;;=> {:users [{:a \"a\"} {:b \"b\"} {:c \"c\"}]}\n\n","author":{"login":"saiberz","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1022999?v=3"},"created-at":1418344457312,"updated-at":1422566109388,"editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"_id":"548a3809e4b04e93c519ffa4"},{"editors":[{"login":"coffeefire","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/14366530?v=3"}],"updated-at":1448358381451,"created-at":1433960090535,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/571777?v=3","account-source":"github","login":"cthulhu-bot"},"body":";; assoc-in into a nested map structure\n(def foo {:user {:bar \"baz\"}})\n(assoc-in foo [:user :id] \"some-id\")\n;;=> {:user {:bar \"baz\", :id \"some-id\"}}\n","_id":"55787e9ae4b01ad59b65f4ef"},{"editors":[{"login":"prudentbot","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/3210379?v=3"}],"body":"(assoc-in {} [:cookie :monster :vocals] \"Finntroll\")\n; => {:cookie {:monster {:vocals \"Finntroll\"}}}\n\n(get-in {:cookie {:monster {:vocals \"Finntroll\"}}} [:cookie :monster])\n; => {:vocals \"Finntroll\"}\n\n(assoc-in {} [1 :connections 4] 2)\n; => {1 {:connections {4 2}}}\n\n;; from http://www.braveclojure.com/functional-programming/","author":{"avatar-url":"https://avatars.githubusercontent.com/u/3210379?v=3","account-source":"github","login":"prudentbot"},"created-at":1438058284679,"updated-at":1438100741796,"_id":"55b7072ce4b06a85937088b7"},{"editors":[{"login":"amirrajan","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/517055?v=3"}],"body":";; assoc-in can be used on vectors too\n\n(def row 0)\n(def col 0)\n\n(assoc-in [[1 1 1]\n [1 1 1]\n [1 1 1]] [row col] 0)\n; => [[0 1 1][1 1 1][1 1 1]]\n\n(get-in [[0 1 1]\n [1 1 1]\n [1 1 1]] [row col])\n; => 0","author":{"avatar-url":"https://avatars.githubusercontent.com/u/517055?v=3","account-source":"github","login":"amirrajan"},"created-at":1445568749511,"updated-at":1445568838675,"_id":"5629a0ede4b04b157a6648d8"},{"editors":[{"login":"gosukiwi","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/161972?v=3"}],"body":"; Playing around with assoc-in\n\n(assoc-in {:person {:name \"Mike\"}} [:person :name] \"Violet\")\n; => {:person {:name \"Violet\"}}\n\n(assoc-in {:person {:name \"Mike\"}} [:person] \"Violet\")\n; => {:person \"Violet\"}\n\n(assoc-in [{:person {:name \"Mike\"}}] [0 :person :name] \"Violet\")\n; => [{:person {:name \"Violet\"}}]\n\n(assoc-in [{:person {:name [\"Mike\"]}}] [0 :person :name 1] \"Smith\")\n; => [{:person {:name [\"Mike\" \"Smith\"]}}]\n\n(assoc-in [{:person {:name [\"Mike\"]}}] [0 :person :name 2] \"Smith\")\n; => IndexOutOfBoundsException","author":{"avatar-url":"https://avatars.githubusercontent.com/u/161972?v=3","account-source":"github","login":"gosukiwi"},"created-at":1470551622806,"updated-at":1470551660418,"_id":"57a6d646e4b0bafd3e2a04cc"},{"editors":[{"login":"loeschzwerg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/24317401?v=4"}],"body":";; Note that, unlike `assoc`, `assoc-in` cannot be used with multiple values.\n\n(def my-map {})\n\n;; This works\n(assoc my-map :a 1\n :b 2\n :c 3)\n; => {:a 1, :b 2, :c 3}\n\n;; This doesn’t\n(assoc-in my-map [:a :aa] 1\n [:b :bb] 2\n [:c :cc] 3)\n; ArityException Wrong number of args (7) passed to: core/assoc-in\n\n;; This works\n(-> my-map\n (assoc-in [:a :aa] 1)\n (assoc-in [:b :bb] 2)\n (assoc-in [:c :cc] 3))","author":{"avatar-url":"https://avatars2.githubusercontent.com/u/1334295?v=4","account-source":"github","login":"bfontaine"},"created-at":1524054770336,"updated-at":1631275246821,"_id":"5ad73af2e4b045c27b7fac3f"}],"notes":[{"body":"Unlike `assoc`, you can only do one kv at a time:\n\n```\n;; Allowed\n(assoc {} :a \"a\" :b \"b\" :c \"c\")\n;; Not allowed:\n(assoc-in {} [:a :b] \"cya\" [:a :d :e] \"f\" [:b :g] \"wow\")\n```","created-at":1648401233813,"updated-at":1648401332618,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/19522656?v=4","account-source":"github","login":"Crowbrammer"},"_id":"62409b51e4b0b1e3652d75c2"}],"arglists":["m [k & ks] v"],"doc":"Associates a value in a nested associative structure, where ks is a\n sequence of keys and v is the new value and returns a new nested structure.\n If any levels do not exist, hash-maps will be created.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/assoc-in"},{"added":"1.0","ns":"clojure.core","name":"char-name-string","file":"clojure/core_print.clj","type":"var","column":1,"see-alsos":[{"created-at":1375209941000,"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-escape-string","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521b76"}],"line":342,"examples":[{"author":{"login":"alilee","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"},"editors":[],"body":"user=> (char-name-string \\newline)\n\"newline\"","created-at":1375209966000,"updated-at":1375209966000,"_id":"542692d2c026201cdc326f5f"},{"updated-at":1592040564496,"created-at":1592040564496,"author":{"login":"ertugrulcetin","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/8271291?v=4"},"body":"(map char-name-string [\\backspace \\tab \\newline \\formfeed \\return \\space])\n;;=> (\"backspace\" \"tab\" \"newline\" \"formfeed\" \"return\" \"space\")","_id":"5ee49c74e4b0b1e3652d7303"}],"notes":null,"tag":"java.lang.String","arglists":[],"doc":"Returns name string for char or nil if none","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/char-name-string"},{"added":"1.0","ns":"clojure.core","name":"bit-test","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1405720487000,"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":"542692ebf6e94c6970521cac"},{"created-at":1405720498000,"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":"542692ebf6e94c6970521cad"},{"created-at":1405720509000,"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":"542692ebf6e94c6970521cae"}],"line":1363,"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=3"}],"body":"(bit-test 2r1001 0) ;;=> true \n(bit-test 2r1001 1) ;;=> false \n(bit-test 2r1001 7) ;;=> false","created-at":1280338595000,"updated-at":1421943187268,"_id":"542692cfc026201cdc326e7c"},{"updated-at":1550024741651,"created-at":1550024741651,"author":{"login":"pauloaug","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/804447?v=4"},"body":";; Note that the index starts from the least significant bit (right to left).\n\n(map #(bit-test 2r10011 %) [0 1 2 3 4])\n;;=> (true true false false true) ","_id":"5c638025e4b0ca44402ef682"},{"editors":[{"login":"reborg","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4"}],"body":";; bit-wise powerset (set of all subsets)\n\n(defn powerset [coll]\n (let [cnt (count coll)\n bits (Math/pow 2 cnt)]\n (for [i (range bits)]\n (for [j (range i)\n :while (< j cnt)\n :when (bit-test i j)]\n (nth coll j)))))\n\n(powerset [1 2 3])\n;; (() (1) (2) (1 2) (3) (1 3) (2 3) (1 2 3))","author":{"avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4","account-source":"github","login":"reborg"},"created-at":1564483500939,"updated-at":1564483573152,"_id":"5d401face4b0ca44402ef78b"}],"notes":null,"arglists":["x n"],"doc":"Test bit at index n","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/bit-test"},{"added":"1.0","ns":"clojure.core","name":"defmethod","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1285162546000,"author":{"login":"kumarshantanu","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/39f90a6c0ffe4995fb9dff4fb6b6bad6?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"defmulti","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521b40"},{"created-at":1341270386000,"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":"542692eaf6e94c6970521b41"},{"created-at":1341270389000,"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":"542692eaf6e94c6970521b42"},{"created-at":1341270393000,"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":"542692eaf6e94c6970521b43"},{"created-at":1341270396000,"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":"542692eaf6e94c6970521b44"},{"created-at":1341270398000,"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":"542692eaf6e94c6970521b45"}],"line":1800,"examples":[{"author":{"login":"Victor","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bc41ebab54cc0e0fbe99d753876d45ce?r=PG&default=identicon"},"editors":[],"body":"(defmulti service-charge (fn [acct] [(account-level acct) (:tag acct)]))\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":1290489730000,"updated-at":1290489730000,"_id":"542692c7c026201cdc3269cb"},{"author":{"login":"Victor","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bc41ebab54cc0e0fbe99d753876d45ce?r=PG&default=identicon"},"editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/104014?v=3","account-source":"github","login":"slester"},{"login":"bfontaine","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/1334295?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;then can use this like this:\n(def english-map {\"id\" \"1\", \"language\" \"English\"})\n(def french-map {\"id\" \"2\", \"language\" \"French\"})\n\n=>(greeting english-map)\n\"Hello!\"\n=>(greeting french-map)\n\"Bonjour!\"\n","created-at":1290492873000,"updated-at":1572016935512,"_id":"542692c7c026201cdc3269cc"},{"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"editors":[],"body":";; Methods can be given a name. Very useful in stack traces.\n(defmethod foo \"a\" name-of-method [params] \"was a\")\n","created-at":1308205150000,"updated-at":1308205150000,"_id":"542692c7c026201cdc3269cd"},{"editors":[{"login":"gariepyalex","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/6105461?v=4"}],"body":"(defmulti ticket-price :customer-status)\n\n(defmethod ticket-price :student\n ;; Everything after the dispatch value is passed to fn.\n student-price\n [customer]\n 10.0)\n\n(defmethod ticket-price :professional\n professional-price\n [customer]\n 650.0)","author":{"avatar-url":"https://avatars2.githubusercontent.com/u/1334295?v=4","account-source":"github","login":"bfontaine"},"created-at":1572017355964,"updated-at":1596053774142,"_id":"5db314cbe4b0ca44402ef7d4"}],"macro":true,"notes":null,"arglists":["multifn dispatch-val & fn-tail"],"doc":"Creates and installs a new method of multimethod associated with dispatch-value. ","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/defmethod"},{"added":"1.10","ns":"clojure.core","name":"requiring-resolve","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1611863381575,"author":{"login":"nbaumanGR","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/76698379?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"resolve","ns":"clojure.core"},"_id":"60131555e4b0b1e3652d7441"}],"line":6145,"examples":[{"editors":[{"login":"daemianmack","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/24476?v=4"}],"body":";; Resolve a qualified symbol\n(requiring-resolve 'clojure.java.shell/sh)\n\n;; Resolve and evaluate\n((requiring-resolve 'some-ns/some-fn))\n\n;; In deps.edn, replace all spaces with the \"Corfield\" comma, ;)\n((requiring-resolve,'clojure.java.shell/sh))","author":{"avatar-url":"https://avatars0.githubusercontent.com/u/705227?v=4","account-source":"github","login":"Hindol"},"created-at":1583391908395,"updated-at":1605911520381,"_id":"5e60a4a4e4b087629b5a18b7"},{"editors":[{"login":"Folcon","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/123055?v=4"}],"body":"(defn debug? [] (= (env :debug?) \"true\"))\n\n;; If you need to do conditional requires such as the one below:\n(if (debug?)\n (do\n (require '[nrepl.cmdline :refer [-main] :rename {-main -nrepl-main}])\n (resolve 'nrepl.cmdline))\n (declare -nrepl-main))\n\n(defn -main [& args]\n (when (debug?)\n (future (apply -nrepl-main args))))\n\n;; This is strictly better!\n(defn -main [& args]\n (when (debug?)\n ;; Swap to require and resolve in one step!\n (future (apply (requiring-resolve 'nrepl.cmdline/-main) args))))","author":{"avatar-url":"https://avatars.githubusercontent.com/u/123055?v=4","account-source":"github","login":"Folcon"},"created-at":1643638396360,"updated-at":1643638468576,"_id":"61f7ee7ce4b0b1e3652d75a4"}],"notes":null,"arglists":["sym"],"doc":"Resolves namespace-qualified sym per 'resolve'. If initial resolve\nfails, attempts to require sym's namespace and retries.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/requiring-resolve"},{"ns":"clojure.core","name":"EMPTY-NODE","file":"clojure/gvec.clj","type":"var","column":1,"see-alsos":null,"line":20,"examples":null,"notes":null,"arglists":[],"library-url":"https://github.com/clojure/clojure","href":"/clojure.core/EMPTY-NODE"},{"added":"1.0","ns":"clojure.core","name":"time","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":null,"line":3910,"examples":[{"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"editors":[],"body":"user> (time (Thread/sleep 100))\n\"Elapsed time: 100.284772 msecs\"\nnil","created-at":1286871374000,"updated-at":1286871374000,"_id":"542692c6c026201cdc326908"},{"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"editors":[],"body":";when working with lazy seqs\n(time (doall (...)))","created-at":1289011003000,"updated-at":1289011003000,"_id":"542692c6c026201cdc326909"},{"author":{"login":"Omer","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/dae0f434afde5246ccb030cdec81fb71?r=PG&default=identicon"},"editors":[{"login":"Omer","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/dae0f434afde5246ccb030cdec81fb71?r=PG&default=identicon"}],"body":";; Time how long it takes to write a string to a file 100 times\n(defn time-test []\n (with-open [w (writer \"test.txt\" :append false)]\n (dotimes [_ 100]\n (.write w \"I am being written to a file.\"))))\n\n\nuser=> (time (time-test))\n\"Elapsed time: 19.596371 msecs\"","created-at":1338273583000,"updated-at":1338273812000,"_id":"542692d5c026201cdc3270a6"},{"author":{"login":"micrub","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/c649274329369f1a7a4869e29655e058?r=PG&default=identicon"},"editors":[],"body":"user=> (time (Thread/sleep 1000))\n\"Elapsed time: 1000.267483 msecs\"\nnil\nuser=> (with-out-str (time (Thread/sleep 1000)))\n\"\\\"Elapsed time: 1010.12942 msecs\\\"\\n\"\n\n","created-at":1400389644000,"updated-at":1400389644000,"_id":"542692d5c026201cdc3270a8"},{"updated-at":1619013512243,"created-at":1619013512243,"author":{"login":"sFritsch09","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/58191603?v=4"},"body":";;get elapsed time in seconds:\n\n(defmacro sectime\n [expr]\n `(let [start# (. System (currentTimeMillis))\n ret# ~expr]\n (prn (str \"Elapsed time: \" (/ (double (- (. System (currentTimeMillis)) start#)) 1000.0) \" secs\"))\n ret#))","_id":"60802f88e4b0b1e3652d74cc"}],"macro":true,"notes":[{"author":{"login":"mars0i","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1836941?v=4"},"updated-at":1646109474809,"created-at":1646109474809,"body":"Because the Java JIT compiler compiles code differently after the code has been running for a bit of time, if you want to use `time` for benchmarking, you should at least \"warm up\" your code by running it several times, using the later `time` outputs as the ones that count. A better strategy is to use a benchmarking library such as [Criterium](https://github.com/hugoduncan/criterium), which will do the warmup for you, and much more.","_id":"621da322e4b0b1e3652d75ae"}],"arglists":["expr"],"doc":"Evaluates expr and prints the time it took. Returns the value of\n expr.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/time"},{"added":"1.0","ns":"clojure.core","name":"memoize","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1358780692000,"author":{"login":"AtKaaZ","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/9e10dfa345f44b0fe72bbe081fd51b83?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"delay","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d2a"}],"line":6414,"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":";; First we define a function that presumably have some expensive computation.\nuser=> (defn myfunc[a] (println \"doing some work\") (+ a 10))\n#'user/myfunc\n\n;; Next we create a memoized version of the function.\nuser=> (def myfunc-memo (memoize myfunc))\n#'user/myfunc-memo\n\n\n;; The first time we call the function with a particular argument the\n;; original function is invoked and the value is returned. The next\n;; time the function is called with the same argument the cached result\n;; is returned and the original function is NOT called.\n\nuser=> (myfunc-memo 1)\ndoing some work\n11\nuser=> (myfunc-memo 1)\n11\nuser=> (myfunc-memo 20)\ndoing some work\n30\nuser=> (myfunc-memo 20)\n30\n","created-at":1280909609000,"updated-at":1285495306000,"_id":"542692ccc026201cdc326c75"},{"body":"\n;; Fibonacci number with recursion.\n(defn fib [n]\n (condp = n\n 0 1\n 1 1\n (+ (fib (dec n)) (fib (- n 2)))))\n\n(time (fib 30))\n;; \"Elapsed time: 8179.04028 msecs\"\n\n;; Fibonacci number with recursion and memoize.\n(def m-fib\n (memoize (fn [n]\n (condp = n\n 0 1\n 1 1\n (+ (m-fib (dec n)) (m-fib (- n 2)))))))\n\n(time (m-fib 30))\n;; \"Elapsed time: 1.282557 msecs\"\n ","author":{"login":"discoverfly","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1535428?v=3"},"created-at":1429269742396,"updated-at":1429269742396,"_id":"5530eceee4b01bb732af0a83"},{"updated-at":1497303795210,"created-at":1497303795210,"author":{"login":"timgilbert","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/94482?v=3"},"body":";; It's possible to memoize a function with multiple arguments:\n(def times (memoize (fn [x y] (* x y))))\n\n(times 1 2) ; => 2\n\n(times 2 0) ; => 0","_id":"593f0af3e4b06e730307db31"},{"updated-at":1532276203982,"created-at":1532276203982,"author":{"login":"comnik","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/1313051?v=4"},"body":";; Memoize is a simple way to make a mapping deterministic.\n(def attribute->id (memoize (fn [attr] (clojure.lang.RT/nextID))))\n\n(attribute->id :name) ; => 16305\n\n(attribute->id :age) ; => 16306\n\n(attribute->id :name) ; => 16305","_id":"5b54adebe4b00ac801ed9e2a"},{"updated-at":1555579882226,"created-at":1555579882226,"author":{"login":"harununal","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/36730353?v=4"},"body":"; We can take a rand and use it repeatly \n; (Just with same parameter)\n\n(defn only-first-one-rand\n [n]\n (rand n))\n\n(def ofor-memo (memoize only-first-one-rand))\n\n(ofor-memo 10) ;=> 3.683571228686361 \n\n(ofor-memo 10) ;=> 3.683571228686361\n\n;And we can assign a random value to an integer\n\n(ofor-memo 6) ;=> 2.8058589761445867\n\n(ofor-memo 10) ;=> 3.683571228686361","_id":"5cb843eae4b0ca44402ef70d"},{"updated-at":1555580792896,"created-at":1555580792896,"author":{"login":"harununal","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/36730353?v=4"},"body":"; When we use memoize, we say to Clojure :\n; \" x function returned with y parameters as z value. \n; No need to repeat this process everytimes. \n; Because you has pure functions. \n; Just keep \"z value\" on your mind. \n; Thank you.\" ","_id":"5cb84778e4b0ca44402ef70e"}],"notes":[{"author":{"login":"rquinlivan","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/485844?v=3"},"updated-at":1480901638909,"created-at":1480901638909,"body":"What is the definition of \"often\" for the purposes of caching? Is there a util like this that allows for different cache eviction strategies?","_id":"5844c406e4b0782b632278d2"},{"author":{"login":"PetrGlad","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/124476?v=3"},"updated-at":1483028454253,"created-at":1483028454253,"body":"@rquinlivan The implementation of clojure.core/memoize is plain straightforward. It should be obvious that computation_cost times number_of_calls should determine whether to use it or not. If you need more control over caching have a look at [clojure.core.cache](https://github.com/clojure/core.cache)","_id":"586537e6e4b0fd5fb1cc964b"},{"author":{"login":"l3nz","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/1101849?v=4"},"updated-at":1591252941044,"created-at":1591252896617,"body":"`memoize` is nice but it may be tricky to use in production, because it just caches everything. Also, the key under which the value is stored are all the parametres you have as input. \n\nIf you need something more flexible, with user-definable keys (eg because you are passing in a database connection) or a flexible eviction policy, see `clojure.core.memoize` that is a wrapper around `clojure.core.cache`.","_id":"5ed897a0e4b087629b5a1922"}],"arglists":["f"],"doc":"Returns a memoized version of a referentially transparent function. The\n memoized version of the function keeps a cache of the mapping from arguments\n to results and, when calls with the same arguments are repeated often, has\n higher performance at the expense of higher memory use.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/memoize"},{"added":"1.0","ns":"clojure.core","name":"alter-meta!","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1375212992000,"author":{"login":"alilee","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"vary-meta","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521bd0"},{"created-at":1375213001000,"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-meta","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521bd1"},{"created-at":1456685895947,"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":"56d34347e4b02a6769b5a4bc"},{"created-at":1458508939384,"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":"reset-meta!","ns":"clojure.core"},"_id":"56ef148be4b09295d75dbf30"}],"line":2423,"examples":[{"updated-at":1456685878779,"created-at":1456685878779,"author":{"login":"svenschoenung","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/10583730?v=3"},"body":"(def ^{:version 1} document \"This is text\")\n;;=> #'user/document\n\n(meta #'document)\n;;=> {:version 1}\n\n(alter-meta! #'document #(update-in % [:version] inc)) ;increase version\n;;=> {:version 2}\n\n(meta #'document) ;metadata of var was changed\n;;=> {:version 2}\n\n(alter-meta! #'document update-in [:version] inc) ;same as above but shorter\n;;=> {:version 3}\n\n(meta #'document) ;metadata of var was changed again\n;;=> {:version 3}\n","_id":"56d34336e4b0b41f39d96cda"}],"notes":null,"arglists":["iref f & args"],"doc":"Atomically sets the metadata for a namespace/var/ref/agent/atom to be:\n\n (apply f its-current-meta args)\n\n f must be free of side-effects","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/alter-meta!"},{"added":"1.1","ns":"clojure.core","name":"future?","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"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":1339251269000,"_id":"542692ebf6e94c6970521ef5"}],"line":6609,"examples":[{"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"}],"body":"user=> (def f (future (inc 0)))\n#'user/f\n\nuser=> (future? f)\ntrue\n\nuser=> (future? 1)\nfalse\n","created-at":1339251424000,"updated-at":1339251441000,"_id":"542692d3c026201cdc326fb9"}],"notes":null,"arglists":["x"],"doc":"Returns true if x is a future","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/future_q"},{"added":"1.0","ns":"clojure.core","name":"zero?","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1400618891000,"author":{"login":"ryo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"pos?","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521dde"},{"created-at":1400618896000,"author":{"login":"ryo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"neg?","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ddf"},{"created-at":1605573252870,"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":"5fb31a84e4b0b1e3652d7406"}],"line":869,"examples":[{"updated-at":1423525588057,"created-at":1279075455000,"body":"(zero? 0) ;;=> true\n(zero? 0.0) ;;=> true\n(zero? 2r000) ;;=> true\n(zero? 0x0) ;;=> true\n\n(zero? 1) ;;=> false\n(zero? 3.14159265358M) ;;=> false\n(zero? (/ 1 2)) ;;=> false\n\n(zero? nil) ;;=> NullPointerException","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3","account-source":"github","login":"jafingerhut"},{"avatar-url":"https://avatars.githubusercontent.com/u/10421?v=3","account-source":"github","login":"devn"},{"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"}],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/147981?v=3","account-source":"github","login":"dpritchett"},"_id":"542692c8c026201cdc326a6d"}],"notes":[{"author":{"login":"chbrown","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/360279?v=3"},"updated-at":1499457802441,"created-at":1499457802441,"body":"`(zero? x)` calls `(clojure.lang.Numbers/isZero x)`, which will throw a `ClassCastException ... cannot be cast to java.lang.Number` or `NullPointerException` if `x` is anything but a number.","_id":"595fe90ae4b06e730307db50"}],"arglists":["num"],"doc":"Returns true if num is zero, else false","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/zero_q"},{"added":"1.9","ns":"clojure.core","name":"simple-keyword?","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1495715327644,"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":"5926cdffe4b093ada4d4d764"},{"created-at":1495715337823,"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":"5926ce09e4b093ada4d4d765"}],"line":1652,"examples":[{"updated-at":1495722311941,"created-at":1495722311941,"author":{"login":"svenschoenung","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/10583730?v=3"},"body":"(simple-keyword? :keyword)\n;;=> true\n\n(simple-keyword? :user/:keyword)\n;;=> false\n(simple-keyword? ::keyword)\n;;=> false\n\n(simple-keyword? \"string\")\n;;=> false\n(simple-keyword? 42)\n;;=> false\n(simple-keyword? nil)\n;;=> false","_id":"5926e947e4b093ada4d4d769"}],"notes":null,"arglists":["x"],"doc":"Return true if x is a keyword without a namespace","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/simple-keyword_q"},{"added":"1.0","ns":"clojure.core","name":"require","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1281451664000,"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":"542692eaf6e94c6970521bf3"},{"created-at":1291628612000,"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":"542692eaf6e94c6970521bf4"},{"created-at":1291628619000,"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":"542692eaf6e94c6970521bf5"},{"to-var":{"library-url":"https://github.com/clojure/clojure","name":"ns","ns":"clojure.core"},"author":{"avatar-url":"https://avatars.githubusercontent.com/u/10421?v=3","account-source":"github","login":"devn"},"created-at":1358655983000,"_id":"542692eaf6e94c6970521bf6"},{"created-at":1423094191542,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"refer","library-url":"https://github.com/clojure/clojure"},"_id":"54d2b1afe4b081e022073c60"},{"created-at":1654081012452,"author":{"login":"PEZ","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/30010?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"requiring-resolve","ns":"clojure.core"},"_id":"629745f4e4b0b1e3652d75f4"},{"created-at":1654081063935,"author":{"login":"PEZ","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/30010?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"resolve","ns":"clojure.core"},"_id":"62974627e4b0b1e3652d75f6"}],"line":6066,"examples":[{"author":{"login":"scode","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/87b4fd6e7ac86cbf1f1b683f7856057?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"},{"avatar-url":"https://avatars.githubusercontent.com/u/8088318?v=3","account-source":"github","login":"jackyfkc"},{"avatar-url":"https://avatars.githubusercontent.com/u/10583730?v=3","account-source":"github","login":"svenschoenung"},{"login":"jkxyz","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/10171367?v=4"}],"body":";; Require clojure.set and call its union function:\n\nuser=> (require 'clojure.set)\nnil\nuser=> (clojure.set/union #{1} #{2})\n#{1 2}\n","created-at":1279160245000,"updated-at":1667391689806,"_id":"542692ccc026201cdc326cb8"},{"updated-at":1461731642529,"created-at":1283923768000,"body":";; alias clojure.java.io as io\nuser=> (require '[clojure.java.io :as io])\nnil\n\nuser=> (io/file \"Filename\")\n#(#{nil} nil) is nil
and (#{false} false) is false
Consider using contains?
instead.","created-at":1351243602000,"author":{"login":"Sgeo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bf4e0e4e4f0b1f703b1372a8dd7b0735?r=PG&default=identicon"},"_id":"542692edf6e94c6970521ff3"}],"arglists":["pred coll"],"doc":"Returns the first logical true value of (pred x) for any x in coll,\n else nil. One common idiom is to use a set as pred, for example\n this will return :fred if :fred is in the sequence, otherwise nil:\n (some #{:fred} coll)","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/some"},{"added":"1.1","ns":"clojure.core","name":"future-cancelled?","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"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":1339251909000,"_id":"542692eaf6e94c6970521aa0"},{"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":1339251915000,"_id":"542692eaf6e94c6970521aa1"},{"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":1339251923000,"_id":"542692eaf6e94c6970521aa2"},{"to-var":{"library-url":"https://github.com/clojure/clojure","name":"future-done?","ns":"clojure.core"},"author":{"avatar-url":"https://avatars.githubusercontent.com/u/528360?v=3","account-source":"github","login":"BertrandDechoux"},"created-at":1339251931000,"_id":"542692eaf6e94c6970521aa3"}],"line":7153,"examples":[{"updated-at":1339251900000,"created-at":1339251900000,"body":"user=> (def f (future (inc 0))) \n#'user/f\n\nuser=> (future-cancel f) \nfalse\n\nuser=> (future-cancelled? f)\nfalse\n\nuser=> (future-done? f) \ntrue\n\nuser=> @f \n1\n","editors":[],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/528360?v=3","account-source":"github","login":"BertrandDechoux"},"_id":"542692d3c026201cdc326fb5"},{"updated-at":1339252110000,"created-at":1339252110000,"body":"user=> (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":"542692d3c026201cdc326fb6"}],"notes":null,"arglists":["f"],"doc":"Returns true if future f is cancelled","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/future-cancelled_q"},{"added":"1.0","ns":"clojure.core","name":"memfn","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":null,"line":3897,"examples":[{"author":{"login":"nipra","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/142529?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":"vmfhrmfoaj","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7251822?v=4"}],"body":"user=> (def *files* (file-seq (java.io.File. \"/tmp/\")))\n#'user/*files*\nuser=> (count (filter (memfn isDirectory) *files*))\n68\nuser=> (count (filter #(.isDirectory %) *files*))\n68\nuser=> (count (filter java.io.File/.isDirectory *files*)) ; Clojure 1.12 or higher\n68\n","created-at":1279241437000,"updated-at":1778890371251,"_id":"542692cac026201cdc326b0d"},{"editors":[{"login":"bsima","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/200617?v=3"}],"updated-at":1447790514365,"created-at":1434489283413,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/519370?v=3","account-source":"github","login":"emidln"},"body":"user=> ;; you must pass arguments to your method to add up to the expected arity\n\nuser=> (def starts-with (memfn startsWith prefix))\n#'user/starts-with\nuser=> (starts-with \"pikachu\" \"pika\")\ntrue\nuser=> (starts-with \"pikachu\" \"bulba\")\nfalse","_id":"558091c3e4b03e2132e7d199"},{"updated-at":1532986210979,"created-at":1532986210979,"author":{"login":"reborg","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4"},"body":"(set! *warn-on-reflection* true)\n\n;; memfn is inherently subject to reflective calls\n\n(time (dotimes [n 100000] (mapv (memfn toLowerCase) [\"A\" \"B\" \"C\"])))\n;; Reflection warning, call to toLowerCase can't be resolved\n;; \"Elapsed time: 794.081758 msecs\"\n\n;; But accepts and propagate type hints to avoid it\n\n(time (dotimes [n 100000] (mapv (memfn ^String toLowerCase) [\"A\" \"B\" \"C\"])))\n;; \"Elapsed time: 33.708462 msecs\"","_id":"5b5f8362e4b00ac801ed9e3d"}],"macro":true,"notes":null,"arglists":["name & args"],"doc":"Expands into code that creates a fn that expects to be passed an\n object and any args and calls the named instance method on the\n object passing the args. Use when you want to treat a Java method as\n a first-class fn. name may be type-hinted with the method receiver's\n type in order to avoid reflective calls.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/memfn"},{"added":"1.9","ns":"clojure.core","name":"neg-int?","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1495640945095,"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":"5925ab71e4b093ada4d4d732"},{"created-at":1495640949709,"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":"nat-int?","ns":"clojure.core"},"_id":"5925ab75e4b093ada4d4d733"},{"created-at":1495705357040,"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":"5926a70de4b093ada4d4d74f"}],"line":1428,"examples":[{"updated-at":1495703597089,"created-at":1495703597089,"author":{"login":"svenschoenung","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/10583730?v=3"},"body":"(neg-int? -1)\n;;=> true\n(neg-int? -9223372036854775808)\n;;=> true\n\n;;;; false for non-negative values\n\n(neg-int? 0)\n;;=> false\n(neg-int? 1)\n;;=> false\n\n;;;; false for decimal values\n\n(neg-int? -1.0)\n;;=> false\n(neg-int? -1/2)\n;;=> false\n\n;;;; false for BigInt values\n\n(neg-int? -1N)\n;;=> false\n(neg-int? -9223372036854775809)\n;;=> false","_id":"5926a02de4b093ada4d4d74a"}],"notes":null,"arglists":["x"],"doc":"Return true if x is a negative fixed precision integer","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/neg-int_q"},{"added":"1.0","ns":"clojure.core","name":"struct-map","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1283400432000,"author":{"login":"james","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/4b163432c99a124feee4be046a3f9d66?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"struct","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521c56"}],"line":4078,"examples":[{"author":{"login":"james","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/4b163432c99a124feee4be046a3f9d66?r=PG&default=identicon"},"editors":[{"login":"zk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2"}],"body":";; create a new struct type\n(defstruct s :1 :2)\n#'user/s\n\nuser=> (type s)\nclojure.lang.PersistentStructMap$Def\n\n;; create an instance of this new struct type\n(def s1 (struct s \"one\" \"two\"))\n#'user/s1\n\nuser=> (println s1)\n{:1 \"one\", :2 \"two\"}\n\nuser=> (type s1)\nclojure.lang.PersistentStructMap\n\n;; create a new struct instance that is based on the previous struct type\n;; with the option of supplying a new key/value pairs\n(def s2 (struct-map s :3 \"three\"))\n#'user/s2\n\nuser=> (println s2)\n{:1 nil, :2 nil, :3 \"three\"}\n\nuser=> (type s2)\nclojure.lang.PersistentStructMap\n","created-at":1283401838000,"updated-at":1285488890000,"_id":"542692ccc026201cdc326c94"},{"updated-at":1473936902003,"created-at":1473936902003,"author":{"login":"PetrGlad","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/124476?v=3"},"body":";; Map -> struct\n(defstruct S :db)\n(into (struct-map S) {:db \"db\" :name \"Grut\"})","_id":"57da7e06e4b0709b524f04fa"}],"notes":null,"arglists":["s & inits"],"doc":"Returns a new structmap instance with the keys of the\n structure-basis. keyvals may contain all, some or none of the basis\n keys - where values are not supplied they will default to nil.\n keyvals can also contain keys not in the basis.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/struct-map"},{"added":"1.0","ns":"clojure.core","name":"drop","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1288872301000,"author":{"login":"jartur","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/8eae7b45fd8d383bc1a49e24bee51c9b?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"take","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521c99"},{"created-at":1288872352000,"author":{"login":"jartur","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/8eae7b45fd8d383bc1a49e24bee51c9b?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"drop-last","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521c9a"},{"created-at":1288872358000,"author":{"login":"jartur","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/8eae7b45fd8d383bc1a49e24bee51c9b?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"drop-while","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521c9b"},{"created-at":1306331554000,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"nthnext","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521c9c"},{"created-at":1356088859000,"author":{"login":"TimMc","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"nthrest","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521c9d"}],"line":2926,"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":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"body":";; although negative (or zero) drop-item-counts are accepted they do nothing\n(drop -1 [1 2 3 4])\n;;=> (1 2 3 4) \n\n(drop 0 [1 2 3 4])\n;;=> (1 2 3 4) \n\n(drop 2 [1 2 3 4])\n;;=> (3 4) \n\n;; dropping more items than are present is allowed, and all items are dropped.\n(drop 5 [1 2 3 4])\n;;=> ()","created-at":1280344844000,"updated-at":1420736258191,"_id":"542692cec026201cdc326da3"},{"body":";; similar to subvec but lazy and with seqs\n(take 3 (drop 5 (range 1 11)))\n;;=> (6 7 8)","author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"},"created-at":1420736116932,"updated-at":1420736116932,"_id":"54aeb674e4b081e022073bf2"}],"notes":null,"arglists":["n","n coll"],"doc":"Returns a laziness-preserving sequence of all but the first n items in coll.\n Returns a stateful transducer when no collection is provided.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/drop"},{"added":"1.4","ns":"clojure.core","name":"*data-readers*","file":"clojure/core.clj","type":"var","column":1,"see-alsos":[{"created-at":1618154998966,"author":{"login":"reborg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/20086?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"print-method","ns":"clojure.core"},"_id":"607315f6e4b0b1e3652d74c2"}],"dynamic":true,"line":7996,"examples":[{"updated-at":1618154693914,"created-at":1618154693914,"author":{"login":"reborg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/20086?v=4"},"body":"(import '[java.net URL])\n\n;; Teaching Clojure how to read URL objects from a string\n\n(binding [*data-readers* {'url #(URL. %)}] \n (read-string \"#url \\\"file:/etc/hosts\\\"\"))\n\n;; #object[java.net.URL 0x64a8c844 \"file:/etc/hosts\"]","_id":"607314c5e4b0b1e3652d74c1"}],"notes":[{"author":{"login":"rmoehn","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/311879?v=3"},"updated-at":1436316512612,"created-at":1436316512612,"body":"`clojure.edn/read` and `clojure.edn/read-string` don't look into\n`*data-readers*` in order to find the reader functions for a reader tag.\nThat's why they won't get the mappings from `data_readers.clj` either.\nSee the [note on `clojure.edn/read`](https://clojuredocs.org/clojure.edn/read)\nfor more information and a warning.","_id":"559c7360e4b00f9508fd66fa"},{"author":{"login":"raxod502","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/6559064?v=3"},"updated-at":1483727344008,"created-at":1483727344008,"body":"Note that if you're using `clojure.reader/read` instead of `clojure.core/read`, you have to bind `clojure.reader/*data-readers*` rather than `clojure.core/*data-readers*`.","_id":"586fe1f0e4b09108c8545a4a"}],"arglists":[],"doc":"Map from reader tag symbols to data reader Vars.\n\n When Clojure starts, it searches for files named 'data_readers.clj'\n and 'data_readers.cljc' at the root of the classpath. Each such file\n must contain a literal map of symbols, like this:\n\n {foo/bar my.project.foo/bar\n foo/baz my.project/baz}\n\n The first symbol in each pair is a tag that will be recognized by\n the Clojure reader. The second symbol in the pair is the\n fully-qualified name of a Var which will be invoked by the reader to\n parse the form following the tag. For example, given the\n data_readers.clj file above, the Clojure reader would parse this\n form:\n\n #foo/bar [1 2 3]\n\n by invoking the Var #'my.project.foo/bar on the vector [1 2 3]. The\n data reader function is invoked on the form AFTER it has been read\n as a normal Clojure data structure by the reader.\n\n Reader tags without namespace qualifiers are reserved for\n Clojure. Default reader tags are defined in\n clojure.core/default-data-readers but may be overridden in\n data_readers.clj, data_readers.cljc, or by rebinding this Var.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/*data-readers*"},{"added":"1.0","ns":"clojure.core","name":"nth","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1303125578000,"author":{"login":"Havvy","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"first","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d83"},{"created-at":1303125582000,"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":"542692ebf6e94c6970521d84"},{"created-at":1303125660000,"author":{"login":"Havvy","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/e799a79441c7543be48562403411cd13?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"nthnext","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d85"},{"created-at":1389744320000,"author":{"login":"jw0","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/ca45063da41a9f3aa9028295d8b66d89?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"get","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d86"},{"created-at":1544035070645,"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-nth","ns":"clojure.core"},"_id":"5c081afee4b0ca44402ef5dd"},{"created-at":1544035081114,"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":"nthrest","ns":"clojure.core"},"_id":"5c081b09e4b0ca44402ef5de"},{"created-at":1544035090445,"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":"5c081b12e4b0ca44402ef5df"}],"line":891,"examples":[{"updated-at":1433457696443,"created-at":1279417427000,"body":"; Note that nth uses zero-based indexing, so that\n; (first my-seq) <=> (nth my-seq 0)\n(def my-seq [\"a\" \"b\" \"c\" \"d\"])\n(nth my-seq 0)\n; => \"a\"\n(nth my-seq 1)\n; => \"b\"\n(nth [] 0)\n; => IndexOutOfBoundsException ...\n(nth [] 0 \"nothing found\")\n; => \"nothing found\"\n(nth [0 1 2] 77 1337)\n; => 1337","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/3272?v=3","account-source":"github","login":"morty"},{"avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3","account-source":"github","login":"Dimagog"},{"avatar-url":"https://avatars.githubusercontent.com/u/7083783?v=3","account-source":"github","login":"cloojure"}],"author":{"avatar-url":"https://avatars2.githubusercontent.com/u/22608?v=4","account-source":"github","login":"MrHus"},"_id":"542692cbc026201cdc326c10"},{"updated-at":1473696117507,"created-at":1473696117507,"author":{"login":"st-keller","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/476463?v=3"},"body":"(nth [\"last\"] -1 \"this is not perl\")\n; => \"this is not perl\"","_id":"57d6d175e4b0709b524f04f5"}],"notes":[{"author":{"login":"pesterhazy","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/106328?v=3"},"updated-at":1475067300924,"created-at":1475067300924,"body":"Rather than throwing an exception, `(nth nil n)` returns `nil` for any number `n`.","_id":"57ebbda4e4b0709b524f050f"},{"author":{"login":"beoliver","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/1413969?v=4"},"updated-at":1558362123119,"created-at":1558362123119,"body":"Floats are treated as indexes `(nth [0 1] 1.9)` returns the element at index `1`. At first glance it may seem as though they are always rounded down. However due to floating point precision `(nth [0 1] 1.9999999999999999)` will raise an `IndexOutOfBoundsException`.","_id":"5ce2b80be4b0ca44402ef727"}],"arglists":["coll index","coll index not-found"],"doc":"Returns the value at the index. get returns nil if index out of\n bounds, nth throws an exception unless not-found is supplied. nth\n also works for strings, Java arrays, regex Matchers and Lists, and,\n in O(n) time, for sequences.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/nth"},{"added":"1.0","ns":"clojure.core","name":"sorted?","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1281961844000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"sorted-map","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521af9"},{"created-at":1281961850000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"sorted-set","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521afa"}],"line":6312,"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=> (sorted? (sorted-set 5 3 1 2 4))\ntrue\nuser=> (sorted? (sorted-map :a 1 :c 3 :b 2))\ntrue\n\n;; Note you can't just pass in a collection that happens to be sorted.\nuser=> (sorted? [1 2 3 4 5])\nfalse\n","created-at":1281961832000,"updated-at":1285494525000,"_id":"542692c7c026201cdc326985"},{"author":{"login":"Alexey Tarasevich","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/43e0398b89022d32b43de4c968069312?r=PG&default=identicon"},"editors":[{"login":"Alexey Tarasevich","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/43e0398b89022d32b43de4c968069312?r=PG&default=identicon"}],"body":"=> (sorted? (sort [1 2]))\nfalse","created-at":1385847625000,"updated-at":1385847666000,"_id":"542692d5c026201cdc327097"}],"notes":null,"arglists":["coll"],"doc":"Returns true if coll implements Sorted","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/sorted_q"},{"added":"1.0","ns":"clojure.core","name":"nil?","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1365638069000,"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"identity","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521c87"},{"created-at":1431460678381,"author":{"login":"mmavko","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1064539?v=3"},"to-var":{"ns":"clojure.core","name":"some?","library-url":"https://github.com/clojure/clojure"},"_id":"55525b46e4b01ad59b65f4ce"}],"line":438,"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":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"}],"body":"user=> (nil? nil)\ntrue\nuser=> (nil? 0)\nfalse\nuser=> (nil? false)\nfalse\nuser=> (nil? '())\nfalse","created-at":1279074467000,"updated-at":1423017086496,"_id":"542692c6c026201cdc326943"},{"updated-at":1514329022413,"created-at":1509054633215,"author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/211644?v=4"},"body":";; as nil? is defined as \"Returns true if x is nil, false otherwise.\"\n;; and some? is defined as \"Returns true if x is not nil, false otherwise.\"\n\n;; (some? x) is just shorthand for (not (nil? x))\n;; this also means that nil? is the same as (not (some? x)) as this\n;; just expands into (not (not (nil? x))).\n\n(def nil?? (complement some?))\n;;#'user/nil??\n\n(for [x [nil 0 false [] '()]]\n (= (nil? x) (nil?? x)))\n;;=> (true true true true true)","editors":[{"avatar-url":"https://avatars2.githubusercontent.com/u/1413969?v=4","account-source":"github","login":"beoliver"},{"login":"phreed","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/211644?v=4"}],"_id":"59f258a9e4b0a08026c48c78"}],"notes":null,"tag":"java.lang.Boolean","arglists":["x"],"doc":"Returns true if x is nil, false otherwise.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/nil_q"},{"added":"1.2","ns":"clojure.core","name":"extend-protocol","file":"clojure/core_deftype.clj","type":"macro","column":1,"see-alsos":[{"created-at":1336670528000,"author":{"login":"Cosmi","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/10f2eae92de67116fa98d06ec55fcf29?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"extend","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521b0a"},{"created-at":1336670535000,"author":{"login":"Cosmi","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/10f2eae92de67116fa98d06ec55fcf29?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"extend-type","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521b0b"},{"created-at":1351471414000,"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":"542692eaf6e94c6970521b0c"}],"line":880,"examples":[{"updated-at":1489086655613,"created-at":1298553541000,"body":"(defprotocol XmlNode\n (as-xml [this]))\n\n(defrecord User [^Integer id ^String name ^java.util.Date dob])\n\n;; Protocols can be extended to existing types and user defined types\n(extend-protocol XmlNode\n Integer\n (as-xml [this] (str this))\n String\n (as-xml [this] (identity this))\n java.util.Date\n (as-xml [this] (-> (java.text.SimpleDateFormat. \"yyyy-MM-dd HH:mm:ss\")\n (.format this)))\n User\n (as-xml [this] (str \"\n(map {:a 1 :b 2 :c 3 :d 4} [:a :d])\n;;=> (1 4)\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":1307,"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":null,"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":7576,"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":null,"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":6251,"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"},{"updated-at":1731003583209,"created-at":1731003583209,"author":{"login":"lpasz","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/42593470?v=4"},"body":";; Will update the value by incrementing it\n(update {:a 1} :a (fn [value] (inc value)))\n;; => {:a 2}\n\n;; Will raise because there is no key with that value\n(update {} :a (fn [value] (inc value)))\n;; => Execution error (NullPointerException) at user/eval1 (REPL:1).\n;; Cannot invoke \"Object.getClass()\" because \"x\" is null \n\n;; In some languages update would provide a default value if none is found\n;; Map.update(map, key, default_value, function)\n;; Map.update(%{}, :a , 1 , & &1 + 1) => %{a: 1}\n\n;; But in Clojure, if no value is found nil is returned to the update function.\n;; So to fix that function we would need to\n(update {} :a (fn [value] (if value (inc value) 1)))\n;; => {:a 1}\n\n;; Other arguments at update level will just be passed along to your function\n\n(def dollar-rate 5.70)\n\n(defn add-funds-to-account [my-account amount coin]\n (update my-account\n :amount-in-brl\n (fn [curr-amount added-amount coin]\n (case coin\n :brl (+ added-amount curr-amount)\n :usd (+ (* dollar-rate added-amount) curr-amount))) \n amount \n coin))\n\n(add-funds-to-account {:amount-in-brl 10} 10 :brl)\n;; => {:amount-in-brl 20}\n(add-funds-to-account {:amount-in-brl 10} 10 :usd)\n;; => {:amount-in-brl 67.0} ","_id":"672d04bf69fbcc0c2261750d"}],"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":null,"line":650,"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 creates an object implementing a protocol or interface.\n 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 Method heads are recursion points for recur, as in a fn. The method\n bodies of reify are lexical closures, and can refer to the surrounding\n 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":6235,"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":null,"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":1820,"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":null,"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":null,"line":3972,"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":7217,"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":null,"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":2866,"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(let [regex #\"abc\"] (re-find regex \"abc\"))\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\n(let [regex \"abc\"] (re-find (re-pattern regex) \"abc\"))\n
","_id":"5648a221e4b053844439826f"}],"arglists":["m","re s"],"doc":"Returns the next regex match, if any, of string to pattern, using\n java.util.regex.Matcher.find(). Uses re-groups to return the\n groups.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/re-find"},{"added":"1.7","ns":"clojure.core","name":"run!","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1502125415874,"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":"doseq","ns":"clojure.core"},"_id":"59889d67e4b0d19c2ce9d70d"},{"created-at":1502125443214,"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":"map","ns":"clojure.core"},"_id":"59889d83e4b0d19c2ce9d70e"},{"created-at":1502125454691,"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":"mapv","ns":"clojure.core"},"_id":"59889d8ee4b0d19c2ce9d70f"}],"line":7902,"examples":[{"updated-at":1451663711803,"created-at":1451663490717,"author":{"login":"s-mage","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/2388396?v=3"},"body":"(run! prn (range 5))\n; 0\n; 1\n; 2\n; 3\n; 4\n; returns nil\n\n; compared to mapv\n(mapv prn (range 5))\n; 0 \n; 1 \n; 2 \n; 3 \n; 4 \n; returns [nil nil nil nil nil] ","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/2388396?v=3","account-source":"github","login":"s-mage"}],"_id":"5686a082e4b0e0706e05bd96"},{"editors":[{"login":"berczeck","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/1321842?v=4"}],"body":"(run! #(http-out-create-person! %) [{:name \"alex\" :country :peru} \n {:name \"eddu\" :country :peru}])\n\n; (http-out-create-person! {:name \"alex\" :country :peru})\n; (http-out-create-person! {:name \"eddu\" :country :peru})\n; nil","author":{"avatar-url":"https://avatars1.githubusercontent.com/u/1321842?v=4","account-source":"github","login":"berczeck"},"created-at":1598157184683,"updated-at":1598157582001,"_id":"5f41f180e4b0b1e3652d7394"}],"notes":null,"arglists":["proc coll"],"doc":"Runs the supplied procedure (via reduce), for purposes of side\n effects, on successive items in the collection. Returns nil","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/run!"},{"added":"1.0","ns":"clojure.core","name":"val","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1318590007000,"author":{"login":"mmwaikar","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"vals","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521efb"},{"created-at":1423522665421,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"key","library-url":"https://github.com/clojure/clojure"},"_id":"54d93b69e4b0e2ac61831d35"},{"created-at":1423522670342,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"keys","library-url":"https://github.com/clojure/clojure"},"_id":"54d93b6ee4b0e2ac61831d36"}],"line":1589,"examples":[{"updated-at":1434396569392,"created-at":1280777702000,"body":";; emulate 'vals'\n(map val {:a 1 :b 2})\n;;=> (1 2)\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":"542692c6c026201cdc3268cd"},{"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"body":"(val (first {:one :two}))\n;;=> :two","created-at":1288970694000,"updated-at":1434396586900,"_id":"542692c6c026201cdc3268cf"},{"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"editors":[],"body":";syntactic sugar for (val)\n(:doc (meta #'meta))","created-at":1288970885000,"updated-at":1288970885000,"_id":"542692c6c026201cdc3268d0"},{"body":";; extracts the key of a map entry\n(val (clojure.lang.MapEntry. :a :b))\n;;=> :b","author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"},"created-at":1434396268230,"updated-at":1434396268230,"_id":"557f266ce4b03e2132e7d193"}],"notes":[{"updated-at":1345454203000,"body":"This is my first attempt at using this site to gain an understanding of a closure function. Two of the examples above seem incorrect. \r\n\r\nExample 3(?) seems to have nothing to do with val \r\n\r\n(notice the lack of example identifiers)\r\n","created-at":1344320583000,"author":{"login":"dansalmo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/e33ee460f5f61bc5ba9b598934766215?r=PG&default=identicon"},"_id":"542692ecf6e94c6970521fe6"}],"arglists":["e"],"doc":"Returns the value in the map entry.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/val"},{"added":"1.0","ns":"clojure.core","name":"defonce","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1421928745226,"author":{"login":"Gitward","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8510849?v=3"},"to-var":{"ns":"clojure.core","name":"def","library-url":"https://github.com/clojure/clojure"},"_id":"54c0e929e4b081e022073c21"}],"line":5881,"examples":[{"author":{"login":"dakrone","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"},"editors":[],"body":"user> (defonce foo 5)\n#'user/foo\n\nuser> foo\n5\n\n;; defonce does nothing the second time\nuser> (defonce foo 10)\nnil\n\nuser> foo\n5","created-at":1293672804000,"updated-at":1293672804000,"_id":"542692cec026201cdc326dba"},{"updated-at":1468533299702,"created-at":1468533299702,"author":{"login":"DanBurton","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/713692?v=3"},"body":";; Supports ^:private\nuser=> (defonce ^:private foo 3)\n#'user/foo\nuser=> foo\n3\nuser=> (in-ns 'user2)\nuser2=> user/foo\n java.lang.IllegalStateException: var: user/foo is not public\n","_id":"57880a33e4b0bafd3e2a04a1"},{"updated-at":1599762924778,"created-at":1599762924778,"author":{"login":"luiszambon","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/41161270?v=4"},"body":"user> (def code {:clojure \"Yes\"})\n#'user/code\n\nuser> code\n{:clojure \"Yes\"}\n\n;; defonce will not be evaluated\nuser> (defonce code (+ 10 10))\nnil\n\nuser> code\n{:clojure \"Yes\"}","_id":"5f5a71ece4b0b1e3652d73b7"}],"macro":true,"notes":[{"updated-at":1385014731000,"body":"Note that this isn't thread safe. I.e. EXPR for the same NAME can be evaluated more than once.","created-at":1385014731000,"author":{"login":"lnostdal","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/a539e214c9980ff4b53ad5ca9347aa91?r=PG&default=identicon"},"_id":"542692edf6e94c697052200d"}],"arglists":["name expr"],"doc":"defs name to have the root value of the expr iff the named var has no root value,\n else expr is unevaluated","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/defonce"},{"added":"1.0","ns":"clojure.core","name":"unchecked-add","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1289215695000,"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":"542692eaf6e94c6970521b8a"},{"created-at":1289215703000,"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":"542692eaf6e94c6970521b8b"},{"created-at":1289215708000,"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":"542692eaf6e94c6970521b8c"},{"created-at":1289215717000,"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":"542692eaf6e94c6970521b8d"},{"created-at":1289215722000,"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":"542692eaf6e94c6970521b8e"},{"created-at":1289215736000,"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":"542692eaf6e94c6970521b8f"},{"created-at":1289215741000,"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":"542692eaf6e94c6970521b90"},{"created-at":1423522050658,"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":"54d93902e4b0e2ac61831d2b"},{"created-at":1423522057832,"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":"54d93909e4b0e2ac61831d2c"}],"line":1212,"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":";; can't interchange INTs with LONGs, only F(int, int) or F(long, long)\n;; F is a function, not an operator.\n;; overflow very easily as shown below.\n\nuser=> (unchecked-add Integer/MAX_VALUE 0)\n2147483647\n\nuser=> (unchecked-add Integer/MAX_VALUE 1)\n-2147483648\n\nuser=> (unchecked-add Integer/MAX_VALUE Integer/MAX_VALUE)\n-2\n\nuser=> (unchecked-add Integer/MAX_VALUE Long/MAX_VALUE)\njava.lang.IllegalArgumentException: No matching method found: unchecked_add (NO_SOURCE_FILE:0)\n\nuser=> (unchecked-add Integer/MAX_VALUE Long/MAX_VALUE)\njava.lang.IllegalArgumentException: No matching method found: unchecked_add (NO_SOURCE_FILE:0)\n\nuser=> (unchecked-add Long/MAX_VALUE Long/MAX_VALUE)\n-2\n\nuser=> (unchecked-add 5 Long/MAX_VALUE)\njava.lang.IllegalArgumentException: No matching method found: unchecked_add (NO_SOURCE_FILE:0)\n\nuser=> (unchecked-add 5555555555 Long/MAX_VALUE)\n-9223372031299220254","created-at":1289215507000,"updated-at":1289267828000,"_id":"542692c9c026201cdc326ac9"}],"notes":null,"arglists":["x y"],"doc":"Returns the sum of x and y, both long.\n Note - uses a primitive operator subject to overflow.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/unchecked-add"},{"added":"1.0","ns":"clojure.core","name":"loaded-libs","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":6167,"examples":[{"editors":[{"login":"reborg","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4"}],"body":";; Show the list of loaded libs (files named after the \"ns\"\n;; declaration they contain) and created namespaces (\"ns\" only). \n;; \"ns\" side effects into loaded-libs, \"create-ns\" (or \"in-ns\") does not:\n\n(ns a)\n(ns b) \n(every? (loaded-libs) ['a 'b])\n;; true\n\n(create-ns 'x)\n(create-ns 'y)\n(not-every? (loaded-libs) ['x 'y])\n;; true","author":{"avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4","account-source":"github","login":"reborg"},"created-at":1546097021308,"updated-at":1546097304134,"_id":"5c27917de4b0ca44402ef604"}],"notes":[{"author":{"login":"reborg","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4"},"updated-at":1546099777305,"created-at":1546099777305,"body":"Trivia: the concept of \"library\" goes all the way back to Clojure contrib and was initially inspired by other packaging systems (it was even named \"Jewels\" at some point, possibly inspired by Ruby Gems). Check the following:\n\n* https://groups.google.com/d/msg/clojure/fjDJfAsxwRo/-5hE4yDMVTQJ\n* https://github.com/clojure/clojure-contrib/blob/da367723d33b20cb89e4aac7dc4221a0138c2f8f/jewel.clj","_id":"5c279c41e4b0ca44402ef606"}],"arglists":[""],"doc":"Returns a sorted set of symbols naming the currently loaded libs","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/loaded-libs"},{"ns":"clojure.core","name":"->Vec","file":"clojure/gvec.clj","type":"function","column":1,"see-alsos":null,"line":170,"examples":null,"notes":null,"arglists":["am cnt shift root tail _meta"],"doc":"Positional factory function for class clojure.core.Vec.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/->Vec"},{"added":"1.9","ns":"clojure.core","name":"bytes?","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1495728541051,"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-array","ns":"clojure.core"},"_id":"5927019de4b093ada4d4d76d"},{"created-at":1495728555435,"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":"bytes","ns":"clojure.core"},"_id":"592701abe4b093ada4d4d76e"}],"line":5441,"examples":[{"updated-at":1495728500906,"created-at":1495728500906,"author":{"login":"svenschoenung","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/10583730?v=3"},"body":";;;; Returns true for byte[] arrays:\n\n(bytes? (.getBytes \"foo\"))\n;;=> true\n(bytes? (byte-array [102 111 111]))\n;;=> true\n\n;;;; Returns false for Byte[] arrays:\n\n(bytes? (to-array (map byte [102 111 111])))\n;;=> false","_id":"59270174e4b093ada4d4d76c"}],"notes":null,"arglists":["x"],"doc":"Return true if x is a byte array","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/bytes_q"},{"added":"1.0","ns":"clojure.core","name":"not","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1301366612000,"author":{"login":"pauldoo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5cb916d3c8abc9f45a093209e72489fb?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"complement","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521dd8"},{"created-at":1375213332000,"author":{"login":"alilee","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/2fb0196dc5a7cd3a5cc73f1b9941c209?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"false?","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521dd9"}],"line":526,"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":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"}],"body":"user=> (not true)\nfalse\nuser=> (not false)\ntrue\nuser=> (not nil)\ntrue\n\n;; acts as complement of `boolean`\nuser=> (boolean \"a string\")\ntrue\nuser=> (not \"a string\")\nfalse\nuser=> (boolean 1)\ntrue\nuser=> (not 1)\nfalse","created-at":1280323469000,"updated-at":1422932403041,"_id":"542692cfc026201cdc326e64"},{"updated-at":1475631952638,"created-at":1475631952638,"author":{"login":"aakoch","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/137713?v=3"},"body":"user=> (not (= \"a\" \"b\"))\ntrue","_id":"57f45b50e4b0709b524f0520"}],"notes":null,"tag":"java.lang.Boolean","arglists":["x"],"doc":"Returns true if x is logical false, false otherwise.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/not"},{"added":"1.0","ns":"clojure.core","name":"with-meta","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1301486163000,"author":{"login":"ninjudd","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/7ced25585a7556e9b9b975c1f9e136e3?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"vary-meta","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d5e"},{"created-at":1341551175000,"author":{"login":"jgauthier","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/e8668403f9cac4041a106e57e8037dff?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"meta","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521d5f"},{"created-at":1374315863000,"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":"542692ebf6e94c6970521d60"}],"line":213,"examples":[{"updated-at":1285495834000,"created-at":1280776037000,"body":"user=> (with-meta [1 2 3] {:my \"meta\"})\n[1 2 3]\n\nuser=> (meta (with-meta [1 2 3] {:my \"meta\"}))\n{:my \"meta\"}\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":"542692c8c026201cdc326a41"},{"author":{"login":"mmwaikar","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/29d36f4c9f39c9f8ff61c07033b13118?r=PG&default=identicon"},"editors":[],"body":";; the same example above in a simplified way\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\"}","created-at":1359717828000,"updated-at":1359717828000,"_id":"542692d6c026201cdc3270ba"},{"editors":[{"login":"Rovanion","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/632775?v=4"}],"body":";; Trying to attach meta data to nil with throw an exception\n(with-meta nil {:my \"meta\"})\n;; Unhandled java.lang.NullPointerException\n\n;; It also only works for Clojure data types implementing clojure.lang.IObj\n(require '[clojure.java.io :as io])\n(with-meta (io/file \".\") {:my \"meta\"})\n;; Unhandled java.lang.ClassCastException\n;; java.io.File cannot be cast to clojure.lang.IObj\n","author":{"avatar-url":"https://avatars2.githubusercontent.com/u/632775?v=4","account-source":"github","login":"Rovanion"},"created-at":1546960387304,"updated-at":1546960610725,"_id":"5c34be03e4b0ca44402ef616"},{"updated-at":1603447088199,"created-at":1603446774741,"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 \n;; dynamic variable whose value is a function.\n\n(defmacro dyn-fun [name lambda-list & body] ;; WRONG\n `(def ^:dynamic ~name (fn ~lambda-list ~@body)))\n\n;; The macro should be written something like the following.\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":"5f92a7f6e4b0b1e3652d73e7"}],"notes":[{"author":{"login":"beoliver","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/1413969?v=4"},"updated-at":1558365596405,"created-at":1558365596405,"body":"The Clojure documentation states that \"metadata does not impact equality (or hash codes). Two objects that differ only in metadata are equal.\" One should be aware that while a function can be compared to itself:\n```\n(defn foo [x] (+ x x))\n```\ntesting equality\n```\n> (= foo foo)\ntrue\n> (= (with-meta foo {:hello :world}) foo)\nfalse\n> (= (with-meta foo {}) foo)\nfalse\n```\n","_id":"5ce2c59ce4b0ca44402ef728"}],"arglists":["obj m"],"doc":"Returns an object of the same type and value as obj, with\n map m as its metadata.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/with-meta"},{"added":"1.7","ns":"clojure.core","name":"unreduced","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1456683860012,"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":"56d33b54e4b02a6769b5a4b7"},{"created-at":1456683872206,"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":"56d33b60e4b02a6769b5a4b8"},{"created-at":1456683877778,"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":"56d33b65e4b02a6769b5a4b9"},{"created-at":1464286441935,"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":"57473ce9e4b0bafd3e2a045e"}],"line":2872,"examples":[{"updated-at":1456683816266,"created-at":1456683816266,"author":{"login":"svenschoenung","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/10583730?v=3"},"body":"(unreduced :foo)\n;;=> :foo\n\n(unreduced (reduced :foo))\n;;=> :foo\n\n(unreduced (clojure.lang.Reduced. :foo))\n;;=> :foo","_id":"56d33b28e4b0b41f39d96cd8"},{"editors":[{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"}],"body":";; Transducers have a \"completing arity\" which is called at the end of the\n;; reduction to finalize the output. This is done outside of the normal\n;; reduction loop, so there is nothing to unwrap a reduced return value, should\n;; the reducing function be called from the completing arity and happen to wrap\n;; the return in a Reduced:\n\n(defn conj-till-odd\n ([coll] coll)\n ([coll x] (cond-> (conj coll x) (odd? x) reduced)))\n\n(defn inc-nums+7 [rf]\n (fn new-rf\n ([result] (rf result 7)) ; A bit contrived, but makes the point\n ([result x] (rf result (inc x)))))\n\n(transduce inc-nums+7 conj-till-odd [] [1 3 5 7 9])\n;; => #\r\n(= (zipmap (keys m) (vals m)) m)\r\n
","created-at":1385457081000,"author":{"login":"akhudek","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/aaf21f137b69cc5154c8afb29b793e18?r=PG&default=identicon"},"_id":"542692edf6e94c6970522011"}],"arglists":["map"],"doc":"Returns a sequence of the map's values, in the same order as (seq map).","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/vals"},{"added":"1.0","ns":"clojure.core","name":"unchecked-subtract","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1289216526000,"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":"542692eaf6e94c6970521b98"},{"created-at":1289216530000,"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":"542692eaf6e94c6970521b99"},{"created-at":1289216535000,"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":"542692eaf6e94c6970521b9a"},{"created-at":1289216540000,"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":"542692eaf6e94c6970521b9b"},{"created-at":1289216544000,"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":"542692eaf6e94c6970521b9c"},{"created-at":1289216549000,"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":"542692eaf6e94c6970521b9d"},{"created-at":1289216555000,"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":"542692eaf6e94c6970521b9e"},{"created-at":1289216559000,"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":"542692eaf6e94c6970521b9f"},{"created-at":1423522496433,"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":"54d93ac0e4b0e2ac61831d33"},{"created-at":1423522501593,"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":"54d93ac5e4b081e022073c77"}],"line":1226,"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"},{"login":"reborg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/20086?v=3"}],"body":";; can't interchange INTs with LONGs, only F(int, int) or F(long, long)\n;; F is a function, not an\n;; overflow very easily as shown below.\n\n(unchecked-subtract Long/MIN_VALUE 5555555554)\nuser=> 9223372031299220254\n\n;; it promotes to long\n(unchecked-subtract Long/MIN_VALUE (int 1))\nuser=> 9223372036854775807\n\n(unchecked-subtract Integer/MIN_VALUE Long/MIN_VALUE)\nuser=> 9223372034707292160\n\n(unchecked-subtract Long/MIN_VALUE Long/MIN_VALUE)\nuser=> 0\n\n(unchecked-subtract Integer/MIN_VALUE Integer/MIN_VALUE)\nuser=> 0\n\n(unchecked-subtract Integer/MIN_VALUE 0)\nuser=> -2147483648\n\n;; Again, promote to long\n(unchecked-subtract Integer/MIN_VALUE 1)\nuser=> -2147483649\n\n;; To prevent long promotion, see unchecked-subtract-int ","created-at":1289216520000,"updated-at":1418679203559,"_id":"542692cac026201cdc326b46"}],"notes":null,"arglists":["x y"],"doc":"Returns the difference of x and y, both long.\n Note - uses a primitive operator subject to overflow.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/unchecked-subtract"},{"added":"1.10","ns":"clojure.core","name":"tap>","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1590688347515,"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":"5ecffa5be4b087629b5a1917"},{"created-at":1590688354528,"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":"5ecffa62e4b087629b5a1918"}],"line":8124,"examples":[{"updated-at":1590688330192,"created-at":1590688330192,"author":{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/109629?v=4"},"body":";; For a bit more documentation, see Clojure 1.10.0 release notes regarding\n;; tap> here:\n\n;; https://github.com/clojure/clojure/blob/master/changes.md#23-tap","_id":"5ecffa4ae4b087629b5a1916"},{"editors":[{"login":"cloojure","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7083783?v=4"}],"body":";; Register a tap handler\n\n(add-tap (bound-fn* clojure.pprint/pprint))\n\n;; Log using the above handler\n\n(tap> \"Hello world\")","author":{"avatar-url":"https://avatars.githubusercontent.com/u/1250807?v=4","account-source":"github","login":"maxthoursie"},"created-at":1630499566267,"updated-at":1638836325268,"_id":"612f72eee4b0b1e3652d7538"},{"updated-at":1685388563826,"created-at":1685388468155,"author":{"login":"cloped","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/25209410?v=4"},"body":";; Using tap but returning initial content\n(defn major-champs [] [{:team-name \"SK\"}\n {:team-name \"LG\"}])\n\n(doto (major-champs)\n (tap>))\n;;=> [{:team-name \"SK\"} {:team-name \"LG\"}]","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/25209410?v=4","account-source":"github","login":"cloped"}],"_id":"6474fcb4e4b08cf8563f4bc4"}],"notes":[{"author":{"login":"Crowbrammer","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/19522656?v=4"},"updated-at":1651676980432,"created-at":1651676980432,"body":"`tap>` is a primary tool in the [Portal](https://github.com/djblue/portal) library. ","_id":"62729734e4b0b1e3652d75e6"}],"arglists":["x"],"doc":"sends x to any taps. Will not block. Returns true if there was room in the queue,\n false if not (dropped).","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/tap>"},{"added":"1.0","ns":"clojure.core","name":"*warn-on-reflection*","type":"var","see-alsos":[{"created-at":1441815046413,"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":"*unchecked-math*","ns":"clojure.core"},"_id":"55f05a06e4b06a9ffaad4fb9"}],"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"},{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"}],"body":";; define two variables then set *warn-on-reflection* to true and try to call\n;; one of their Java methods. Warnings are generated in both cases\n;; set *warn-on-reflection* to false and note that you can call both functions\n;; without a warning\n\nuser=> (def i 23)\n#'user/i\nuser=> (def s \"123\")\n#'user/s\nuser=> (set! *warn-on-reflection* true)\ntrue\nuser=> (.toString i)\nReflection warning, NO_SOURCE_PATH:4 - reference to field toString can't be resolved.\n\"23\"\nuser=> (.toString s)\nReflection warning, NO_SOURCE_PATH:5 - reference to field toString can't be resolved.\n\"123\"\n\n;; Reflection (and hence reflection warnings) could be removed by giving type hints:\nuser=> (.toString ^String s)\n\"123\"\n\nuser=> (set! *warn-on-reflection* false)\nfalse\nuser=> (.toString i)\n\"23\"\nuser=> (.toString s)\n\"123\"\nuser=>","created-at":1313969775000,"updated-at":1423526770411,"_id":"542692c9c026201cdc326a80"},{"updated-at":1672450302873,"created-at":1672450302873,"author":{"login":"randomizedthinking","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/5283430?v=4"},"body":"(set! *warn-on-reflection* true) ;; turn on *warn-on-reflection*\n(def s \"abc\") ;; define s\n(.toString s) ;; => \"abc\"; WARN: type of s is unknown\n(.toString ^String s) ;; => \"abc\"; no warn given the type hint\n(let [s \"abc\"] (.toString s)) ;; => \"abc\"; no warn since Clojure can infer\n ;; type for the local binding\n(set! *warn-on-reflection* false) ;; turn off *warn-on-reflection*\n","_id":"63af90fee4b08cf8563f4b57"},{"updated-at":1672450954887,"created-at":1672450954887,"author":{"login":"randomizedthinking","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/5283430?v=4"},"body":";; Important to note *warn-on-reflection* take its effect at compile time,\n;; so binding the option won't work... even with a set! inside.\n;; - binding creates a new env to evaluate subsequent statements\n;; - yet, compiler still lives in the current env, so it won't see the value\n\n(binding [*warn-on-reflection* true]\n (set! *warn-on-reflection* true)\n (def s \"abc\")\n (.toString s)) ;; => \"abc\", no warning\n(println *warn-on-reflection*) ;; => false\n","_id":"63af938ae4b08cf8563f4b58"}],"notes":null,"arglists":[],"doc":"When set to true, the compiler will emit warnings when reflection is\n needed to resolve Java method calls or field accesses.\n\n Defaults to false.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/*warn-on-reflection*"},{"added":"1.1","ns":"clojure.core","name":"sorted-set-by","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1317095652000,"author":{"login":"pauldoo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5cb916d3c8abc9f45a093209e72489fb?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"sorted-set","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521e50"},{"created-at":1353458232000,"author":{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"},"to-var":{"ns":"clojure.core","name":"sorted-map-by","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521e51"},{"created-at":1353822010000,"author":{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"},"to-var":{"ns":"clojure.core","name":"compare","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521e52"}],"line":427,"examples":[{"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"editors":[],"body":"user> (sorted-set-by > 3 5 8 2 1)\n#{8 5 3 2 1}","created-at":1286955847000,"updated-at":1286955847000,"_id":"542692cdc026201cdc326ccc"},{"updated-at":1548548862480,"created-at":1353462397000,"body":";; Be cautious about comparison functions that only compare part of\n;; the objects:\nuser=> (defn second-< [x y]\n (< (second x) (second y)))\nuser=> (sorted-set-by second-< [:a 1] [:b 1] [:c 1])\n#{[:a 1]}\n\n;; Where did the other elements go?\n\n;; Replacing < with <= might look like a fix, but doesn't work,\n;; either:\nuser=> (defn second-<= [x y]\n (<= (second x) (second y)))\nuser=> (def s2 (sorted-set-by second-<= [:a 1] [:b 1] [:c 1]))\n#'user/s2\nuser=> s2\n#{[:c 1] [:b 1] [:a 1]}\n;; So far, so good, but set membership tests can't find the elements.\nuser=> (contains? s2 [:b 1])\nfalse\nuser=> (s2 [:c 1])\nnil\n\n;; Here is one way to write a good comparison function. When the two\n;; objects are equal in the parts we care about, use the tie-breaker\n;; 'compare' on the whole values to give them a consistent order that\n;; is only equal if the entire values are equal.\nuser=> (defn second-<-with-tie-break [x y]\n (let [c (compare (second x) (second y))]\n (if (not= c 0)\n c\n ;; Otherwise we don't care as long as ties are broken\n ;; consistently.\n (compare x y))))\nuser=> (def s3 (sorted-set-by second-<-with-tie-break [:a 1] [:b 1] [:c 1]))\n#'user/s3\nuser=> s3\n#{[:a 1] [:b 1] [:c 1]}\nuser=> (contains? s3 [:b 1])\ntrue\nuser=> (s3 [:c 1])\n[:c 1]\n;; All good now!\n\n;; See this article for more details: https://clojure.org/guides/comparators","editors":[{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/109629?v=4"}],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3","account-source":"github","login":"jafingerhut"},"_id":"542692d5c026201cdc327096"},{"updated-at":1533310624576,"created-at":1533310624576,"author":{"login":"reborg","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4"},"body":";; Another custom comparator example.\n;; sorted-set of colls by size descending, then normal coll equality:\n\n(sorted-set-by \n (fn [x y] (compare [(count y) x] [(count x) y]))\n [3 :a] [:b] [1 :c] [:v] [:a])\n\n;; #{[1 :c] [3 :a] [:a] [:b] [:v]}","_id":"5b6476a0e4b00ac801ed9e47"}],"notes":null,"arglists":["comparator & keys"],"doc":"Returns a new sorted set with supplied keys, using the supplied\n comparator. Any equal keys are handled as if by repeated uses of\n conj.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/sorted-set-by"},{"added":"1.0","ns":"clojure.core","name":"sync","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1285922313000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"dosync","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521c4a"}],"line":2515,"examples":null,"macro":true,"notes":[{"updated-at":1285922372000,"body":"Same as dosync but allows for extra options (which are not currently supported). Probably best to use dosync instead at the moment.","created-at":1285922372000,"author":{"login":"gstamp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/cd4185cdca53ccdc11cd24ebc0cfb46d?r=PG&default=identicon"},"_id":"542692ecf6e94c6970521f97"}],"arglists":["flags-ignored-for-now & body"],"doc":"transaction-flags => TBD, pass nil for now\n\n Runs the exprs (in an implicit do) in a transaction that encompasses\n exprs and any nested calls. Starts a transaction if none is already\n running on this thread. Any uncaught exception will abort the\n transaction and flow out of sync. The exprs may be run more than\n once, but any effects on Refs will be atomic.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/sync"},{"added":"1.9","ns":"clojure.core","name":"qualified-ident?","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1495714973950,"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":"ident?","ns":"clojure.core"},"_id":"5926cc9de4b093ada4d4d759"},{"created-at":1495714979401,"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-ident?","ns":"clojure.core"},"_id":"5926cca3e4b093ada4d4d75a"},{"created-at":1596595698804,"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":"qualified-symbol?","ns":"clojure.core"},"_id":"5f2a1df2e4b0b1e3652d736e"},{"created-at":1596595706676,"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":"qualified-keyword?","ns":"clojure.core"},"_id":"5f2a1dfae4b0b1e3652d736f"}],"line":1637,"examples":[{"updated-at":1596596073730,"created-at":1596596073730,"author":{"login":"wdhowe","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/4631165?v=4"},"body":"(qualified-ident? 'clojure.core/asymbol)\n;;=> true\n\n(qualified-ident? ::akeyword)\n;;=> true\n\n(qualified-ident? 'asymbol)\n;;=> false\n\n(qualified-ident? :akeyword)\n;;=> false\n\n(qualified-ident? \"hello\")\n;;=> false\n\n(qualified-ident? 7)\n;;=> false\n\n(qualified-ident? nil)\n;;=> false","_id":"5f2a1f69e4b0b1e3652d7370"}],"notes":null,"arglists":["x"],"doc":"Return true if x is a symbol or keyword with a namespace","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/qualified-ident_q"},{"added":"1.0","ns":"clojure.core","name":"assert","file":"clojure/core.clj","type":"macro","column":1,"see-alsos":[{"created-at":1538056745370,"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":"assert","ns":"clojure.spec.alpha"},"_id":"5bace229e4b00ac801ed9eaa"}],"line":4866,"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"}],"body":"user=> (assert true)\nnil\n\nuser=> (assert false)\njava.lang.AssertionError: Assert failed: false (NO_SOURCE_FILE:0)\n\nuser=> (assert nil)\njava.lang.AssertionError: Assert failed: nil (NO_SOURCE_FILE:0)\n\nuser=> (assert 0)\nnil\n\nuser=> (assert [1 2 3])\nnil\n\nuser=> (assert \"foo\")\nnil","created-at":1280547946000,"updated-at":1285496150000,"_id":"542692cac026201cdc326aff"},{"body":";; Messages can help you track down what went wrong.\nuser=> (assert (= 5 (+ 2 2)) \"There are four lights!\")\n\nAssertionError Assert failed: There are four lights!","author":{"login":"jakebasile","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/766907?v=2"},"created-at":1412964928037,"updated-at":1412964928037,"_id":"54382240e4b0ae7956031582"},{"updated-at":1704391970105,"created-at":1704391970105,"author":{"login":"sofiiahitlan","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/48576209?v=4"},"body":";; AssertionError isn't an Exception so it should be caught properly:\nuser=> (try\n (let [some-with-cond? (fn [el]\n {:pre [(some? el)]}\n (some? el))]\n (some-with-cond? nil))\n (catch AssertionError e \"AssertionError caught.\"))\n\nAssertionError caught.\n\n;; catch Exception wouldn't work:\nuser=> (try\n (let [some-with-cond? (fn [el]\n {:pre [(some? el)]}\n (some? el))]\n (some-with-cond? nil))\n (catch Exception e \"AssertionError caught.\"))\n\nExecution error (AssertionError) at loaders.core/eval26824$some-with-cond? (form-init14472288491470508923.clj:5587).\nAssert failed: (some? el)","_id":"6596f52269fbcc0c2261747e"}],"macro":true,"notes":[{"updated-at":1372297439000,"body":"The documentation (\"... and throws an exception if ...\") is incorrect. It throws AssertionError which an Error and not an Exception. They both extend Throwable but Error is not an Exception.","created-at":1372297439000,"author":{"login":"Steve Kuo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/160d6580f280b5e9e5a1188b32c4ef2d?r=PG&default=identicon"},"_id":"542692edf6e94c6970522007"},{"body":"By default, assertions are turned on, since the value of `*assert*` defaults to true in Clojure.","created-at":1571604965857,"updated-at":1571606716980,"author":{"avatar-url":"https://avatars3.githubusercontent.com/u/601540?v=4","account-source":"github","login":"didibus"},"_id":"5dacc9e5e4b0ca44402ef7cf"},{"body":"in [shadow-cljs](https://shadow-cljs.github.io/docs/UsersGuide.html#compiler-options), All assertions are removed in `release` mode by default. In other words, *assert* is false in release mode. (see `:elide-asserts` option) It is applied to schema libraries like malli, `malli.core/assert` is removed on release mode.\n\n","created-at":1757391428304,"updated-at":1757391451899,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/160077355?v=4","account-source":"github","login":"taehee-kim-sherpas"},"_id":"68bfaa44cd84df5de54e2095"}],"arglists":["x","x message"],"doc":"Evaluates expression x and throws an AssertionError with optional\n message if x does not evaluate to logical true.\n\n Assertion checks are omitted from compiled code if '*assert*' is\n false.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/assert"},{"added":"1.0","ns":"clojure.core","name":"*compile-path*","type":"var","see-alsos":null,"examples":[{"updated-at":1615140201244,"created-at":1613936568196,"author":{"login":"reborg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/20086?v=4"},"body":";; Assuming \"mypath\" exists on disk, the following AOT-compiles any form\n;; inside \"eval\" into the folder specified by \"*compile-path*\".\n\n(binding [*compile-files* true \n *compile-path* \"mypath\"]\n (eval '(+ 1 1)))\n;; 2","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/20086?v=4","account-source":"github","login":"reborg"}],"_id":"6032b7b8e4b0b1e3652d7461"}],"notes":null,"arglists":[],"doc":"Specifies the directory where 'compile' will write out .class\n files. This directory must be in the classpath for 'compile' to\n work.\n\n Defaults to \"classes\"","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/*compile-path*"},{"added":"1.0","ns":"clojure.core","name":"true?","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1303250769000,"author":{"login":"TimMc","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/5d532e51427ef2f4ded31aaca16c8baf?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"false?","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521da5"},{"created-at":1420558589659,"author":{"login":"kappa","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/47310?v=3"},"to-var":{"ns":"clojure.core","name":"boolean","library-url":"https://github.com/clojure/clojure"},"_id":"54ac00fde4b04e93c519ffb5"}],"line":514,"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=> (true? true)\ntrue\nuser=> (true? 1)\nfalse\nuser=> (true? (= 1 1))\ntrue","created-at":1279075280000,"updated-at":1332951307000,"_id":"542692c7c026201cdc32699f"},{"updated-at":1651781147567,"created-at":1651781147567,"author":{"login":"starain31","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/6347630?v=4"},"body":"user=> (true? false)\nfalse","_id":"62742e1be4b0b1e3652d75e7"}],"notes":null,"tag":"java.lang.Boolean","arglists":["x"],"doc":"Returns true if x is the value true, false otherwise.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/true_q"},{"added":"1.0","ns":"clojure.core","name":"release-pending-sends","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":null,"line":2150,"examples":[{"updated-at":1553649905128,"created-at":1553649905128,"author":{"login":"reborg","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/20086?v=4"},"body":";; release-pending-sends makes sense when an agent produces\n;; additional actions and there is no need to wait for the update\n;; of the current agent's state.\n\n(require '[clojure.string :refer [split]])\n(def alpha (mapv agent (repeat 26 0))) ; one for each letter of the alphabet\n(def others (agent 0))\n(def words (agent {}))\n\n(def war-and-peace \"http://www.gutenberg.org/files/2600/2600-0.txt\")\n(def book (slurp war-and-peace)) ; a large book\n\n(send-off words\n (fn [state]\n (doseq [letter book\n :let [l (Character/toLowerCase letter)\n idx (- (int l) (int \\a))]] ; get the index of the correct agent\n (send (get alpha idx others) inc)) ; send an increment for each letter\n (release-pending-sends) ; release those sends\n (merge-with + state ; move on to calculate word frequencies\n (frequencies (split book #\"\\s+\")))))\n\n(apply await alpha) ; give it some time\n(map deref alpha) ; see each letter frequency in the book\n;; (202719 34657 61621 118297 313572\n;; 54901 51327 167415 172257 2575 20432\n;; 96530 61648 184185 190083 45533 2331\n;; 148431 162897 226414 64400 27087\n;; 59209 4384 46236 2388)\n","_id":"5c9ad0f1e4b0ca44402ef6e0"}],"notes":null,"arglists":[""],"doc":"Normally, actions sent directly or indirectly during another action\n are held until the action completes (changes the agent's\n state). This function can be used to dispatch any pending sent\n actions immediately. This has no impact on actions sent during a\n transaction, which are still held until commit. If no action is\n occurring, does nothing. Returns the number of actions dispatched.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/release-pending-sends"},{"added":"1.0","ns":"clojure.core","name":"print","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1290672979000,"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":"542692ebf6e94c6970521ca4"},{"created-at":1374264324000,"author":{"login":"lbeschastny","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/416170465e4045f810f09a9300dda4dd?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"println","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ca5"},{"created-at":1374264330000,"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":"542692ebf6e94c6970521ca6"},{"created-at":1518042801277,"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":"pprint","ns":"clojure.pprint"},"_id":"5a7b7eb1e4b0316c0f44f8ab"},{"created-at":1565163732742,"author":{"login":"bbatsov","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/103882?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"printf","ns":"clojure.core"},"_id":"5d4a80d4e4b0ca44402ef792"},{"created-at":1565163762897,"author":{"login":"bbatsov","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/103882?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"println-str","ns":"clojure.core"},"_id":"5d4a80f2e4b0ca44402ef793"}],"line":3750,"examples":[{"author":{"login":"dakrone","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bcacd00a7f05c4772329cf9f446c7987?r=PG&default=identicon"},"editors":[],"body":";; same as println, but without a newline\nuser> (print \"foo\") (print \"foo\")\nfoofoo","created-at":1293674014000,"updated-at":1293674014000,"_id":"542692c8c026201cdc326a67"},{"updated-at":1638001638376,"created-at":1638001638376,"author":{"login":"owenRiddy","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8080718?v=4"},"body":";; Output only flushes when there is a newline. It is likely that (print)\n;; will be seen in the company of (flush).\n\n;; Buggy case. Wants to print a prompt character, but it doesn't appear.\n(print \"> \") ;; This doesn't work,\n(readline)\n\n;; Working case. The output can be flushed this way.\n(print \"> \")\n(flush)\n(readline)","_id":"61a1ebe6e4b0b1e3652d757b"},{"updated-at":1668538912352,"created-at":1668538912352,"author":{"login":"slk500","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/13615024?v=4"},"body":"(print \"foo\" \"foo\")\n;; => foo foo","_id":"6373e220e4b0b1e3652d7682"}],"notes":[{"author":{"login":"jcburley","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/430319?v=4"},"updated-at":1514410810601,"created-at":1514410810601,"body":"\"Human consumption\" means, for example, that a string is printed as-is -- without surrounding double quotes and without nonprinting characters being escaped.","_id":"5a44133ae4b0a08026c48ce1"}],"arglists":["& more"],"doc":"Prints the object(s) to the output stream that is the current value\n of *out*. print and println produce output for human consumption.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/print"},{"added":"1.0","ns":"clojure.core","name":"empty","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1311798862000,"author":{"login":"OnesimusUnbound","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/2fa4c391db0d2d1744cc2cd0d787dd3d?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"not-empty","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521caf"},{"created-at":1435246081050,"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":"558c1e01e4b0fad27b85f925"}],"line":5294,"examples":[{"updated-at":1422931647361,"created-at":1280319600000,"body":"(empty '(1 2)) ;; => ()\n(empty [1 2]) ;; => []\n(empty {1 2}) ;; => {}\n(empty #{1 2}) ;; => #{}\n\n;; Works for PersistentQueue as well, which is slightly harder to see\n(def q (conj clojure.lang.PersistentQueue/EMPTY 1))\n;; => #'user/q\nq\n;; => #\n(defn testme [] \n (let [twice (fn [x] (* x 2))\n six-times (fn [y] (* (twice y) 3))] \n (println \"15x6=\" (six-times 15))))\n
\n\nBut this one for instance doesn't compile (and would be ok with letfn):\n\n\n(defn testme [] \n (let [twelve-times (fn [x] (* (six-times x) 2)) \n six-times (fn [y] (* y 6))] \n (println \"2x12=\" (twelve-times 2))))\n
\n","created-at":1428350072457,"updated-at":1428350719864,"author":{"login":"reborg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/20086?v=3"},"_id":"5522e478e4b033f34014b766"},{"body":"\n(letfn [(six-times [y]\n (* (twice y) 3))\n (twice [x]\n (* x 2))]\n (println \"Twice 15 =\" (twice 15))\n (println \"Six times 15 =\" (six-times 15)))\n;; Twice 15 = 30\n;; Six times 15 = 90\n;;=> nil\n
","created-at":1434901354547,"updated-at":1434901354547,"author":{"login":"muhuk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/40178?v=3"},"_id":"5586db6ae4b0fad27b85f91b"},{"author":{"login":"mars0i","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/1836941?v=4"},"updated-at":1592847494238,"created-at":1592847494238,"body":"And just to clarify further what is already implicit in other remarks, `letfn` allows a definition to refer to itself recursively: \n```\n(letfn [(my-range [n]\n (when (pos? n)\n (cons n (my-range (dec n)))))]\n (my-range 5))\n;;=> (5 4 3 2 1)\n```\nbut `let` doesn't:\n```\n(let [my-range (fn [n]\n (when (pos? n)\n (cons n (my-range (dec n)))))]\n (my-range 5))\nSyntax error compiling at ...\nUnable to resolve symbol: my-range in this context\n```\n","_id":"5ef0ec86e4b0b1e3652d730c"},{"author":{"login":"miner","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/25400?v=4"},"updated-at":1751048868656,"created-at":1751047008047,"body":"This is a bit of tangent, but the `fn` form optionally takes a name, which allows recursive calls. You still need `leftn` for mutually recursive functions.\n\n```clojure\n(let [my-range (fn my-range [n]\n (when (pos? n)\n (cons n (my-range (dec n)))))]\n (my-range 5))\n;;=> (5 4 3 2 1)\n```","_id":"685edb60cd84df5de54e208a"}],"url":null,"arglists":["fnspecs & body"],"doc":"fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+)\n\n Takes a vector of function specs and a body, and generates a set of\n bindings of functions to their names. All of the names are available\n in all of the definitions of the functions, as well as the body.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/letfn","forms":["(letfn [fnspecs*] exprs*)"]},{"added":"1.7","ns":"clojure.core","name":"volatile!","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1437144380666,"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":"vswap!","ns":"clojure.core"},"_id":"55a9153ce4b0080a1b79cda2"},{"created-at":1437144392165,"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":"vreset!","ns":"clojure.core"},"_id":"55a91548e4b0080a1b79cda3"},{"created-at":1437144401502,"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":"55a91551e4b06a85937088ad"},{"created-at":1437146220915,"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":"atom","ns":"clojure.core"},"_id":"55a91c6ce4b06a85937088af"}],"line":2542,"examples":[{"updated-at":1437146196403,"created-at":1437146196403,"author":{"login":"claj","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/353113?v=3"},"body":"(def val (volatile! 0))\n\n@val\n;;=> 0\n\n(vswap! val inc)\n;;=> 1\n\n(vreset! val \"nothing\")\n;;=> \"nothing\"\n\n@val\n;;=> \"nothing\"","_id":"55a91c54e4b06a85937088ae"}],"notes":[{"author":{"login":"claj","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/353113?v=3"},"updated-at":1437144350368,"created-at":1437144350368,"body":"An exhaustive StackOverflow question about volatile!\n\nhttp://stackoverflow.com/questions/31288608/what-is-clojure-volatile#comment50623688_31288608","_id":"55a9151ee4b06a85937088ab"},{"author":{"login":"claj","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/353113?v=3"},"updated-at":1437145076111,"created-at":1437144891888,"body":"Volatiles are meant to hold state in stateful transducers, since they are more performant (and less capable) than atoms.\n\nVolatiles are just a wrapped Java `volatile Object` reference. The Java `volatile`\nkeyword implies that reading and writing from this variable will not be reordered by JIT or the CPU. It does *not* imply atomicity.\n\nChanges to references made `volatile` are always \"written through\" CPU caches all the way to main memory (which is somewhat expensive), this means changes are guaranteed to propagate to other threads (nescessary in stateful transducers).","_id":"55a9173be4b0080a1b79cda4"}],"tag":"clojure.lang.Volatile","arglists":["val"],"doc":"Creates and returns a Volatile with an initial value of val.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/volatile!"},{"added":"1.0","ns":"clojure.core","name":"/","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1330259296000,"author":{"login":"frangio","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/646001f0ba2b7df47a16c0a1d5b62225?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"quot","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521dc8"},{"created-at":1423528033194,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"to-var":{"ns":"clojure.core","name":"unchecked-divide-int","library-url":"https://github.com/clojure/clojure"},"_id":"54d95061e4b0e2ac61831d45"},{"created-at":1691574231088,"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":"ratio?","ns":"clojure.core"},"_id":"64d35fd7e4b08cf8563f4bdd"}],"line":1022,"examples":[{"updated-at":1467677691841,"created-at":1279992021000,"body":"user=> (/ 6 3)\n2\n\nuser=> (/ 6 3 2)\n1\n\nuser=> (/ 10)\n1/10\n\nuser=> (/ 1 3)\n1/3\n\nuser=> (/)\nArityException Wrong number of args (0) passed to: core$-SLASH-\n\nuser=> (/ 1 0)\njava.lang.ArithmeticException\n\nuser=> (/ 0)\njava.lang.ArithmeticException\n","editors":[{"avatar-url":"https://www.gravatar.com/avatar/e7869fe1a48cb1814c657eaca6bea3eb?r=PG&default=identicon","account-source":"clojuredocs","login":"replore"},{"avatar-url":"https://www.gravatar.com/avatar/e7869fe1a48cb1814c657eaca6bea3eb?r=PG&default=identicon","account-source":"clojuredocs","login":"replore"},{"avatar-url":"https://www.gravatar.com/avatar/67e9a6f766dc4b30bd5e9ff3e77c1777?r=PG&default=identicon","account-source":"clojuredocs","login":"jmglov"},{"login":"bkovitz","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/4142015?v=3"}],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2","account-source":"github","login":"zk"},"_id":"542692c9c026201cdc326ac5"},{"author":{"login":"rebcabin","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/880b0bb3a4be9237326dd69565444dee?r=PG&default=identicon"},"editors":[],"body":";;; Automatically handles floating point:\n\nuser=> (/ 43.0 2)\n21.5","created-at":1387152003000,"updated-at":1387152003000,"_id":"542692d1c026201cdc326f44"},{"editors":[{"login":"ferdinand-beyer","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/23474334?v=4"}],"body":"user=> (numerator (/ 2 6)) \n1\nuser=> (denominator (/ 2 6)) \n3","author":{"avatar-url":"https://avatars.githubusercontent.com/u/870478?v=4","account-source":"github","login":"idrozd"},"created-at":1639061278628,"updated-at":1691574194163,"_id":"61b2171ee4b0b1e3652d7586"}],"notes":null,"arglists":["x","x y","x y & more"],"doc":"If no denominators are supplied, returns 1/numerator,\n else returns numerator divided by all of the denominators.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/_fs"},{"added":"1.0","ns":"clojure.core","name":"read-line","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1425998580860,"author":{"login":"kimtg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7685905?v=3"},"to-var":{"ns":"clojure.core","name":"flush","library-url":"https://github.com/clojure/clojure"},"_id":"54ff02f4e4b01ed96c93c888"}],"line":3822,"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-line)\nline to be read ;Type text into console\n\"line to be read\"\n","created-at":1282634673000,"updated-at":1285494406000,"_id":"542692c6c026201cdc3268c5"},{"body":";; (flush) is needed to display print values.\n;; Otherwise the print value stays buffered until you hit enter.\nuser=> (do (print \"What's your name? \") \n (flush) \n (read-line))\nWhat's your name? Clojure\n\"Clojure\"","author":{"login":"kimtg","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7685905?v=3"},"created-at":1425998545713,"updated-at":1587658953937,"editors":[{"avatar-url":"https://avatars3.githubusercontent.com/u/24317401?v=4","account-source":"github","login":"loeschzwerg"},{"login":"dijonkitchen","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/11434205?v=4"}],"_id":"54ff02d1e4b01ed96c93c887"},{"updated-at":1475631664273,"created-at":1475631664273,"author":{"login":"aakoch","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/137713?v=3"},"body":"(println \"Enter something> \")\n(def x (read-line))\n(println (str \"You typed \\\"\" x \"\\\"\"))","_id":"57f45a30e4b0709b524f051f"},{"editors":[{"login":"stathissideris","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/162007?v=4"}],"body":";; Example of a tiny menu system. Usage:\n\n(menu {:prompt \"Which database\" \n :options [\"Localhost\" \"Remote\" {:id \"o\" :text \"Other\"}]})\n\n;; Implementation\n(require '[clojure.string :as str])\n\n(defn menu [{:keys [prompt options]}]\n (let [options (map (fn [o idx]\n (if (string? o)\n {:id (str (inc idx)) :text o}\n o)) options (range))\n valid-options (set (map :id options))]\n (loop []\n (when prompt\n (println)\n (println prompt)\n (println))\n (doseq [{:keys [id text]} options]\n (println (str \" [\" id \"]\") text))\n (println)\n (println \"or press int counter = 0;\r\nwhile (true) {\r\n if (counter < 10) {\r\n // recur\r\n counter = inc(counter);\r\n } else {\r\n break;\r\n }\r\n}\r\n\r\n\r\nIn that sense `loop` is a recur target as in \"target for recursion\".","created-at":1279847110000,"author":{"login":"devijvers","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/81018e4231ac1ce8b7a9e6d377092656?r=PG&default=identicon"},"_id":"542692ebf6e94c6970521f84"},{"updated-at":1279866045000,"body":"I wish the word recur in this document linked to the recur function. That'd be... awesome.","created-at":1279866045000,"author":{"login":"Jacolyte","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/1703a0c3ed358b787f4b1bf3b2799472?r=PG&default=identicon"},"_id":"542692ebf6e94c6970521f85"},{"updated-at":1279892164000,"body":"It really should (and will) show up in the 'vars in' section. \r\n\r\nThe problem is that recur is a special form, and is not parsed out correctly like other vars. This will be fixed in the future.","created-at":1279892142000,"author":{"login":"zk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2"},"_id":"542692ebf6e94c6970521f86"},{"body":"Majority of `loop`s that novices write can be expressed more elegantly using 3 fundamental functions `map`, `filter` and `reduce`. Or using list comprehension `for`.","created-at":1423042890947,"updated-at":1423043065278,"author":{"login":"Dimagog","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3"},"_id":"54d1e94ae4b0e2ac61831d0e"},{"body":"To be clear, there's no *technical* reason the JVM can't support tail recursion (despite some complications to do with call stacks and security) - it just doesn't happen to support them currently.\n\nPeople have been requesting this enhancement for at least a decade - [here's one proposal](https://blogs.oracle.com/jrose/entry/tail_calls_in_the_vm), for example.","created-at":1430499038628,"updated-at":1430499038628,"author":{"login":"pmonks","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/54865?v=3"},"_id":"5543aedee4b06eaacc9cda86"}],"arglists":["bindings & body"],"doc":"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. Acts as a recur target.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/loop","forms":["(loop [bindings*] exprs*)"]},{"added":"1.0","ns":"clojure.core","name":"add-classpath","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":5205,"examples":[{"updated-at":1507317464731,"created-at":1507317464731,"author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/211644?v=4"},"body":";; There are alternatives\n\n;; https://github.com/cemerick/pomegranate\n\n;; http://grokbase.com/p/gg/clojure/12bnhbvmpy/how-to-add-an-url-into-the-classpath\n","_id":"59d7d6d8e4b03026fe14ea57"}],"deprecated":"1.1","notes":null,"arglists":["url"],"doc":"DEPRECATED \n\n Adds the url (String or URL object) to the classpath per\n URLClassLoader.addURL","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/add-classpath"},{"added":"1.0","ns":"clojure.core","name":"bit-flip","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":null,"line":1357,"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-flip 2r1011 2)\n15 \n;; 15 = 2r1111\n\n(bit-flip 2r1111 2)\n11 \n;; 11 = 2r1011","created-at":1280339556000,"updated-at":1332952408000,"_id":"542692c8c026201cdc326a6b"}],"notes":null,"arglists":["x n"],"doc":"Flip bit at index n","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/bit-flip"},{"added":"1.0","ns":"clojure.core","name":"long-array","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"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":1342917397000,"_id":"542692ebf6e94c6970521ea2"},{"created-at":1581624427170,"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":"int-array","ns":"clojure.core"},"_id":"5e45ac6be4b0ca44402ef834"},{"created-at":1581624433858,"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-array","ns":"clojure.core"},"_id":"5e45ac71e4b0ca44402ef835"},{"created-at":1581624442586,"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":"double-array","ns":"clojure.core"},"_id":"5e45ac7ae4b0ca44402ef836"},{"created-at":1581624451957,"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":"boolean-array","ns":"clojure.core"},"_id":"5e45ac83e4b0ca44402ef837"}],"line":5393,"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"},{"login":"shockbob","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"},{"login":"shockbob","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"}],"body":";; create a long array using long-array and show it can be used\n;; with the standard Java Arrays functions binarySearch and fill\n;; note the needed coercions\n\nuser=> (def is (long-array (range 3 20)))\n#'user/is\nuser=> (vec is)\n[3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19]\nuser=> (java.util.Arrays/binarySearch is (long 10))\n7\nuser=> (java.util.Arrays/fill is 3 8 (long 99))\nnil\nuser=> (vec is)\n[3 4 5 99 99 99 99 99 11 12 13 14 15 16 17 18 19]\nuser=>","created-at":1313907019000,"updated-at":1313963219000,"_id":"542692c7c026201cdc326962"}],"notes":null,"arglists":["size-or-seq","size init-val-or-seq"],"doc":"Creates an array of longs","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/long-array"},{"added":"1.0","ns":"clojure.core","name":"descendants","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1400492134000,"author":{"login":"ryo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"ancestors","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ead"}],"line":5667,"examples":[{"author":{"login":"shockbob","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon"},"editors":[],"body":";; simple example a toy poodle is a poodle is a dog is an animal\n\nuser=> (derive ::dog ::animal)\nnil\nuser=> (derive ::poodle ::dog)\nnil\nuser=> (derive ::toy_poodle ::poodle)\nnil\nuser=> (descendants ::animal)\n#{:user/toy_poodle :user/poodle :user/dog}\nuser=>","created-at":1313968073000,"updated-at":1313968073000,"_id":"542692c8c026201cdc326a24"},{"updated-at":1597842188323,"created-at":1597842188323,"author":{"login":"uosl","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/3865590?v=4"},"body":";; You can combine `descendants` with `parents` to only get the immediate children.\n\n(filter #(contains? (parents h %) tag)\n (descendants h tag))","_id":"5f3d230ce4b0b1e3652d7381"}],"notes":null,"arglists":["tag","h tag"],"doc":"Returns the immediate and indirect children of tag, through a\n relationship established via derive. h must be a hierarchy obtained\n from make-hierarchy, if not supplied defaults to the global\n hierarchy. Note: does not work on Java type inheritance\n relationships.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/descendants"},{"added":"1.11","ns":"clojure.core","name":"iteration","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":7910,"examples":[{"updated-at":1698272254989,"created-at":1698272254989,"author":{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"},"body":";; Let's set up an atom to act like a paginated data source…\n(def pages\n (atom {\"a\" {:items [\"Rose\" \"Tulip\" \"Marigold\" \"Lavender\" \"Daffodil\"] :next-page \"b\"}\n \"b\" {:items [\"Sunflower\" \"Petunia\" \"Chrysanthemum\" \"Dandelion\" \"Pansy\"] :next-page \"c\"}\n \"c\" {:items [\"Orchid\" \"Daisy\" \"Lily\" \"Geranium\" \"Hyacinth\"] :next-page \"d\"}\n \"d\" {:items [\"Azalea\" \"Begonia\" \"Iris\" \"Poppy\" \"Jasmine\"]}}))\n\n;; And let's set up a function to access that atom, with a delay to simulate\n;; network slowness…\n(defn get-page! [id]\n (Thread/sleep 3000)\n (get @pages id))\n\n;; See that `iteration` allows for a very succinct, lazy way to get pages…\n(-> (iteration get-page! :initk \"a\", :vf :items, :kf :next-page)\n first\n time)\n\"Elapsed time: 3000.947447 msecs\"\n;; => [\"Rose\" \"Tulip\" \"Marigold\" \"Lavender\" \"Daffodil\"]\n\n(-> (iteration get-page! :initk \"a\", :vf :items, :kf :next-page)\n second\n time)\n\"Elapsed time: 6002.736159 msecs\"\n;; => [\"Sunflower\" \"Petunia\" \"Chrysanthemum\" \"Dandelion\" \"Pansy\"]\n\n;; Note that common methods to lazily concatenate pages can get hit by a\n;; chunking time penalty…\n(->> (iteration get-page! :initk \"a\", :vf :items, :kf :next-page)\n (sequence cat)\n second\n time)\n\"Elapsed time: 12013.729409 msecs\"\n;; => \"Tulip\"\n\n;; So consider using `lazy-seq` and/or `lazy-cat` for lazier performance","_id":"653993fe69fbcc0c226173e2"}],"notes":null,"arglists":["step & {:keys [somef vf kf initk], :or {vf identity, kf identity, somef some?, initk nil}}"],"doc":"Creates a seqable/reducible via repeated calls to step,\n a function of some (continuation token) 'k'. The first call to step\n will be passed initk, returning 'ret'. Iff (somef ret) is true,\n (vf ret) will be included in the iteration, else iteration will\n terminate and vf/kf will not be called. If (kf ret) is non-nil it\n will be passed to the next step call, else iteration will terminate.\n\n This can be used e.g. to consume APIs that return paginated or batched data.\n\n step - (possibly impure) fn of 'k' -> 'ret'\n\n :somef - fn of 'ret' -> logical true/false, default 'some?'\n :vf - fn of 'ret' -> 'v', a value produced by the iteration, default 'identity'\n :kf - fn of 'ret' -> 'next-k' or nil (signaling 'do not continue'), default 'identity'\n :initk - the first value passed to step, default 'nil'\n\n It is presumed that step with non-initk is unreproducible/non-idempotent.\n If step with initk is unreproducible it is on the consumer to not consume twice.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/iteration"},{"added":"1.0","ns":"clojure.core","name":"merge","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1294676416000,"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-with","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521ad7"},{"created-at":1317787765000,"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":"542692eaf6e94c6970521ad8"},{"created-at":1536776434976,"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":"assoc","ns":"clojure.core"},"_id":"5b9958f2e4b00ac801ed9e95"}],"line":3065,"examples":[{"author":{"login":"dpritchett","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/147981?v=3"},"editors":[{"login":"srid","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bd3a68d670372cd09876c26270a4299a?r=PG&default=identicon"},{"login":"srid","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bd3a68d670372cd09876c26270a4299a?r=PG&default=identicon"},{"login":"srid","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bd3a68d670372cd09876c26270a4299a?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":"(merge {:a 1 :b 2 :c 3} {:b 9 :d 4})\n;;=> {:d 4, :a 1, :b 9, :c 3}","created-at":1279071769000,"updated-at":1422374016946,"_id":"542692cfc026201cdc326e73"},{"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"},{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"body":"(merge {:a 1} nil) ;=> {:a 1}\n(merge nil {:a 1}) ;=> {:a 1}\n(merge nil nil) ;=> nil\n","created-at":1401310493000,"updated-at":1422374049474,"_id":"542692d4c026201cdc32700c"},{"body":";; `merge` can be used to support the setting of default values\n(merge {:foo \"foo-default\" :bar \"bar-default\"} \n {:foo \"custom-value\"})\n;;=> {:foo \"custom-value\" :bar \"bar-default\"}\n\n;; This is useful when a function has a number of options\n;; with default values.\n(defn baz [& options]\n (let [options (merge {:opt1 \"default-1\" :opt2 \"default-2\"} \n (first options))]\n options))\n\n(baz {:opt1 \"custom-1\" :opt3 \"custom-3\"})\n;;=> {:opt3 \"custom-3\" :opt1 \"custom-1 :opt2 \"default-2\"}\n","author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"},"created-at":1422375001817,"updated-at":1422375001817,"_id":"54c7b859e4b0e2ac61831cdf"},{"editors":[{"login":"dijonkitchen","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/11434205?v=4"}],"body":";; For recursively merging deeply-nested maps:\n\n(defn deep-merge [v & vs]\n (letfn [(rec-merge [v1 v2]\n (if (and (map? v1) (map? v2))\n (merge-with deep-merge v1 v2)\n v2))]\n (if (some identity vs)\n (reduce #(rec-merge %1 %2) v vs)\n (last vs))))\n\n(deep-merge {:a {:b true}} {:a {:b false}} {:a {:b nil}})\n;; {:a {:b nil}}\n\n(deep-merge {:a 1} nil)\n;; nil ;; note that this isn't consistent with the regular merge function\n\n;; Source: https://gist.github.com/danielpcox/c70a8aa2c36766200a95#gistcomment-2677502","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/11434205?v=4","account-source":"github","login":"dijonkitchen"},"created-at":1535149214818,"updated-at":1536856542156,"_id":"5b80849ee4b00ac801ed9e75"},{"updated-at":1548252366101,"created-at":1548252366101,"author":{"login":"genmeblog","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/38646601?v=4"},"body":";; latest comment under above gist provides another\n;; simpler and more consistent version of deep-merge\n;; Source: https://gist.github.com/danielpcox/c70a8aa2c36766200a95#gistcomment-2759497\n\n(defn deep-merge [a & maps]\n (if (map? a)\n (apply merge-with deep-merge a maps)\n (apply merge-with deep-merge maps)))\n\n(deep-merge {:a {:b true}} {:a {:b false}} {:a {:b nil}})\n;; => {:a {:b nil}}\n\n(deep-merge {:a 1} nil)\n;; => {:a 1}\n","_id":"5c4874cee4b0ca44402ef622"},{"updated-at":1566278942641,"created-at":1566278942641,"author":{"login":"liuchong","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/236058?v=4"},"body":"(merge {:x 1 :y 2} {:y 3 :z 4})\n;; => {:x 1, :y 3, :z 4}","_id":"5d5b851ee4b0ca44402ef7a8"},{"editors":[{"login":"Crowbrammer","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/19522656?v=4"}],"body":";; Looking at the source code, merge starts with the \n;; original collection and uses conj which adds elements \n;; as is into the collection, so merge can be used\n;; with more than just maps--i.e. using a vector returns a vector.\n\n(merge [:a \"Whoa\"] [:c \"Crash Bandicoot\"])\n;; => [:a \"Whoa\" [:c \"Crash Bandicoot\"]]\n(merge [:a \"Whoa\"] \"Crash Bandicoot\")\n;; => [:a \"Whoa\" \"Crash Bandicoot\"]","author":{"avatar-url":"https://avatars0.githubusercontent.com/u/19522656?v=4","account-source":"github","login":"Crowbrammer"},"created-at":1610333321854,"updated-at":1610333698491,"_id":"5ffbbc89e4b0b1e3652d7429"},{"updated-at":1693812802785,"created-at":1693812463082,"author":{"login":"rainspeaker","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/4544929?v=4"},"body":";; in the source, merge uses `or` to substitute an empty map if given\n;; `nil` for the first value. Since \"or\" also catches false, this works: \n\n(merge false {:a 1})\n;; => {:a 1}\n\n;; On the other hand, this throws a ClassCastException:\n\n(merge true {:a 1}) \n\n;; This probably shouldn't be relied on","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/4544929?v=4","account-source":"github","login":"rainspeaker"}],"_id":"64f586efe4b08cf8563f4be8"},{"updated-at":1726844460386,"created-at":1726844460386,"author":{"login":"raszi","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/76983?v=4"},"body":";; This could be handy in certain situations.\n\n(defn reverse-merge\n \"Same as `merge` but works in reverse order.\"\n [& maps]\n (apply merge (reverse maps)))\n\n(reverse-merge {:foo \"FOO\"}\n {:foo \"---\" :bar \"BAR\"}\n {:bar \"---\" :baz \"BAZ\"})\n;; => {:bar \"BAR\", :baz \"BAZ\", :foo \"FOO\"}","_id":"66ed8e2c69fbcc0c226174f9"}],"notes":[{"body":"### When to use assoc, conj, merge\n\n`assoc`, `conj` & `merge` behave very differently for different data structures\n\nIf you are writing a function that can handle multiple kinds of collections, then your choice will make a big difference.\n\nTreat merge as a maps-only function (its similar to conj for other collections).\n\nMy opinion:\n\n* `assoc` - use when you are 'changing' existing key/value pairs\n* `conj` - use when you are 'adding' new key/value pairs\n* `merge` - use when you are combining two or more maps\n\nRef : https://stackoverflow.com/a/3204346","created-at":1620798989281,"updated-at":1620799011530,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/1042312?v=4","account-source":"github","login":"udkl"},"_id":"609b6e0de4b0b1e3652d74f9"},{"author":{"login":"rainspeaker","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/4544929?v=4"},"updated-at":1693813134298,"created-at":1693813134298,"body":"Merge is more similar to concat than to conj IMO. ","_id":"64f5898ee4b08cf8563f4bed"}],"arglists":["& maps"],"doc":"Returns a map that consists of the rest of the maps conj-ed onto\n the first. If a key occurs in more than one map, the mapping from\n the latter (left-to-right) will be the mapping in the result.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/merge"},{"added":"1.0","ns":"clojure.core","name":"accessor","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1412886553460,"author":{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=2"},"to-var":{"ns":"clojure.core","name":"get","library-url":"https://github.com/clojure/clojure"},"_id":"5436f019e4b0ae795603157e"}],"line":4097,"examples":[{"author":{"login":"tormaroe","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/8bc7bb10bee96efb190053fe92ffd250?r=PG&default=identicon"},"editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/50778?v=4","account-source":"github","login":"edipofederle"}],"body":"(defstruct car-struct :make :model :year :color)\n\n(def car (struct car-struct \"Toyota\" \"Prius\" 2010))\n\n(def make (accessor car-struct :make))\n\n; Same as both (car :make) and (:make car)\n(make car) \n;;=> \"Toyota\" \n\n","created-at":1289603045000,"updated-at":1700649761310,"_id":"542692cac026201cdc326b11"}],"notes":null,"arglists":["s key"],"doc":"Returns a fn that, given an instance of a structmap with the basis,\n returns the value at the key. The key must be in the basis. The\n returned function should be (slightly) more efficient than using\n get, but such use of accessors should be limited to known\n performance-critical areas.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/accessor"},{"added":"1.0","ns":"clojure.core","name":"integer?","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1440146014714,"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":"number?","ns":"clojure.core"},"_id":"55d6e25ee4b0831e02cddf15"},{"created-at":1495654427514,"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":"int?","ns":"clojure.core"},"_id":"5925e01be4b093ada4d4d73b"}],"line":1388,"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=> (integer? 1)\ntrue\nuser=> (integer? 1.0)\nfalse","created-at":1279074074000,"updated-at":1332950732000,"_id":"542692c8c026201cdc326a30"},{"updated-at":1487037245803,"created-at":1487037245803,"author":{"login":"jungziege","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/405465?v=3"},"body":";; Note: tests if it's a math integer, not a Java Integer\nuser=> (integer? (inc Integer/MAX_VALUE))\ntrue","_id":"58a2633de4b01f4add58fe53"},{"updated-at":1495656170180,"created-at":1495656170180,"author":{"login":"timgilbert","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/94482?v=3"},"body":";; integer? returns true for BigInts. If you don't want this behavior, you can \n;; use the int? predicate instead in Clojure 1.9 or later:\n\n(integer? 13N)\n;; => true\n\n(int? 13N)\n;; => false","_id":"5925e6eae4b093ada4d4d742"}],"notes":null,"arglists":["n"],"doc":"Returns true if n is an integer","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/integer_q"},{"added":"1.4","ns":"clojure.core","name":"mapv","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1413326056085,"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":"543da4e8e4b02688d208b1b8"},{"created-at":1507137288794,"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":"vec","ns":"clojure.core"},"_id":"59d51708e4b03026fe14ea4f"},{"created-at":1516208408133,"author":{"login":"jcburley","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/430319?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"reduce","ns":"clojure.core"},"_id":"5a5f8118e4b0a08026c48cfa"},{"created-at":1516208418039,"author":{"login":"jcburley","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/430319?v=4"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"pmap","ns":"clojure.core"},"_id":"5a5f8122e4b0a08026c48cfb"}],"line":7050,"examples":[{"editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},{"login":"totorigolo","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/1183296?v=4"}],"updated-at":1542244482242,"created-at":1421096939041,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},"body":"(mapv inc [1 2 3 4 5])\n;;=> [2 3 4 5 6]\n\n\n;; mapv can be used with multiple collections. Collections will be consumed\n;; and passed to the mapping function in parallel:\n(mapv + [1 2 3] [4 5 6])\n;;=> [5 7 9]\n\n\n;; When mapv is passed more than one collection, the mapping function will\n;; be applied until one of the collections runs out:\n(mapv + [1 2 3] (iterate inc 1))\n;;=> [2 4 6]\n\n\n\n;; mapv is often used in conjunction with the # reader macro:\n(mapv #(str \"Hello \" % \"!\" ) [\"Ford\" \"Arthur\" \"Tricia\"])\n;;=> [\"Hello Ford!\" \"Hello Arthur!\" \"Hello Tricia!\"]\n\n;; A useful idiom to pull \"columns\" out of a collection of collections. \n;; Note, it is equivalent to:\n;; (mapv vector [:a :b :c] [:d :e :f] [:g :h :i])\n\n(apply mapv vector [[:a :b :c]\n [:d :e :f]\n [:g :h :i]])\n;;=> [[:a :d :g] [:b :e :h] [:c :f :i]]","_id":"54b437ebe4b081e022073c02"},{"updated-at":1584701507565,"created-at":1573719104514,"author":{"login":"kangbb","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/15232085?v=4"},"body":";; The difference between `map` and `mapv` is that:\n;; `map` return a lazy sequence,\n;; `mapv` return a sequence.\n(def result (map println [1 2 3]))\n;;=> #'user/result\nresult\n;;=> 1\n;; 2\n;; 3\n;; (nil nil nil)\n\n(def result (mapv println [1 2 3]))\n;;=> 1\n;; 2\n;; 3\n;; #'user/result\nresult\n;;=> [nil nil nil]\n\n;; So, we can use it when we want to get a side effect immediately.\n","editors":[{"avatar-url":"https://avatars1.githubusercontent.com/u/15232085?v=4","account-source":"github","login":"kangbb"},{"login":"graycodes","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/1530754?v=4"}],"_id":"5dcd0c40e4b0ca44402ef7de"},{"updated-at":1619002206128,"created-at":1619001516133,"author":{"login":"sFritsch09","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/58191603?v=4"},"body":";; convert number to vector:\n; numb = 210\n\n((fn [numb] (mapv #(Character/digit % 10) (str numb))) 210)\n;;=> [2 1 0]\n\n;; and the other way around:\n\n(read-string (reduce str [2 1 0]))\n;;=> 210","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/58191603?v=4","account-source":"github","login":"sFritsch09"}],"_id":"608000ace4b0b1e3652d74c9"}],"notes":[{"body":"Like `map` but returns a vector. In most cases equivalent to calling `(into [] (map f c1 c2 ...))`. Is much faster than map (but is not lazy!) in the `(mapv f coll)` case.","created-at":1430433040188,"updated-at":1430433049879,"author":{"login":"num1","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/466333?v=3"},"_id":"5542ad10e4b06eaacc9cda82"},{"author":{"login":"KingMob","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/946421?v=4"},"updated-at":1596048409289,"created-at":1596048409289,"body":"It's not necessarily true at all that `mapv` will be faster than `map`. `mapv` (and related fns like `filterv`) have increased memory needs (creating unused values, realizing intermediate sequences, etc) that hurt it.\n\nHere's a simple example showing how `mapv`/`filterv` can be slower. (Benchmarked with criterium.)\n\n```\n(let [nums (range 10000000)]\n (bench\n (reduce +' 0 (filter even? (map #(* % %) nums))))\n\n (bench\n (reduce +' 0 (filterv even? (mapv #(* % %) nums)))))\n```\nand the results, showing `map` is actually a little faster than `mapv`:\n\n```\nEvaluation count : 120 in 60 samples of 2 calls.\n Execution time mean : 768.870217 ms\n Execution time std-deviation : 21.043586 ms\n Execution time lower quantile : 756.049838 ms ( 2.5%)\n Execution time upper quantile : 835.719808 ms (97.5%)\n Overhead used : 1.805367 ns\n\nFound 9 outliers in 60 samples (15.0000 %)\n\tlow-severe\t 3 (5.0000 %)\n\tlow-mild\t 6 (10.0000 %)\n Variance from outliers : 14.2178 % Variance is moderately inflated by outliers\n\n\n\nEvaluation count : 120 in 60 samples of 2 calls.\n Execution time mean : 800.356084 ms\n Execution time std-deviation : 49.667013 ms\n Execution time lower quantile : 756.382597 ms ( 2.5%)\n Execution time upper quantile : 883.471627 ms (97.5%)\n Overhead used : 1.805367 ns\n\nFound 12 outliers in 60 samples (20.0000 %)\n\tlow-severe\t 5 (8.3333 %)\n\tlow-mild\t 1 (1.6667 %)\n\thigh-mild\t 6 (10.0000 %)\n Variance from outliers : 46.7536 % Variance is moderately inflated by outliers\n```\n\nThe takeaway is, don't pick `mapv` just for speed reasons.","_id":"5f21c419e4b0b1e3652d7327"}],"arglists":["f coll","f c1 c2","f c1 c2 c3","f c1 c2 c3 & colls"],"doc":"Returns a vector consisting of the result of applying f to the\n set of first items of each coll, followed by applying f to the set\n of second items in each coll, until any one of the colls is\n exhausted. Any remaining items in other colls are ignored. Function\n f should accept number-of-colls arguments.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/mapv"},{"added":"1.11","ns":"clojure.core","name":"infinite?","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":8223,"examples":[{"updated-at":1698252954064,"created-at":1698252954064,"author":{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"},"body":";; This works for doubles…\n(infinite? (/ 1.0 0.0))\n;; => true\n\n;; But infinity is not a concept for longs…\n(infinite? (/ 1 0))\n;; Execution error (ArithmeticException) at…\n;; Divide by zero\n\n;; But it is worth being aware of what is considered to be infinite…\n(infinite? (+ Double/MAX_VALUE 1e292))\n;; => true\n;; And what isn't…\n(infinite? (+ Double/MAX_VALUE 1e291))\n;; => false","_id":"6539489a69fbcc0c226173d4"}],"notes":null,"arglists":["num"],"doc":"Returns true if num is negative or positive infinity, else false","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/infinite_q"},{"added":"1.2","ns":"clojure.core","name":"partition-all","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1313710375000,"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"partition","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521c74"},{"created-at":1313710383000,"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"partition-by","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521c75"}],"line":7388,"examples":[{"updated-at":1420742107199,"created-at":1279643883000,"body":"(partition 4 [0 1 2 3 4 5 6 7 8 9])\n;;=> ((0 1 2 3) (4 5 6 7))\n\n(partition-all 4 [0 1 2 3 4 5 6 7 8 9])\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"},{"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":"542692ccc026201cdc326c8e"},{"author":{"login":"Tap","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/925c5d43b739098e6f16f804f5dc4868?r=PG&default=identicon"},"editors":[{"login":"phreed","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3"}],"body":"(partition-all 2 4 [0 1 2 3 4 5 6 7 8 9])\n;;=> ((0 1) (4 5) (8 9))","created-at":1349617127000,"updated-at":1420742136613,"_id":"542692d4c026201cdc327029"},{"updated-at":1599548333018,"created-at":1373311985000,"body":";; Caution: Partitioning lazy sequence code freeze\n;; Edit: Only because (rdr l) is buggy and returns an infinite sequence!\n\n(def l [1 2 3 4 5])\n;create a simple lazy sequence function testing only\n;(rdr l) returns a lazy sequence from l\n(def rdr (fn reader[x] (cons (first x) (lazy-seq (reader (rest x))))))\n\n;the line below will freeze\n(doall (partition-all 2 (rdr l)) )\n\n;add-in a take-while statement do exit the lazy sequence on nil\n(doall (partition-all 2 (take-while (complement nil?) (rdr l))))","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/211644?v=3","account-source":"github","login":"phreed"},{"login":"rbuchmann","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/611792?v=4"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/ee33873c26c4a6b7e1daa3ebb777d58c?r=PG&default=identicon","account-source":"clojuredocs","login":"gerritjvv"},"_id":"542692d4c026201cdc32702a"},{"updated-at":1561100812644,"created-at":1561100482422,"author":{"login":"ningDr","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/38251752?v=4"},"body":";; When the step parameter is provided, the starting index value of the first item in the \n;; next group steps relative to the current index value\n;; 提供step参数时,下一个分组的第一项的起始索引值相对于当前索引值的步进(+ pre-index step)\n(println (partition-all 2 3 '(0 1 2 3 4 5 6 7 8 9)))\n;; => ((0 1) (3 4) (6 7) (9))\n(println (partition-all 4 3 '(0 1 2 3 4 5 6 7 8 9)))\n;; => ((0 1 2 3) (3 4 5 6) (6 7 8 9) (9))\n;; When n is equal to step, it is equivalent to no step parameter\n;; 当n与step相等,相当于无step参数\n(println (partition-all 3 3 '(0 1 2 3 4 5 6 7 8 9)))\n;; => ((0 1 2) (3 4 5) (6 7 8) (9))","editors":[{"avatar-url":"https://avatars0.githubusercontent.com/u/38251752?v=4","account-source":"github","login":"ningDr"}],"_id":"5d0c80c2e4b0ca44402ef75b"}],"notes":[{"body":"be aware of the case of n is 0\n\n(partition-all 0 '(1 2 3))\n\nwill cause repl blocked and cpu 100%","created-at":1716860281141,"updated-at":1716860322687,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/46063475?v=4","account-source":"github","login":"kkprop"},"_id":"6655357969fbcc0c226174ca"}],"arglists":["n","n coll","n step coll"],"doc":"Returns a lazy sequence of lists like partition, but may include\n partitions with fewer than n items at the end. Returns a stateful\n transducer when no collection is provided.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/partition-all"},{"added":"1.2","ns":"clojure.core","name":"partition-by","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1313710412000,"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"partition","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ee1"},{"created-at":1313710420000,"author":{"login":"boxie","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/bfc366066e3c1beee98f3a6666728169?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"partition-all","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ee2"},{"created-at":1331014947000,"author":{"login":"abrooks","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/69976?v=2"},"to-var":{"ns":"clojure.core","name":"group-by","library-url":"https://github.com/clojure/clojure"},"_id":"542692ebf6e94c6970521ee3"},{"created-at":1496446489487,"author":{"login":"stellingsimon","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/7038847?v=3"},"to-var":{"library-url":"https://github.com/clojure/clojure","name":"dedupe","ns":"clojure.core"},"_id":"5931f619e4b06e730307db21"},{"created-at":1553712274503,"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":"sort","ns":"clojure.core"},"_id":"5c9bc492e4b0ca44402ef6ea"},{"created-at":1659193765852,"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":"split-with","ns":"clojure.core"},"_id":"62e549a5e4b0b1e3652d7634"}],"line":7308,"examples":[{"author":{"login":"wilkes","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/20a7eb5b792999d37386ddf622543c71?r=PG&default=identicon"},"editors":[{"login":"jafingerhut","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/109629?v=3"}],"body":"user=> (partition-by #(= 3 %) [1 2 3 4 5])\n((1 2) (3) (4 5))","created-at":1279936678000,"updated-at":1332949621000,"_id":"542692c7c026201cdc3269da"},{"author":{"login":"wilkes","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/20a7eb5b792999d37386ddf622543c71?r=PG&default=identicon"},"editors":[{"login":"wilkes","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/20a7eb5b792999d37386ddf622543c71?r=PG&default=identicon"},{"login":"zk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/7194?v=2"}],"body":"user=> (partition-by odd? [1 1 1 2 2 3 3])\n((1 1 1) (2 2) (3 3))\n\nuser=> (partition-by even? [1 1 1 2 2 3 3])\n((1 1 1) (2 2) (3 3))\n","created-at":1279936736000,"updated-at":1285497469000,"_id":"542692c7c026201cdc3269dc"},{"updated-at":1597775773722,"created-at":1318525613000,"body":";; (this is part of a solution from 4clojure.com/problem 30)\nuser=> (partition-by identity \"Leeeeeerrroyyy\")\n((\\L) (\\e \\e \\e \\e \\e \\e) (\\r \\r \\r) (\\o) (\\y \\y \\y))","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/109629?v=3","account-source":"github","login":"jafingerhut"},{"login":"rfemygdio","account-source":"github","avatar-url":"https://avatars1.githubusercontent.com/u/26044589?v=4"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/8d3c423e74750fa42c0386833e4b8209?r=PG&default=identicon","account-source":"clojuredocs","login":"belun"},"_id":"542692d4c026201cdc32702b"},{"editors":[{"login":"smnplk","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/380618?v=3"}],"updated-at":1466670505123,"created-at":1412082807145,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/1698238?v=2","account-source":"github","login":"martinhynar"},"body":";; Note that previously created 'bins' are not used when same value is seen again\nuser=> (partition-by identity \"ABBA\")\n((\\A) (\\B \\B) (\\A))\n\n;; That is why you use group-by function if you want all the the same values in the same 'bins' :) \n;; Which gives you a hash, but you can extract values from that if you need.\n\n(group-by identity \"ABBA\")\n=> {\\A [\\A \\A], \\B [\\B \\B]}","_id":"542aac77e4b0df9bb778a599"},{"body":";; Arbitrary partitioning\n(let [seen (atom true)]\n (partition-by #(cond\n (#{1} %) (reset! seen (not @seen))\n (or (and (string? %)\n (< (count %) 2))\n (char? %)) \"letter\"\n (string? %) \"string\"\n (#{0} %) 0\n (vector? %) (count %)\n :else \"rest\")\n [1 1 1 2 3 nil \"a\" \\l 0 4 5 {:a 1} \"bc\" \"aa\" \"k\" [0] [1 1] [2 2]]))\n;;=> ((1) (1) (1) (2 3 nil) (\"a\" \\l) (0) (4 5 {:a 1}) (\"bc\" \"aa\") (\"k\") ([0]) ([1 1] [2 2]))","author":{"login":"vede1","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8151095?v=2"},"created-at":1414773403982,"updated-at":1415348351870,"editors":[{"login":"vede1","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8151095?v=2"}],"_id":"5453ba9be4b0dc573b892fb5"},{"updated-at":1458482052841,"created-at":1458482052841,"author":{"login":"ertugrulcetin","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/8271291?v=3"},"body":"user=> (partition-by count [\"a\" \"b\" \"ab\" \"ac\" \"c\"])\n\n;;=> ((\"a\" \"b\") (\"ab\" \"ac\") (\"c\"))","_id":"56eeab84e4b0b41f39d96cea"},{"updated-at":1557411490030,"created-at":1557411490030,"author":{"login":"artemiy312","account-source":"github","avatar-url":"https://avatars0.githubusercontent.com/u/13870342?v=4"},"body":"user=> (partition-by identity [1 1 1 1 2 2 3])\n;;=> ((1 1 1 1) (2 2) (3))\n","_id":"5cd436a2e4b0ca44402ef71e"},{"editors":[{"login":"johanatan","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/583903?v=4"}],"body":"I think this is a better (more agnostic & more declarative/functional)\narbitrary partitioning. The ratio of true:false can be tweaked for longer\naverage sequence length.\n\n(defn arbitrarily-partition [coll]\n (let [signals (take (count coll) (cycle [true false]))\n shuffled (shuffle signals)\n zipped (map vector shuffled coll)\n partitioned (partition-by first zipped)]\n (for [c partitioned]\n (map second c))))\n\n;;=> (arbitrarily-partition (range 100))\n((0 1) (2) (3) (4 5) (6 7) (8 9 10) (11) (12) (13 14 15) (16) (17 18) (19) (20) (21) (22 23 24 25 26) (27 28) (29) (30 31) (32) (33 34 35 36 37 38) (39 40 41) (42) (43 44 45 46 47) (48 49) (50) (51 52 53) (54) (55 56) (57 58) (59 60 61) (62) (63) (64) (65 66) (67 68) (69) (70) (71) (72 73 74 75) (76) (77 78) (79) (80) (81 82) (83 84 85) (86) (87 88) (89 90 91 92 93) (94) (95 96 97) (98) (99))","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/583903?v=4","account-source":"github","login":"johanatan"},"created-at":1597704699181,"updated-at":1597724481351,"_id":"5f3b09fbe4b0b1e3652d737a"}],"notes":[{"updated-at":1338786617000,"body":"It's worth mentioning that `(partition-by identity …)` is equivalent to the `Data.List.group` function in Haskell:\r\n\r\n \r\n(defn group [coll]\r\n (partition-by identity coll))\r\n
\r\n\r\nWhich proves to be an interesting idiom:\r\n\r\nuser=> (apply str \r\n (for [ch (group \"fffffffuuuuuuuuuuuu\")] \r\n (str (first ch) (count ch))))\r\n⇒ \"f7u12\"\r\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":3608,"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":null,"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":null,"line":5378,"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":null,"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":4765,"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":null,"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":6430,"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":5679,"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":null,"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.12","ns":"clojure.core","name":"partitionv-all","file":"clojure/core.clj","type":"function","column":1,"see-alsos":null,"line":7451,"examples":null,"notes":null,"arglists":["n","n coll","n step coll"],"doc":"Returns a lazy sequence of vector partitions, but may include\n partitions with fewer than n items at the end.\n Returns a stateful transducer when no collection is provided.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/partitionv-all"},{"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":4115,"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":null,"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":null,"line":5021,"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":null,"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":5651,"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":null,"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":5162,"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":null,"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":2221,"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 #(. 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":576,"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":3602,"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":null,"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":757,"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":null,"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":6388,"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"},{"updated-at":1701598683066,"created-at":1701598683066,"author":{"login":"tomdl89","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/33435574?v=4"},"body":";; `intern` can be used to allow defining in other namespaces…\nuser> (create-ns 'other-ns)\n#namespace[other-ns]\n\nuser> (intern 'other-ns 'foo 42)\n#'other-ns/foo\n\nuser> (inc other-ns/foo)\n43","_id":"656c55db69fbcc0c2261746a"}],"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":null,"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":null,"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":7284,"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\nuser=> (flatten [[[1]] [[2 3]]])\n(1 2 3)\n
\n\nWith mapcat identity:\n\nuser=> (mapcat identity [[[1]] [[2 3]]])\n([1] [2 3])\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":5431,"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\nuser=> (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\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":7823,"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"},{"updated-at":1698678471391,"created-at":1520774510308,"author":{"login":"glts","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/1483271?v=4"},"body":";; \"halt-when\" can only really be used with \"transduce\" (and \"into\" \n;; as of Clojure 1.11.1), but not with other functions that\n;; support transducers like \"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","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/43875?v=4","account-source":"github","login":"seancorfield"},{"login":"daemianmack","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/24476?v=4"}],"_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":4776,"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":null,"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":2179,"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":null,"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":4832,"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\" #\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":4673,"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"},{"updated-at":1706781086822,"created-at":1706781086822,"author":{"login":"jimka2001","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/6414129?v=4"},"body":";; to map across a hashmap\n(for [[k v] {:a 1 :b 10 :c 100}]\n (list k v))\n\n;; -> ((:a 1) (:b 10) (:c 100))\n","_id":"65bb699e69fbcc0c22617496"},{"updated-at":1733228483818,"created-at":1733228483818,"author":{"login":"ottonascarella","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1014206?v=4"},"body":";; all right triangles with integer sides from 1 to 11\n(for [a (range 1 11)\n b (range 1 a)\n c (range 1 b)\n :when (= (* a a) (+ (* b b) (* c c)))]\n [a b c])","_id":"674ef7c369fbcc0c22617522"}],"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\r\n(filter even? (map (partial * 3) [0 1 2 3 4 5]))\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\nuser=> (mapcat (fn [e] (map (fn [x] (* x e)) [1 2 3])) [1 2 3])\r\n(1 2 3 2 4 6 3 6 9)\r\nuser=> (mapcat (fn [e] (map (fn [x] [e x]) [1 2 3])) ['a 'b 'c])\r\n([a 1] [a 2] [a 3] [b 1] [b 2] [b 3] [c 1] [c 2] [c 3])\r\nuser=> (map (fn [e] [e (* e e)(* e e e)]) (range 1 6))\r\n([1 1 1] [2 4 8] [3 9 27] [4 16 64] [5 25 125])\r\nuser=> (map (fn [e] (* e e)) (range 3 7))\r\n(9 16 25 36)\r\nuser=> (map first (filter (fn [[x y]] (= y 0)) '([:a 1] [:b 2] [:c 0])))\r\n(:c)\r\nuser=>\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":1964,"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#\r\n IllegalStateException Can't dynamically bind non-dynamic var: clojure.core/max\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\n(defn find-max [x y]\n (max x y)) ;; => #'user/find-max\n(binding [max clojure.core/min]\n (find-max 10 20)) ;; Can't dynamically bind non-dynamic var: clojure.core/max\n(def ^:dynamic max clojure.core/max)\n(binding [max clojure.core/min]\n (find-max 10 20)) ;; => 20\n(defn find-max [x y]\n (max x y)) ;; => #'user/find-max\n(binding [max clojure.core/min]\n (find-max 10 20)) ;; => 10\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":2631,"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;=> #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.
&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\n\r\nWe can see why:\r\n\r\n
(macroexpand-1 '(m)) ; => (clojure.core/let [user/x 1] user/x)\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
(defmacro m [] `(let [x# 1] x#))\r\n(m) ; => 1\r\n(macroexpand-1 '(m)) ; => (clojure.core/let [x__383__auto__ 1] x__383__auto__)","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
(defmacro m [] `(let [~'x 1] ~'x))\r\n(m) ; => 1\r\n(macroexpand-1 '(m)) ; => (clojure.core/let [x 1] x)\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-alldoesn'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"},{"body":"```\n(defn foldl\n [p i ss]\n (if (andmap seq ss)\n ;; `recur` is not a procedure\n (recur p (p i (map first ss)) (map rest ss))\n i))\n(defn andmap [p s] (reduce #(and %1 (p %2)) true s))\n(defn seq-of-len?\n [l t n]\n (and (t l) (= n (count l))))\n\n(defmacro for-fold\n \"A macro like for/fold in Racket\"\n [[& accs] [& itrs] & body]\n\n (doseq\n [cl (into `~accs `~itrs)]\n (assert (and (seq-of-len? cl list? 2) (symbol? (first cl))) (str \"Invalid accumulator or iterator:\" cl)))\n\n (let [acc-ids (map first `~accs)\n inits (map second `~accs)\n itr-ids (map first `~itrs)\n seqs (map second `~itrs)\n sym `result#\n len (count `~accs)\n\n all (into acc-ids itr-ids)]\n\n (assert (= (count all) (count (set all)))\n \"Duplicate names\")\n\n `(foldl (fn [[~@acc-ids] [~@itr-ids]]\n (let [~sym (let [] ~@body)]\n (assert (seq-of-len? ~sym vector? ~len) (str \"Invalid result:\" ~sym))\n ~sym))\n [~@inits]\n [~@seqs])))\n\n```","created-at":1720783640888,"updated-at":1720783703839,"author":{"avatar-url":"https://avatars.githubusercontent.com/u/93880182?v=4","account-source":"github","login":"Antigen-1"},"_id":"6691131869fbcc0c226174dc"}],"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":7588,"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
\nuser> ((every-pred (constantly false)))\ntrue\nuser> ((every-pred (constantly false)) 1)\nfalse\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":1570,"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":null,"line":1291,"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"},{"updated-at":1709613053865,"created-at":1313970180000,"body":";; create a clojure file on the fly using spit\n;; then load it into the REPL and use its function\n;; notice the return value is var quote of the last form of file\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","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/138993?v=3","account-source":"github","login":"Dimagog"},{"login":"bfontaine","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/1334295?v=4"},{"avatar-url":"https://avatars.githubusercontent.com/u/24317401?v=4","account-source":"github","login":"loeschzwerg"},{"login":"zenfey","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/6791543?v=4"}],"author":{"avatar-url":"https://www.gravatar.com/avatar/16046bb426a0fd26cbc876970fd8f746?r=PG&default=identicon","account-source":"clojuredocs","login":"shockbob"},"_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\nException similar to:
\r\njava.lang.ClassFormatError: Unknown constant tag 49 in class file parse$eval13\r\n\r\n
Please use read-string instead.
\r\n\r\nExample:(read-string (slurp \"data.clj\"))\r\n\r\nSource: Google Groups","created-at":1350351731000,"author":{"login":"dedeibel","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/e89e54d864f1e584c5ef4102f98bc83?r=PG&default=identicon"},"_id":"542692ecf6e94c6970521fee"},{"updated-at":1371613686000,"body":"
The following marginally helpful error will be thrown if you have a typo in your file:
\r\n\r\nCompilerException java.lang.RuntimeException: Unable to resolve symbol: load-file in this context, compiling:(NO_SOURCE_PATH:1:1)\r\n\r\n
Fix the syntax error(s) in and you'll be able to use load-file again.
\r\n\r\n\r\n","created-at":1371447277000,"author":{"login":"arkh","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/1c6ed9b963d758914c2744befd4974ca?r=PG&default=identicon"},"_id":"542692edf6e94c6970522005"}],"arglists":["name"],"doc":"Sequentially read and evaluate the set of forms contained in the file.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/load-file"},{"added":"1.0","ns":"clojure.core","name":"distinct?","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1396938477000,"author":{"login":"ryo","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/3f7913b563c72083c74030d928ba407e?r=PG&default=identicon"},"to-var":{"ns":"clojure.core","name":"distinct","library-url":"https://github.com/clojure/clojure"},"_id":"542692eaf6e94c6970521bf7"}],"line":5738,"examples":[{"updated-at":1521560626736,"created-at":1279073728000,"body":"user=> (distinct? 1 2 3)\ntrue\nuser=> (distinct? 1 2 3 3)\nfalse\nuser=> (distinct? 1 2 3 1)\nfalse","editors":[{"avatar-url":"https://avatars.githubusercontent.com/u/675861?v=3","account-source":"github","login":"fellipebrito"},{"login":"bfontaine","account-source":"github","avatar-url":"https://avatars2.githubusercontent.com/u/1334295?v=4"}],"author":{"avatar-url":"https://avatars.githubusercontent.com/u/147981?v=3","account-source":"github","login":"dpritchett"},"_id":"542692c9c026201cdc326a8f"},{"editors":[{"login":"Crowbrammer","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/19522656?v=4"},{"login":"rmfbarker","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/4708454?v=4"}],"body":"(distinct? ['A 'A 'c]) ;;=> true\n(distinct? 'A 'A 'c) ;;=> false\n(apply distinct? ['A 'A 'c]) ;;=> false\n\n(distinct? [1 1 'c]) ;;=> true\n(distinct? 1 1 'c) ;;=> false\n\n;; Like `min` or `max` and unlike `distinct` the \n;; parameters are taken separately, i.e. not in a \n;; collection. ","author":{"avatar-url":"https://avatars.githubusercontent.com/u/19522656?v=4","account-source":"github","login":"Crowbrammer"},"created-at":1615302123852,"updated-at":1687644700733,"_id":"60478debe4b0b1e3652d747d"}],"notes":null,"tag":"java.lang.Boolean","arglists":["x","x y","x y & more"],"doc":"Returns true if no two of the arguments are =","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/distinct_q"},{"added":"1.9","ns":"clojure.core","name":"pos-int?","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1495640931493,"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":"5925ab63e4b093ada4d4d730"},{"created-at":1495640936398,"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":"nat-int?","ns":"clojure.core"},"_id":"5925ab68e4b093ada4d4d731"},{"created-at":1495705345491,"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":"5926a701e4b093ada4d4d74e"}],"line":1422,"examples":[{"editors":[{"login":"svenschoenung","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/10583730?v=3"}],"body":"(pos-int? 1)\n;;=> true\n(pos-int? 9223372036854775807)\n;;=> true\n\n;;;; false for non-positive values\n\n(pos-int? 0)\n;;=> false\n(pos-int? -1)\n;;=> false\n\n;;;; false for decimal values\n\n(pos-int? 1.0)\n;;=> false\n(pos-int? 1/2)\n;;=> false\n\n;;;; false for BigInt values\n\n(pos-int? 1N)\n;;=> false\n(pos-int? 9223372036854775808)\n;;=> false","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/10583730?v=3","account-source":"github","login":"svenschoenung"},"created-at":1495703711193,"updated-at":1495703782768,"_id":"5926a09fe4b093ada4d4d74b"}],"notes":null,"arglists":["x"],"doc":"Return true if x is a positive fixed precision integer","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/pos-int_q"},{"added":"1.2","ns":"clojure.core","name":"extenders","file":"clojure/core_deftype.clj","type":"function","column":1,"see-alsos":[{"created-at":1542365699743,"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":"defprotocol","ns":"clojure.core"},"_id":"5beea203e4b00ac801ed9eff"},{"created-at":1542365712085,"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":"extends?","ns":"clojure.core"},"_id":"5beea210e4b00ac801ed9f00"}],"line":565,"examples":[{"author":{"login":"leifp","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/d2f37720f063404ef83b987d2824353d?r=PG&default=identicon"},"editors":[],"body":"user=> (defprotocol P (id [this]))\nP\nuser=> (extend-protocol P \n String \n (id [this] this)\n clojure.lang.Symbol \n (id [this] (name this))\n clojure.lang.Keyword\n (id [this] (name this)))\nnil\nuser=> (extenders P)\n(java.lang.String clojure.lang.Symbol clojure.lang.Keyword)\n","created-at":1342531381000,"updated-at":1342531381000,"_id":"542692d3c026201cdc326fa3"}],"notes":[{"author":{"login":"jumarko","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1083629?v=4"},"updated-at":1719483648471,"created-at":1719483648471,"body":";;; it doesn't cover defrecord or deftype\n;;; (Using example of the P protocol defined above)\n(defrecord PP []\n P\n (id [this] (str this \":\" this)))\n\n(deftype PPP []\n P\n (id [this] (str this \":\" this \":\" this)))\n\n(extenders P)\n;; => (java.lang.String clojure.lang.Symbol clojure.lang.Keyword)\n","_id":"667d3d0069fbcc0c226174d9"}],"arglists":["protocol"],"doc":"Returns a collection of the types explicitly extending protocol","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/extenders"},{"added":"1.3","ns":"clojure.core","name":"unchecked-short","file":"clojure/core.clj","type":"function","column":1,"see-alsos":[{"created-at":1496261308269,"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":"short","ns":"clojure.core"},"_id":"592f22bce4b06e730307db19"}],"line":3548,"examples":[{"editors":[{"login":"svenschoenung","account-source":"github","avatar-url":"https://avatars3.githubusercontent.com/u/10583730?v=3"}],"body":"(unchecked-short 1)\n;;=> 1\n(unchecked-short 1N)\n;;=> 1\n(unchecked-short 1.1)\n;;=> 1\n(unchecked-short 1.9)\n;;=> 1\n(unchecked-short 5/3)\n;;=> 1\n\n(unchecked-short -1)\n;;=> -1\n(unchecked-short -1N)\n;;=> -1\n(unchecked-short -1.1)\n;;=> -1\n(unchecked-short -1.9)\n;;=> -1\n(unchecked-short -5/3)\n;;=> -1\n\n;;;; Note that (unchecked-short) does not range check its argument\n;;;; so integer overflow or rounding may occur. \n;;;; Use (short) if you want to throw an exception in such cases.\n\n(unchecked-short 32768)\n;;=> -32768\n(unchecked-short -32769)\n;;=> 32767\n\n(short 32768)\n;;=> IllegalArgumentException Value out of range for short: 32768\n(short -32769)\n;;=> IllegalArgumentException Value out of range for short: -32769\n\n(unchecked-short 1.0E4)\n;;=> 10000\n(unchecked-short 1.0E5)\n;;=> -31072\n\n(short 1.0E4)\n;;=> 10000\n(short 1.0E5)\n;;=> IllegalArgumentException Value out of range for short: 100000.0\n","author":{"avatar-url":"https://avatars3.githubusercontent.com/u/10583730?v=3","account-source":"github","login":"svenschoenung"},"created-at":1496261208846,"updated-at":1496261256909,"_id":"592f2258e4b06e730307db17"}],"notes":null,"arglists":["x"],"doc":"Coerce to short. Subject to rounding or truncation.","library-url":"https://github.com/clojure/clojure","href":"/clojure.core/unchecked-short"},{"added":"1.0","ns":"clojure.core","name":"methods","file":"clojure/core.clj","static":true,"type":"function","column":1,"see-alsos":[{"created-at":1337585063000,"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":"542692ebf6e94c6970521f4f"},{"created-at":1337585066000,"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":"542692ebf6e94c6970521f50"},{"created-at":1337585074000,"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":"542692ebf6e94c6970521f51"},{"created-at":1337585077000,"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":"542692ebf6e94c6970521f52"}],"line":1828,"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=> (use 'clojure.pprint)\nuser=> (pprint (methods print-dup))\n{nil #(fn [coll]\r\n (let [gp (group-by identity coll)] \r\n (zipmap (keys gp) (map #(count (second %)) gp))))","created-at":1358885188000,"author":{"login":"lispro06","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/20c3faad6f66a434dae42b5ed8ad305?r=PG&default=identicon"},"_id":"542692edf6e94c6970521ffb"},{"updated-at":1370062406000,"body":" (into {} (for [[k v] (group-by identity \"abbbc\")] [k (count v)]))\r\n","created-at":1370062406000,"author":{"login":"danneu","account-source":"clojuredocs","avatar-url":"https://www.gravatar.com/avatar/c42635853936e509f76ece9d8187c4aa?r=PG&default=identicon"},"_id":"542692edf6e94c6970522004"},{"author":{"login":"ppsreejith","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1743700?v=3"},"updated-at":1453125303725,"created-at":1453125303725,"body":"
\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":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"}],"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":334,"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":[{"author":{"login":"p-himik","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/4410314?v=4"},"updated-at":1740861513006,"created-at":1740861513006,"body":"Note that the proxied methods are set up only after the constructor is called, so if you want to override anything that the constructor of the superclass calls, `proxy` is not the right thing to do it.","_id":"67c37049cd84df5de54e2080"}],"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":5179,"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":null,"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":924,"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":1834,"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#
(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":381,"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":1858,"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"},{"body":";; Works well with collections\n\n(def x {:whatever 1})\n\n(if-let [value (:whatever x)] value \"Not found\")\n;=> 1\n\n(if-let [value (:no-match x)] value \"Not found\")\n;=> \"Not found\"\n\n\n;; But destructuring presents a gotcha\n\n(if-let [{:keys [whatever]} x] whatever \"Not found\")\n;=> 1\n\n(if-let [{:keys [:no-match]} nil] no-match \"Not found\")\n;=> \"Not found\"\n\n(if-let [{:keys [no-match]} x] no-match \"Not found\")\n;=> nil\n\n(if-let [[a] [1 2 3]] a \"Not found\")\n;=> 1\n\n(if-let [[a] nil] a \"Not found\")\n;=> \"Not found\"\n\n(if-let [[a] []] a \"Not found\")\n;=> nil","author":{"login":"mattvvhat","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/367789?v=3"},"created-at":1428550556244,"updated-at":1768813183289,"editors":[{"login":"mattvvhat","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/367789?v=3"},{"avatar-url":"https://avatars.githubusercontent.com/u/2713?v=3","account-source":"github","login":"antonmos"},{"login":"pikariop","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/1998952?v=4"}],"_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":5717,"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":null,"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":2496,"examples":null,"notes":null,"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":473,"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":null,"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":507,"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":null,"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":null,"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":null,"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":5426,"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":null,"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":3486,"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"},{"updated-at":1726884771055,"created-at":1726884771055,"author":{"login":"wlkr","account-source":"github","avatar-url":"https://avatars.githubusercontent.com/u/5406568?v=4"},"body":";; attempting to get the class of a macro fails (see also `type`)\nuser=> (class let)\nCan't take value of a macro: #'clojure.core/let","_id":"66ee2ba369fbcc0c226174fa"}],"notes":null,"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":7628,"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":null,"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":6789,"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(let [myseq [1 2]]\r\n (case myseq\r\n [] \"empty seq\"\r\n [1 2] \"my seq\"\r\n \"default\"))\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
\r\n(defn equ\r\n [a b]\r\n (case [a b]\r\n ([true true] [false false]) true\r\n true))\r\n\r\n(equ true true) ;; returns true\r\n(equ false false) ;; returns true\r\n(equ false true) ;; return false\r\n(equ true false) ;; returns false\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":null,"examples":null,"notes":null,"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":340,"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#