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: Collecting in the opposite order in a CL loop Date: Fri, 26 Feb 2010 17:35:15 -0800 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1267234840 20491 80.91.229.12 (27 Feb 2010 01:40:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 27 Feb 2010 01:40:40 +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 02:40:36 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 1NlBfY-0006SP-FP for geh-help-gnu-emacs@m.gmane.org; Sat, 27 Feb 2010 02:40:36 +0100 Original-Received: from localhost ([127.0.0.1]:58601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NlBfY-0008Bu-0k for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Feb 2010 20:40:36 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.glorb.com!news2.glorb.com!news.glorb.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 19:35:17 -0600 Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (darwin) Cancel-Lock: sha1:I6sxxivKL6j0Kcq7eZfgBaY5CJM= Original-Lines: 28 Original-X-Trace: sv3-rL9ic7wmnuw1jhVydWbl88AQQPL4nFt7u8bX997wudQYWiw+q4Vv1Ruj5Iifba5tXgaiw8DJ/7O4CA4!qFqha6DMWYiHoYUhC9CVd5FhcPFegxImWF0btbSr1auYAsBXI1ayuxapdD/KnbclrfgF3S8/24Mm!UehKDJOuVBFRa0s+vHpOAsixiuDPVhsOio1Vd6hrzR4P75FzX31r81xzliNYJJJEGA== 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:177140 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:72175 Archived-At: Recently I composed this little function: (defun digits-of (num) (assert (and (wholenump num) (not (zerop num)))) (nreverse (loop for x = num then (/ x 10) until (zerop x) collect (mod x 10)))) It's short and sweet, but it bugs me just a little than I'm building up a list only to immediately reverse it. It seems to me that I ought to be able to create the list already in the right order, but all I can come up with so far (that uses the Common Lisp loop facility) is this: (loop for x = num then (/ x 10) until (zerop x) with result = nil do (setq result (cons (mod x 10) result)) finally return result) That's substantially uglier than this routine that doesn't use a CL loop at all: (while (not (zerop x)) (setq result (cons (mod x 10) result) x (/ x 10))) ...which I guess I could use, but I prefer to stick with the CL loop macro when possible, if only because Emacs provides my only opportunity to write any Common-Lisp(-like) code at all. Is there an elegant way to build up a list "backwards" using the CL loop facility?