From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Heime Newsgroups: gmane.emacs.help Subject: Re: Alist remaining empty Date: Sat, 28 Sep 2024 09:11:36 +0000 Message-ID: References: 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="6915"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: tomas@tuxteam.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 28 11:12:26 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 1suTV3-0001cN-Vs for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 28 Sep 2024 11:12:25 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suTUS-0007TH-CS; Sat, 28 Sep 2024 05:11:48 -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 1suTUQ-0007MT-Fl for help-gnu-emacs@gnu.org; Sat, 28 Sep 2024 05:11:46 -0400 Original-Received: from mail-40138.protonmail.ch ([185.70.40.138]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1suTUO-0004Hu-DD for help-gnu-emacs@gnu.org; Sat, 28 Sep 2024 05:11:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1727514701; x=1727773901; bh=y+ZwCIJ1muBnnddDxb7++0pSt31blUCr+Nmzkg8Ysyw=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=sNzriN5xEwB/k4ea84PH9P54acLtR2D1g4Z39tdzD4QE1/3gWYYklUf9jb/YzzC/A sNG9x/eEgoLPOTplmrot/YUaGj8c+HZzbyLNAVEPlSIzbBobstsAMVveXm8LNqc/sV vNSjh84hMg/ETQD8y8s2qLiUiSjFN4VsB/A3hh25hShRZ8F0mqdjz44yTpkP+uEIZ2 PGxryPdM2TLtNA0swE+FqhL+f3uBHI7HznhdEkofPOSnFYmyzSr+La9na9ZBzdXpwb vhJFghU3YAluOAoly4Xs2fdpxYkCbLxOc20UD4lKPyaGBXSKT3j4dZsziZyYgBWBP1 nI4Fk7DXTmCMA== In-Reply-To: Feedback-ID: 57735886:user:proton X-Pm-Message-ID: 242042b53d93cf259af31b5f44c3f3df5e2a96de Received-SPF: pass client-ip=185.70.40.138; envelope-from=heimeborgia@protonmail.com; helo=mail-40138.protonmail.ch 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, FREEMAIL_FROM=0.001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-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:148082 Archived-At: On Saturday, September 28th, 2024 at 5:26 PM, tomas@tuxteam.de wrote: > On Fri, Sep 27, 2024 at 10:50:21PM +0000, Heime wrote: >=20 > > 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 emp= ty. >=20 >=20 > As it should. Please, please: learn about variables, variable scopes, > values. Otherwise, you're bound to stay in an endless loop. >=20 > I intersperse comments into your code: >=20 > ;; Somewhere "outside", warn-alist has been defined. Or not. > ;; We just don't know. >=20 > > (defun warn-test () > >=20 > > (interactive) > >=20 > > (setq warn-alist nil) I set the global to nil so that the push upon qwpanel will execute on first call. =20 =20 > ;; 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) >=20 >=20 > ;; 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)) >=20 >=20 > ;; 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 >=20 >=20 > ;; 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). Right, agreed =20 > > (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)) )) >=20 >=20 > ;; 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. Inside the let scope I call the following function with qwpanel =20 (defun alcons (alist &optional bfrn) "Print Associateed List ALIST to the buffer BFRN." (let* ( (bfname (or bfrn "ALIST Cons")) (dbuffer (get-buffer-create (concat "=F0=92=86=B3 " bfname))) ) (with-current-buffer dbuffer (face-remap-add-relative 'default :background "blue") (insert "\n ALIST Cons \n\n") (dolist (entry alist) (insert (format " %S\n" entry)))) )) ;; -------------------------------------------------------------------- (defun warn-test () (setq warn-alist nil) (let ( (qwpanel warn-alist) ) (unless qwpanel (push (cons 'ques-string "Warning Message") qwpanel) (push (cons 'ques-number 42) qwpanel)) (alcons qwpanel "Alist Cons Test")) ) > Working as designed, I'd say. >=20 > Cheers > -- > tom=C3=A1s