improve-getting-started

phronmophobic 2024-06-21T20:41:18.834089Z

I've noticed a few folks learning clojure that got tripped up on the namespace maps syntax (eg. #:foo{:bar 42} , https://clojurians.slack.com/archives/C053AK3F9/p1719000006167789). It took me a while to find any docs on it and I'm already familiar with the syntax (searching for "namespace map" or "#:" didn't work). I found mentions at https://www.clojure.org/guides/weird_characters#_and_namespace_map_syntax and https://clojure.org/reference/reader#map_namespace_syntax which seem helpful. • Maybe there are a few other places where it would be helpful to add a link or mention? • Maybe https://www.clojure.org/guides/learn/syntax should mention it?

1
ericnormand 2024-06-30T00:09:15.232029Z

I rarely use them and I get weirded out when I see them. It's not something I would even think to teach.

ericnormand 2024-06-30T00:10:06.176279Z

I think ChatGPT didn't know about them because they're relatively new. And they often don't come up in the scale of problem you would blog about.

seancorfield 2024-06-30T03:00:23.296169Z

I think seeing #:foo{:bar 42 :quux 13} is very different from seeing {:foo/bar 42 :foo/quux 13} so I can understand beginners going "whoa! what is that weird syntax?" -- but I think qualified keywords should be considered a "basic" Clojure idiom and I think it's unfortunate that the default REPL behavior is the shorthand reader syntax when all the qualifiers are the same 😕

seancorfield 2024-06-30T03:02:52.622109Z

There's definitely an opportunity to improve our "getting started" documentation around hash maps. I'm going to create a ticket against http://clojure-doc.org to figure out how to introduce them early and explain the shorthand syntax and the *print-namespace-maps* thing...

1
2024-06-21T21:01:38.870259Z

It is already mentioned in the Clojure cheatsheet, I see: https://clojure.org/api/cheatsheet

phronmophobic 2024-06-21T21:17:13.886319Z

That makes sense since namespaced keywords are also probably unfamiliar syntax on top of the idea of keywords on top of the concept of namespaced keywords.

plexus 2024-07-01T04:51:40.057179Z

I really wish there was a global way to turn them off...

phronmophobic 2024-07-01T15:03:25.075569Z

I can't tell if that's sarcasm, but (set! *print-namespace-maps* false) should work in the repl.

plexus 2024-07-01T19:30:23.373079Z

I mean system global, something in ~/.clojure or an env var. I guess I could add this to launchpad.

phronmophobic 2024-07-01T19:32:08.255049Z

It's set by the repl, so you should be able to use middleware or tweak your dev setup to set a different value.