This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-14
Channels
- # announcements (2)
- # babashka (7)
- # beginners (20)
- # calva (2)
- # clj-kondo (7)
- # clojure (31)
- # clojure-australia (3)
- # clojure-dev (10)
- # clojure-europe (7)
- # clojurescript (13)
- # conjure (1)
- # cursive (27)
- # datomic (168)
- # events (3)
- # fulcro (2)
- # garden (3)
- # honeysql (2)
- # jobs (1)
- # joker (1)
- # lsp (52)
- # releases (1)
- # shadow-cljs (11)
- # slack-help (4)
- # spacemacs (22)
- # sql (1)
Is there a reason why vectors can be used as keys in metadata when defined via ^
reader macro?
these all work:
(meta (with-meta {} {:int true}))
; => {:int true}
(meta ^{:int true} {})
; => {:int true}
(meta ^:int {})
; => {:int true}
here, the last doesn’t:
(meta (with-meta {} {[:tuple :int] true}))
; => {[:tuple :int] true}
(meta ^{[:tuple :int] true} {})
; => {[:tuple :int] true}
(meta ^[:tuple :int] {})
; =throws=> Metadata must be Symbol,Keyword,String or Map
I believe shorthand syntax has been allocated parsimoniously as needed. So keyword shorthand was for opt-in flags and not a default transformation “if not a map or a type (sym/string) turn x in {x true}”.
Yes, the general case of metadata is always a map. The ^:kw
is just a light syntactic sugar that is replaced with a map {:kw true}
and only for keywords. (Well, there is also ^Classname
-> {:tag Classname}
)
ok, thanks. String also seems to write :tag
:
(meta ^int? {}) ; => {:tag #object[clojure.core$int_QMARK_"]}
(meta ^:int {}) ; => {:int true}
(meta ^"int" {}) ; => {:tag "int"}
(meta ^{:type :int} {}) ; => {:type :int}
(meta ^Integer {}) ; => {:tag java.lang.Integer}