Fork me on GitHub
#clojure-dev
<
2024-05-28
>
Noah Bogart19:05:06

In a thread in #beginners, @daveliepmann mentioned that it's technically illegal for keywords to contain periods in the name part. I thought this was wrong but looked it up in the https://clojure.org/reference/reader#_literals and it seems this is correct. Is this another issue with a broken reader regex and undefined behavior, now governed by Hyrum's Law? Or was the stance on periods in keywords relaxed at some point? I ask because a large part of https://github.com/seancorfield/honeysql/tree/v1's dsl is built around using the period as the separator for sql tables and columns, and I'd prefer to not rely on undefined behavior in our app UPDATE: the restriction has been removed from the reference documentation

1
cgrand19:05:27

Given Clojure’s record of backward compatibility don’t worry about it. I guess this line is very very old. The EDN spec doesn’t mention it https://github.com/edn-format/edn

Noah Bogart19:05:01

that's true, but as recently as 2018 alex updated the text to "allow" it in the namespace portion: https://github.com/clojure/clojure-site/commit/5481163d24491ec2ebc5863bc2d0876d36aacc5a

cgrand19:05:16

Weird. This has already been abused in 2018. I’m now eager to hear an official position.

cgrand19:05:21

If this was enforced it would break all hiccup-style libs for a start.

Noah Bogart19:05:26

Yeah, it seems to me like the cat's out of the bag and it would be wise to change the docs to allow it, but I don't know the reasons for continuing to discourage it.

daveliepmann19:05:33

FWIW the major reason I noticed was that in the original thread it was a leading period, which jumped out at me because keyword rules are basically symbol rules and symbols with a leading period are reserved by Clojure.

👍 1
Alex Miller (Clojure team)19:05:30

it is legal to use . in the name part to designate a fully-qualified class name, so the regex must allow it. because the reader does not know whether it is a class, this can't be a reader error

cgrand19:05:45

So :div.hero is somehow illegal?

Noah Bogart19:05:17

Sure, the regex allows it. But matchSymbol could be written to throw an error if a keyword's name portion contains a period.

Alex Miller (Clojure team)19:05:26

so the spec is saying that you should not do this. I'm talking about symbols so far. this is already problematic in many ways:

user=> (def a.b.c 5)
#'user/a.b.c
user=> a.b.c
Syntax error (ClassNotFoundException) compiling at (REPL:0:0).

Alex Miller (Clojure team)19:05:11

moving to keywords, they are generally "like symbols", so the question is whether this line of the symbol spec is also "like symbols" for keywords

Alex Miller (Clojure team)19:05:45

afaik there is nothing interpreting the name parts of keywords as classes so it seems likely to me that this operates as expected now. generally I expect to see . in the namespace part, not the name part of symbolic identifiers but I guess it is somewhat ambiguous in this case (similar ambiguity we have with leading numbers)

Noah Bogart19:05:47

Right, I agree about symbols and their particular needs

Alex Miller (Clojure team)19:05:43

given the presumed prevalence of this due to hiccup, honeysql, etc, seems unlikely that it could be disallowed at this point if we wanted to

Noah Bogart19:05:51

Given such prevalence, what's the reasoning for not allowing it explicitly?

Alex Miller (Clojure team)19:05:50

I didn't give a reasoning for that :)

Noah Bogart19:05:01

lol I know, which is why I asked

Alex Miller (Clojure team)19:05:20

I don't have a reason, but I don't just change things willy-nilly on the reference pages :)

😂 3
Alex Miller (Clojure team)19:05:39

that is, would need to double-check with Rich

👍 1
Noah Bogart19:05:43

ah here we go, here's a jira ticket from 2011 about dots in keywords https://clojure.atlassian.net/browse/CLJ-889

Alex Miller (Clojure team)19:05:14

that's useful thx

👍 2
Alex Miller (Clojure team)14:05:19

Updated docs to remove "They cannot contain '.' in the name part, or name classes." for keywords

🎉 2
😮 1
clojure-spin 2
Noah Bogart14:05:40

yooooooooooooooo

daveliepmann15:05:21

Cool, thanks Alex