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 foo.bar | |
(:use [quil.core]) | |
(:require [clojure.string :as s])) | |
(defn setup [] | |
(frame-rate 1) | |
(background 255)) | |
(def *scale* 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
(defprotocol IMutable | |
(-cas! [o oldval newval] | |
"Sets the value to newval if and only if the current value | |
is identical to oldval. Returns true if set happened, | |
otherwse returns false. Mutates `o`.") | |
(-alter! [o f] [o f x] [o f x y] [o f x y z] [o f x y z args] | |
"Changes referenced value with (apply f val args). | |
Returns new value. Mutates `o`.") | |
(-reset! [o val] | |
"Resets the referenced value to `val`. |
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 update-in* | |
[m [k & ks] f & args] | |
(let [k (if (and (instance? clojure.lang.Indexed m) | |
(integer? k) | |
(neg? k)) | |
(+ (count m) k) | |
k)] | |
(if ks | |
(assoc m k (apply update-in* (get m k) ks f args)) | |
(assoc m k (apply f (get m k) args))))) |
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
;; Input vector of bytes | |
(def vec (into (vector-of :byte) | |
(repeatedly 1000000 #(rand-int 128)))) | |
;; Output file | |
(def out (java.io.FileOutputStream. "out.bin")) | |
;; Classic reduction -> 3835 ms | |
(let [write-fn (fn [r w] (.write out w))] | |
(time (reduce write-fn nil (map dec vec)))) |
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
;; Multireducibles (with support for folding) | |
(def s1 "Hello World") | |
(def s2 "lllllllllll") | |
;; create multireducible with zip | |
(seq (zip s1 s2)) | |
;; => ((\H \l) (\e \l) (\l \l) (\l \l) (\o \l) (\space \l) (\W \l) (\o \l) (\r \l) (\l \l) (\d \l)) |
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
;; excerpt of foldable multireducible impl | |
;; | |
;; - introducing concept of mutable iterator, which is | |
;; much faster than seq | |
;; - this is for a (yet unreleased) custom patched clojure, | |
;; where clojure.lang interfaces can behave like protocols | |
;; - map is reducer variant, thats why I have to call seq on it | |
;; - seq is patched to support any reducible, not just Seqable | |
(defn fold-sectionable |
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
alert(); |
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
JSON-LD | |
{ | |
"@context": { | |
"name": "http://xmlns.com/foaf/0.1/name", | |
"homepage": { | |
"@id": "http://xmlns.com/foaf/0.1/homepage", | |
"@type": "@id" | |
} | |
}, |
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 redtest.core | |
(:require [clojure.core.reducers] | |
[clojure.core.protocols :refer | |
[CollReduce coll-reduce]])) | |
;; state is kept in a ret | |
(deftype WrapState [ret n]) | |
(deftype WrapTake [coll 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
(defprotocol IReducing | |
"A value protocol for augmented reducing functions." | |
(-init | |
"Returns default initial unwrapped value." | |
[this]) | |
(-finish | |
"Returns final wrapped result, and performs flushing or cleaning | |
of internal state. Returned wrap should have cleaned state, | |
so that eventual subsequent calls to -finish will perform | |
correctly. |
OlderNewer