Mercurial > lasercutter
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 functions3 ;; by Stuart Sierra, http://stuartsierra.com/4 ;; January 28, 20096 ;; Copyright (c) Stuart Sierra, 2009. All rights reserved. The use7 ;; and distribution terms for this software are covered by the Eclipse8 ;; 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 this10 ;; distribution. By using this software in any fashion, you are11 ;; agreeing to be bound by the terms of this license. You must not12 ;; remove this notice, or any other, from this software.15 ;; Don't use this. I mean it. It's evil. How evil? You can't16 ;; handle it, that's how evil it is. That's right. I did it so you17 ;; don't have to, ok? Look but don't touch. Use this lib and you'll18 ;; 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- spread27 "Flatten final argument list as in apply."28 [arglist]29 (cond30 (nil? arglist) nil31 (nil? (rest arglist)) (seq (first arglist))32 :else (cons (first arglist) (spread (rest arglist)))))34 (defmacro apply-macro35 "This is evil. Don't ever use it. It makes a macro behave like a36 function. Seriously, how messed up is that?38 Evaluates all args, then uses them as arguments to the macro as with39 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))))