view src/clojure/contrib/apply_macro.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
line wrap: on
line source
1 ;;; apply_macro.clj: make macros behave like functions
3 ;; by Stuart Sierra, http://stuartsierra.com/
4 ;; January 28, 2009
6 ;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use
7 ;; and distribution terms for this software are covered by the Eclipse
8 ;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
9 ;; which can be found in the file epl-v10.html at the root of this
10 ;; distribution. By using this software in any fashion, you are
11 ;; agreeing to be bound by the terms of this license. You must not
12 ;; remove this notice, or any other, from this software.
15 ;; Don't use this. I mean it. It's evil. How evil? You can't
16 ;; handle it, that's how evil it is. That's right. I did it so you
17 ;; don't have to, ok? Look but don't touch. Use this lib and you'll
18 ;; go blind.
20 ;; DEPRECATED in 1.2 with no replacement.
22 (ns ^{:deprecated "1.2"}
23 clojure.contrib.apply-macro)
25 ;; Copied from clojure.core/spread, which is private.
26 (defn- spread
27 "Flatten final argument list as in apply."
28 [arglist]
29 (cond
30 (nil? arglist) nil
31 (nil? (rest arglist)) (seq (first arglist))
32 :else (cons (first arglist) (spread (rest arglist)))))
34 (defmacro apply-macro
35 "This is evil. Don't ever use it. It makes a macro behave like a
36 function. Seriously, how messed up is that?
38 Evaluates all args, then uses them as arguments to the macro as with
39 apply.
41 (def things [true true false])
42 (apply-macro and things)
43 ;; Expands to: (and true true false)"
44 [macro & args]
45 (cons macro (spread (map eval args))))