rewrite-clj

https://github.com/clj-commons/rewrite-clj
lread 2020-12-09T21:03:13.170900Z

@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}

borkdude 2020-12-09T21:04:58.171300Z

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

borkdude 2020-12-09T21:05:03.171500Z

round-trip

lread 2020-12-09T21:06:14.172100Z

was just confused about REPL behaviour in my last example.

borkdude 2020-12-09T21:07:49.172300Z

you should just read this as EDN

borkdude 2020-12-09T21:07:58.172700Z

'x is really (quote x)

lread 2020-12-09T21:19:07.174800Z

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.

lread 2020-12-09T21:26:16.175900Z

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.

borkdude 2020-12-09T21:28:54.177200Z

You don't understand this one?

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

borkdude 2020-12-09T21:29:20.177800Z

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

borkdude 2020-12-09T21:29:26.178Z

(apparently)

lread 2020-12-09T21:29:29.178100Z

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

lread 2020-12-09T21:32:29.180200Z

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)

borkdude 2020-12-09T21:33:02.180400Z

yes

borkdude 2020-12-09T21:35:45.180900Z

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

lread 2020-12-09T21:36:40.181400Z

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

lread 2020-12-09T21:36:51.181900Z

just to understand the concept.

borkdude 2020-12-09T21:37:08.182300Z

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

borkdude 2020-12-09T21:37:40.182600Z

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

lread 2020-12-09T21:41:15.183100Z

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

borkdude 2020-12-09T21:42:04.183900Z

makes sense

lread 2020-12-09T21:42:18.184200Z

ya, I’m getting it, I think.

lread 2020-12-09T21:43:56.184700Z

thanks for the ping and the help in understanding!

borkdude 2020-12-09T21:44:21.184900Z

:thumbsup: