This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Unlike fully lazy languages such as Haskell, Clojure seqs often implement chunking. | |
;; This means that when accessing the first element of a sequence, 32 members will be evaluated. | |
;; An example of this can be seen by implementing some side effect in a map. | |
(first (map (fn [x] (prn x) x) (range 5))) ;; prints 0 through 4, then returns 0 | |
;; The above example will return 0 (as expected), but you'll notice it prints off all 5 elements | |
;; of (range 5). | |
;; In the next case we can see that the evaluation caused by the access of the first element stops after | |
;; the first 32 elements are evaluated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Demonstrates the usage of vars that are useful when working in the REPL. | |
;; Created: November 14, 2018 | |
;; | |
;; My suggested method of reading this file is to copy it into some project and actually | |
;; go through the code snippets and evaluate in the REPL to play around with them. | |
;; | |
;; WARNING: Some of the examples will create a file called 'output.txt' from the directory | |
;; that your REPL is started in. | |
;; | |
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; This document is meant to demonstrate a common misunderstanding in how | |
;; clojure.async's go blocks handle parallel processing. | |
(require '[clojure.core.async :as a]) | |
;; non-blocking core async example. | |
(time (let [n 1000 | |
vals-coll (atom [])] | |
(let [pipeline-chan (a/chan 1)] | |
(dotimes [i n] (a/go (a/>! pipeline-chan i))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; I use these when I want to throw a lot of `time` functions into code, | |
;; as it allows me to append a log to it. Using log-time-str I can | |
;; pass the str to whatever logging library I'm using at the time, | |
;; to achieve any benefits from that. | |
(defmacro log-time | |
"prints msg and the approximate number of milliseconds it took to | |
eval the given expression. Returns the result of the expr." | |
[msg expr] | |
`(let [start-time# (System/nanoTime) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am enforser on github. | |
* I am enforser (https://keybase.io/enforser) on keybase. | |
* I have a public key ASAA7YHJZ-i09gJFWLxJKP2fUwHfgfFpu0GbvgvXvGYCcAo | |
To claim this, I am signing this object: |