[racket] Rationale behind missing string-trim

From: Chad Albers (calbers at neomantic.com)
Date: Wed May 9 13:29:59 EDT 2012

Thanks Eli.  I'm happy you recognize the issue.

I did write my own string-trim-both function using Racket's regexp as

  (define (string-trim-both string)
    (cadr (regexp-match #px"[\\s]*(\\S+)[\\s]*" string)))

May not be the best, but it works.  Even though it's easy to implement, my
issue was why it wasn't included.  I guess I'm just used to such utilities
functions being provided for free in the language I usually  work in: Ruby.
  I was surprised that I had to either 1) roll my own, or 2) require the

Thanks for you help.


On Wed, May 9, 2012 at 11:42 AM, Eli Barzilay <eli at barzilay.org> wrote:

> 30 minutes ago, Chad Albers wrote:
> > I'm having a long running discussion with my colleagues about the
> > practically of scheme.  I've argued that it is, and using Racket
> > Scheme to prove my point.  However, on the other side of the debate,
> > I've noticed that Racket's string API is missing what I consider to
> > be a extremely practical procedure - string-trim.  This procedure is
> > actually in srfi 13.  While I can 'require' srfi13, I can't import
> > it as is, because sfri-13's procedures overlap Racket's string
> > procedures.  I believe Racket's require feature allows me to just
> > import those procedures I need from srfi 13, but I find that kind of
> > awkward.
> >
> > My question is, then, why would such a practical procedure missing
> > from Racket's string API?
> In no particular order:
> * If two libraries provide the same name, you'd only run into problems
>  if you `require' both -- otherwise, as Laurent showed, there
>  shouldn't be any problems.  If you do need to require both, then you
>  can use a prefix or grab only the functionality that you need.
> * I don't see a big meta point about the practicality of Racket
>  ("Scheme" is trickier to talk about) -- we did have regexp
>  operations for a long time now, and as any Perl hacker knows, you
>  don't need anything more...  But more seriously it definitely means
>  that practicality is important.
> * The particular functionality that `string-trim' provides is one that
>  can easily be done using regexps.  This is why it wasn't an urgent
>  addition.  That's not to say that it's not needed -- and in fact
>  this exact point came up recently -- it's just that if the main goal
>  is to provide some simpler interface than regexps, then it's not
>  clear how such an interface should look.
> * As a result of the recent discussion, I've added it, and it will be
>  included in the next release.  Also, it just happens that you wrote
>  this email just when I was working on that exact function.  (We had
>  talked about the general interface to these functions and reached
>  some conclusions that slightly change the way it's implemented.)
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120509/3bc79181/attachment.html>

Posted on the users mailing list.