You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CL-USER> (setf nn #j"aa")
#\SIMPLE-ERROR: ref vector out of range
at https://jscl-project.github.io/jscl.js:43039:7
at https://jscl-project.github.io/jscl.js:43042:3
at Object.JSCL_USER_ERROR [as fvalue] (https://jscl-project.github.io/jscl.js:43043:3)
at internals.error (https://jscl-project.github.io/jscl.js:83:12)
at https://jscl-project.github.io/jscl.js:9583:26
at https://jscl-project.github.io/jscl.js:9585:3
at JSCL_USER_AREF (https://jscl-project.github.io/jscl.js:9586:3)
at Object.mvcall (https://jscl-project.github.io/jscl.js:73:10)
at https://jscl-project.github.io/jscl.js:6670:27
at https://jscl-project.github.io/jscl.js:6671:3
at Object.JSCL_USER_CHARNAME [as fvalue] (https://jscl-project.github.io/jscl.js:6672:3)
at https://jscl-project.github.io/jscl.js:26285:205
at JSCL_USER_WRITECHARAUX (https://jscl-project.github.io/jscl.js:26286:3)
at Object.mvcall (https://jscl-project.github.io/jscl.js:73:10)
at https://jscl-project.github.io/jscl.js:26404:54
at https://jscl-project.github.io/jscl.js:26443:3
at Object.JSCL_USER_WRITEAUX [as fvalue] (https://jscl-project.github.io/jscl.js:26447:4)
at JSCL_USER_NIL (https://jscl-project.github.io/jscl.js:26561:7)
at Object.mvcall (https://jscl-project.github.io/jscl.js:73:10)
at https://jscl-project.github.io/jscl.js:26570:18
... 23 more frames, increase JSCL::*BACKTRACE-LIMIT* to view more
CL-USER> (setf nn #j"aaa")
#j"aaa"```lisp
It's probably confused between whether #j"aa" is a CHARACTER or STRING...
I think so.
A two-character string is a Unicode character. Maybe internals.char_to_codepoint.
CL-USER> (setf nn (jscl::jsstring "aaa"))
#j"aaa"
CL-USER> (setf nn (jscl::jsstring "a"))
#\a
CL-USER> (setf nn (jscl::jsstring "aa"))
#\SIMPLE-ERROR: ref vector out of range```
Hello.
Upon investigation, it appears the issue stemmed from an attempt to support UTF-16, where a sequence with a length of 2 was being treated as a single character.
;; In src/compiler/compiler.lisp, 1381
(define-builtin characterp (x)
`(selfcall
(var (x ,x))
(return,(convert-to-bool
`(and (== (typeof x) "string")
(or (== (get x "length") 1)
(== (get x "length") 2)))))))
Upon investigation, it appears the issue stemmed from an attempt to support UTF-16, where a sequence with a length of 2 was being treated as a single character.
That’s not the bottom of the rabbit hole yet.
In prelude.js, there is a function:
internals.char_from_codepoint = function (x)
which incorrectly identifies those very graphemes. Consequently, the compiler misidentifies the object.
Furthermore, in char.lisp, the char-name function stumbles over a missing slot in the +ascii-name+ array.
The author of char.lisp hasn't maintained their creation for a long time,
and I currently have no way to set up SBCL for debugging.
As for integrating third-party libraries for graphemes - I don't think that's the best idea.
Hmm, I see. Alternatively, by using codePointAt in this way, it was possible to treat two characters that do not form a surrogate pair (e.g., "aa") as a single string.
However, this does not mean they are treated as a "single character." 👨👩👧👦 is still determined to be a string composed of multiple code points.
diff --git a/src/compiler/compiler.lisp b/src/compiler/compiler.lisp
index 045bc62..3ec0ff0 100644
--- a/src/compiler/compiler.lisp
+++ b/src/compiler/compiler.lisp
@@ -1384,7 +1384,11 @@
(return ,(convert-to-bool
`(and (== (typeof x) "string")
(or (== (get x "length") 1)
- (== (get x "length") 2)))))))
+ (and (== (get x "length") 2)
+ (>= (method-call x "charCodeAt" 0) 55296)
+ (<= (method-call x "charCodeAt" 0) 56319))))))))
Also, it will be good to check the character code to be <128:
diff --git a/src/char.lisp b/src/char.lisp
index e7967ff..bda1372 100644
--- a/src/char.lisp
+++ b/src/char.lisp
@@ -281,7 +281,7 @@ For the first 32 characters ('C0 controls'), the first
;; not much in FORMAT yet. I'm only implementing ASCII names right
;; now, since Unicode is kind of big.
(let ((code (char-code char)))
- (if (<= code 127)
+ (if (and (> code 0) (< code 128))
(aref +ascii-names+ code)
nil))) ;; for now, no name
Activity
kparen commentedon Apr 9, 2026
It's probably confused between whether
#j"aa"is aCHARACTERorSTRING...vlad-km commentedon Apr 9, 2026
I think so.
A two-character string is a Unicode character. Maybe
internals.char_to_codepoint.iwami4438 commentedon Aug 18, 2026
Hello.
Upon investigation, it appears the issue stemmed from an attempt to support UTF-16, where a sequence with a length of 2 was being treated as a single character.
However, simply removing that part does not seem to solve the problem. Please take a look at this MDN article.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter
I also think this article will be helpful for us. (It is written in Japanese.)
https://qiita.com/bon127/items/491b25e90208188dafbd
As a solution, I propose using the library mentioned in the article above.
https://www.npmjs.com/package/graphemesplit
It does add a dependency, which is a bit of a hassle, though.
Please consider this suggestion.
iwami4438 commentedon Aug 18, 2026
The investigation was prompted by
aref.Details
vlad-km commentedon Aug 18, 2026
That’s not the bottom of the rabbit hole yet.
In
prelude.js, there is a function:which incorrectly identifies those very graphemes. Consequently, the compiler misidentifies the object.
Furthermore, in
char.lisp, thechar-namefunction stumbles over a missing slot in the+ascii-name+array.The author of
char.lisphasn't maintained their creation for a long time,and I currently have no way to set up
SBCLfor debugging.As for integrating third-party libraries for graphemes - I don't think that's the best idea.
V.
iwami4438 commentedon Aug 18, 2026
Hmm, I see. Alternatively, by using
codePointAtin this way, it was possible to treat two characters that do not form a surrogate pair (e.g., "aa") as a single string.However, this does not mean they are treated as a "single character." 👨👩👧👦 is still determined to be a string composed of multiple code points.
hemml commentedon Aug 18, 2026
It can be fixed the following way:
Also, it will be good to check the character code to be <128: