The quote special form behaves strangely on maps

Hi,

I’ve tried things below:

user> 'org.clojure/clojure
org.clojure/clojure

user> '{org.clojure/clojure 3}
#:org.clojure{clojure 3}

user> '{org.clojure/clojure 3 :k 8}
 {org.clojure/clojure 3, :k 8}

I think that the second case must show {org.clojure/clojure 3} similar to the third trial. Why do the quote operate differently in two cases? Is it intended or a bug?

This is intended. It isn’t related to the quote, but to the printer. In Clojure 1.9 (I think that’s the right version), they introduced a new reader/printer syntax for maps whose keys all have the same namespace qualifier. Which is that you don’t need to repeat the namespace qualifier for every key, you can put it once on the whole map as in your example.

https://clojure.atlassian.net/plugins/servlet/mobile?originPath=%2Fbrowse%2FCLJ-1910#issue/CLJ-1910

The variable print-namespace-maps controls whether the printer prints using namespaced map syntax or not.

In the third case, because the map has a mix of namespace qualifier, it can’t be printed using namespaced maps, and so it isn’t.

2 Likes

Thank you for kindly answer!
I updated http://clojuredocs.org/clojure.core/quote for other questioners with your reply URL.

This is not a thing about quote. It is about map with key of namespaced keyword.

I absolutely agree with you. But I think someone, who expect the quote will preserve visually the original form, might try to find the reason in the quote section firstly. So I added the sample in the quote section. For preventing the misunderstanding, I will add your comment in that section. Thanks for your indicating.

yeah, quote won’t prevent the reader.

user=> '#(inc %)
(fn* [p1__2#] (inc p1__2#))
1 Like

Thanks for helping me widen my sight.:slightly_smiling_face:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.