trivia icon indicating copy to clipboard operation
trivia copied to clipboard

Base string patterns don't match general strings

Open pfdietz opened this issue 3 years ago • 5 comments

CL-USER> (trivia:match "x" (#.(coerce "x" 'base-string) t)) NIL CL-USER> (trivia:match (coerce "x" 'base-string) (#.(coerce "x" 'base-string) t)) T CL-USER> (trivia:match (coerce "x" 'base-string) ("x" t)) T

pfdietz avatar Aug 04 '22 15:08 pfdietz

This is in SBCL, where base-char and character are different types and where (upgraded-array-element-type 'base-char) is base-char.

pfdietz avatar Aug 04 '22 15:08 pfdietz

Also, I note that these matches all work in Optima.

pfdietz avatar Aug 05 '22 12:08 pfdietz

Hmmmm

guicho271828 avatar Aug 09 '22 16:08 guicho271828

There would be a mention in CLHS about the default type for literal strings which I don't remember. On the pattern side, it might be a bit complicated due to the default restructuring rule

guicho271828 avatar Aug 09 '22 16:08 guicho271828

The standard macro for " (see http://www.lispworks.com/documentation/lw50/CLHS/Body/02_de.htm ) is described as returning a simple-string. A simple-string can have any element-type that is either character or a subtype of character.

In SBCL, there's a readtable flag that causes SBCL to read strings as simple-base-strings when all the characters are base-chars. This is normally disabled, and turning it on breaks some quicklisp packages (because they assume a string constant can be copied and then updated with an arbitrary non-base-char, which is not standard compliant code.)

The particular problem I had with this was worked around by explicitly converting the strings to (array character (*)) when the match form was constructed (inside a macro). The underlying problem is still there, though, I'm just not hitting it.

pfdietz avatar Aug 09 '22 20:08 pfdietz