chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] string-ci<=? and string-ci>=?


From: Sven Hartrumpf
Subject: Re: [Chicken-users] string-ci<=? and string-ci>=?
Date: Tue, 11 Sep 2018 10:12:46 +0200 (CEST)

Hi Vasilij.

VS wrote, 2018-09-11 09:26:
>> > (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?

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]