The sequence in the transcript below shows runtime exceptions when a numeric keyword is followed by a list starting with a symbol or character.
Would anyone help me with a reason for the failing cases?user=> (clojure-version)
"1.6.0"
user=> '(:42 a)
(:42 a)
user=> '(:42 "a")
(:42 "a")
user=> '(:42 \a)
(:42 \a)
user=> '(:42 nil)
(:42 nil)
user=> '(:42 true)
(:42 true)
user=> '(:42 :43)
(:42 :43)
user=> '(:42 (a))
RuntimeException EOF while reading, starting at line 1 clojure.lang.Util.runtimeException (Util.java:221)
RuntimeException Unmatched delimiter: ) clojure.lang.Util.runtimeException (Util.java:221)
user=> '(:42 ("a"))
(:42 ("a"))
user=> '(:42 (\a))
> Just FYI, some background on keywords that start with a number...
>
> The reader docs (http://clojure.org/reader) states that symbols (and keywords follow symbols in these rules) must "begin with a non-numeric character".
Thanks, Alex. The REPL-y and sjacket issues cited the Clojure issues in Jira and I looked through them.
There seems to be an assumption in the discussion I’ve seen that the current description of keywords at http://clojure.org/reader means that the characters *after* the leading colon in a keyword have to follow the rules for a symbol.
I think another reasonable way to interpret the description of keywords is that the spelling of a keyword *including the leading colon* has to follow the rules for a symbol
— with the obvious exception that a symbol’s spelling *cannot* begin with a colon. Since a colon is always non-numeric, keywords *always* pass the “begins with a non-numeric character” test.
When I looked in the past at what it takes to parse a token in Clojure, I concluded that the syntax of numbers vs. non-numbers (including the syntax for numbers with a radix component) was chosen such that a token represents a number if and only if it has a leading numeric character. I’ve always interpreted the “no leading numeric character” rule for the spelling of symbols (and keywords, including the leading colon) as in support of that simple distinction. More generally, the reader can classify a token by its leading character, or leading 2 characters in the case of a leading #.
I don’t see a similarly compelling reason to disallow numeric characters immediately after the leading colon in a keyword.
—Steve
Thanks Alex and Steve,
I've based a ton of work on keywords where the second character is numeric.The http://clojure.org/readers page should be the normative reference.
The work is based on reliance on the definitions in the readers page. I believe it is unambiguous in demanding a colon as the first character of a keyword, and allowing the second character to be numeric.
I am frightened that opinions differ; especially Rich's, obviously.
On Friday, April 25, 2014 9:48:10 AM UTC-5, Greg D wrote:Thanks Alex and Steve,
I've based a ton of work on keywords where the second character is numeric.The http://clojure.org/readers page should be the normative reference.
The work is based on reliance on the definitions in the readers page. I believe it is unambiguous in demanding a colon as the first character of a keyword, and allowing the second character to be numeric.
Well I'll contend it is at least ambiguous because I read it differently. :) I think everyone can agree that keywords begin with a colon. My understanding is that symbols and keywords share naming rules as a result of "Keywords are like symbols". I think the interpretation depends on whether you see the ":" as being part of the name;
On Fri, Apr 25, 2014 at 11:19 AM, Alex Miller <al...@puredanger.com> wrote:
On Friday, April 25, 2014 9:48:10 AM UTC-5, Greg D wrote:Thanks Alex and Steve,
I've based a ton of work on keywords where the second character is numeric.The http://clojure.org/readers page should be the normative reference.
The work is based on reliance on the definitions in the readers page. I believe it is unambiguous in demanding a colon as the first character of a keyword, and allowing the second character to be numeric.
Well I'll contend it is at least ambiguous because I read it differently. :) I think everyone can agree that keywords begin with a colon. My understanding is that symbols and keywords share naming rules as a result of "Keywords are like symbols". I think the interpretation depends on whether you see the ":" as being part of the name;
Since the very next thing after "Keywords are like symbols" is "except: They can and must begin with a colon, e.g. :fred." and the rule for symbols is that they "begin with a non-numeric character", it seems pretty forgivable to assume that the colon is part of the keyword (the fact that it isn't stored is immaterial; if you know it's a keyword you also know it starts with a colon) and that it can therefore contain numeric characters immediately after the colon. "Begin" should mean "begin" in both bullet points, right?