diff options
author | Rich Hickey <richhickey@gmail.com> | 2008-10-16 15:39:11 +0000 |
---|---|---|
committer | Rich Hickey <richhickey@gmail.com> | 2008-10-16 15:39:11 +0000 |
commit | 6176d97fba40fcd8879045f60a3a970a98119603 (patch) | |
tree | 950dc252a191fab0c225fc94eecfbcb4605e2c84 /src | |
parent | 50c4543f9d56c50feb9432f32874491716bc8331 (diff) |
improved nil handling in merge, merge-with
fixed metadata reading on vars
Diffstat (limited to 'src')
-rw-r--r-- | src/clj/clojure/boot.clj | 9 | ||||
-rw-r--r-- | src/jvm/clojure/lang/LispReader.java | 5 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/clj/clojure/boot.clj b/src/clj/clojure/boot.clj index 8ca40583..9de4cdd2 100644 --- a/src/clj/clojure/boot.clj +++ b/src/clj/clojure/boot.clj @@ -1357,7 +1357,9 @@ "Returns a map that consists of the rest of the maps conj-ed onto the first. If a key occurs in more than one map, the mapping from the latter (left-to-right) will be the mapping in the result." - [& maps] (reduce conj maps)) + [& maps] + (when (some identity maps) + (reduce #(conj (or %1 {}) %2) maps))) (defn merge-with "Returns a map that consists of the rest of the maps conj-ed onto @@ -1365,14 +1367,15 @@ from the latter (left-to-right) will be combined with the mapping in the result by calling (f val-in-result val-in-latter)." [f & maps] + (when (some identity maps) (let [merge-entry (fn [m e] (let [k (key e) v (val e)] (if (contains? m k) (assoc m k (f (m k) v)) (assoc m k v)))) merge2 (fn [m1 m2] - (reduce merge-entry m1 (seq m2)))] - (reduce merge2 maps))) + (reduce merge-entry (or m1 {}) (seq m2)))] + (reduce merge2 maps)))) diff --git a/src/jvm/clojure/lang/LispReader.java b/src/jvm/clojure/lang/LispReader.java index e3b01c4b..40917b7e 100644 --- a/src/jvm/clojure/lang/LispReader.java +++ b/src/jvm/clojure/lang/LispReader.java @@ -623,6 +623,11 @@ static class MetaReader extends AFn{ {
if(line != -1 && o instanceof ISeq)
meta = ((IPersistentMap) meta).assoc(RT.LINE_KEY, line);
+ if(o instanceof Var)
+ {
+ ((Var)o).setMeta((IPersistentMap) meta);
+ return o;
+ }
return ((IObj) o).withMeta((IPersistentMap) meta);
}
else
|