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
(reduce (fn [mentioned-files file] | |
(if (some #{file} mentioned-files) | |
mentioned-files | |
(let [duplicates (duplicates-of-file file files (:precision options))] | |
(when (seq duplicates) | |
(printf "%s\n" file) | |
(doseq [d duplicates] | |
(printf "%s\n" d)) | |
(printf "\n")) | |
(concat mentioned-files duplicates)))) |
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
def categorize(fn, coll): | |
"""Like group_by, but fn returns multiple keys""" | |
acc = {} | |
for e in coll: | |
for key in fn(e): | |
acc.setdefault(key, []).append(e) | |
return acc | |
def group_by(fn, l): |
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
(fn [o] | |
(set | |
((fn q [s o c] | |
(apply concat | |
(let [a (when (pos? o) | |
(q (concat s "(") (dec o) (inc c))) | |
b (when (pos? c) | |
(q (concat s ")") o (dec c)))] | |
(if (and (zero? o) (zero? c)) | |
[[(clojure.string/join s)]] |
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
;; not sure whether this is an improvement but I don't really like letfn | |
(defn keep-only | |
[n bucket-fn s] | |
((fn my-filter | |
[s seen] | |
(lazy-seq | |
(when (seq s) | |
(let [e (first s) | |
b (bucket-fn e) | |
c (inc (get seen b 0))] |
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
(use 'name.choi.joshua.fnparse) | |
(def tokenize (partial re-seq #"[\[\](){}]|[^\[\](){}]+")) | |
(defn initial-state | |
[input] {:remainder (tokenize input) | |
:brackets (list)}) |
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
(import java.awt.event.ActionListener) | |
(defn add-action [cmp fn] | |
(doto cmp | |
(.addActionListener (doto (proxy [ActionListener] []) | |
(update-proxy {"actionPerformed" fn}))))) | |
(defn add-action [cmp fn] | |
(doto cmp | |
(.addActionListener (reify ActionListener |
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
(defmacro when-lets [bindings & body] | |
(reduce (fn [acc tstform] | |
`(when-let ~tstform ~acc)) | |
(cons 'do body) | |
(reverse (map vec (partition 2 bindings))))) | |
(when-lets [n (first sizes) | |
s (seq coll)] | |
(cons (take n coll) | |
(partitions (next sizes) (drop n coll))))) |
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
(defmacro phase-fn | |
([argvec] identity) | |
([argvec subphase & left] | |
`(fn [session# ~@argvec] | |
(--> session# | |
~subphase | |
~@(when left | |
[`((phase-fn ~argvec ~@left))]))))) |
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
(defmacro defratios | |
"Defines two converter functions with num-expr being how many of a make up b. | |
For example, there are 100 centimeters in a meter. To tell the program to make | |
(centimeter->meter) and (meter->centimeter), use (defratios meter centimeters 100)" | |
[a-symb b-symb num-expr] | |
(and (every? #{clojure.lang.Symbol} | |
(map type [a-symb b-symb])) | |
(let [ab-symb (symbol (arr a-symb b-symb)) | |
ba-symb (symbol (arr b-symb a-symb)) | |
num (gensym "num-")] |
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 routes | |
"Calculates all the routes from [x y] to [0 0]. | |
Routes move only down and left." | |
[x y] | |
((fn routes* [queue] | |
(lazy-seq | |
(loop [queue queue] | |
(when (pos? (count queue)) | |
(let [[current-level [x y]] (peek queue) | |
queue-left (pop queue) |
OlderNewer