clojure / clojure-site

clojure.org site
https://clojure.org
Eclipse Public License 1.0
249 stars 266 forks source link

Reader doc for Symbol various errors/obmissions/vague #672

Closed lgrapenthin closed 7 months ago

lgrapenthin commented 9 months ago
puredanger commented 7 months ago

"Symbols begin with a non-numeric character": What constitutes a character? Aside from letters, they can begin with some of the special characters listed subsequently. However, ' and : are certainly not valid starts for symbols on the reader level.

Generally, any character. This is not a formal grammar - the intent here is truly "any" (other than exceptions). There are layers of semantics and implementation here and it's hard to tease them apart. ' will be tokenized as a quote so the reader will never read a symbol with a leading ' (yet you could create one programatically).

I believe there are some historical artifacts that happen here with symbols and keywords in that keywords are in some ways (especially in this page) treated as "a special kind of symbol that starts with :". That may have even been true in the implementation in very old versions of Clojure. There are some long-standing bugs in the regexes for these that relate to this too - particularly are parsing keywords that start with numerical digits.

The special character list "*, +, !, -, _, ', ?, <, > and =" misses "$", "&", "|" and inside a symbol also "#"

"other characters may be allowed" :)

""." has special meaning..." - This not true in the reader context, afaik the reader does not implement any special behavior for "."

From an implementation point of view, that's true, but it does have special meaning at analysis time. That this is in the analyzer vs the reader is not guaranteed, other implementation choices could be made. For example, some of the implementation options we considered for method values in 1.12 have moved some of this interpretation to the reader. (I don't think we will end up there.)

"Symbols beginning or ending with . are reserved by Clojure" - What does this mean? I should not give them to the reader? Datomic requires me to type the symbol ... which does begin and end with ".". Also typical interop expressions require me to type "(.method myClass)"

"reserved by Clojure" means there may be special meaning for such symbols either now or in the future, so you should not define symbols with names such as these. What happens if you do is undefined and subject to change. .method is one example of a symbol starting with . that has special meaning. String. is an example of a symbol with . at the end that has special meaning. Yes, ... violates this - don't do that (but it's good to be the king). :)

"Symbols beginning or ending with ':' are reserved by Clojure." - Afaik the reader can't read symbols beginning with ":". Again, what does it mean that symbols ending with ":" are reserved by Clojure? Should I not give them to the reader?

This is the historical ambiguity I mentioned above - keywords are treated in this document as "symbols starting with :" in some places. Symbols ending with ":" are "reserved by Clojure" and thus may have special interpretation now or in the future - that interpretation is undefined and subject to change.

We have an existing Clojure ticket to update this page. I am loathe to do so without a lot of input from Rich, not planning on doing so soon.

lgrapenthin commented 7 months ago

Thank you