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
(s/def ::quine | |
((fn [x] | |
(s/cat :the-def #{'s/def} | |
:the-quine #{::quine} | |
:the-spec (s/spec | |
(s/cat :x #{x} | |
:x' (s/spec | |
(s/cat :quote #{'quote} | |
:x #{x})))))) | |
'(fn [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
(ns forty-two-doubles.core | |
(:require [clojure.walk :as walk] | |
[clojure.string :as string] | |
#?(:clj [com.gfredericks.doubles :refer [parse-double]]) | |
[forty-two-doubles.four :as four #?@(:cljs [:include-macros true])] | |
[plumbing.core :as p])) | |
(defn positive-infinity? | |
[x] | |
#?(:clj (= x Double/POSITIVE_INFINITY) |
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 lazy-shuffle | |
"Returns a locally-shuffled lazy seq from the given collection. The first | |
arg has something to do with how it works so make sure it's a good one." | |
[window-size coll] | |
(let [[xs more] (split-at window-size coll)] | |
((fn self [v more] | |
(lazy-seq | |
(if (empty? more) | |
v | |
(let [[x & more] more |
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
;; | |
;; Example of using bind to generate a sequence of events, where each | |
;; event can be generated based on the previous events | |
;; | |
(ns user | |
(:require [clojure.test.check.generators :as gen])) | |
(def init-state | |
{:ids #{}}) |
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
;; example use at the bottom | |
(ns user | |
(:require [schema.core :as s] | |
[camel-snake-kebab.core :as csk] | |
[plumbing.core :refer [for-map map-keys map-vals]])) | |
(defn key->keyword | |
[k] | |
(cond (keyword? k) k |
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 sneaky-NaNs | |
"Secret codez.") | |
(defn char->NaN | |
[c] | |
(-> c | |
(int) | |
(bit-or 0x7ff8000000000000) | |
(Double/longBitsToDouble))) | |
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
# | |
# In your project.clj, make sure you're currently using test.check | |
# version 0.7.0, then add a plugins entry: | |
# | |
# :plugins [[com.gfredericks/corncob-cigar "0.1.4"]] | |
# | |
# Then run: | |
echo "Testing 0.7.0..." > test.check.log | |
lein do clean, benchmark-task 10 test 2>/dev/null | grep "Ran task 10 times" >> test.check.log |
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
$ grep unchecked_multiply clojure/lang/Numbers.java | |
static public long unchecked_multiply(long x, long y){return x * y;} | |
static public Number unchecked_multiply(Object x, Object y){return multiply(x,y);} | |
static public double unchecked_multiply(double x, double y){return multiply(x,y);} | |
static public double unchecked_multiply(double x, Object y){return multiply(x,y);} | |
static public double unchecked_multiply(Object x, double y){return multiply(x,y);} | |
static public double unchecked_multiply(double x, long y){return multiply(x,y);} | |
static public double unchecked_multiply(long x, double y){return multiply(x,y);} | |
static public Number unchecked_multiply(long x, Object y){return multiply(x,y);} | |
static public Number unchecked_multiply(Object x, long y){return multiply(x,y);} |
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
;; 0: | |
(-> Math/E Math/toRadians Math/round) | |
;; 1: | |
(-> Math/E Math/log Math/round) | |
;; 2: | |
(-> Math/E Math/sqrt Math/round) | |
;; 3: | |
(-> Math/E Math/round) | |
;; 4: | |
(-> Math/PI Math/ceil Math/round) |
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
(defmacro rec-lazy-seq | |
"Like lazy-seq, but also takes a single binding form that will be | |
a reference to the lazy seq object itself, so that the lazy seq can | |
be defined in terms of itself." | |
[[name] & body] | |
`(let [p# (promise) | |
ls# (lazy-seq | |
(let [~name (lazy-seq @p#)] | |
~@body))] | |
(deliver p# ls#) |