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 e-bind [f] | |
| (fn [v] | |
| (let [[e *v] (try [true (f v)] (catch Exception e [false (.toString e)]))] | |
| (if e *v (handler e *v f))))) | |
| ;; presumably this would do something constructive, and | |
| ;; probably expect more preceding state from preceding computations | |
| ;; in a domonad form | |
| (defn handler [s x f] |
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 playground) | |
| (deftype TypedFn | |
| [signature function] :as this | |
| clojure.lang.IFn | |
| (applyTo [args] (apply function args)) | |
| (call [] (function)) | |
| (invoke [arg] (function arg))) | |
| (defmacro fnt |
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 debuggery | |
| (:use clojure.walk | |
| clojure.stacktrace | |
| clojure.contrib.macro-utils | |
| clojure.contrib.pprint)) | |
| (comment | |
| (with-debuggery | |
| (defn bad-plus [n] (+ n nil)) | |
| (defn use-bad-plus [] (bad-plus 42))) |
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.clj) | |
| (comment | |
| (def f | |
| (statefully | |
| x <- (*read*) | |
| (*write* 42) | |
| y <- (*read*) | |
| (*update* str " was frobnicated!") |
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
| module Kumochan where | |
| import Monad | |
| import Control.Monad.State | |
| data Env = Env {nodeId::Int, symId::Int} deriving (Show) | |
| root = Env (-1) (-1) | |
| nextNodeId :: Env -> (Int, Env) |
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
| ;; using a pattern matching macro | |
| (defn test [x] | |
| (match x | |
| (? (comp not number?)) :not-a-number | |
| (? #(< % 42)) (recur (inc x)) | |
| 42 :booya! | |
| _ :too-high!)) | |
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
| ;; silly example tail-elimination from cps style to javascript | |
| (EV '(let* (f (fn (k x) | |
| (k (op* * x x))) | |
| g (fn (k _f x) | |
| (_f k x)) | |
| h (fn (k _f) | |
| (k (fn (_k x) | |
| (_f _k x)))) | |
| (Array (h (fn (k*) (k* (fn (x) x) 42)) f)) |
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
| ;; pointless ml-style syntax | |
| ;; (now just need a parser combinator to add incanter's infix math and were in business) | |
| (defmacro mlet [& xs] | |
| (let [[[n & args] l2] (split-with #(not= '= %) xs) | |
| [l2 l3] (split-with #(not= 'in %) l2)] | |
| `(let [~n (fn ~n [~@args] ~(rest l2))] ~(rest l3)))) | |
| (comment | |
| (mlet f x = * x x in |
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 combinatrix.sequence | |
| (:require [combinatrix.core :as combinatrix])) | |
| (combinatrix/defmonad | |
| :name :sequence | |
| :do in-sequence | |
| :bind (fn [mv f] (mapcat (fn [x] (f x)) mv)) | |
| :return list | |
| :zero () | |
| :plus concat) |
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 combinatrix.sequence | |
| (:use combinatrix.core)) | |
| (defmonad | |
| :name :sequence | |
| :do in-sequence | |
| :bind (fn [mv f] (mapcat (fn [x] (f x)) mv)) | |
| :return list | |
| :zero () | |
| :plus concat |