summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRich Hickey <richhickey@gmail.com>2008-03-17 14:21:02 +0000
committerRich Hickey <richhickey@gmail.com>2008-03-17 14:21:02 +0000
commitd1f6bffa642555938c67a7f776018c50c899d3aa (patch)
tree4335013422ddd4e69c285028d718b28c9c306073 /src
parente8f4200da5b6243402fc95ca0cb7a183b60ce023 (diff)
added if-let, when-let, replace
Diffstat (limited to 'src')
-rw-r--r--src/boot.clj26
-rw-r--r--src/zip.clj2
2 files changed, 27 insertions, 1 deletions
diff --git a/src/boot.clj b/src/boot.clj
index c3be2d8f..ed86b3d0 100644
--- a/src/boot.clj
+++ b/src/boot.clj
@@ -2246,3 +2246,29 @@ make-proxy [classes method-map]
(if (seen f) (recur r seen)
(lazy-cons f (step r (conj seen f))))))]
(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)))
+
+(defmacro when-let
+ "Same as (let [name test] (when name body))"
+ [name test & body]
+ `(let [~name ~test]
+ (when ~name ~@body)))
+
+(defn replace
+ "Given a map of replacement pairs and a vector/collection, returns a
+ vector/seq with any elements = a key in smap replaced with the
+ corresponding val in smap"
+ [smap coll]
+ (if (vector? coll)
+ (reduce (fn [v i]
+ (if-let e (find smap (nth v i))
+ (assoc v i (val e))
+ v))
+ coll (range (count coll)))
+ (map #(if-let e (find smap %) (val e) %) coll)))
+ \ No newline at end of file
diff --git a/src/zip.clj b/src/zip.clj
index 1e33fc44..e6794e73 100644
--- a/src/zip.clj
+++ b/src/zip.clj
@@ -10,7 +10,7 @@
;see Huet
(in-ns 'zip)
-(clojure/refer 'clojure)
+(clojure/refer 'clojure :exclude '(replace))
(defn zipper
"Creates a new zipper structure.