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
user> (def x 1) | |
#'user/x | |
user> (defn get-x [] x) | |
#'user/get-x | |
user> (binding [x 2] (get-x)) | |
IllegalStateException Can't dynamically bind non-dynamic var: user/x clojure.lang.Var.pushThreadBindings (Var.java:320) | |
user> (.setDynamic #'x) | |
#'user/x | |
user> (binding [x 2] (get-x)) | |
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
(ns schema->gen | |
"Functions for generating test data from schemas." | |
(:require [four.stateful :as four] | |
[re-rand :refer [re-rand]] | |
[schema.core :as sch] | |
[simple-check.generators :as gen])) | |
(defn ^:private re-randify-regex | |
"schema requires ^$ while re-rand forbids them" | |
[re] |
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 gen-subset | |
"Generates an even-cardinality subset of the given elements" | |
[elements] | |
(gen/for [bools (apply gen/tuple (repeat (count elements) gen/boolean)) | |
:let [true-count (->> bools (filter identity) (count))] | |
:when (even? true-count)] | |
(->> (map list bools elements) | |
(filter first) | |
(map second) | |
(set)))) |
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 quarto.core | |
"Trying to count the number of stalemate positions in quarto." | |
(:refer-clojure :exclude [bit-clear bit-test]) | |
(:require [clojure.set :as sets])) | |
(def quadruples | |
#{#{0 1 2 3} #{4 5 6 7} #{8 9 10 11} #{12 13 14 15} | |
#{0 4 8 12} #{1 5 9 13} #{2 6 10 14} #{3 7 11 15} | |
#{0 5 10 15} #{3 6 9 12}}) |
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 seque | |
[n s] | |
(let [ch (async/chan n)] | |
(async/go-loop [s s] | |
(try | |
(if-let [[x & xs] (seq s)] | |
(do (async/>! ch (list x)) | |
(recur xs)) | |
(async/close! ch)) | |
(catch Throwable t |
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 brainfuck | |
"A lazy brainfuck interpreter. | |
Memory consists of a fixed-length array of bytes in the range | |
0..255, where arithmetic wraps around. Moving the data pointer | |
out of the range of memory throws a SEGFAULT error. | |
Input must be given as a string or sequence when calling one | |
of the eval functions, and if the program tries to read after | |
input has been exhausted an exception will be thrown.") |
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#) |
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
$ 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
# | |
# 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 |
OlderNewer