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