This file contains hidden or 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
| ;; From e.g. https://github.com/scottjad/uteal | |
| (defmacro dlet | |
| "let with inspected bindings" | |
| [bindings & body] | |
| `(let [~@(mapcat (fn [[n v]] | |
| (if (or (vector? n) (map? n)) | |
| [n v] | |
| [n v '_ `(println (name '~n) ":" ~v)])) | |
| (partition 2 bindings))] | |
| ~@body)) |
This file contains hidden or 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
| (ns dft.core) | |
| (defn fft [x] | |
| (let [length (count x)] | |
| (if (<= length 1) | |
| (->> x | |
| (persistent!) | |
| (vec)) | |
| (let [x (transient x) | |
| even (recur (map #(nth % x) (range length))) |
This file contains hidden or 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
| { pkgs }: | |
| { | |
| allowUnfree = true; | |
| allowBroken = true; | |
| packageOverrides = self: with self; rec { | |
| etsEnv = self.buildEnv { | |
| name = "etsEnv"; |
This file contains hidden or 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 str-to-longs [^String s] | |
| (map #(Character/codePointAt s (long %)) (range (count s)))) |
This file contains hidden or 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 map-longest [f default & colls] | |
| (lazy-seq | |
| (when (some seq colls) | |
| (cons | |
| (apply f (map #(if (seq %) (first %) default) colls)) | |
| (apply map-longest f default (map rest colls)))))) |
This file contains hidden or 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 double [i] | |
| (bit-shift-left i 1)) | |
| (defn to-binary-seq [^long x] | |
| (map #(- (int %) (int \0)) | |
| (Long/toBinaryString x))) | |
| (defn addition-chain [x] | |
| (reduce #(if (zero? %2) | |
| (conj %1 (double (peek %1))) |
This file contains hidden or 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 halve [i] | |
| (bit-shift-right i 1)) | |
| (defn double [i] | |
| (bit-shift-left i 1)) | |
| (defn mul [x y] | |
| (let [x (take-while #(not= % 0) (iterate halve x))] | |
| (->> y | |
| (iterate double) |
This file contains hidden or 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 Y [f] | |
| ((fn [x] (x x)) | |
| (fn [x] | |
| (f (fn [& args] | |
| (apply (x x) args)))))) | |
| (def fac | |
| (fn [f] | |
| (fn [n] | |
| (if (zero? n) 1 (* n (f (dec n))))))) |
This file contains hidden or 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 max-index [v] | |
| (->> v | |
| (map-indexed vector) | |
| (apply max-key second) | |
| (first))) |
This file contains hidden or 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 swap [v i1 i2] | |
| (assoc v i2 (v i1) i1 (v i2))) |