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
(definterface INode | |
(getNext []) | |
(setNext [n]) | |
(getPrev []) | |
(setPrev [n])) | |
(deftype Node | |
[data | |
^:unsynchronized-mutable prev | |
^:unsynchronized-mutable next] |
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
(declare permutations) | |
(defn permute [s x] | |
(let [ps (permutations (remove (partial = x) s))] | |
(map #(cons x %) ps))) | |
(defn permutations [s] | |
(if (-> s (count) (= 1)) | |
(list s) | |
(mapcat (partial permute s) s))) |
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
length :: | |
List a | |
-> Int | |
length Nil = 0 | |
length (_ :. xs) = 1 + length xs | |
-- >> length infinity | |
-- *** Exception: stack overflow |
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 trampoline(func): | |
def decorated(*args): | |
f = func(*args) | |
while callable(f): | |
f = f() | |
return f | |
return decorated | |
@trampoline | |
def fact(n, acc=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
import functools | |
import types | |
def gentramp(gen): | |
def unroll(g): | |
while isinstance(g, types.GeneratorType): | |
g = g.next() | |
return g |
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 combinations | |
([s] (combinations s (list ()))) | |
([s acc] | |
(if-not s | |
acc | |
(let [combos (map #(conj % (first s)) acc)] | |
(recur (next s) (concat acc combos)))))) |
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
;; Greater-Than and Less-Than comparator->bool helpers | |
(defn gt? [x y] | |
(case (compare x y) | |
1 true | |
0 false | |
-1 false)) | |
(defn lt? [x y] | |
(case (compare 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
(def gt? (comp pos? compare)) | |
(def lt? (comp neg? compare)) | |
(definterface INode | |
(getLeft []) | |
(getRight []) | |
(setLeft [n]) | |
(setRight [n]) | |
(getKey []) |
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
;; A simple mark-and-sweep implementation over a toy VM | |
(ns broom.core | |
(:clojure-refer :exclude [pop])) | |
;; Maximum stack size | |
(def ^:const STACK-MAX 256) | |
;; Virtual Machine global ref | |
(def ^:private vm (ref {:max-objs 10 |
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 locksmithing.queue-model-test | |
(:require [clojure.pprint :refer [pprint]] | |
[clojure.test :refer :all] | |
[knossos.core :refer [linearizations | |
linearizable-prefix | |
op | |
->Register]] | |
[locksmithing.queue :refer [queue]]) | |
(:import [locksmithing.queue Node] | |
[java.util.concurrent.atomic AtomicReference])) |
OlderNewer