Skip to content

Instantly share code, notes, and snippets.

View aboekhoff's full-sized avatar

Andrew Boekhoff aboekhoff

  • DemandingBear
  • San Francisco
View GitHub Profile
(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)))
(ns playground)
(deftype TypedFn
[signature function] :as this
clojure.lang.IFn
(applyTo [args] (apply function args))
(call [] (function))
(invoke [arg] (function arg)))
(defmacro fnt
(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]
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;
(defmacro and-let
[bindings & body]
(if (seq bindings)
(let [[a b & cs] bindings]
`(when-let [~a ~b] (and-let ~cs ~@body)))
`(do ~@body))
(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))
(deftype ConsType [_first _more] [ISeq] :as this
ISeq
(first ([] _first))
(next ([] (when (first _more) _more))
(seq ([] this))
(cons ([x] (ConsType. x this)))
(let [cursor (fetch-eager :where {... whatever ...})
res (transient [])]
(while (.hasNext cursor)
(conj! res (-> cursor .next .toClojure)))
(persistent! res))
;;
(defmacro defn-src
[& body]
`(alter-meta!
(defn ~@body)
assoc :defn-src (quote ~(cons 'defn body))))
;;;; 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")