Welcome! Please see the About page for a little more info on how this works.

+1 vote
ago in Clojure by

It looks like Clojure has no problem with either :0 or :0/a, but when used together in a namesapced map it fails during some internal conversion.

Worst part: it prints back an unreadable form when if I feed it {:0/a :val}

user=> :0
:0
user=> :0/a
:0/a
user=> {:0/a :val}
#:0{:a :val}
user=> #:0{:a :val}
Syntax error reading source at (REPL:45:5).
Namespaced map must specify a valid namespace: 0
:a
:val
Syntax error reading source at (REPL:45:13).
Unmatched delimiter: }

1 Answer

0 votes
ago by
selected ago by
 
Best answer

It looks like Clojure has no problem with either :0 or :0/a

It does, it just doesn't complain - there are very few explicit checks and in general it's GIGO (garbage in, garbage out).

From https://clojure.org/reference/reader:

Symbols begin with a non-numeric character [...] [...]
Keywords are like symbols [...]

ago by
Correct, this is not valid.
ago by
Interesting! I wonder if Rich meant to explicitly allow keywords that start with numbers (commit message seems unrelated), but he essentially did https://github.com/clojure/clojure/commit/00061735edd435995167ee7bbf01a17d8ae2cc66#diff-0a8564b06ce5d306c0449c3711a3df88720e392b411e469c2aa99041a96a4886L43
ago by
Looks like keywords starting with a number are canon now https://clojure.atlassian.net/browse/CLJ-1252
ago by
It is not valid Clojure, but it is not rejected in all situations, so it should not be relied on. There are some widely used Clojure libraries out there that assume it is not rejected in certain situations, so banning it is problematic—but also do not expect any changes that make it more widely accepted.
...