guicho271828 / trivia

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

String pattern matching is more strict than STRING= #121

Closed zc1036 closed 3 years ago

zc1036 commented 3 years ago

Trivia does not think that a vector of characters matches a string, even though STRING= says they're equal. This behavior is counter-intuitive. For example:

CL-USER> (defvar vec (make-array 3 :adjustable t :initial-contents "abc" :element-type 'character))
VEC
CL-USER> vec
"abc"
CL-USER> (string= vec "abc")
T
CL-USER> (type-of vec)
(VECTOR CHARACTER 3)
CL-USER> (type-of "abc")
(SIMPLE-ARRAY CHARACTER (3))
CL-USER> (match vec 
           ("abc" 'yes)
           (_ 'no))
NO

What would you guys think about changing this behavior so that VEC matches "abc"?

guicho271828 commented 3 years ago
CL-USER> (defun fn (x)
           (match x
             (#.(make-array 3  :adjustable t :initial-contents "abc" :element-type 'character) 'yes)
             (_ 'no)))
FN
CL-USER> (fn (make-array 3  :adjustable t :initial-contents "abc" :element-type 'character))
YES