From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tim Landscheidt Newsgroups: gmane.emacs.help Subject: Re: Idiomatic way to avoid unused lexical variable in =?utf-8?B?4oCYZG90aW1lc+KAmQ==?= or =?utf-8?B?4oCYZG9saXN04oCZPw==?= Date: Wed, 27 Mar 2024 03:52:47 +0000 Organization: https://www.tim-landscheidt.de/ Message-ID: <87le648h68.fsf@vagabond.tim-landscheidt.de> References: <87ttks8wam.fsf@gmail.com> <87msqk8maf.fsf@gmail.com> 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="26493"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.3 (gnu/linux) Cc: help-gnu-emacs@gnu.org, Stefan Monnier To: tpeplt@gmail.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 27 04:53:38 2024 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 1rpKM6-0006jd-Ph for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 27 Mar 2024 04:53:38 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rpKLP-0005TB-H8; Tue, 26 Mar 2024 23:52:55 -0400 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 1rpKLN-0005SW-PO for help-gnu-emacs@gnu.org; Tue, 26 Mar 2024 23:52:53 -0400 Original-Received: from gavdos.tim-landscheidt.de ([2a01:4f8:1c0c:4bd6::1]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rpKLM-0000TK-0c for help-gnu-emacs@gnu.org; Tue, 26 Mar 2024 23:52:53 -0400 Original-Received: from [85.195.93.93] (port=60612 helo=vagabond) by gavdos.tim-landscheidt.de with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1rpKLI-00GbRb-0t; Wed, 27 Mar 2024 03:52:48 +0000 In-Reply-To: <87msqk8maf.fsf@gmail.com> (tpeplt@gmail.com's message of "Tue, 26 Mar 2024 22:02:16 -0400") Received-SPF: pass client-ip=2a01:4f8:1c0c:4bd6::1; envelope-from=tim@tim-landscheidt.de; helo=gavdos.tim-landscheidt.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=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:146181 Archived-At: (anonymous) wrote: >>> 1. Is there an idiom in Emacs Lisp for writing this that >>> eliminates this warning? >> (dotimes (_ 100) >> (insert "I will not obey absurd orders\n")) >> Or any other var name that starts with an underscore. > Thank you. I have not been able to find this documented anywhere (that > is, that lexical variables whose names begin with an underscore are not > flagged with a warning message if they are not referenced). This > appears to be true with, for example, =E2=80=98let=E2=80=99 expressions, = also. It is mentioned in the GNU Emacs Lisp Reference Manual (C-h i g (elisp) RET) in the node "Converting to Lexical Binding": | [=E2=80=A6] | A warning about an unused variable may be a good hint that the | variable was intended to be dynamically scoped (because it is actually | used, but in another function), but it may also be an indication that | the variable is simply really not used and could simply be removed. So | you need to find out which case it is, and based on that, either add a | =E2=80=98defvar=E2=80=99 or remove the variable altogether. If removal i= s not possible | or not desirable (typically because it is a formal argument and that we | cannot or don=E2=80=99t want to change all the callers), you can also add= a | leading underscore to the variable=E2=80=99s name to indicate to the comp= iler | that this is a variable known not to be used.) | [=E2=80=A6] Tim