aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2009-01-29 03:28:00 +0000
committerStuart Sierra <mail@stuartsierra.com>2009-01-29 03:28:00 +0000
commitdba686c99a109a8733c1205d1bfcf25803907343 (patch)
tree0685f9f7a72fcb60bfbb103c9ae533a0e1190360 /src
parent8af4e0dca554057868cf0c67acb590fc30da7640 (diff)
apply_macro.clj: added new (evil) lib
Diffstat (limited to 'src')
-rw-r--r--src/clojure/contrib/apply_macro.clj43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/clojure/contrib/apply_macro.clj b/src/clojure/contrib/apply_macro.clj
new file mode 100644
index 00000000..eeb15e9d
--- /dev/null
+++ b/src/clojure/contrib/apply_macro.clj
@@ -0,0 +1,43 @@
+;;; apply_macro.clj: make macros behave like functions
+
+;; by Stuart Sierra, http://stuartsierra.com/
+;; January 28, 2009
+
+;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use
+;; and distribution terms for this software are covered by the Eclipse
+;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
+;; which can be found in the file epl-v10.html at the root of this
+;; distribution. By using this software in any fashion, you are
+;; agreeing to be bound by the terms of this license. You must not
+;; remove this notice, or any other, from this software.
+
+
+;; Don't use this. I mean it. It's evil. How evil? You can't
+;; handle it, that's how evil it is. That's right. I did it so you
+;; don't have to, ok? Look but don't touch. Use this lib and you'll
+;; go blind.
+
+
+(ns apply-macro)
+
+;; Copied from clojure.core/spread, which is private.
+(defn- spread
+ "Flatten final argument list as in apply."
+ [arglist]
+ (cond
+ (nil? arglist) nil
+ (nil? (rest arglist)) (seq (first arglist))
+ :else (cons (first arglist) (spread (rest arglist)))))
+
+(defmacro apply-macro
+ "This is evil. Don't ever use it. It makes a macro behave like a
+ function. Seriously, how messed up is that?
+
+ Evaluates all args, then uses them as arguments to the macro as with
+ apply.
+
+ (def things [true true false])
+ (apply-macro and things)
+ ;; Expands to: (and true true false)"
+ [macro & args]
+ (cons macro (spread (map eval args))))