Mercurial > lasercutter
view 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 |
line wrap: on
line source
1 ;; Copyright (c) Stephen C. Gilardi. All rights reserved. The use and2 ;; distribution terms for this software are covered by the Eclipse Public3 ;; License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) which can4 ;; be found in the file epl-v10.html at the root of this distribution. By5 ;; using this software in any fashion, you are agreeing to be bound by the6 ;; terms of this license. You must not remove this notice, or any other,7 ;; from this software.8 ;;9 ;; File: cond.clj10 ;;11 ;; scgilardi (gmail)12 ;; 2 October 200814 (ns ^{:author "Stephen C. Gilardi"15 :doc "Extensions to the basic cond function."}16 clojure.contrib.cond)18 (defmacro cond-let19 "Takes a binding-form and a set of test/expr pairs. Evaluates each test20 one at a time. If a test returns logical true, cond-let evaluates and21 returns expr with binding-form bound to the value of test and doesn't22 evaluate any of the other tests or exprs. To provide a default value23 either provide a literal that evaluates to logical true and is24 binding-compatible with binding-form, or use :else as the test and don't25 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 expr32 `(if-let [~binding ~test]33 ~expr34 (cond-let ~bindings ~@more))))))