From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robin Tarsiger Newsgroups: gmane.emacs.devel Subject: Re: Ad-hoc list structure tutorializing (was: Lispref add-to-list - doc is unnecessary convoluted) Date: Fri, 4 Dec 2020 10:14:45 -0600 Message-ID: <8ac1cf69-73ef-d8b9-df79-5a895f194936@dasyatidae.com> References: <83zh2udle7.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23045"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 Cc: emacs-devel@gnu.org To: Arthur Miller Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 04 21:07:38 2020 Return-path: Envelope-to: ged-emacs-devel@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 1klHMf-0005tJ-Gd for ged-emacs-devel@m.gmane-mx.org; Fri, 04 Dec 2020 21:07:37 +0100 Original-Received: from localhost ([::1]:57900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1klHMe-0003SN-Dn for ged-emacs-devel@m.gmane-mx.org; Fri, 04 Dec 2020 15:07:36 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klEeJ-0007ik-Pk for emacs-devel@gnu.org; Fri, 04 Dec 2020 12:13:40 -0500 Original-Received: from out2-smtp.messagingengine.com ([66.111.4.26]:42967) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klEcO-0007RQ-BC for emacs-devel@gnu.org; Fri, 04 Dec 2020 12:13:19 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 928725C01B6; Fri, 4 Dec 2020 11:14:41 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 04 Dec 2020 11:14:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=adMGn4JwoD+iprPIC3WvlXcPuMKnIa8y4UCf+dBwL Ag=; b=Sq1tdZMcQfQKu9s2snAd+toukSMRwRfvgsY/2auQkSXfsD5KxIaDaqpaf CcgqFcqOA5XAxeV+/1CwfJvA1hx3mKr+sXGieqhkBz1ZlDQivcC8HIAn+KVTRlXe hBjaQfhZg9kwyszlVwg96hUmSjL4xZfb90vJLIJP6Bz2jS/hIhigHrZv4Ui0EepO nqnxJQx8bKk1a/b8rkC9X2gS2DHbXn5J0v5XRNeK5bpp6MHu7n9f8y0n5jH7IWiE dPoa18HV7LBNv/riCoyGA+/Kwg12dLAPVcsxvoxrn1CUHpJ9Nv+hw1bHMKOnCvVU alEf6alWqrqqXRXu4NDg2hI4aG7mQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeikedgkeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvfhfukffffgggjggtgfesthekredttdefjeenucfhrhhomheptfhosghi nhcuvfgrrhhsihhgvghruceorhhtthesuggrshihrghtihgurggvrdgtohhmqeenucggtf frrghtthgvrhhnpeffhfefheehuefgjeeikedvheeuuddtueektdffvdelvdevffeitdek veefudevveenucfkphepjeeirddvheefrdejhedrfeegnecuvehluhhsthgvrhfuihiivg eptdenucfrrghrrghmpehmrghilhhfrhhomheprhhtthesuggrshihrghtihgurggvrdgt ohhm X-ME-Proxy: Original-Received: from [192.168.1.65] (76-253-75-34.lightspeed.austtx.sbcglobal.net [76.253.75.34]) by mail.messagingengine.com (Postfix) with ESMTPA id 1B1CC240059; Fri, 4 Dec 2020 11:14:41 -0500 (EST) Autocrypt: addr=rtt@dasyatidae.com; prefer-encrypt=mutual; keydata= mQINBFlZ32YBEADE52MDC4u9v99gDRaMycG7kJQ1fz5pmRUQtLPfMYUWOkAVBC/dgpUsVdtG MnYpEl6cdVaRBfSNbJG0TPyHuM3DxiPMoBsnTGbf8BY43ZvRnk6Ibku/yv48m17crQFRvJaJ fr7e1z+cKcNqrnfYtuf5sJ+I5X3lqtKQcHAMNqYboRVLPWv7XlM1H34Mnzmb9lJAlowvXBU3 UaRe0D71vytKza/jtoQQsJeGVSQiuNElRbUns/jzpZgiQ+zRDcZQyPACsWzWnnsZbhqdxiwD IACKeIyqpgGyxbccXqe2iwJ/V3q/acl4rgX31eU1kaBuEh/Kc8Zz3uEG9SjHJMIcwm+nR5E4 KI0p2vecHU09scQoGDCwwSXqWtv5GaFU7Akf+CKaYDQ0Z2+iDnHZUU9U8kpqEn+Ys0ChjLeC ya85OJ37T4M8KUbEPshOI6kuiWmGHjxyRJKkr0nQztS6swr1Fb0iIZeX/fplHP9g+LBh+lJE iZQfRytz84AjPz74qdFwh5qVa8VqOQ0CJirevFCYVcwf/1gyGC44oVgWN64fMxBg4WsubCjB CBPACqZrKT8uahPObgzhJ4EIROoOSY3u6tWCK6/GSGiDPLHyLkRWYwvO+neoI9mUub+ZC+29 JFrKnbtIudRXSb1t5OsbDgQmnYm/H6Df16NhX8ikqrnkmknnZQARAQABtCNSb2JpbiBUYXJz aWdlciA8cnR0QGRhc3lhdGlkYWUuY29tPokCUAQTAQgAOgIbAQIeAQIXgAQLCQcDBBUKCQgD FgIAFiEEEgc4poGjw In-Reply-To: Content-Language: en-US-large Received-SPF: none client-ip=66.111.4.26; envelope-from=rtt@dasyatidae.com; helo=out2-smtp.messagingengine.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, NICE_REPLY_A=-0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:260312 Archived-At: Robin Tarsiger wrote: > Arthur Miller wrote: >> Maybe I don't understand lisp enough, but why is this not desirable: >> >> (add-to-list '(1 2 3) '4) or (add-to-list (list 1 2 3) 4) > > [...] For general list manipulation, the docstring > explicitly calls out "please do not abuse it in Elisp code, where you > are usually better off using ‘push’ or ‘cl-pushnew’". To be abundantly clear on this, by the way, the non-mutating version of that (without APPEND) is just the cons primitive itself: (cons 4 '(1 2 3)) => (4 1 2 3) and when APPEND is set, it's almost equivalent to, well, append: (append '(1 2 3) (list 4)) => (1 2 3 4) What those don't do is store the new list back where the old one came from, which is where push and cl-pushnew come in for local-variable/general-programming purposes and where add-to-list comes in for config-variable-like purposes. The names are something of a mishmash, admittedly, I imagine for historical reasons. Note that you can try to "modify" the tail of a list with nconc: (let ((x '(1 2 3))) (nconc x (list 4)) ;; wrong! see below x) => (1 2 3 4) ... but you still need the store-back in general, because the empty list has no cons cells to mutate! (let ((x '())) (nconc x (list 4)) ;; oops x) => nil so that's only usable as an "optimization" in narrow cases where you need fast append and can arrange the right guarantees about the actual list structure, including that no other code is going to be holding onto any of the sublists at the same time (else they get a nasty surprise). Don't do that without a really good reason. (Aside: why not replace add-to-list with cl-pushnew always? Aside from historical reasons and things like the buffer-local variable idiom, being able to toggle APPEND is useful when list entries are going to be processed in a specific order.) -RTT