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