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
lein uberjar error: | |
lein uberjar | |
Cleaning up | |
Exception in thread "main" clojure.lang.LispReader$ReaderException: java.lang.Exception: Invalid token: d: | |
at clojure.lang.LispReader.read(LispReader.java:180) | |
at clojure.core$read.invoke(core.clj:2872) | |
at clojure.core$read.invoke(core.clj:2870) | |
at clojure.main$eval_opt.invoke(main.clj:233) | |
at clojure.main$initialize.invoke(main.clj:254) |
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
#!/usr/bin/env python | |
import os | |
import sys | |
class_path = [] | |
dot_clojure = os.path.join(os.environ['HOME'], '.clojure') | |
dot_jars = os.path.join(os.environ['HOME'], '.jars') |
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 merge-seqs | |
"Merges sorted seqs of Comparable objects as in merge sort. Uses | |
left-to-right precedence order among the input seqs when duplicates | |
are present. Uses clojure.core/compare." | |
([xs ys] | |
(lazy-seq | |
(if (or (empty? xs) (empty? ys)) | |
(concat xs ys) | |
(let [x (first xs) | |
y (first ys)] |
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
(def CONS | |
(fn [a b] | |
(fn [x] | |
(if (= x -1) | |
'CONS | |
(if (= x 0) | |
a | |
b))))) | |
(def 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 munge [vs] | |
(if (== 1 (count (first vs))) | |
(reduce into vs) | |
(let [gs (group-by #(% 0) vs)] | |
(map (fn [k v] | |
{:data k :children v}) | |
(keys gs) | |
(->> (vals gs) | |
(map (partial map #(subvec % 1))) | |
(map munge)))))) |
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
;;; (set! *warn-on-reflection* true) | |
;;; for more spectacular results | |
(defn fact [n] | |
(loop [n (long n) r 1] | |
(if (zero? n) | |
r | |
(recur (num (dec n)) (* r 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
;;; implementation of Rob Lachlan's idea, see | |
;;; http://stackoverflow.com/questions/3078811#3080868 | |
(defn prime-Powers-LCM [m] | |
(zipmap (primes m) | |
(map (fn [p] | |
(->> (range) | |
(drop-while #(<= (expt p %) m)) | |
first | |
dec)) | |
(primes m)))) |
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 gcd | |
([x y] | |
(cond (zero? x) y | |
(< y x) (recur y x) | |
:else (recur x (rem y x)))) | |
([x y & zs] | |
(reduce gcd (gcd x y) zs))) | |
(defn lcm | |
([x y] (/ (* x y) (gcd x y))) |
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
;;; how come the first version seems to be faster...? | |
(defn fact [n] | |
(loop [n n r 1] | |
(if (zero? n) | |
r | |
(recur (dec' n) (*' r n))))) | |
(defn ^:static fact ^long [^long n] | |
(loop [n n r 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
user> (defn multi-comparator [& comps] | |
(reify java.util.Comparator | |
(compare [this x y] | |
(reduce (fn [r ^java.util.Comparator c] | |
(if (zero? r) (.compare c x y) r)) | |
0 | |
comps)))) | |
#'user/multi-comparator | |
;;; earlier versions, last-to-first |