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 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))) |
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
(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))) |
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 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)) |
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
(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)] |
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 user | |
(:use clojure.set)) | |
;; core | |
(defstruct monad :unit :bind :run :zero :plus) | |
(defmacro defmonad [name & fdecl] | |
(let [[doc defs] | |
(if (string? (first fdecl)) |
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
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] |
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 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]))) |
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 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] |
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 user | |
(:use clojure.set)) | |
;; core | |
(defstruct monad :unit :bind :run :zero :plus) | |
(defmacro defmonad [name & fdecl] | |
(let [[doc defs] | |
(if (string? (first fdecl)) |
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 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)))))) |