Skip to content

Instantly share code, notes, and snippets.

View laurentpetit's full-sized avatar

Laurent Petit laurentpetit

View GitHub Profile
@laurentpetit
laurentpetit / mutabots.clj
Last active May 12, 2021 23:21 — forked from cgrand/mutabots.clj
Reimplementation of transducers, in terms of processing functions instead of reducing functions. WIP.
(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 :
(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)))))))
@laurentpetit
laurentpetit / gist:2912899
Created June 11, 2012 21:37 — forked from charles-dyfis-net/gist:2909106
clojure.osgi aware nREPL middleware
(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))))
@laurentpetit
laurentpetit / gist:1233437
Created September 21, 2011 21:56 — forked from denlab/gist:1231894
coding-dojo-20110921
(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)
; 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))