ClojureScript

ClojureScript reader throws TypeError when map keys start with colon then number

Details

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

Description

ClojureScript:cljs.user> (cljs.reader/read-string "{:9k true}")
"Error evaluating:" (cljs.reader/read-string "{:9k true}") :as "cljs.reader.read_string.call(null,\"{:9k true}\");\n"
#<TypeError: Cannot read property 'length' of null>
TypeError: Cannot read property 'length' of null
    at http://localhost:8080/javascripts/out/cljs/reader.js:530:38
    at http://localhost:8080/javascripts/out/cljs/reader.js:534:2
    at read_keyword (http://localhost:8080/javascripts/out/cljs/reader.js:547:2)
    at read_delimited_list (http://localhost:8080/javascripts/out/cljs/reader.js:373:32)
    at read_map (http://localhost:8080/javascripts/out/cljs/reader.js:418:47)
    at read (http://localhost:8080/javascripts/out/cljs/reader.js:675:115)
    at read_string (http://localhost:8080/javascripts/out/cljs/reader.js:707:25)
    at eval at <anonymous> (http://localhost:8080/javascripts/out/clojure/browser/repl.js:21:158)
    at eval at <anonymous> (http://localhost:8080/javascripts/out/clojure/browser/repl.js:21:158)
    at http://localhost:8080/javascripts/out/clojure/browser/repl.js:21:153
nil

Activity

Hide
David Nolen added a comment -

There is no evidence that this allowed.

Show
David Nolen added a comment - There is no evidence that this allowed.
Hide
Brian Taylor added a comment - - edited

@David

Digging around LispReader.java in clojure, I found the symbol pattern:

"[:]?([\\D&&[^/]].*/)?([\\D&&[^/]][^/]*)"

Best I can tell, that transcribes directly to the regex the clojurescript reader is using. I'm a bit surprised that clojure allows keywords that start with a number.

I created a Clojure issue mentioning this: CLJ-1003

Show
Brian Taylor added a comment - - edited @David Digging around LispReader.java in clojure, I found the symbol pattern:
"[:]?([\\D&&[^/]].*/)?([\\D&&[^/]][^/]*)"
Best I can tell, that transcribes directly to the regex the clojurescript reader is using. I'm a bit surprised that clojure allows keywords that start with a number. I created a Clojure issue mentioning this: CLJ-1003
Hide
David Nolen added a comment -

You can just use regular Strings, Keywords are an illusion anyhow in ClojureScript.

Show
David Nolen added a comment - You can just use regular Strings, Keywords are an illusion anyhow in ClojureScript.
Hide
Murphy McMahon added a comment -

OK, I see. I had wanted to use UUIDs as map keys for quick lookups. I'll rethink my approach.

Show
Murphy McMahon added a comment - OK, I see. I had wanted to use UUIDs as map keys for quick lookups. I'll rethink my approach.
Hide
David Nolen added a comment -

After looking over this http://clojure.org/reader I'm not sure that the current behavior is a problem. The fact that keywords that start with numbers happens to work may just be an oversight.

Show
David Nolen added a comment - After looking over this http://clojure.org/reader I'm not sure that the current behavior is a problem. The fact that keywords that start with numbers happens to work may just be an oversight.
Hide
Murphy McMahon added a comment -

Probably related: the read-string function throws an "Uncaught Invalid number format" for any non-numeric value beginning with a number.

Show
Murphy McMahon added a comment - Probably related: the read-string function throws an "Uncaught Invalid number format" for any non-numeric value beginning with a number.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: