Skip to content

Instantly share code, notes, and snippets.

View threader.clj
(ns psykotic.threader
(:use clojure.walk))
(defmacro >> [& xs]
(reduce (fn [x1 x2]
(let [x1- (gensym)]
`(let [~x1- ~x1]
~(postwalk (fn [x] (if (= x '%) x1- x)) x2))))
(macroexpand-all xs)))
View drag.el
(require 'cl)
(defmacro ignore-errors (error-symbols &rest body)
`(condition-case nil
(progn ,@body)
,@(loop for error-symbol in error-symbols
collect `(,error-symbol nil))))
(defmacro swap (x y)
(let ((temp (gensym)))
View cut.clj
(defn cut [is xs]
(if (and (seq xs) (seq is))
(let [[ls rs] (split-at (first is) xs)]
(lazy-seq (cons ls (cut (rest is) rs))))
(when (seq xs) [xs])))
;; user> (cut [2 3] (range 10))
;; ((0 1) (2 3 4) (5 6 7 8 9))
;; user> (cut (repeat 2) (range 10))
;; ((0 1) (2 3) (4 5) (6 7) (8 9))
View defbinop.clj
(def *max-unroll-arity* 8) ; should probably be a defbinop keyword argument instead
(defmacro defbinop [name & fdecl]
(let [var-supply (repeatedly gensym)]
`(defn ~name
~@fdecl
~@(for [n (range 3 *max-unroll-arity*)]
(let [vars (take n var-supply)]
`([~@vars] ~(reduce (fn [x y] `(~name ~x ~y)) vars))))
~(let [vars (take *max-unroll-arity* var-supply)]
View monad.clj
(ns user
(:use clojure.set))
;; core
(defstruct monad :unit :bind :run :zero :plus)
(defmacro defmonad [name & fdecl]
(let [[doc defs]
(if (string? (first fdecl))
View deftype patch
diff --git a/src/clj/clojure/core_deftype.clj b/src/clj/clojure/core_deftype.clj
index 0e72136..7d2e32e 100644
--- a/src/clj/clojure/core_deftype.clj
+++ b/src/clj/clojure/core_deftype.clj
@@ -110,7 +110,7 @@
(defn- emit-deftype*
"Do not use this directly - use deftype"
- [tagname name fields interfaces methods]
+ [tagname name superclass fields interfaces methods]
View unconj.clj
(defn unconj [coll]
(when (seq coll)
(let [x ((if (vector? coll) peek first) coll)]
[(cond
(list? coll) (rest coll)
(vector? coll) (subvec coll 0 (dec (count coll)))
(set? coll) (disj coll x)
(map? coll) (dissoc coll (x 0)))
x])))
View letrec.clj
(ns user
(:use clojure.walk))
(defn unzip [n s]
(if (seq s)
(lazy-seq
(map cons (first s) (unzip n (rest s))))
(replicate n ())))
(defn- deref-vars [vars form]
View monad.clj
(ns user
(:use clojure.set))
;; core
(defstruct monad :unit :bind :run :zero :plus)
(defmacro defmonad [name & fdecl]
(let [[doc defs]
(if (string? (first fdecl))
View sift.clj
(defn sift [p xs]
(when (seq xs)
(lazy-seq
(let [[as bs] (split-with p xs)
[cs ds] (split-with (comp not p) bs)]
(cons [as cs] (sift p ds))))))