guile-devel
[Top][All Lists]
Advanced

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

Re: new proc for string-fun.scm: `mapconcat'


From: Dirk Herrmann
Subject: Re: new proc for string-fun.scm: `mapconcat'
Date: Fri, 9 Feb 2001 12:43:45 +0100 (MET)

On Wed, 7 Feb 2001, thi wrote:

> please see below for `mapconcat'.  i've re-implemented this several
> times (although less generally), and thought it might be nice to add to
> ice-9/string-fun.scm.  some example usage:
> 
> guile> (mapconcat id '(1 2 3) "x")
> "1x2x3"
> guile> (mapconcat id '(a b c) "x")
> "axbxc"
> guile> (mapconcat id '((nested) (funky) (stuff)) "x")
> "(nested)x(funky)x(stuff)"
> guile> (mapconcat id #(1 2 3) "x")
> "1x2x3"
> guile> (mapconcat id "123" "x")
> "1x2x3"
> guile> (mapconcat (lambda (n) (- n 42)) '(1 2 3) "x")
> "-41x-40x-39"
> 
> if "mapconcat" is not a sufficiently guilish name, maybe
> "string-map-append" (or some permutation) would work....

What I don't like about the function is its do-everything-in-one-step
nature.  The disadvantage shows in the fact that most of the time in your
examples you are using 'id' as the function that is to be applied.  This
is unnecessary and will slow down the computation. (OK, an optimizing
compiler would be able to get rid of unnecessary stuff, but currently we
don't have one.)

I'd prefer a set of the following functions:

(sequence->list seq)
  - transforms a sequence into a list.
(obj->string obj)
  - makes a string from every object.
(append/separator sep string ...)
  - appends the strings with the separator inserted between two
    consecutive strings

Given these functions, mapconcat is still easy to implement, but the
flexibility is increased, since in most applications you already know
about the nature of your parameters.  Thus, you would not need to apply
sequence->list to lists nor obj->string to strings nor id to everything.
Moreover, the functions above may also be useful in other contexts, at
least obj->string is one of my favorites.

Best regards,
Dirk Herrmann




reply via email to

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