On Thu, Feb 7, 2013 at 12:20 AM, Alex Shinn <[email protected]> wrote: > 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:
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 > _______________________________________________ Chicken-hackers mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/chicken-hackers
