Skip to content

Commit a804f7c

Browse files
cgrandrichhickey
authored andcommitted
read ^:foo bar as ^{:foo true} bar and merge existing metatada. See #375.
Signed-off-by: Rich Hickey <[email protected]>
1 parent 42df6a0 commit a804f7c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

src/jvm/clojure/lang/LispReader.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,8 +657,10 @@ public Object invoke(Object reader, Object caret) throws Exception{
657657
if(r instanceof LineNumberingPushbackReader)
658658
line = ((LineNumberingPushbackReader) r).getLineNumber();
659659
Object meta = read(r, true, null, true);
660-
if(meta instanceof Symbol || meta instanceof Keyword || meta instanceof String)
660+
if(meta instanceof Symbol || meta instanceof String)
661661
meta = RT.map(RT.TAG_KEY, meta);
662+
else if (meta instanceof Keyword)
663+
meta = RT.map(meta, true);
662664
else if(!(meta instanceof IPersistentMap))
663665
throw new IllegalArgumentException("Metadata must be Symbol,Keyword,String or Map");
664666

@@ -672,7 +674,12 @@ else if(!(meta instanceof IPersistentMap))
672674
((IReference)o).resetMeta((IPersistentMap) meta);
673675
return o;
674676
}
675-
return ((IObj) o).withMeta((IPersistentMap) meta);
677+
Object ometa = RT.meta(o);
678+
for(ISeq s = RT.seq(meta); s != null; s = s.next()) {
679+
IMapEntry kv = (IMapEntry) s.first();
680+
ometa = RT.assoc(ometa, kv.getKey(), kv.getValue());
681+
}
682+
return ((IObj) o).withMeta((IPersistentMap) ometa);
676683
}
677684
else
678685
throw new IllegalArgumentException("Metadata can only be applied to IMetas");

test/clojure/test_clojure/reader.clj

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,6 @@
274274

275275
(deftest t-Comment)
276276

277-
;; Meta (^)
278-
279-
(deftest t-Meta)
280-
281277
;; Deref (@)
282278

283279
(deftest t-Deref)
@@ -290,9 +286,10 @@
290286

291287
(deftest t-Regex)
292288

293-
;; Metadata (#^)
289+
;; Metadata (^ or #^ (deprecated))
294290

295-
(deftest t-Metadata)
291+
(deftest t-Metadata
292+
(is (= (meta '^:static ^:awesome ^{:static false :bar :baz} sym) {:awesome true, :bar :baz, :static true})))
296293

297294
;; Var-quote (#')
298295

0 commit comments

Comments
 (0)