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 flog) | |
(defprotocol Log | |
(append [log expression]) | |
(replay [log])) | |
(deftype SeqLog [log-ref] | |
Log | |
(append [seqlog expression] (alter log-ref conj expression)) | |
(replay [seqlog] |
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 event-expr) | |
(declare send-event) | |
(defprotocol PrintEventHandler | |
(handle-print [this])) | |
(defprotocol BarEventHandler | |
(handle-bar [this])) |
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 reify-generic | |
"reify a protocol such that every method is delegated to a specified method") | |
(defmacro reify-generic | |
"Reify the given protocols. Every method of any protocol is implemented such | |
that f is called as (apply f protocol-method args) | |
Example: | |
(defprotocol Calculator |
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 state-is-a-fold | |
(:use clojure.test)) | |
;;; After all, state is a fold of events. For example let's say the events are a sequence of numbers | |
;;; and we are folding by addition: | |
(deftest simple | |
(let [events [1 5 2 4 3] | |
state (reduce + events)] | |
(is (= 15 state)))) |
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
;; On my journey into event sourcing in clojure I'm trying different approaches | |
;; of modeling events and event handling in clojure. | |
;; A little ceremony to pay homage to the gods of clojure: | |
(ns handler-protocol | |
(:use clojure.contrib.trace) | |
(:use clojure.pprint) | |
(:use clojure.test)) | |
;; My example problem domain for this will be a very simple sketch of twitter. |
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 s (start-server 3000 inc false)) | |
;; echo 10\n20\n30 | nc localhost 3000 | |
;; => 11\n21\n31 | |
(stop-server 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
(defprotocol Foo (foo [this])) | |
(defrecord FooImpl [x] Foo (foo [_] (->FooImpl x))) | |
;; => Unable to resolve symbol: ->Foo in this context |
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 actors) | |
(defn receive [f] | |
f) | |
(defn send_ [f & args] | |
(dosync (alter f apply args))) | |
(defn actor [f state] | |
(ref (f state))) |
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 sandbox.live | |
(:use [clojure.pprint :only (pprint)] ) | |
(:import [javax.swing JFrame JTextArea JScrollPane] | |
[java.awt BorderLayout Font] | |
[java.awt.event WindowAdapter])) | |
(defn schedule [interval f] | |
(let [flag (atom nil)] | |
(.start (Thread. #(loop [] (f) | |
(Thread/sleep interval) |
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
(provide 'dedicated-2) | |
(defvar d2-mode-window-map ()) | |
(defvar d2-regexp-window-map ()) | |
(defun buffer-mode (buf) | |
(with-current-buffer buf major-mode)) | |
(defun d2-get-window-by-mode (buffer) | |
(let* ((mode (buffer-mode buffer)) |