diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/rlm/dreams.clj	Tue Oct 18 00:57:08 2011 -0700
     1.3 @@ -0,0 +1,50 @@
     1.4 +(ns rlm.dreams
     1.5 +  "These are functions and ideas that I have generated in dreams or
     1.6 +   on the edge of sleep, hastily written down on scraps of paper in a
     1.7 +   semi-somniac haze..."
     1.8 +  {:author "Robert McIntyre"}
     1.9 +)
    1.10 +
    1.11 +
    1.12 +(defn not-implemented []
    1.13 +  (throw (Exception. "not-implemented")))
    1.14 +
    1.15 +(defn get-current-ns [] *ns*)
    1.16 +
    1.17 +
    1.18 +(defmacro silence
    1.19 +  "no print statements can escape from this form!!"
    1.20 +  [& body]
    1.21 +  `(binding [*out* (java.io.StringWriter.)
    1.22 +	     *err* (java.io.StringWriter.) 
    1.23 +	     ] ~@body))
    1.24 +
    1.25 +(defmacro megadef
    1.26 +  "Like def but defines the var in every namespace
    1.27 +   currently in existance.  Sometimes usefull for weeding
    1.28 +   out namespace errors."
    1.29 +  {:author "Robert McIntyre"}
    1.30 +  [symbol form]
    1.31 +  `(do ~@(map (fn [n] `(intern ~n ~(list 'quote symbol) ~form)) (all-ns))))
    1.32 +
    1.33 +
    1.34 +(defmacro megaundef
    1.35 +  "hurrrrrrrrrrrr!!!!!!!"
    1.36 +  {:author "Robert McIntyre the Great"}
    1.37 +  [sym]
    1.38 +  `(do ~@(map (fn [n] `(ns-unmap ~n ~(list 'quote sym))) (all-ns))))
    1.39 +
    1.40 +(defmacro defn-decorated
    1.41 +  "like defn-memo except it accepts an additional vector of
    1.42 +   decorator functions which will be applied to the base definition."
    1.43 +  {:author "Robert McIntyre"}
    1.44 +  [decorators fn-name & defn-stuff]
    1.45 +  (let [decorations
    1.46 +	(map (fn [d] (list 'alter-var-root (list 'var fn-name) d)) decorators)]
    1.47 +    `(do
    1.48 +       (defn ~fn-name ~@defn-stuff)
    1.49 +       ~@decorations
    1.50 +       (var ~fn-name))))
    1.51 +
    1.52 +
    1.53 +