summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-04-13 23:43:36 +0000
committerRich Hickey <richhickey@gmail.com>2008-04-13 23:43:36 +0000
commitd5c487f85c6ef98911d4175729d1df56f86fac7e (patch)
tree6e055decf66c548ba03570ac492af4f61969b7d3 /src
parentbacb2d4e4d2e7cd7d6784e595f7599ec6befadb6 (diff)
added destructuring support to if-let/when-let
Diffstat (limited to 'src')
-rw-r--r--src/boot.clj21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/boot.clj b/src/boot.clj
index f609aafc..d4aac8e6 100644
--- a/src/boot.clj
+++ b/src/boot.clj
@@ -2277,16 +2277,21 @@ not-every? (comp not every?))
(step (seq coll) #{})))
(defmacro if-let
- "Same as (let [name test] (if name then else))"
- [name test then else]
- `(let [~name ~test]
- (if ~name ~then ~else)))
+ "if test is true, evaluates then with binding-form bound to the value of test, if not, yields else"
+ [binding-form test then else]
+ `(let [temp# ~test]
+ (if temp#
+ (let [~binding-form temp#]
+ ~then)
+ ~else)))
(defmacro when-let
- "Same as (let [name test] (when name body))"
- [name test & body]
- `(let [~name ~test]
- (when ~name ~@body)))
+ "when test is true, evaluates body with binding-form bound to the value of test"
+ [binding-form test & body]
+ `(let [temp# ~test]
+ (when temp#
+ (let [~binding-form temp#]
+ ~@body))))
(defn replace
"Given a map of replacement pairs and a vector/collection, returns a