From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Francis Moreau Newsgroups: gmane.emacs.help Subject: Re: Basic questions about elisp Date: Thu, 5 Nov 2009 06:25:03 -0800 (PST) Organization: http://groups.google.com Message-ID: References: <1e9f8449-09ec-4a84-a332-9f05fadb8aa3@z41g2000yqz.googlegroups.com> <87r5sdm8kn.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1257432116 4758 80.91.229.12 (5 Nov 2009 14:41:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 5 Nov 2009 14:41:56 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 05 15:41:49 2009 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.50) id 1N63X0-00029X-3i for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 15:41:46 +0100 Original-Received: from localhost ([127.0.0.1]:45557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N63Wz-0007vv-Ax for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Nov 2009 09:41:45 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!postnews.google.com!w19g2000yqk.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 58 Original-NNTP-Posting-Host: 213.41.232.205 Original-X-Trace: posting.google.com 1257431103 7659 127.0.0.1 (5 Nov 2009 14:25:03 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Thu, 5 Nov 2009 14:25:03 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: w19g2000yqk.googlegroups.com; posting-host=213.41.232.205; posting-account=ekTE0goAAADiVCThPmo4ph0C5bTUhQOx User-Agent: G2/1.0 X-HTTP-Via: 1.1 grimoire.wyplay.int:3128 (squid/2.5.STABLE14) X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.11) Gecko/2009061118 Fedora/3.0.11-1.fc9 Firefox/3.0.11, gzip(gfe), gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:174419 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:69494 Archived-At: On Nov 5, 1:59=A0pm, David Kastrup wrote: > Francis Moreau writes: > > > =A0 (defmacro x-nconc (l e) > > =A0 =A0 `(if (null ,l) (setq ,l ,e) (nconc ,l ,e))) > > Actually, that's pretty stupid thanks > since it is exactly the same as > (defmacro (l e) `(setq ,l (nconc ,l ,e))) > > It is less obscure to use nconc in the same manner as append, namely > using the return value (and accepting the side-effect for efficiency's > sake). =A0And then you don't need your personal macro and get more > readable code. yes, I actually missed the use of the return value. > > The usual iteration would be something like > > (while lst > =A0 > =A0 > =A0 (setq lst (cdr lst))) > > If you really want efficiency, you'll not append something to lst in > order to avoid quadratic behavior. =A0Then you'd rather do something like > > (let ((iter lst) app) > =A0 (while > =A0 =A0 (progn > =A0 =A0 =A0 =A0(while iter > =A0 =A0 =A0 =A0 =A0 > =A0 =A0 =A0 =A0 =A0 > =A0 =A0 =A0 =A0 =A0 (setq lst (cdr lst))) > =A0 =A0 =A0 =A0 app) > =A0 =A0 =A0(setq iter (nreverse app) app nil))) > hmm, it's probably my lack of elisp usage/knowledge, but it's terribly hard to read for something really simple to achieve... BTW, is '(setq lst (cdr lst)))' correct ? > Note that this does not change the original list at all. =A0If that's not > what is desired, you can write the last setq as > > (setq iter (nreverse app) lst (nconc lst iter) app nil) > > This still is suboptimal since the nconc will repeatedly traverse the > same elements. Lists are really implemented as simply linked list ? Thanks