From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sean McAfee Newsgroups: gmane.emacs.help Subject: Re: Collecting in the opposite order in a CL loop Date: Fri, 26 Feb 2010 19:49:54 -0800 Message-ID: References: <874ol3bds5.fsf@galatea.lan.informatimago.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1267245654 14828 80.91.229.12 (27 Feb 2010 04:40:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 27 Feb 2010 04:40:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Feb 27 05:40:50 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NlETx-0003cN-BG for geh-help-gnu-emacs@m.gmane.org; Sat, 27 Feb 2010 05:40:49 +0100 Original-Received: from localhost ([127.0.0.1]:39181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NlETu-000677-Gs for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Feb 2010 23:40:46 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!news1.google.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.supernews.com!news.supernews.com.POSTED!not-for-mail Original-NNTP-Posting-Date: Fri, 26 Feb 2010 21:49:54 -0600 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) Cancel-Lock: sha1:0+yK+Pyg5nPtsvtOOCnOO42ZQrs= Original-Lines: 50 Original-X-Trace: sv3-7azAhvL/nHcvhoMyDQh/kIzHI4JwYhZH08QemNPQ+t9PpfW9jzFaRF+VgQHF2rbI0Y0XTF07v9i58L0!U/Gc6t4ignGQQBOkvpChGY6wSffj1ya/VjCAq50QsntHxUik70mxN6UD Original-X-Complaints-To: www.supernews.com/docs/abuse.html X-DMCA-Complaints-To: www.supernews.com/docs/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 Original-Xref: news.stanford.edu gnu.emacs.help:177144 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:72179 Archived-At: pjb@informatimago.com (Pascal J. Bourguignon) writes: > Sean McAfee writes: >> (loop for x = num then (/ x 10) until (zerop x) with result = nil do >> (setq result (cons (mod x 10) result)) >> finally return result) > Use push instead of setq cons. > Use truncate instead of / for integer division. > Use finally (return ...); finally return is ClTl2, not Common Lisp. Thanks for the tips. But what's the reason for the last two? They seem equivalent to me, aside from the latter forms having the small advantage of brevity over the former. >> Is there an elegant way to build up a list "backwards" using the CL loop >> facility? > Notice that building this list backwards as you want it is wrong: > > 1234 --> (1 2 3 4) > 34 --> (3 4) > > with the most significant digits in the lowest indexes, you cannot use > the list of digits do to anything. Nothing except what I need it for. I want to transform my input text in chunks of a certain small unit, identified by a regexp, and to do so a variable number of units at a time, inserting a space between the groups. The basic outline of my code is as follows: (defun transform-text (arg) (interactive "p") (save-match-data (loop for count in (digits-of arg) do (loop repeat count do (search-forward-regexp "\\=\\s *\\(etc.etc.\\)") (replace-match (compute-replacement-text (match-string 1))) finally (insert " ")) finally (backward-delete-char 1)))) So an argument of 123 to this routine would mean "transform one unit, insert a space, transform two more units, add a space, and lastly transform three more units." I need the digits most-significant-first because that's the order I typed them in. Anyway, I like how the collect clause lets me accumulate a return value for the loop without having to declare one explicitly, and was hoping a similar construction might let me do the same in the correct order for this usage.