chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] [PATH] fix for srfi-13 string-trim-right start par


From: John Cowan
Subject: Re: [Chicken-hackers] [PATH] fix for srfi-13 string-trim-right start parameter
Date: Sat, 11 Jan 2014 14:04:07 -0500
User-agent: Mutt/1.5.20 (2009-06-14)

Mario Domenech Goulart scripsit:

> As as I understand it, (string-trim-right "abc  " char-whitespace? 1)
> should trim "bc  ", not that it should trim "abc  " then substring it
> from 1.

That's correct, but in fact what's happening here is that the
reference version is effectively ignoring the start argument altogether.
The code figures out where the new right end should be and then returns
a substring; unfortunately, the start argument passed to substring is
always 0.  The patch changes it to start, which eliminates this bug.
But see below!

> > Racket returns "abc" but appears, like CHICKEN, to have faithfully
> > ported the bug from the reference implementation.
> 
> So does Scheme48.

Not surprising, since nobody else seems to have noted this bug yet.

> However, both Scheme48 and Racket return "" for 
> 
>   (string-trim-right "abc   " char-whitespace? 4 4)
> 
> CHICKEN returns "abc", which looks like a bug to me.

It certainly is, since the value of (substring s k k) is always "" for any
legal k.  And indeed the proposed patch, which passes start rather than
0 to substring, will actually make this bug worse.  The correct value to
pass is (min start (+ i 1)), which guarantees that start is always safe.

-- 
Samuel Johnson on playing the violin:           John Cowan
"Difficult do you call it, Sir?                 address@hidden
 I wish it were impossible."                    http://www.ccil.org/~cowan



reply via email to

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