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 first-cloj.core) | |
(def list-of-words ["horse" "dog" "bird"]) | |
(def init {:guesses [] :incorrect-guesses 0}) | |
(def hang-vec | |
[" ______" | |
" | |" | |
" O |" | |
"/|\\ |" |
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 '[meander.epsilon :as m]) | |
(require '[meander.strategy.epsilon :as m*]) | |
(def simplify-conjunctions | |
(m*/rewrite | |
[:and_expr ?x] ?x | |
[:or_expr ?x] ?x)) | |
(def simplify-all-conjs | |
(m*/bottom-up |
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 '[cognitect.transit :as t]) | |
(def jt js/transit) | |
(def r (t/reader :json)) | |
(def w (t/writer :json)) | |
(def jr (jt.reader "json")) | |
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
Outside of the bevy of good answers, I think there's some utility in discerning between concurrency and parallelism. I like rob pike's talk "Concurrency is not Parallelism". Clojure has great features for handling concurrency (dealing with lots of things happening at the same time) and enabling correct solutions without much effort. Those features extend into enabling parallelism (doing lots of things at the same time). I think the immutable data model and the early focus on integrated STM constructs (designed to be used with the immutable data structures) helped a lot. core.async borrowing the communicating sequential processes (CSP) from go added even more options for correct concurrency. | |
So if you can write correct concurrent programs, then you can begin to leverage system resources (e.g. cores) to distribute how work is done and maybe get some performance improvement on top (or maybe not, or maybe up to a point....it depends). | |
Alternately, if you have a bunch of independent work that you want to chew th |
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 some-fast [f xs] | |
(reduce (fn [acc x] | |
(let [res (f x)] | |
(if res (reduced res) | |
acc))) | |
false xs)) | |
(defn toDigits [s] (mapv read-string (re-seq #"\d+" s))) | |
(defn parseInput [d] |
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 prims) | |
(defprotocol IPrimitiveReducible | |
(reduce-prim- [this f init])) | |
(definterface IPrimitiveReduce | |
(^long LLLreduce [^clojure.lang.IFn$LLL f ^long init]) | |
(^double DDDreduce [^clojure.lang.IFn$DDD f ^double init])) | |
(def am->type |
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 '[leiningen.core.utils :refer [get-os]]) | |
(def JVMOPTS | |
"Per os jvm options. Options common to all cases go under | |
`:any`. Options specific to one OS go under the key returned by | |
`leiningen.core.eval/get-os` for that system. Temporarily disabled | |
options can be kept under `:disabled`." | |
{:any | |
["-Xms512m" "-Xmx1g" ; Minimum and maximum sizes of the heap | |
"-XX:MaxGCPauseMillis=20" ; Specify a target of 20ms for max gc pauses |
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 threadjunk | |
(:import [java.util.concurrent ConcurrentHashMap] | |
[java.util.function Function])) | |
;;satisfy conc hashmap's needs.. | |
(defn Func ^Function [f] | |
(reify Function | |
(apply [this v] (f v)))) | |
(defn get-binding! [^ConcurrentHashMap ctx k ^Function f] |
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 data {:people [{:username :bilbo} {:username :jim}]}) | |
;;benign mutation. | |
(defn person-joined2 [state person] | |
(let [username (:username person) | |
seen (atom nil) | |
is-joined-user? #(when (= username (:username %)) | |
(reset! seen username))] | |
(update state :people | |
(fn [people] |
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
(defprotocol INominal | |
(partial-nominal [this args])) | |
(defn ->args [xs] | |
(let [arg->idx (zipmap xs (range (count xs)))] | |
(reduce (fn [acc k] (assoc acc k :binding/unbound)) | |
(sorted-map-by (fn [l r] | |
(compare (arg->idx l) (arg->idx r)))) xs))) | |
(defn supply [params xs] |
NewerOlder