From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime Newsgroups: gmane.emacs.help Subject: Re: Easy to add with push but not to the end of a list Date: Tue, 29 Nov 2022 10:15:35 +0000 Message-ID: <1U5D5raKm6LALc-O6Arn0DkwBYTxGl03zPs0Ypi6V55fdnDFGmizuGVG5yG8D3uyvVsbPYb1APAU9adrRwINbJOizxpoVvHr3GQFnWzs0Ek=@protonmail.com> References: <878rju96i5.fsf@dataswamp.org> <87wn7ew474.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1521"; mail-complaints-to="usenet@ciao.gmane.io" Cc: tomas@tuxteam.de, help-gnu-emacs@gnu.org To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 29 11:17:02 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ozxfi-0000AW-Ad for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 29 Nov 2022 11:17:02 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozxez-0002nR-Kd; Tue, 29 Nov 2022 05:16:19 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozxea-0002l1-N3 for help-gnu-emacs@gnu.org; Tue, 29 Nov 2022 05:15:53 -0500 Original-Received: from mail-4324.protonmail.ch ([185.70.43.24]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozxeY-00066N-Fd for help-gnu-emacs@gnu.org; Tue, 29 Nov 2022 05:15:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1669716946; x=1669976146; bh=ZXR2pUk+HdZNM7qp8j+Z296E4bVTzFPhMoMIHJdhKN8=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=Y0HxP8bo2CN9lFQHBmWkWeyQI57ORl+278DEagjDxYM86DkRewejp3hiJ80b1+li7 tBCRdwZqiYh6vdVT2MsoY4jzMiVRos58c7WDuLToXO1THuvWke/hDQER6RbebtmCwO K+quMKZS8cxfSH99UEZkEfLA6mBlB0xGq5w3n9lGIwgb9Zgu8vgUU0XeQmwGvoERF2 ZOCuCzsYF52HSzMgKGR+tmVcZRgKMXVgSIT+NEdREsQeOtbrDnDmkG3Mv/uqd6lzwG yy/og0IhB9a8t7XeJpT7WH52cy8IkyDl6cOxemBCJIqd/J/auH1udQANtiIQYDjxea PHP3Jk8Rc6/cw== In-Reply-To: <87wn7ew474.fsf@mbork.pl> Feedback-ID: 57735886:user:proton Received-SPF: pass client-ip=185.70.43.24; envelope-from=heimeborgia@protonmail.com; helo=mail-4324.protonmail.ch X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:141238 Archived-At: ------- Original Message ------- On Tuesday, November 29th, 2022 at 8:33 AM, Marcin Borkowski wrote: > On 2022-11-29, at 08:56, Heime heimeborgia@protonmail.com wrote: >=20 > > Programming has got nothing to do with engineering or craft. >=20 >=20 > What is it, then? (I'm genuinely curious about your opinion.) Programming should be included in the Department of Sports. :) =20 > > > Singly linked lists are a tool. They are simple, lightweight, > > > and appropriate for keeping things in sequence, and for adding > > > things at the front. Not at the end. > >=20 > > Stefan mentioned using reverse to put it into another list. If needed > > the execution time would not be much different than actually place > > new elements at end of list. >=20 >=20 > The difference is that you keep adding items at the front and then > reverse the list /once/. >=20 > Another pattern you might use is to ditch lists and keep the items in > a temporary buffer, keeping point at its end (which is easy with > `insert'), and then traverse the buffer to gather the results as needed. = You might even want to keep them in a buffer as a printed representation of= a list, and then read it, using the Elisp parser. (I don't know what funct= ion would help with that, but I'm pretty certain such a function exists.) N= ot sure how efficient this would be, but I'd guess it could be pretty good = with really large number of items. Yet another option would be to keep the = whole list in some variable, but use another variable (say,` last') as a "p= ointer" to the last cons of > that list. Then, you can define `fast-append' like this: (defvar last nil= ) (defvar my-list nil) (defun fast-append (el) "Append EL at the end of` my= -list' in O(1) time." > (if (not my-list) > (setf my-list (cons el nil) > last my-list) > (setf (cdr last) (cons el nil) > last (cdr last)))) >=20 > This then would be O(1). >=20 > > > Core library functions express idioms. They are expected to > > > help people to find patterns on how to use tools appropriately > > > (it's not much different from tools: a screwdriver has a > > > handle, which spells "grip me here, please"). > > >=20 > > > Adding a function to core (say `hsup') which suggests that > > > it is as easy to push something at the end of a list would > > > be misleading people to hold the screwdriver (or the knife!) > > > at the wrong end and hurt themselves. > >=20 > > Nobody will get hurt. Just inefficient for long lists or for > > large number of calls. >=20 > Every time someone appends to the end of a singly linked list, a cute > kitty dies... >=20 > ;-) Pussy Riot it is, then! =20 > -- > Marcin Borkowski > http://mbork.pl