From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Joe Casadonte" Newsgroups: gmane.emacs.help Subject: Re: Creating string from list of strings Date: 14 Oct 2002 10:00:07 -0400 Organization: Llama Fresh Farms, Neare Paraguay Sender: help-gnu-emacs-admin@gnu.org Message-ID: References: <80of9xtu2k.fsf@gbr.newt.com> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1034604356 25085 127.0.0.1 (14 Oct 2002 14:05:56 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 14 Oct 2002 14:05:56 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1815qz-0006WK-00 for ; Mon, 14 Oct 2002 16:05:54 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 1815rP-0004Jb-00; Mon, 14 Oct 2002 10:06:19 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!canoe.uoregon.edu!arclight.uoregon.edu!wn14feed!worldnet.att.net!199.45.45.8!cyclone1.gnilink.net!news-out.nuthinbutnews.com!propagator2-sterling!news-in-sterling.newsfeed.com!news-in.nuthinbutnews.com!newshosting.com!news-xfer1.atl.newshosting.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.2 Original-Lines: 68 Original-NNTP-Posting-Host: f6593877.news.newshosting.com Original-X-Trace: DXC=[[_NVVn6bR?SgQG3TYX3U>XMDXCI2J8L3XkcEe:=NIi;5d]1?:Qbfc5G:8?R8PEOUnbQ:1?>FfRhk4SE07KAcl]ULLb0 Original-X-Complaints-To: abuse@newshosting.com Original-Xref: shelby.stanford.edu gnu.emacs.help:106036 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:2584 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:2584 On Mon, 14 Oct 2002, Bill Wohler wrote: > I wasn't able to figure out from the Elisp manual how to turn a > list of strings into a single string. For example, how does one > print the following list of strings? > > (setq list-of-strings '("foo" "bar")) > (message (perform-magic-with list-of-strings)) > > While the following works, it seems that there should be a > one-liner to do this already: > > (defvar my-string) > (while list-of-strings > (setq my-string (concat my-string (car list-of-strings))) > (setq list-of-strings (cdr list-of-strings))) > (message (my-string)) 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)) -- Regards, joe Joe Casadonte jcasadonte@northbound-train.com ------------------------------------------------------------------------------ Llama Fresh Farms => http://www.northbound-train.com Gay Media Resource List => http://www.northbound-train.com/gaymedia.html Perl for Win32 => http://www.northbound-train.com/perlwin32.html Emacs Stuff => http://www.northbound-train.com/emacs.html Music CD Trading => http://www.northbound-train.com/cdr.html ------------------------------------------------------------------------------ Live Free, that's the message! ------------------------------------------------------------------------------