Fork me on GitHub
#clojure-dev
<
2018-07-03
>
chrisblom14:07:41

I ran into surprising behaviour where a symbol does not get metadata when using the ^:some-key syntax

chrisblom14:07:45

(def map-meta-from-reader ^:foo {})
(def map-meta-explicit (with-meta {} {:foo true}))

(def symbol-meta-from-reader ^:foo 'a)
(def symbol-meta-explicit (with-meta 'a {:foo true}))

(meta symbol-meta-from-reader) ;; => nil
(meta symbol-meta-explicit) ;; => {:foo 1}
(meta map-meta-from-reader) ;; => {:foo true}
(meta map-meta-explicit) ;; => {:foo true}

chrisblom14:07:42

I would expect that (meta ^:foo 'a) returns {:foo true}, but that is not the case

chrisblom14:07:55

Is this a known issue?

arrdem14:07:47

@chrisblom ^:foo 'a is ^:foo (quote a), the eval of which is a. this is expected behavior. note that '^:foo a does what you're expecting above.

chrisblom14:07:07

ok, that seems to work indeed

bronsa14:07:14

what @arrdem said, note that ^:foo 'a isn't losing any metadata, ,it's just attaching metadata to the (quote a) form which is only accessible at compile time

chrisblom14:07:47

ow wow, that is new to me, i’ve never seen the quoted metadata reader syntax '^:some-key before

bronsa14:07:40

that's not syntax

bronsa14:07:45

it's just the composition of ' and ^:

bronsa14:07:58

do the expansion in your head

bronsa14:07:09

that's equivalent to (quote ^:foo a)

chrisblom14:07:49

ok, that makes sense

chrisblom14:07:46

ok, i was trying to use ^:marker some-symbol for a config format

chrisblom14:07:12

luckily (meta (read-string "^:foo a")) returns the expected result

petterik17:07:54

The library coding standards can be made gender neutral. There are 2 occurrences of he in https://dev.clojure.org/display/community/Library+Coding+Standards : One should only extend a protocol to a type if he owns either the type or the protocol. Replace he with either they, one or she/he, or similar?

slipset18:07:33

@petterik Alex is offline, but I would imagine that any rework on that article would start by republishing it on http://clojure.org.

seancorfield18:07:13

I think that's a small enough and reasonable enough change that I went ahead and made it.

👍 8
seancorfield18:07:03

It's hard to say whether that page belongs on http://clojure.org ...

arrdem18:07:11

That’s just one of the confluence pages - anyone can edit them.

👍 4
arrdem18:07:58

And Sean just did it.