Skip to content

Commit

Permalink
Rename cond* to cond+ and write a similar let+
Browse files Browse the repository at this point in the history
  • Loading branch information
amalloy committed May 24, 2011
1 parent 57eb84f commit 56bb59c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/amalloy/utils/core.clj
Expand Up @@ -2,7 +2,11 @@
(:use amalloy.utils
(amalloy.utils [seq :only [lazy-loop]])))

(defmacro cond* [& clauses]
(defmacro cond+
"Like cond, but allowing bracketed [test expr] pairs to be grouped
together, as required in common lisp, for cases in which that
improves readability."
[& clauses]
(cons `cond
(lazy-loop [[test & [expr & more :as all]] clauses]
(when test
Expand All @@ -12,6 +16,21 @@
(concat [test expr]
(lazy-recur more)))))))

(defmacro let+
"Like let, but allowing (binding expr) pairs to be grouped together,
as required in common lisp, for cases in which that improves
readability."
[clauses & body]
`(let ~(vec
(lazy-loop [[test & [expr & more :as all]] clauses]
(when test
(if (seq? test)
(concat test
(lazy-recur all))
(concat [test expr]
(lazy-recur more))))))
~@body))

(comment
(cond*
(zero? x) 1
Expand Down

0 comments on commit 56bb59c

Please sign in to comment.