Subject: Re: The LOOP macro
From: rpw3@rpw3.org (Rob Warnock)
Date: Tue, 23 Mar 2004 11:19:15 -0600
Newsgroups: comp.lang.lisp
Message-ID: <RXudnYQxeO8O7P3d3czS-g@speakeasy.net>
Thomas A. Russ <tar@sevak.isi.edu> wrote:
+---------------
| rpw3@rpw3.org (Rob Warnock) writes:
| > 	     (loop for tail on strings
...
| > 	       when (cdr tail)
| > 		 collect ", ")))
| 
| Using some other interesting loop iteration constructs one
| can even get rid of the (cdr tail) test:
| 
| (defun join-strings/sql-quoted (strings)
|   (apply #'concatenate 'string
|  	 (loop for glue = "" then ", "
|              for item in strings
|          collect glue
|  	   collect "'"
|  	   collect (sql-escape-single-quotes item)
|  	   collect "'")))
+---------------

Neat! I like it!  In fact, I'm wordering why I didn't see it before,
since I already use the "for first-time = t then nil" idiom routinely.


-Rob

p.s. That could be written just as well as:

   	 (loop for glue = "" then ", "
               AND item in strings
	   ...)

Is there any advantage/disadvantage one way or the other in this case?

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607