This file contains hidden or 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
;; Playing around with Joy in Clojure | |
;; http://en.wikipedia.org/wiki/Joy_%28programming_language%29 | |
;; The code is partly based on Joy in Scheme by John Cowan | |
;; http://home.ccil.org/~cowan/ | |
(defn get-var [var env] (@env var)) | |
(defn set-var! [var val env] (swap! env conj {var val})) | |
(def global-env (atom {})) | |
(def joy-stack (atom [])) |
This file contains hidden or 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 kvmap [fun hash] | |
(into {} (map (fn [[k v]] [k (fun k v)]) | |
(seq hash)))) | |
(kvmap (fn [k v] (str v "/" k)) {"host" "http://localhost" "most" "umph"}) | |
;; => {"most" "umph/most", "host" "http://localhost/host"} | |
(defn kvmpa [fun hs] | |
(reduce-kv (fn [all k v] |
This file contains hidden or 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 interp.core) | |
(defn get-var [var env] (@env var)) | |
(defn set-var! [var val env] | |
(swap! env conj {var val})) | |
(def global-env (atom {})) | |
(defn ext-env [vars vals env] | |
(->> (zipmap vars vals) |
This file contains hidden or 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
(evil-leader/set-leader ",") | |
(evil-leader/set-key | |
"f" 'ido-find-file | |
"b" 'ido-switch-buffer | |
"w" 'save-buffer | |
"s" 'save-buffer | |
"K" 'kill-buffer | |
"k" 'kill-this-buffer | |
"T" 'eshell |
This file contains hidden or 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
;; MCons Hack - https://gist.github.com/fredyr/6341286 | |
;; Haskell MVars - http://chimera.labs.oreilly.com/books/1230000000929/ch07.html | |
;; http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html | |
defn empty-mvar [] | |
(let [take-sem (java.util.concurrent.Semaphore. 1) | |
put-sem (java.util.concurrent.Semaphore. 1)] | |
(.acquire take-sem) | |
(mcons nil (mcons take-sem put-sem)))) |
This file contains hidden or 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
;; http://docs.racket-lang.org/reference/mpairs.html | |
(defprotocol IMCons | |
(mcar [p]) | |
(mcdr [p]) | |
(set-mcar! [p val]) | |
(set-mcdr! [p val])) | |
(deftype MCons [^{:volatile-mutable true} car ^{:volatile-mutable true} cdr] | |
IMCons |
This file contains hidden or 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
;; Mouse move handler | |
(let [el "#only-mouse" | |
ch (Bacon.fromEventTarget js/window "mousemove")] | |
(-> ch | |
(.map (ƒ [e] (str (.-offsetX e) ", " (.-offsetY e)))) | |
(.onValue (js/$ el) "text"))) | |
(defn location [ch] | |
(.map ch (ƒ [[tag e]] | |
[tag {:x (.-offsetX e) :y (.-offsetY e)}]))) |
This file contains hidden or 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 game-results {:rock {:rock :tie, :paper :lose, :scissor :win} | |
:paper {:rock :win, :paper :tie, :scissor :lose} | |
:scissor {:rock :lose, :paper :win, :scissor :tie}}) | |
(defn create-game-command | |
[{:keys [aggregate-id player move]} state] | |
[{:event :game-created :game-id aggregate-id :creator player | |
:state-change {:state :started :creator player}} | |
{:event :move-decided :game-id aggregate-id :player player :move move | |
:state-change {:move move}}]) |
This file contains hidden or 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 random | |
board = ["GO", "A1", "CC1", "A2", "T1", "R1", "B1", "CH1", "B2", "B3", "JAIL", | |
"C1", "U1", "C2", "C3", "R2", "D1", "CC2", "D2", "D3", "FP", | |
"E1", "CH2", "E2", "E3", "R3", "F1", "F2", "U2", "F3", "G2J", | |
"G1", "G2", "CC3", "G3", "R4", "CH3", "H1", "T2", "H2"] | |
double_board = board * 2 | |
visits = [0] * len(board) | |
cc_cards = ["GO", "JAIL"] + ["NOP"] * 14 |
This file contains hidden or 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
; gilded.clj | |
; (def item {:name "Aged Brie" :sell-in 12 :quality 3}) | |
(defn force-range [quality] | |
(cond | |
(< quality 0) 0 | |
(> quality 50) 50 | |
:else quality)) | |
(defn backstage [quality sell-in] |