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 primes3 [max] | |
(let [enqueue (fn [sieve n factor] | |
(let [m (+ n (+ factor factor))] | |
(if (sieve m) | |
(recur sieve m factor) | |
(assoc sieve m factor)))) | |
next-sieve (fn [sieve candidate] | |
(if-let [factor (sieve candidate)] | |
(-> sieve | |
(dissoc candidate) |
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 x (ref 0)) | |
(def a (agent nil)) | |
(defn alter-and-send-side-effects | |
"Alters refs then sends println actions to agent with new values" | |
[] | |
(dosync | |
(let [newx (alter x inc)]) | |
(send a (fn [_] (println "x is" newx))))) |
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 [q (ref []), x (ref 0)] | |
(defn run-side-effects [_] | |
(let [fs (dosync | |
(let [q' @q] | |
(ref-set q []) | |
q'))] | |
(doseq [f fs] (f)))) | |
(defn alter-and-order-side-effects [] | |
(dosync |
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 hello [x] | |
(println "Hello" x)) | |
(hello "name") |
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
(require '[clojure.core.logic :refer :all]) | |
(require '[clojure.core.logic.fd :as fd]) | |
(defn sumo | |
([l n] (sumo l 0 n)) | |
([l acc n] | |
(matche [l] | |
([[]] (fd/== acc n)) | |
([[x . r]] | |
(fresh [nacc] |
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
(require '[clojure.core.logic :refer :all]) | |
(require '[clojure.tools.macro :as macro]) | |
(defne righto [x y l] | |
([_ _ [x y . ?r]]) | |
([_ _ [_ . ?r]] (righto x y ?r))) | |
(defn nexto [x y l] | |
(conde | |
((righto x y 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
;; works with core.logic 0.8.4 | |
(require '[clojure.core.logic :refer :all]) | |
(require '[clojure.core.logic.fd :as fd]) | |
(defn get-square [rows x y] | |
(for [x (range x (+ x 3)) | |
y (range y (+ y 3))] | |
(get-in rows [x y]))) | |
(defn init [vars hints] |
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 lame[]) |
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 m | |
[{:home "Manchester United" :away "Manchester City" :home_score 1 :away_score 0} | |
{:home "Manchester United" :away "Manchester City" :home_score 2 :away_score 0} | |
{:home "Manchester City" :away "Arsenal" :home_score 1 :away_score 1}]) | |
(def teams | |
{"Manchester United" {:points 1200} | |
"Manchester City" {:points 1200} | |
"Arsenal" {:points 1200}}) |
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
(add-hook 'js-mode-hook | |
(lambda () | |
(paredit-mode 1) | |
(local-set-key "{" 'paredit-open-curly) | |
(local-set-key "}" 'paredit-close-curly) | |
(local-set-key "\M-{" 'paredit-wrap-curly) | |
(local-set-key "\M-}" 'paredit-close-curly-and-newline) | |
(local-set-key "\M-[" 'paredit-wrap-square) | |
(local-set-key "\M-]" 'paredit-close-square-and-newline))) |
OlderNewer