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: Vasilij Schneidermann
Subject: Re: [Chicken-users] string-ci<=? and string-ci>=?
Date: Tue, 11 Sep 2018 09:26:18 +0200

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



reply via email to

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