aboutsummaryrefslogtreecommitdiff
path: root/src/clojure
diff options
context:
space:
mode:
authorStuart Sierra <mail@stuartsierra.com>2009-06-23 15:43:05 -0400
committerStuart Sierra <mail@stuartsierra.com>2009-06-23 15:43:05 -0400
commit3e719d8e9752ab52690ab71967d7ce31e1b2aa9c (patch)
treebf3a0a4fc692d424d777df698ab6d1e222e84ee7 /src/clojure
parent7770c0088b699b86aec53545c29bc5236e72da73 (diff)
condt.clj: removed, as it depended on the old template.clj
Diffstat (limited to 'src/clojure')
-rw-r--r--src/clojure/contrib/condt.clj62
1 files changed, 0 insertions, 62 deletions
diff --git a/src/clojure/contrib/condt.clj b/src/clojure/contrib/condt.clj
deleted file mode 100644
index b5ac4da4..00000000
--- a/src/clojure/contrib/condt.clj
+++ /dev/null
@@ -1,62 +0,0 @@
-;;; condt.clj - generic case-like macro using template expressions
-
-;; By Stuart Sierra, http://stuartsierra.com/
-;; February 21, 2009
-
-;; Copyright (c) Stuart Sierra, 2008. 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.
-
-
-;; CHANGE LOG
-;;
-;; February 21, 2009: fixed to work with new lazy Clojure
-;;
-;; December 23, 2008: renamed to condt, since clojure.core now
-;; contains a (different) condp as of Clojure SVN rev. 1180
-;;
-;; December 15, 2008: original version, named "condp"
-
-
-(ns
- #^{:author "Stuart Sierra"
- :doc "Generic case-like macro using template expressions"}
- clojure.contrib.condt
- (:require clojure.contrib.template))
-
-(defmacro condt
- "expr is a template expression (see template), clauses are test/expr
- pairs like cond. Evalautes the template on each test value, one at
- a time. If a test returns logical true, condt evaluates the
- corresponding expr and returns its value. If none of the tests are
- true, and there are an odd number of clauses, the last clause is
- evaluated, otherwise returns nil."
- [expr & clauses]
- (let [test-fn-sym (gensym "test_")
- f (fn this [c]
- (cond
- (empty? c) nil
- (= 1 (count c)) (first c)
- :else (list 'if (list test-fn-sym (first c))
- (second c)
- (this (nthnext c 2)))))]
- `(let [~test-fn-sym (clojure.contrib.template/template ~expr)]
- ~(f clauses))))
-
-(defmacro econdt
- "Like condt but throws Exception if no tests match."
- [expr & clauses]
- (let [test-fn-sym (gensym "test_")
- f (fn this [c]
- (cond
- (empty? c) '(throw (Exception. "Nothing matched in econdt."))
- (= 1 (count c)) (throw (IllegalStateException. "Odd number of clauses in econdt."))
- :else (list 'if (list test-fn-sym (first c))
- (second c)
- (this (nthnext c 2)))))]
- `(let [~test-fn-sym (clojure.contrib.template/template ~expr)]
- ~(f clauses))))