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: Mon, 28 Nov 2022 22:01:24 +0000 Message-ID: References: <878rju96i5.fsf@dataswamp.org> 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="24365"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Nov 28 23:02:12 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 1ozmCZ-00060W-Pg for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 28 Nov 2022 23:02:11 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ozmCG-0005Tl-4t; Mon, 28 Nov 2022 17:01:55 -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 1ozmC5-0005RC-Oe for help-gnu-emacs@gnu.org; Mon, 28 Nov 2022 17:01:41 -0500 Original-Received: from mail-4325.protonmail.ch ([185.70.43.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ozmC3-0001jQ-7F for help-gnu-emacs@gnu.org; Mon, 28 Nov 2022 17:01:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1669672896; x=1669932096; bh=EtRgPlObhRXYbN72JgqnUDcrqPUK6GGgftD7oC9OpoY=; 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=DyS08cl1GP2eFkrji/V+OA96Dq34y4Ki1yOWmSup5cMljYR6jt0EKynMUR92E/tTJ dZFHGvJeKNyc/kxGZxhBYOYwLtm5TQ0OPsiNBgwpANvdlOP5PRaW2P9bxWgUJo/Evf GaYbM8JWEENh8ui6SVdWxxuNX+6RwzYdK9OFr1KsHRqkbdwgqeWQN1Z725J8lT2RJr z8JNacMM10NUME4gKWYanPoCt96lI6LXLDfZP4ohU/ZINqdF5G7ldBpqjd17idPHHj LWpfa1lDrnTqG5morEPVVEC1A5quk4HBJ7KxsZiajEvkkxQsQm4zjb1KDyK5oKT8Tn CAb0jeGhk0/XQ== In-Reply-To: <878rju96i5.fsf@dataswamp.org> Feedback-ID: 57735886:user:proton Received-SPF: pass client-ip=185.70.43.25; envelope-from=heimeborgia@protonmail.com; helo=mail-4325.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:141227 Archived-At: ------- Original Message ------- On Monday, November 28th, 2022 at 8:19 PM, Emanuel Berg wrote: > Stefan Monnier via Users list for the GNU Emacs text editor wrote: >=20 > > > Although it is easy to add to a list using push, it > > > currently looks hideous to be able to add to the end of > > > a list. > >=20 > > That's because adding to the end of a Lisp list is > > a bad idea. The bad idea comment disregards necessity. Suppose I am accumulating indicators that are done at increasing value of time and want to introduce them into another list in the order they were encountered. What should one= =20 handle these things?=20 =20 > Let's make it as good as possible first ... >=20 > Why is the below O(N), because of `last'? >=20 > (defun push-last (elem lst) > (let ((elem-lst (list elem))) > (if lst > (setcdr (last lst) elem-lst) > (setq lst elem-lst) ) > lst) ) >=20 > ;; (setq nil-lst nil) > ;; > ;; (push-last 1 nil-lst) ; (1) > ;; > ;; (setq lst '(1 2 3 4)) > ;; > ;; (push-last 5 lst) ; (1 2 3 4 5) > ;; > ;; lst ; (1 2 3 4 5) >=20 > -- > underground experts united > https://dataswamp.org/~incal