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

+1 vote
in Clojure by

Hi,

The pipe char | is accepted as a symbol constituent char both in clj and cljs:

user> {:one|two 'three|four}
{:one|two three|four}

cljs.user> {:one|two 'three|four}
{:one|two three|four}

though it is not mentioned as such in official sources:

https://clojure.org/reference/reader#_symbols
https://github.com/edn-format/edn#symbols

Is it safe to assume it is a valid symbol constituent character since it is accepted by the reader as such?

Thanks

1 Answer

+3 votes
by

You should not use |, it is being reserved for possible delimited names.

Specifically, something like :one|two 'three|four might in the future actually read as a single keyword with embedded space and quote.

by
Thanks, I got this coming up as keyword key while converting java hasmaps into keywordized clojure maps.

Would it better perhaps to have the reader throw this as an invalid char for symbols? Or is there a danger that backward compatibility could break if this char is starting to have a more elaborate meaning in a later release?
by
See https://clojure.org/guides/faq#unreadable_keywords for why we don't validate this. By using characters not on the reader list, you are in undefined behavior territory.
...