comparison src/clojure/contrib/cond.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
comparison
equal deleted inserted replaced
9:35cf337adfcf 10:ef7dbbd6452c
1 ;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and
2 ;; distribution terms for this software are covered by the Eclipse Public
3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can
4 ;; be found in the file epl-v10.html at the root of this distribution. By
5 ;; using this software in any fashion, you are agreeing to be bound by the
6 ;; terms of this license. You must not remove this notice, or any other,
7 ;; from this software.
8 ;;
9 ;; File: cond.clj
10 ;;
11 ;; scgilardi (gmail)
12 ;; 2 October 2008
13
14 (ns ^{:author "Stephen C. Gilardi"
15 :doc "Extensions to the basic cond function."}
16 clojure.contrib.cond)
17
18 (defmacro cond-let
19 "Takes a binding-form and a set of test/expr pairs. Evaluates each test
20 one at a time. If a test returns logical true, cond-let evaluates and
21 returns expr with binding-form bound to the value of test and doesn't
22 evaluate any of the other tests or exprs. To provide a default value
23 either provide a literal that evaluates to logical true and is
24 binding-compatible with binding-form, or use :else as the test and don't
25 refer to any parts of binding-form in the expr. (cond-let binding-form)
26 returns nil."
27 [bindings & clauses]
28 (let [binding (first bindings)]
29 (when-let [[test expr & more] clauses]
30 (if (= test :else)
31 expr
32 `(if-let [~binding ~test]
33 ~expr
34 (cond-let ~bindings ~@more))))))