Clojure

:100 is a valid Clojure keyword. Is that intentional?

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:

Description

In the latest clojure (eccde24c7),

These parse as keywords:

:100
:100/a

This is an error:

:a/100

Is this behavior intentional?

In LispReader.java, the pattern for a symbol (and keyword) is "[:]?([\\D&&[^/]].*/)?([
D&&[^/]][^/]*)". If I'm mentally parsing that correctly, it seems like none of my examples should be valid keywords. I don't know why the first two cases parse.

http://clojure.org/reader says that none of my examples should parse.

Clojurescript does not accept any of my examples, see CLJS-142

Activity

Hide
Andy Fingerhut added a comment -

The reason that :100 parses as a keyword is that [
D&[^/]] matches a colon character, too. So the first : of :100 is not matching the [:]? at the beginning of the regular expression, but by a later part of it. Regexps can be tricky.

Whether this is intentional or not, my guess is probably not. Given that the docs at http://clojure.org/reader also say "A symbol can contain one or more non-repeating ':'s", writing a regexp that matches only what is documented there looks fairly complex.

Clojure has a history of allowing things, without throwing exceptions or giving any other errors, even if they are documented as not legal. This may be one of those cases. Do not consider this last paragraph as any kind of authoritative answer. It is only my observation.

Show
Andy Fingerhut added a comment - The reason that :100 parses as a keyword is that [
D&[^/]] matches a colon character, too. So the first : of :100 is not matching the [:]? at the beginning of the regular expression, but by a later part of it. Regexps can be tricky. Whether this is intentional or not, my guess is probably not. Given that the docs at http://clojure.org/reader also say "A symbol can contain one or more non-repeating ':'s", writing a regexp that matches only what is documented there looks fairly complex. Clojure has a history of allowing things, without throwing exceptions or giving any other errors, even if they are documented as not legal. This may be one of those cases. Do not consider this last paragraph as any kind of authoritative answer. It is only my observation.
Alex Miller made changes -
Field Original Value New Value
Labels reader
Hide
Andy Fingerhut added a comment -

Perhaps this should be marked as duplicate of CLJ-1252

Show
Andy Fingerhut added a comment - Perhaps this should be marked as duplicate of CLJ-1252
Hide
Alex Miller added a comment -

Dupe of CLJ-1252

Show
Alex Miller added a comment - Dupe of CLJ-1252
Alex Miller made changes -
Resolution Duplicate [ 3 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: