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
(ns n01se.citystate) | |
(defn vitality | |
"Vitality of city." | |
[city]) | |
(defn owner | |
"Owning city. None is returned if no owner exists." | |
[city]) |
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
; STM history stress-test | |
(defn stress-ref [r] | |
(let [slow-tries (atom 0)] | |
(future | |
(dosync | |
(swap! slow-tries inc) | |
(Thread/sleep 200) | |
@r) | |
(println (format "r is: %s, history: %d, after: %d tries" |
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 cartes4 [a b & [c & cs :as more]] | |
(let [so-far (for [x a, y b] [x y])] | |
(if more | |
(recur so-far c cs) | |
(map flatten so-far)))) | |
(cartes4 [1 2 3] [9] [4 5] [6 7 8]) |
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 print-markdown-doc | |
"This is a modified version of print-doc which outputs the documentation in markdown format." | |
[v] | |
(let [{:keys [ns name arglists macro doc]} (meta v)] | |
(into [(format "###%s###" name) ""] | |
(->> (str " *" (ns-name ns) "/" name "*\n\n" | |
" :::clojure\n" | |
" " arglists "\n\n" | |
(when macro "*Macro*\n") | |
" " doc) |
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.net URL) '(java.io InputStreamReader BufferedReader)) | |
(defn get-url [x] | |
(with-open [a (-> (doto (-> x URL. .openConnection) | |
(.setRequestProperty "User-Agent" "clojurebot")) | |
.getInputStream InputStreamReader. BufferedReader.)] | |
(apply str (take-while identity (repeatedly #(.readLine a)))))) |
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 isPal [string] | |
(let [lower (.toLowerCase string)] | |
(= (seq lower) (reverse lower)))) |
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 status "this is my status") | |
(def rdr (java.io.PushbackReader. (java.io.StringReader. status))) | |
(distinct | |
(loop [words []] | |
(let [word (read rdr false nil)] | |
(if (word) | |
(recur (conj words word)) | |
words)))) | |
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
(ns org.drewolson.test-dragon | |
(:use clojure.contrib.test-is org.drewolson.dragon) | |
(:gen-class)) | |
(deftest foo | |
(is (= 1 1))) | |
(defn -main [] | |
(run-tests 'org.drewolson.test-dragon) | |
(.flush *test-out*)) |