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 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
(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
lang.EmptyCons = { | |
first: function() {return null;}, | |
rest: function() {return lang.EmptyCons;}, | |
seq: function() {return null;}, | |
toString: function() {return "()";} | |
} | |
lang.Cons = function(_first, _rest) { | |
if (!_rest) { _rest = lang.EmptyCons; } | |
this._first = _first; |
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
(defmacro and-let | |
[bindings & body] | |
(if (seq bindings) | |
(let [[a b & cs] bindings] | |
`(when-let [~a ~b] (and-let ~cs ~@body))) | |
`(do ~@body)) |
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
(add-to-list 'swank-clojure-classpath (expand-file-name "classes/" path)) | |
(add-to-list 'swank-clojure-classpath (expand-file-name "src/" path)) | |
(add-to-list 'swank-clojure-classpath (expand-file-name "test/" path)) | |
;; in swank-clojure.el | |
;; add resources to swank-clojure-project classpath | |
(add-to-list 'swank-clojure-classpath (expand-file-name "resources/" path)) |
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
(deftype ConsType [_first _more] [ISeq] :as this | |
ISeq | |
(first ([] _first)) | |
(next ([] (when (first _more) _more)) | |
(seq ([] this)) | |
(cons ([x] (ConsType. x this))) |
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
(let [cursor (fetch-eager :where {... whatever ...}) | |
res (transient [])] | |
(while (.hasNext cursor) | |
(conj! res (-> cursor .next .toClojure))) | |
(persistent! res)) | |
;; |
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
(defmacro defn-src | |
[& body] | |
`(alter-meta! | |
(defn ~@body) | |
assoc :defn-src (quote ~(cons 'defn body)))) |
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
;;;; point-free SHA1 hash | |
(import java.security.MessageDigest) | |
(defmacro >> | |
"(>> 1 2 3 4 5) => (2 3 4 5 1)" | |
[x & xs] | |
`(~@xs ~x)) | |
(defn sha1 [#^String s] | |
(-> (doto (MessageDigest/getInstance "SHA1") |