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 mutabots | |
"Reimplementation of transducers, in terms of processing functions instead | |
of reducing functions. | |
tl;dr: reducing-fn based transducers are a special case, influenced by reducers, | |
of processing-fn based transducers. | |
In Clojure 1.7.0-alpha2, transducers are expressed in terms of the existing | |
concept of reducing functions. | |
To sum it up, a transducer has currently the signature : |
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 optimize [bids] | |
(letfn [(plan-at [plans h] (val (first (subseq plans >= h)))) | |
(step [plans [h bids]] | |
(assoc plans h (apply max-key :gain (val (first plans)) | |
(for [{:keys [vol depart prix]} bids | |
:let [{:keys [gain path]} (plan-at plans depart)]] | |
{:gain (+ gain prix) :path (conj path vol)}))))] | |
(val (first (reduce step (sorted-map-by > 0 {:gain 0 :path []}) | |
(sort-by key (group-by #(+ (:duree %) (:depart %)) bids))))))) |
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 classloader-handler | |
"Call cl-provider with the session each time a msg is sent. | |
The resulting classloader will then be used as context for executing msg." | |
[h cl-provider] | |
(fn [msg] | |
(let [classloader (cl-provider (:session msg)) | |
dynamic-loader (and classloader (clojure.lang.DynamicClassLoader. classloader))] | |
(when dynamic-loader | |
(swap! (:session msg) assoc clojure.lang.Compiler/LOADER dynamic-loader)) | |
(h msg)))) |
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 primes [] | |
((fn primes [candidate seen] | |
(lazy-seq | |
(letfn [(prime? [candidate] (when-not (some #(zero? (rem candidate %)) seen) candidate))] | |
(when-let [candidate (some prime? (iterate inc candidate))] | |
(cons candidate (primes (inc candidate) (cons candidate seen))))))) | |
2 ())) | |
(fact | |
(primes 1) => (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
; Daniel Shiffman's initial example in his PVector + Processing Tutorial | |
; re-written in clojure | |
(ns example1 | |
(:use [rosado.processing] | |
[rosado.processing.applet])) | |
(set! *warn-on-reflection* true) | |
(def x (atom 100)) |