Fork me on GitHub
#rewrite-clj
<
2020-12-09
>
lread21:12:13

@borkdude, I am playing in the Clojure REPL trying to understand how namespaced maps apply to symbols. The well understood keyword behaves as expected:

user=> #:foo {:x 1 :bar/y 2}
{:foo/x 1, :bar/y 2}
For less understood symbol, if I follow CLJ-1910 examples, it works:
user=> '#:foo {x 1 :bar/y 2}
{foo/x 1, :bar/y 2}
In my naiveté, I was expecting x to be namespaced here too:
user=> #:foo {'x 1 :bar/y 2}
{x 1, :bar/y 2}

borkdude21:12:58

they behave as expected when parsing and sexpr-ing with rewrite-cljc?

lread21:12:14

was just confused about REPL behaviour in my last example.

borkdude21:12:49

you should just read this as EDN

borkdude21:12:58

'x is really (quote x)

lread21:12:07

I see how a Clojure program can contain a namespaced map that affects a keyword key, but I don’t yet see how a Clojure program would contain a namespaced map that affects a symbol key.

lread21:12:16

I guess it is important to remember we are just reading and not running. But I’m still currently a little confused by the namespaced symbol.

borkdude21:12:54

You don't understand this one?

user=> '#:foo {x 1 :bar/y 2}
{foo/x 1, :bar/y 2}

borkdude21:12:20

so for a namespaced map, unqualified keywords and symbols are auto-namespaced

borkdude21:12:26

(apparently)

lread21:12:29

I had a brain sprain, I think I am ok now.

lread21:12:29

A Clojure program would just have to use the quote as CLJ-1910 illustrated. So it would just:

(def my-map '#:foo {x 1 :bar/y 2})
(keys my-map)
;; => (foo/x :bar/y)

borkdude21:12:45

but this is irrelevant for rewrite-clj since it doesn't do evaluation

lread21:12:40

yeah, but my brain needed to see an example that would work.

lread21:12:51

just to understand the concept.

borkdude21:12:08

user=> #:clojure.core {x 1 :bar/y 2})
Syntax error compiling at (REPL:0:0).
No such var: clojure.core/x
So it reads as {clojure.core/x :bar/y 2} and then it tries to eval clojure.core/x

borkdude21:12:40

but for rewrite-clj only the read-phase is relevant

lread21:12:15

(def x #:clojure.core {*clojure-version* 1 :bar/y 2})
(keys x)
 ;; => ({:major 1, :minor 10, :incremental 1, :qualifier nil} :bar/y)

borkdude21:12:04

makes sense

lread21:12:18

ya, I’m getting it, I think.

lread21:12:56

thanks for the ping and the help in understanding!