From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: Alist remaining empty Date: Sat, 28 Sep 2024 07:26:54 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="OUpQBnODTEqnxmGb" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10272"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 28 07:27:59 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 1suPzq-0002VL-Qg for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 28 Sep 2024 07:27:58 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suPz0-0007BN-Jf; Sat, 28 Sep 2024 01:27:06 -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 1suPyx-0007Aw-5q for help-gnu-emacs@gnu.org; Sat, 28 Sep 2024 01:27:03 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1suPyu-0002vg-Bf for help-gnu-emacs@gnu.org; Sat, 28 Sep 2024 01:27:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=MM++n8AAPzaNEbvhoOHDRQQyHUB5Tfn0tBp+qUtqWlE=; b=fuThe+YIVKLI1oLGnnt4qYHH9E rXy2Uo78YAqzQDxwGLLVZX4D4JsYlbOEqNdlOlNZ8NIoFJ2Fe3+Rv1NT1F6h55RzW7UdjKjWpZqZn l2MLrLba133O/Ei4MAcTQxDJb8QeLONvHLOBrpcRyj7/QGHS9VcOPr/PUKRcokuPRcSh8bL72AWNj B8L5PfnHZcLTELBGus7vrhrBiiYVkX6BzHTHoo8aRHJhrJXV8OAhtCSR973Phxv8JE6FSSy9Kf7xD HdJU3o2Lq5U+H1sRy7yeZwMLrnjNMlR7ARdEjyY4xmEbiuSdnF7ABPMLHf5U5dxzehAHgCWYDCN1i HrVgfCpg==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1suPyo-0002Cn-MI for help-gnu-emacs@gnu.org; Sat, 28 Sep 2024 07:26:54 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de 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, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, 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:148081 Archived-At: --OUpQBnODTEqnxmGb Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Sep 27, 2024 at 10:50:21PM +0000, Heime wrote: > I have alist variable warn-alist, which I set to nil. I am supposed > to push some alist examples if the values have not been added yet. >=20 > But I find that with the following function, the warn-alist remains empty. As it should. Please, please: learn about variables, variable scopes, values. Otherwise, you're bound to stay in an endless loop. I intersperse comments into your code: ;; Somewhere "outside", warn-alist has been defined. Or not. ;; We just don't know. > (defun warn-test () >=20 > (interactive) >=20 > (setq warn-alist nil) ;; Here, its value is set to nil (whatever its value was before). ;; Is it global? Buffer-local? Lexical? We don't know. We don't ;; know either whether it matters. >=20 > (let ( (qwpanel warn-alist) ;; A new (probably lexical, but possibly dynamic) binding for ;; qwpanel is introduced: its value is set to the value of ;; warn-alist -- which is nil (see above) >=20 > ;; Init flag to track if values have been added > (already-added nil) ) >=20 > ;; If the alist is empty, add the cons data > (unless qwpanel > (setq already-added t)) ;; Things are done in a somewhat roundabout way. In the conditional ;; above, we /know/ that qwpanel is nil, so already-added stays nil >=20 > (unless already-added ;; this means we could replace here "unless already-added" by ;; "unless qwpanel", and then completely do away with it (a smart ;; compiler is going to do that for you anyway). > (push (cons 'ques-string "Warning Message") qwpanel) > (push (cons 'ques-number 42) qwpanel) > (push (cons 'ques-symbol 'example-symbol) qwpanel) > (push (cons 'ques-list '(1 2 3)) qwpanel) > (push (cons 'ques-boolean t) qwpanel) > (push (cons 'ques-nil nil) qwpanel) > (push (cons 'ques-cons (cons 'nested "cell")) qwpanel) > (push (cons 'ques-function #'print) qwpanel)) )) ;; and now, when leaving the (let ...) scope, you throw away your ;; qwpanel binding, and all of its value, for the garbage collector ;; to feast on it. Viewed "from the outside", which you haven't ;; shown to us, nothing, except possibly setting warn-alist to nil ;; has happened. Working as designed, I'd say. Cheers --=20 tom=C3=A1s --OUpQBnODTEqnxmGb Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iFwEABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCZveTlwAKCRAFyCz1etHa RregAJjQDE158YEthWvGatq9mQhEYjXmAJ4oNTTLqQU3qkPFMi+O2x1cR082Yw== =S8Tk -----END PGP SIGNATURE----- --OUpQBnODTEqnxmGb--