I was reading this https://clojuredocs.org/clojure.core/keyword#example-542692d3c026201cdc326fde and had a thought to test this out, and seems clj-kondo doesn’t warn about these non-conformant keywords. Should it/could it?
@suomi.esko can you give a concrete example that doesn't require me to read this entire page?
Hmm, the anchor link doesn’t work for you? There’s a list of non-conformant keywords, eg. (keyword "abc def")
(keyword "")
(keyword "...")
and one I’ve actually seen in production, (keyword ":a")
the link works, but I don't have time to read all this, so if you can condense your question that would be helpful.
clj-kondo can check those kinds of things, but in general the argument to keyword
are runtime values, not literal strings - this is something which clj-kondo cannot check
That’s the could/should part. I’m not really sure why Clojure hasn’t natively spec’d that part, since it’s quite easy to make all kinds of mangled garble with the keyword
function.
this topic has come up often in the #clojure channel. I think one of the problems with narrowing down the possible keys is that it would break existing code which clojure will never do
you can always write your own my-keyword
function that checks things. one other reason is performance. creating keywords should be very fast in clojure. additional checks will mean a performance penalty
In the future these things will maybe be made valid too
@dominicm in which context do you mean valid? is anything invalid right now?
Well, :1
isn't valid right now, but it works in some places
I guess what I really mean is that Alex has hinted that (keyword "foo bar")
will eventually print in such a way that it can be (read-string)
interesting, I wonder how they're going to do that
It was hinted that the syntax would be something like :|foo bar|
and |
would ergo be the only restricted character.
:"foo"
could also work
Yeah, I recall the pipe character being mentioned explicitly
so tl;dr: clj-kondo isn't going to do anything about this 🙂
I think this was the conversation
Nope, a separate one 😁
https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/clojure-dev/near/182433674 this was a good conversation
https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/clojure-dev/near/182434173 I guess this one is your tease
I'm bored of searching now, I swear there was a | syntax though
maybe specifically for symbols? Dunno
https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/clojure/near/177714921AHA! I was right
symbols was the key term
@borkdude fwiw, I think the specific typo of (keyword ":ANYTHING")
might be worth catching
(having reflected on it for all of 30s)
Nothing broad, just catching the silly mistake of putting :
when using the function
wouldn't that also be valid in the future with :|:foo|
?
Yeah, I suppose it would :)
I’m willing to bet that pipe surrounded form will break backwards compatibility even worse though… 🙂
I doubt it. Besides, anyone relying on that is relying on something that was never promised.
I think the Clojure on DotNet has special syntax which uses this. It will break them