var c = chan();
go(function() {
// async block
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 java.util.*; | |
import java.util.concurrent.Callable; | |
import java.util.function.Function; | |
class SLIP { | |
/** | |
* Keywords | |
*/ | |
public static final Object | |
_IF = new Object(), |
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 event [env type val] | |
(let [rc (chan)] | |
(>! (:queue @env) | |
{:type type :val val :rc rc :time (:now @env)}) | |
(<! rc))) | |
(defn bench [] | |
(time | |
(let [n 100000 |
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 history) | |
;; AN EXCERCISE IN TIME TRAVEL | |
;; =========================== | |
(defn hatom | |
"Atom that remembers previous states." | |
[x] | |
(atom {:value x | |
:history ()})) |
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
;; clojure solution for https://medium.com/@bellmar/is-cobol-holding-you-hostage-with-math-5498c0eb428b | |
;; HN: https://news.ycombinator.com/item?id=17636029 | |
(defn rec [y z] | |
(- 108 | |
(/ (- 815 | |
(/ 1500 z)) | |
y))) | |
(defn rec-list [N] |
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 extrapolate | |
"Returns a lazy seq produced by extrapolating `coll` with given rules. | |
On each iteration, | |
`gen-next` is called with the entire seq generated till this iteration | |
`shrink` is called with the extrapolated seq (`identity` by default)" | |
([gen-next coll] | |
(extrapolate gen-next identity coll)) | |
([gen-next shrink coll] | |
(concat coll | |
(let [curr (volatile! (seq coll))] |
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 fork-join-recur | |
(:import [java.util.concurrent ForkJoinPool | |
ForkJoinWorkerThread ForkJoinTask RecursiveTask])) | |
;; API | |
;; === | |
(def ^:dynamic ^ForkJoinPool *pool* (ForkJoinPool/commonPool)) | |
(defmacro fork [& body] | |
`(let [^ForkJoinTask task# (proxy [RecursiveTask] [] |
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 calculus) | |
(defonce ^:const dx 0.00001M) | |
(defn df | |
"Returns the derivative of f." | |
[f] | |
(fn [x] | |
(/ (- (f (+ x dx)) (f x)) | |
dx))) |
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 do(*body): | |
return body[-1] | |
# Example (Python 2) | |
# ======= | |
map(lambda x: do( | |
print('x =', x), | |
x * x), | |
range(5)) |
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
# Abstract Class | |
# ============== | |
class ISeq | |
def first | |
end | |
def rest | |
end | |
def [](idx) |