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 monad-explore.core | |
| (:use clojure.algo.monads)) | |
| (defmacro let? | |
| "Almost the same as let. If you add the :ensure keyword paired with | |
| some predicate as a var in the let form, let? will not continue | |
| unless the predicate evaluates to true. (The predicate will have | |
| access to all bindings above.)" | |
| [bindings & body] | |
| (let [[bind [kwd pred & more]] (split-with (complement #{:ensure}) bindings)] |
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 ded | |
| "Structural Data EDitor for Clojure with zippers. Inspired by Interlisp: http://larry.masinter.net/interlisp-ieee.pdf" | |
| (:require [clojure.zip :as z]) | |
| (:use [clojure.pprint :only (with-pprint-dispatch code-dispatch pprint)] | |
| [clojure.repl :only (source-fn)])) | |
| (defn print-hr | |
| "Prints 30 dashes and a newline." | |
| [c] | |
| (println (apply str (repeat 30 c)))) |
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
| ;; Adapted from "An empirical comparison of C, C++, Java, Perl, | |
| ;; Python, Rexx, and Tcl for a search/string-processing program" | |
| ;; by Lutz Prechelt | |
| ;; This was a 15-minute effort while listening to a talk. It's *not* | |
| ;; well thought-out or designed. | |
| ;; By Stuart Sierra, | |
| ;; @stuartsierra on Twitter |
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 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 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 logic.y | |
| (:refer-clojure :exclude [== reify inc]) | |
| (:use [clojure.core.logic minikanren prelude | |
| nonrel match])) | |
| (defna findo [x l o] | |
| ([_ [[?y :- o] . _] _] | |
| (project [x ?y] (== (= x ?y) true))) | |
| ([_ [_ . ?c] _] (findo x ?c o))) |
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 lazy-sort) | |
| (defn qsort [[head & tail]] | |
| (when head | |
| (lazy-cat (qsort (filter #(< % head) tail)) | |
| [head] | |
| (qsort (remove #(< % head) tail))))) | |
| (defn merge* | |
| [[f1 & r1 :as l1] [f2 & r2 :as l2]] |
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
| // Step 1. global definition | |
| function Map(config) { | |
| this._init(config); | |
| } | |
| Map.prototype = { | |
| _container: null, | |
| _init: function (config) { | |
| this._container = document.getElementById(config.container); |
NewerOlder