Note: I am not a person who is authorized to make decisions on what the Clojure language is, or is not, but a close observer for multiple years hoping to provide some background information.
This is historically a bleeding edge case in Clojure, asked about many times, but it appears maybe not on ask.clojure.org before.
Interpretations have differed on the precise meaning of the official docs here https://clojure.org/reference/reader but it does say there that "Symbols begin with a non-numeric character" and "Keywords are like symbols, except ... They can and must begin with a colon".
The function keyword
allows one to construct values of type keyword that the Clojure reader cannot read. If you want a variant of keyword
that restricts you to only constructing keyword values that the Clojure reader can read, probably the best way is to write a function that (a) constructs the keyword using keyword
, and (b) converts that to a string, and (c) attempts to read it with the Clojure reader, returning some kind of error status, throwing an exception, or whatever you want if the resulting keyword is unreadable.
There was a ticket CLJ-1252 https://clojure.atlassian.net/browse/CLJ-1252 where they temporarily changed the Clojure reader to disallow reading of some keywords that had leading digits, but rolled that back because some libraries out in the wild were already relying upon the behavior, and they did not want to break backwards compatibility for this issue.