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: add-to-list vs cl-pushnew Date: Fri, 4 Dec 2020 15:40:43 -0600 Message-ID: <8c92ca59-a6bd-4d9a-341a-cf481b5494b1@dasyatidae.com> References: <83zh2udle7.fsf@gnu.org> <8ac1cf69-73ef-d8b9-df79-5a895f194936@dasyatidae.com> 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="4818"; 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: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 04 22:42:27 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 1klIqP-00016N-G1 for ged-emacs-devel@m.gmane-mx.org; Fri, 04 Dec 2020 22:42:25 +0100 Original-Received: from localhost ([::1]:60034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1klIqO-0003kO-G0 for ged-emacs-devel@m.gmane-mx.org; Fri, 04 Dec 2020 16:42:24 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klIow-0002Ev-Aj for emacs-devel@gnu.org; Fri, 04 Dec 2020 16:40:56 -0500 Original-Received: from wout5-smtp.messagingengine.com ([64.147.123.21]:48681) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klIok-0000rm-FR for emacs-devel@gnu.org; Fri, 04 Dec 2020 16:40:54 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 03183C61; Fri, 4 Dec 2020 16:40:38 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 04 Dec 2020 16:40:39 -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=JP6XMF+ZUfiRkm4DVi1T5bfJ7bO3dq9ZqCE8D+RAa Qk=; b=FPZhlU90mVJeaITBlysbNND8q/OWnkatbuABaq871CaMtXj0z/WBOm+j7 p9u5IsIl1wmjuSl+3JAasvvZglqWPMnEk3/rVG2NrSvgBxynKKN6ybKZ28nILeAH ukkfNc07oO3BwgCCuPg62N/Peonv35sVqYud+SmfdZ4LCN/29fhbQkkaR3M7Z5NW aOvCCiiIpS0Gbi3f4aRiPIyv3I8oyanZjMou55KIGUDyYrzxHZwz1VM9oZTrBpfL nkgLcG5Pbgg1xaZ2U9YEp6SO0D7rYyhEc6JFlitGWblV9ya42/eo5rGY+Yco5ZBU ERqFjGIhEsB3VoMeQA/3CQ8P16xnQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeikedgudehvdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefvfhfhuffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeftohgs ihhnucfvrghrshhighgvrhcuoehrthhtsegurghshigrthhiuggrvgdrtghomheqnecugg ftrfgrthhtvghrnhepvddugfegffeigeekueeufedvkeffkeehvedvtdegveeltdehhfek feefgfekgfeknecukfhppeejiedrvdehfedrjeehrdefgeenucevlhhushhtvghrufhiii gvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrthhtsegurghshigrthhiuggrvgdr tghomh 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 1F623240059; Fri, 4 Dec 2020 16:40:38 -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=64.147.123.21; envelope-from=rtt@dasyatidae.com; helo=wout5-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_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham 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:260329 Archived-At: Stefan Monnier wrote: >> (Aside: why not replace add-to-list with cl-pushnew always? > > Good question. > > > Stefan "who really doesn't like `add-to-list`" In case it was interpreted differently, my original question was rhetorical. There's several reasons I can think of to keep using add-to-list's current behavior as-is for its primary use case, as opposed to recommending that new code avoid it entirely: - The unquoted variable name argument leaving available the make-local-variable idiom and similar. - The presence of the APPEND arg. This being a toggle lets it be plumbed through wrapper functions easily, so that you can write (defun foo-add-bar (bar &optional at-end) ...) and call (add-to-list 'foo-bar-list rectified-bar at-end) from it. - The use of equal, not eql, as the default comparison function. This becomes important if any of the list variables contain almost anything other than symbols, and I could see eql as a default in this case leading to subtle bugs since duplicates wouldn't be common, nor necessarily punished in practice. (eql "foo" "foo") is allowed to be nil. - The docstring mentioning the potential need for eval-after-load to handle package ordering issues, which is an easy source of bugs in add-to-list's main use case but irrelevant in most list processing. If you just use the general list processing functions, there isn't as good a place to warn about that. - I recall a while ago that pulling in the cl library for one or two symbols was considered bad style because it was quite heavy, but I don't know if that's still true. However, I would not be averse to finding it a better primary name and demoting the add-to-list name to being a compatibility alias, especially if new elisp programmers are likely to stumble into it and skip over the the "please do not abuse for general list manipulation" part of the doc, since the name itself both doesn't imply that right now and is paradoxically easier to find than the push family by some (albeit not-so-good) routes. If you do this, you'd want to hit add-to-ordered-list too. I also think upon looking at the "List Variables" section again that it could usefully be split up, since putting push and add-to-list right next to each other when the latter is so much more specialized could be structurally misleading. (The "please do not abuse" text is also nowhere there, instead obscured behind "Do not use this function when SYMBOL refers to a lexical variable.", which could lead off into the weeds of e.g. "ah, so if I want to use this function on locals then I have to not use lexical-binding" to someone not already receiving usage cues from other places.) -RTT