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 breadth-first-traversal | |
([g start] | |
(breadth-first-traversal g [start] [[] #{}])) | |
([g queue [path visited]] | |
(if (seq queue) | |
(let [node (first queue) | |
next (remove visited (neighbors g node))] | |
(lazy-seq (breadth-first-traversal g (into (subvec queue 1) next) | |
[(conj path node) | |
(into (conj visited node) next)]))) |
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 se.raek.pipes.examples | |
(:use se.raek.pipes | |
clojure.contrib.server-socket | |
clojure.test)) | |
(with-test | |
(defn upper-responses [seq] | |
(->> seq | |
(filter #(.startsWith % "to-upper: ")) | |
(map #(.toUpperCase %)))) |
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 se.raek.trattern | |
(:use irclj.irclj)) | |
(defn on-message [{:keys [nick channel message irc]}] | |
(try | |
(when (re-find #"tratt" message) | |
(send-message irc channel "*TRollkarlshATT*")) | |
(catch Exception _ nil))) | |
(defonce bot (connect (create-irc {:name "trattern", :server "irc.quakenet.org", :fnmap {:on-message #'on-message}}) :channels ["#d1d"])) |
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
;; Eats stack, don't do this | |
(defn fac-naive [n] | |
(if (zero? n) | |
1 | |
(* n (fac-naive (dec n))))) | |
;; Uses a helper function to get an extra parameter when recurring | |
(defn fac-recur-hepler [n] | |
(letfn [(fac-helper [n acc] | |
(if (zero? n) |
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 parse-divs [divs] | |
(loop [divs divs, | |
date nil, | |
time nil, | |
result []] | |
(if (empty? divs) | |
(seq result) | |
(let [{:keys [type, content], :as div} (first divs)] | |
(condp = type | |
:date (recur (rest divs) content time result) |
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
;;; Color theme based on Tango Palette. Based on a color theme by danranx@gmail.com | |
(defun color-theme-dark-clojure () | |
"A color theme based on Tango Palette." | |
(interactive) | |
(color-theme-install | |
'(color-theme-dark-clojure | |
((background-color . "#2e3436") | |
(background-mode . dark) | |
(border-color . "#888a85") | |
(cursor-color . "#fce94f") |
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
{:constant-pool | |
([:text "clojure/core$comp"] | |
[:class "clojure.core$comp"] | |
[:text "clojure/lang/RestFn"] | |
[:class "clojure.lang.RestFn"] | |
[:text "core.clj"] | |
[:text "const__0"] | |
[:text "Lclojure/lang/Var;"] | |
[:text "const__1"] | |
[:text "Lclojure/lang/Keyword;"] |
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
{:constant-pool | |
([:method | |
["clojure.lang.Obj" | |
["<init>" {:params (), :return [:primitive :void]}]]] | |
[:field | |
["clojure.lang.LazySeq" ["fn" [:reference "clojure.lang.IFn"]]]] | |
[:method | |
["clojure.lang.Obj" | |
["<init>" | |
{:params ([:reference "clojure.lang.IPersistentMap"]), |
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 my-repeat [n x] | |
(when-not (zero? n) | |
(cons x (my-repeat (dec n) x)))) | |
(defn my-repeat [n x] | |
(lazy-seq | |
(when-not (zero? n) | |
(cons x (my-repeat (dec n) 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
(defn remove-prefix [xs ys] | |
(loop [xs (seq xs), ys (seq ys)] | |
(if (or (and (nil? xs) (nil? ys)) | |
(not= (first xs) (first ys))) | |
[xs ys] | |
(recur (next xs) (next ys))))) |