Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base string patterns don't match general strings #136

Open
pfdietz opened this issue Aug 4, 2022 · 5 comments
Open

Base string patterns don't match general strings #136

pfdietz opened this issue Aug 4, 2022 · 5 comments

Comments

@pfdietz
Copy link
Contributor

pfdietz commented Aug 4, 2022

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 pfdietz changed the title Base string pattern don't match general strings Base string patterns don't match general strings Aug 4, 2022
@pfdietz
Copy link
Contributor Author

pfdietz commented Aug 4, 2022

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

@pfdietz
Copy link
Contributor Author

pfdietz commented Aug 5, 2022

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

@guicho271828
Copy link
Owner

Hmmmm

@guicho271828
Copy link
Owner

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
Copy link
Contributor Author

pfdietz commented Aug 9, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants