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 test.core | |
(:require [clojure.spec :as s] | |
[clojure.spec.test :as stest] | |
[clojure.test.check.generators :as gen])) | |
(s/def ::file-count nat-int?) | |
(s/def ::operations (s/map-of keyword? pos-int?)) | |
(s/def ::time-total (s/and double? (complement neg?))) | |
(s/def ::summary-res |
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
(transform | |
[MAP-VALS | |
(view frequencies) | |
(collect-one (view #(apply max (vals %))))] | |
(fn [mx fs] (transform MAP-VALS #(/ % mx) fs)) | |
{:a [1 1 3 4] :b [1 1 2 2 2 3]}) | |
;; => {:a {1 1, 3 1/2, 4 1/2}, :b {1 2/3, 2 1, 3 1/3}} |
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
;; Expanding the following expression as far as it can go: | |
(filter even? (range 10)) | |
;; equals | |
(lazy-seq | |
(when-let [s (seq (range 10))] | |
(if (chunked-seq? s) | |
(let [c (chunk-first s), size (count c), b (chunk-buffer size)] |
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 rdp-214.core | |
(:require [clojure.java.io :as io] | |
[clojure.string :as str] | |
[clojure.core.typed :as t | |
:refer [ann U Seq Str Vec Sequential]])) | |
;;;; Boilerplate ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
(t/tc-ignore |
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 little-schemer.benchmark | |
"Benchmarking the function C of the Collatz Conjencture: | |
http://en.wikipedia.org/wiki/Collatz_conjecture | |
in regular Clojure (C*) and as it is defined in the book The Little Schemer, | |
where all of the parts are defined recursively in terms of add1 and sub1." | |
(:gen-class) | |
(:refer-clojure :exclude [even?]) | |
(:require [criterium.core :refer [quick-bench]])) |
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 C | |
[n] | |
(cond | |
(one? n) 1 | |
(even? n) (C (div n 2)) | |
:else (C (add1 (times 3 n))))) | |
(defn C* [n] | |
(cond | |
(= 1 n) 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
(defn C [n] | |
(cond | |
(one? n) 1 | |
(even? n) (C (div n 2)) | |
:else (C (add1 (times 3 n))))) | |
(defn C* [n] | |
(cond | |
(= 1 n) 1 | |
(clojure.core/even? n) (C (quot n 2)) |
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
(filter even? (range 10)) | |
;; equals | |
(new clojure.lang.LazySeq | |
(fn [] | |
(when-let | |
[s (. clojure.lang.RT | |
(seq (new clojure.lang.LazySeq | |
#(let [b (clojure.lang.ChunkBuffer. 32) |
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 debug-walker.core | |
(:refer-clojure :exclude [read-string]) | |
(:require [clojure.java.io :as io] | |
[clojure.repl :as repl] | |
[clojure.tools.reader :refer [read-string]] | |
[clojure.pprint :refer [pprint]] | |
[rewrite-clj.zip :as z]) | |
(:import [java.io LineNumberReader InputStreamReader PushbackReader])) | |
(defn file-source-fn |
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
;; Given that: | |
(destructure | |
'[[f [a b] {:keys [c d]} & rs] | |
[:first [:a 1 :b 2] {:c "C" :d "D"} 3 4 5]]) | |
;; => | |
[vec__22487 [:first [:a 1 :b 2] {:c "C", :d "D"} 3 4 5] | |
f (clojure.core/nth vec__22487 0 nil) | |
vec__22488 (clojure.core/nth vec__22487 1 nil) | |
a (clojure.core/nth vec__22488 0 nil) |