diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/clojure/contrib/condt.clj (renamed from src/clojure/contrib/condp.clj) | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/clojure/contrib/condp.clj b/src/clojure/contrib/condt.clj index 4f7c0dd2..f4019ba8 100644 --- a/src/clojure/contrib/condp.clj +++ b/src/clojure/contrib/condt.clj @@ -1,7 +1,7 @@ -;;; condp.clj - generic case-like macro using template expressions +;;; condt.clj - generic case-like macro using template expressions ;; By Stuart Sierra, http://stuartsierra.com/ -;; December 15, 2008 +;; December 23, 2008 ;; Copyright (c) Stuart Sierra, 2008. All rights reserved. The use ;; and distribution terms for this software are covered by the Eclipse @@ -12,13 +12,21 @@ ;; remove this notice, or any other, from this software. -(ns clojure.contrib.condp +;; CHANGE LOG +;; +;; 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 clojure.contrib.condt (:require clojure.contrib.template)) -(defmacro condp +(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, condp evaluates the + 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." @@ -34,14 +42,14 @@ `(let [~test-fn-sym (clojure.contrib.template/template ~expr)] ~(f clauses)))) -(defmacro econdp - "Like condp but throws Exception if no tests match." +(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 econdp.")) - (= 1 (count c)) (throw (IllegalStateException. "Odd number of clauses in econdp.")) + (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 (rrest c)))))] |