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.
by
I'm curious about the status of using `|` for delimited names like that. Is that something that's planned in the medium term? Would it allow for `:abc/123` to be read eg with :abc/|123|` or something along those lines?
by
Not actively planned, but something we want to leave space for. Yes, that's the idea - would be lots of questions to answer of course if we were to do this. This is all similar to Common Lisp multiple escape characters (https://www.lispworks.com/documentation/HyperSpec/Body/02_adea.htm).
...