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: Alex Shinn
Subject: Re: [Chicken-hackers] substring function and bounds checks
Date: Thu, 7 Feb 2013 08:20:25 +0900

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:

  (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]