Hi,
On Thu, Feb 7, 2013 at 3:20 AM, Michele La Monaca <
[email protected]> 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
_______________________________________________
Chicken-hackers mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-hackers