guicho271828 / trivia

Pattern Matcher Compatible with Optima
Other
334 stars 22 forks source link

Base string patterns don't match general strings #136

Open pfdietz opened 2 years ago

pfdietz commented 2 years ago

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 commented 2 years ago

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

pfdietz commented 2 years ago

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

guicho271828 commented 2 years ago

Hmmmm

guicho271828 commented 2 years ago

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

pfdietz commented 2 years ago

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.