view src/rlm/dreams.clj @ 0:78a630e650d2

initial import
author Robert McIntyre <rlm@mit.edu>
date Tue, 18 Oct 2011 00:57:08 -0700
parents
children
line wrap: on
line source
1 (ns rlm.dreams
2 "These are functions and ideas that I have generated in dreams or
3 on the edge of sleep, hastily written down on scraps of paper in a
4 semi-somniac haze..."
5 {:author "Robert McIntyre"}
6 )
9 (defn not-implemented []
10 (throw (Exception. "not-implemented")))
12 (defn get-current-ns [] *ns*)
15 (defmacro silence
16 "no print statements can escape from this form!!"
17 [& body]
18 `(binding [*out* (java.io.StringWriter.)
19 *err* (java.io.StringWriter.)
20 ] ~@body))
22 (defmacro megadef
23 "Like def but defines the var in every namespace
24 currently in existance. Sometimes usefull for weeding
25 out namespace errors."
26 {:author "Robert McIntyre"}
27 [symbol form]
28 `(do ~@(map (fn [n] `(intern ~n ~(list 'quote symbol) ~form)) (all-ns))))
31 (defmacro megaundef
32 "hurrrrrrrrrrrr!!!!!!!"
33 {:author "Robert McIntyre the Great"}
34 [sym]
35 `(do ~@(map (fn [n] `(ns-unmap ~n ~(list 'quote sym))) (all-ns))))
37 (defmacro defn-decorated
38 "like defn-memo except it accepts an additional vector of
39 decorator functions which will be applied to the base definition."
40 {:author "Robert McIntyre"}
41 [decorators fn-name & defn-stuff]
42 (let [decorations
43 (map (fn [d] (list 'alter-var-root (list 'var fn-name) d)) decorators)]
44 `(do
45 (defn ~fn-name ~@defn-stuff)
46 ~@decorations
47 (var ~fn-name))))