clojure-dev

2024-05-28T19:01:06.870989Z

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
Alex Miller (Clojure team) 2024-05-29T14:21:19.419489Z

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

2
๐Ÿ˜ฎ 1
๐ŸŽ‰ 2
2024-05-29T14:21:40.022819Z

yooooooooooooooo

daveliepmann 2024-05-29T15:33:21.964059Z

Cool, thanks Alex

cgrand 2024-05-28T19:16:27.015059Z

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

2024-05-28T19:18:01.469029Z

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

cgrand 2024-05-28T19:21:16.040229Z

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

cgrand 2024-05-28T19:23:21.469459Z

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

2024-05-28T19:24:26.426989Z

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.

daveliepmann 2024-05-28T19:26:33.075839Z

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) 2024-05-28T19:34:30.913699Z

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

cgrand 2024-05-28T19:35:45.510009Z

So :div.hero is somehow illegal?

2024-05-28T19:36:17.499709Z

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) 2024-05-28T19:36:26.383909Z

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) 2024-05-28T19:37:11.219189Z

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) 2024-05-28T19:38:45.320389Z

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)

2024-05-28T19:38:47.522489Z

Right, I agree about symbols and their particular needs

Alex Miller (Clojure team) 2024-05-28T19:40:43.634669Z

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

2024-05-28T19:42:51.777509Z

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

Alex Miller (Clojure team) 2024-05-28T19:44:50.128259Z

I didn't give a reasoning for that :)

2024-05-28T19:45:01.269819Z

lol I know, which is why I asked

Alex Miller (Clojure team) 2024-05-28T19:45:20.322529Z

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

๐Ÿ˜‚ 3
Alex Miller (Clojure team) 2024-05-28T19:45:39.686039Z

that is, would need to double-check with Rich

๐Ÿ‘ 1
2024-05-28T19:45:43.200859Z

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) 2024-05-28T19:46:14.550639Z

that's useful thx

๐Ÿ‘ 2
2024-05-28T19:51:19.372279Z

(and associated Ask for voting: https://ask.clojure.org/index.php/2808/specifically-allow-inside-keywords)