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
package leak; | |
import clojure.lang.IFn; | |
import clojure.lang.RT; | |
import clojure.lang.Symbol; | |
public class Klass { | |
static { | |
RT.var("clojure.core", "require").invoke(Symbol.intern("leak.leaky")); | |
} |
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
;; lenses in Clojure again, van Laarhoven-style this time | |
(defprotocol Lens | |
(through [lens x cont])) | |
(extend-protocol Lens | |
clojure.lang.Keyword | |
(through [k x cont] | |
(cont #(assoc x k %) (k x)))) |
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
;; no general let rec in clojure (there's its limited form letfn) | |
;; let s = connect arg (\data -> handle s data) | |
(let [s (promise)] | |
(deliver s (connect (fn [data] (handle @s data)))) | |
@s) | |
;; you can tie the knot in other places (and other ways too: promises are not the only way) |
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
;; a number is a function of 3 args: f0, f1 and init. | |
;; f0 and f1 are functions of one arg: the half of the current number | |
;; init is returned only by zero | |
;; I could have done with only one f taking two arguments (the bit and the half). | |
;; I also prefer this to a true right fold representation. | |
(defn zero [f0 f1 init] init) ; zero returns init | |
(defn one [f0 f1 init] (f1 zero)) ; one calls f1 on its half (zero) | |
(defn x2 |
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
(cond-> (remix-wrapper-doc doc body-tag a-charte appli) | |
(nil? menu) (doto (-> (.select ".barretitretitre") (.attr "style" "padding-top:30px")))) |
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
(defmulti transmogrify | |
"Rewrites the last form of a thread-last to use transducer (if possible)." | |
(fn [f xform src & args] f)) | |
(defmacro transmogrify->> | |
"Like ->> but uses transducers" | |
([x] x) | |
([src & xs] | |
(let [end (last xs) | |
xforms (butlast xs) |
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
;; is a macro really called for? when evaluating defs? | |
;; | |
;; for M2M instead of a macro woudn't it be better to upgrade your own repl (capture all streams and don't let the real repl handle this) | |
;; | |
;; also for M2M you can choose to pretty print on the client side and use tagged literals to make abbreviated datastructure (*print-level* and *print-length*) | |
;; readable so that further printing can be done on demand while the user browse the data. | |
(defmacro rpc [& body] | |
`(let [out-eval# (java.io.StringWriter.) | |
err-eval# (java.io.StringWriter.) | |
out-print# (java.io.StringWriter.) |
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
;; my branch | |
ser=> Map of size 16 | |
WARNING: Final GC required 8.58679825463792 % of runtime | |
Evaluation count : 289770 in 6 samples of 48295 calls. | |
Execution time mean : 2,112323 µs | |
Execution time std-deviation : 122,879960 ns | |
Execution time lower quantile : 2,003930 µs ( 2,5%) | |
Execution time upper quantile : 2,295635 µs (97,5%) | |
Overhead used : 2,012747 ns |
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 1 column, instead of 6. in line 4.
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
PersistentHashMap benchmark: kvbitmap vs master | |
results are kvbitmap runtime / master runtime | |
below 100% kvbitmap is faster | |
above 100% master is faster | |
size assoc! assoc get dissoc dissoc! | |
16 84,64% 91,21% 96,56% 99,84% 89,91% | |
64 80,12% 91,66% 98,66% 104,97% 92,78% | |
256 89,37% 99,33% 97,59% 111,69% 98,20% |
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
(defn hilbert-distance [n x y] | |
(loop [s (bit-shift-right n 1) d 0 x (long x) y (long y)] | |
(if (pos? s) | |
(let [rx (bit-and x s) | |
ry (bit-and y s) | |
d (+ d (* s (bit-xor (* 3 rx) ry))) | |
s' (bit-shift-right s 1)] | |
(if (zero? ry) | |
(if (zero? rx) | |
(recur s' d y x) |