Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Syntax and reader by
edited by

I tried defining a Unicode data-literal tag, and was surprised to find that it throws an error:

(defn wrap-λ [expr]
  `(fn [~'%] ~expr))
    
(set! *data-readers*
  (assoc *data-readers*
    'λ #'wrap-λ))

(read-string "#λ(inc %)")
;; => Execution error (ArrayIndexOutOfBoundsException) at lib/eval74486 (REPL:15).
;;    Index 955 out of bounds for length 256

955 is the Unicode codepoint for \λ, and the error suggests it only supports the ASCII range.
The first few lines of the stacktrace:

       LispReader.java:  840  clojure.lang.LispReader$DispatchReader/invoke
       LispReader.java:  285  clojure.lang.LispReader/read
       LispReader.java:  216  clojure.lang.LispReader/read
       LispReader.java:  205  clojure.lang.LispReader/read

Is this expected behavior? Clojurescript does not have the same issue:

(cljs.reader/register-tag-parser! 'λ wrap-λ)
(cljs.reader/read-string "#λ(inc %)")
;; => (cljs.core/fn [% & args] (inc %))

1 Answer

+1 vote
by

I'm not sure it's specified concretely anywhere, certainly by the way it's implemented I don't find this error surprising but doesn't seem like it needs to be limited.

Logged as https://clojure.atlassian.net/browse/CLJ-2623

...