chicken-hackers
[Top][All Lists]
Advanced

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

Re: [Chicken-hackers] substring function and bounds checks


From: Michele La Monaca
Subject: Re: [Chicken-hackers] substring function and bounds checks
Date: Thu, 7 Feb 2013 18:23:50 +0100

On Thu, Feb 7, 2013 at 12:20 AM, Alex Shinn <address@hidden> wrote:
> Hi,
>
> On Thu, Feb 7, 2013 at 3:20 AM, Michele La Monaca
> <address@hidden> wrote:
>>
>> [..] I don't think
>>
>> (substring2 "foo" 0 10) -> "foo"
>>
>> is conceptually wrong or sloppy as long as you know exactly what the
>> semantic of the function is ("give me at most N chars" -> perl or
>> "give me chars up to the Nth position or up to the end of the string
>> whatever the first" -> python, ruby).
>
>
> Truncating a string to a maximum length is a common
> operation for formatting - I was surprised there was no
> easy way to do this with SRFI-13.  But in this case the
> start argument isn't needed and distracting.  You probably
> want something like:

Well, no. If I wanted a truncate function I would have asked for it. I
used 0 as START to simplify the exposition (in that case the END
parameter can be interpreted as length or position indifferently).
Anyway, thanks for raising the point. Maybe the reason there is no
string-truncate around is that a sane substring function would just do
the job?

Regards,
Michele

>
>   (string-truncate "foo" 10) => "foo"
>   (string-truncate "foofoofoofoo" 10) => "foofoofoof"
>
> In the fmt egg:
>
>   (fmt #f (trim 10 "foo")) => "foo"
>
> Conflating this with substring is confusing and hides
> potential errors, as others have pointed out.
>
> --
> Alex
>



reply via email to

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