Mercurial > lasercutter
diff 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 diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/clojure/contrib/apply_macro.clj Sat Aug 21 06:25:44 2010 -0400 1.3 @@ -0,0 +1,45 @@ 1.4 +;;; apply_macro.clj: make macros behave like functions 1.5 + 1.6 +;; by Stuart Sierra, http://stuartsierra.com/ 1.7 +;; January 28, 2009 1.8 + 1.9 +;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use 1.10 +;; and distribution terms for this software are covered by the Eclipse 1.11 +;; Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) 1.12 +;; which can be found in the file epl-v10.html at the root of this 1.13 +;; distribution. By using this software in any fashion, you are 1.14 +;; agreeing to be bound by the terms of this license. You must not 1.15 +;; remove this notice, or any other, from this software. 1.16 + 1.17 + 1.18 +;; Don't use this. I mean it. It's evil. How evil? You can't 1.19 +;; handle it, that's how evil it is. That's right. I did it so you 1.20 +;; don't have to, ok? Look but don't touch. Use this lib and you'll 1.21 +;; go blind. 1.22 + 1.23 +;; DEPRECATED in 1.2 with no replacement. 1.24 + 1.25 +(ns ^{:deprecated "1.2"} 1.26 + clojure.contrib.apply-macro) 1.27 + 1.28 +;; Copied from clojure.core/spread, which is private. 1.29 +(defn- spread 1.30 + "Flatten final argument list as in apply." 1.31 + [arglist] 1.32 + (cond 1.33 + (nil? arglist) nil 1.34 + (nil? (rest arglist)) (seq (first arglist)) 1.35 + :else (cons (first arglist) (spread (rest arglist))))) 1.36 + 1.37 +(defmacro apply-macro 1.38 + "This is evil. Don't ever use it. It makes a macro behave like a 1.39 + function. Seriously, how messed up is that? 1.40 + 1.41 + Evaluates all args, then uses them as arguments to the macro as with 1.42 + apply. 1.43 + 1.44 + (def things [true true false]) 1.45 + (apply-macro and things) 1.46 + ;; Expands to: (and true true false)" 1.47 + [macro & args] 1.48 + (cons macro (spread (map eval args))))