Discussion:
[Chicken-users] string-ci<=? and string-ci>=?
Sven Hartrumpf
2018-09-11 06:26:49 UTC
Permalink
Hi.

The issue reported by Nils Holm
in http://groups.google.com/group/comp.lang.scheme/t/6b8be06b84b39a7
(string-ci<=? "test" "tes")
#t
(string-ci>=? "test" "tes")
#f

Ciao
Sven
Vasilij Schneidermann
2018-09-11 07:26:18 UTC
Permalink
Hey Sven,
(string-ci<=? "test" "tes")
#t
(string-ci>=? "test" "tes")
#f
This is odd. Here's some source code:

(set! scheme#string-ci<=? (lambda (s1 s2)
(compare
s1 s2 'string-ci<=?
(lambda (len1 len2 cmp)
(if (eq? cmp 0)
(fx>= len1 len2)
(fx< cmp 0) ) ) ) ) )
(set! scheme#string-ci>=? (lambda (s1 s2)
(compare
s1 s2 'string-ci>=?
(lambda (len1 len2 cmp)
(if (eq? cmp 0)
(fx<= len1 len2)
(fx> cmp 0) ) ) ) ) )

From what I can tell, `cmp` ends up being zero if the `memcmp` called by
`compare` returns zero for both strings, with the smaller length as last
argument. This happens when they share the same prefix, so in this case
you'd run into that branch, then compare `len1` against `len2`. As
`len1` is larger, `string-ci<=?` returns #t. The question is, what
should the correct comparator be here?

Vasilij
Sven Hartrumpf
2018-09-11 08:12:46 UTC
Permalink
Hi Vasilij.
Post by Vasilij Schneidermann
(string-ci<=? "test" "tes")
#t
(string-ci>=? "test" "tes")
#f
(set! scheme#string-ci<=? (lambda (s1 s2)
(compare
s1 s2 'string-ci<=?
(lambda (len1 len2 cmp)
(if (eq? cmp 0)
(fx>= len1 len2)
(fx< cmp 0) ) ) ) ) )
(set! scheme#string-ci>=? (lambda (s1 s2)
(compare
s1 s2 'string-ci>=?
(lambda (len1 len2 cmp)
(if (eq? cmp 0)
(fx<= len1 len2)
(fx> cmp 0) ) ) ) ) )
From what I can tell, `cmp` ends up being zero if the `memcmp` called by
`compare` returns zero for both strings, with the smaller length as last
argument. This happens when they share the same prefix, so in this case
you'd run into that branch, then compare `len1` against `len2`. As
`len1` is larger, `string-ci<=?` returns #t. The question is, what
should the correct comparator be here?
The line
(fx>= len1 len2)
should be moved down to scheme#string-ci>=?, and the line
(fx<= len1 len2)
should be moved to to scheme#string-ci<=?
Am I missing something?

Ciao
Sven
Peter Bex
2018-09-11 19:05:52 UTC
Permalink
Post by Sven Hartrumpf
Hi.
The issue reported by Nils Holm
in http://groups.google.com/group/comp.lang.scheme/t/6b8be06b84b39a7
(string-ci<=? "test" "tes")
#t
(string-ci>=? "test" "tes")
#f
Thanks for reporting this. I've filed a ticket to track this at
https://bugs.call-cc.org/ticket/1534

I've assigned it to milestone 5.0 and version 5.0.0rc2 so we don't
forget to fix it before releasing 5.0 and it should be in the list
of things which changes since 5.0.0rc2. We still should apply it
to the chicken-4 branch, so it's included if we ever make a 4.14
version.

Cheers,
Peter

Loading...