help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Creating string from list of strings


From: Tom Capey
Subject: Re: Creating string from list of strings
Date: 14 Oct 2002 16:15:29 +0100
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2

* Joe Casadonte <jcasadonte@northbound-train.com> writes:

>On Mon, 14 Oct 2002, Bill Wohler wrote:
> [question on concatenating list strings elided]

> Some folks have already showed you what to do to get a simple concat
> like you had asked for.  Here's something I whipped up to get a
> perl-like join command.
> 
> (defun my-perl-join (join-string elements)
>   "[Internal] Function to mimic Perl's join() function.
> 
> JOIN-STRING is the string to use to join them together.
> ELEMENTS is a list of what to join.
> 
> Example:
> 
>   \(my-perl-join \"/\" (list \"some\" \"file\" \"path\")
> 
> would result in the string:
> 
>   some/file/path
> 
> Note that no leading slash is put in; JOIN-STRING is only put in
> between the joined elements."
>   (let (rc active subsequent-pass)
>       (while elements
>         (setq active (car elements))
>         (setq elements (cdr elements))
> 
>         (if (not subsequent-pass)
>                 (setq subsequent-pass t)
>               (setq rc (concat rc join-string))
>               )
> 
>         (setq rc (concat rc active)))
>       rc))
> 


  or using the cl package' `loop':

(loop for elts on (list "some" "file" "path")
      if (cdr elts)
      concat (concat (car elts) "/")
      else concat (car elts))


/Tom
-- 
"...and so, as the La-La of time plays with the Tinky-Winky of
destiny, and the Dipsy of fate sits on the Po of eternity."
                                                      -- Humph


reply via email to

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