From fe48612915a33d2c54a46f5e0c32b59a2ed76dfd Mon Sep 17 00:00:00 2001 From: Steve Miner Date: Mon, 3 Sep 2012 16:26:40 -0400 Subject: [PATCH] avoid double evaluation in when-first --- src/clj/clojure/core.clj | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index 4a6e61f..295519b 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -4118,16 +4118,16 @@ (defmacro when-first "bindings => x xs - Same as (when (seq xs) (let [x (first xs)] body))" + Roughly the same as (when (seq xs) (let [x (first xs)] body)) but xs is evaluated only once" {:added "1.0"} [bindings & body] (assert-args (vector? bindings) "a vector for its binding" (= 2 (count bindings)) "exactly 2 forms in binding vector") (let [[x xs] bindings] - `(when (seq ~xs) - (let [~x (first ~xs)] - ~@body)))) + `(when-let [xs# (seq ~xs)] + (let [~x (first xs#)] + ~@body)))) (defmacro lazy-cat "Expands to code which yields a lazy sequence of the concatenation -- 1.7.4.1