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: Lispref add-to-list - doc is unnecessary convoluted Date: Fri, 4 Dec 2020 09:56:21 -0600 Message-ID: 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="16024"; 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 16:57:06 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 1klDSE-000434-0Q for ged-emacs-devel@m.gmane-mx.org; Fri, 04 Dec 2020 16:57:06 +0100 Original-Received: from localhost ([::1]:39474 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1klDSD-0005In-1E for ged-emacs-devel@m.gmane-mx.org; Fri, 04 Dec 2020 10:57:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47940) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klDRU-0004k8-D1 for emacs-devel@gnu.org; Fri, 04 Dec 2020 10:56:20 -0500 Original-Received: from out2-smtp.messagingengine.com ([66.111.4.26]:35609) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1klDRS-0002IL-Ia for emacs-devel@gnu.org; Fri, 04 Dec 2020 10:56:20 -0500 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id D99E15C00BE; Fri, 4 Dec 2020 10:56:17 -0500 (EST) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 04 Dec 2020 10:56:17 -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=9rI0nZw6Lx62AeXKa4yWFFY2FPFyYMd0IjrEQt6BA cg=; b=j9eL6mdFpNg8PuOL1vhE79l7x05qMYmnWAe4OMPvWR/hBJge8er3BvU2h j03RMj3S0ckny5DFWZkRvR2PfDTW73r3iHkfMyjYeMGQy8MtG9QJLhtaDF9LcZ+M p0Wt4ST+SandPzv97WDclBZZA1Tr1mZL+x8YQeaO6icKRD9Eok/OzCl/pDhyi5K2 8apVImLk+fGivSpLh9jh1nyRQ52OX1CEaUsvk3ntTKBtlxU9ElavHVldtaZBka4Q r0dDtQQWp43sMS4nKU91eLfEGPv2+r9Q3vvpO7VeplXrMOF14AZ5HNEkBv4XVw2h 7cFYZPaV6qz0Gu6nDtvQ1kJny+TpQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedrudeikedgkeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepvfhfhffukffffgggjggtgfesthekredttdefjeenucfhrhhomheptfhosghi nhcuvfgrrhhsihhgvghruceorhhtthesuggrshihrghtihgurggvrdgtohhmqeenucggtf frrghtthgvrhhnpedvudfggeffieegkeeuueefvdekffekheevvddtgeevledthefhkeef fefgkefgkeenucfkphepjeeirddvheefrdejhedrfeegnecuvehluhhsthgvrhfuihiivg 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 3566A24005C; Fri, 4 Dec 2020 10:56:17 -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=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:260304 Archived-At: Arthur Miller wrote: > Another question, why doesn't add-to-list take a list value, why symbol? > 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) Because that is not how lists work in Lisp. The idea of a "mutable list" as a conceptual unit does not fall naturally out of the cons-cell-based formulation of them. If we were in Python or Java, for instance, a variable would store a reference to a mutable list object, and passing the mutable list object into a function to mutate it would be an acceptable style. But what add-to-list does is construct a new list (if needed) and store it back into the original location. Lists are mostly processed without mutation, with any "non-consing" in-place mutation functions being secondary and not covering all the operations. (To preempt "Isn't this horribly inefficient?": no, in part because "adding to" the head of a list involves allocating one cons cell and the rest of the list is structurally incorporated rather than copied.) The point where it _sets a variable with a specified name_ in order to do the mutation is very important both in terms of it being clear what side effects arise. It does this because add-to-list is intended for conveniently registering unique entries in lists that are part of global (or buffer-local) state. 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’". It is not just an "implementation detail". The symbol is not the list. The variable is not the list. "list" already means something and it is not that. LIST-NAME would be potentially sane if everything else had already used -NAME, but I doubt it's stylistically appropriate. -VAR is clear: you use it mainly in conjunction with symbols that are set up using defvar. Calling out the part where it's not setq-like explicitly is useful because many forms that operate on variables _are_ setq-like, and in particular the alternatives of push and cl-pushnew are both setq-like and treat the place argument specially. > "If that is I want"? :-) If I don't want - is it not needed then? :-) Consider: (add-to-list (make-local-variable 'some-lovely-config-list) '(happy config entry here)) along the lines of the (set (make-local-variable ...) ...) idiom, to say "do this mutation buffer-locally, by ensuring that the variable is buffer-local first, without repeating the variable name". This is not something you can do with the setq-like forms. -RTT