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
;; xalan 2.6 gets put on the classpath when using | |
;; Incanter, causes issues with clj-xpath. So DON'T | |
;; use Incanter when using clj-xpath. | |
(->> (ClassLoader/getSystemClassLoader) | |
(.getURLs) | |
(map #(.toString %)) | |
(clojure.string/join "\n") | |
(re-seq #".*xalan.*") | |
(pprint)) |
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 | |
(html [:html | |
[:head | |
[:meta {:charset "utf-8"}] | |
[:title "Title"]] | |
[:body | |
[:header | |
[:h1 "H1 header!"]] | |
[:section | |
[:ul |
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 lazy-map [f coll] | |
(if (seq coll) | |
(lazy-seq (cons (f (first coll)) (lazy-map f (rest coll)))) | |
nil)) | |
;; The difference | |
clj-print.core> (type (seq (map print (range 50)))) | |
012345678910111213141516171819202122232425262728293031 | |
clojure.lang.ChunkedCons |
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
;; Grouped by n (0 choose k, 1 choose k, 2 choose k ... 19 choose k) | |
;; Again, making it harder than it needs to be | |
(let [binomial-cfs (for [n (range 20) | |
k (range (inc n))] | |
{:n n | |
:k k | |
:nCk (choose n k)})] | |
(doseq [n (into #{} (map :n binomial-cfs))] | |
(println (map :nCk (filter #(= n (:n %)) binomial-cfs))))) |
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
(pprint (take 500 (iterate (fn [fib] (+ 1 (/ 1 fib))) 1))) | |
; (1 | |
; 2 | |
; 3/2 | |
; 5/3 | |
; 8/5 | |
; 13/8 | |
; 21/13 | |
; 34/21 | |
; 55/34 |
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
;; Quicky Merge sort and test | |
(defn merge-sort [coll] | |
(letfn [(sort [coll] | |
(if (= 1 (count coll)) coll | |
(let [sz (count coll) | |
left (take (/ sz 2) coll) | |
right (drop (/ sz 2) coll)] | |
(merge (sort left) (sort right))))) | |
(merge [left right] |
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 [x] (list x (list (quote quote) x))) ;; yields (x (quote x)) | |
(quote (fn [x] (list x (list (quote quote) x)))) ;; yields (fn [x] (list x (list (quote quote) x))) | |
) ;; so the whole thing, via substituion, yields ((fn [x] (list x (list (quote quote) x))) (quote (fn [x] (list x (list (quote quote) 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
(let [is-dir (memfn isDirectory) | |
ff (reify java.io.FileFilter | |
(accept [this f] | |
(is-dir f)))] | |
(pprint | |
(seq | |
(.listFiles (java.io.File. "C:/") ff)))) | |
;; (#<File C:\$Recycle.Bin> | |
;; #<File C:\apache-ant-1.7.1> | |
;; #<File C:\Applications> |
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
(print-table | |
(for [n (range 15) | |
:let [row (map #(choose n %) (range (inc n)))]] | |
{:row (with-out-str (print row)) | |
:sum (reduce + row) | |
:binary (cl-format nil "~b" (bit-shift-left 2r00000001 n))})) | |
; | :row | :sum | :binary | | |
; |--------------------------------------------------------------+-------+-----------------| | |
; | (1) | 1 | 1 | |
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
(letfn [(m-even [v] | |
(if (zero? v) v | |
(fn [] (m-odd (dec v))))) | |
(m-odd [v] | |
(if (zero? v) v | |
(fn [] (m-even (dec v)))))] | |
(trampoline m-even 100000)) | |
;; => 0 | |
(letfn [(m-even [v] | |
(if (zero? v) v |
OlderNewer