From: Heime <heimeborgia@protonmail.com>
To: tomas@tuxteam.de
Cc: help-gnu-emacs@gnu.org
Subject: Re: Alist remaining empty
Date: Sat, 28 Sep 2024 09:11:36 +0000 [thread overview]
Message-ID: <ZJH4mdU_OVmmvvhD223huuxfE_3Z3-mhc5l6sB7XRl_6ldTn3VjX-AFhT4x-Atmti49lQLjFT86rNenQgohtygEnteNEsOjSkx05J8cxYhI=@protonmail.com> (raw)
In-Reply-To: <ZveTnlsqxOYLQ26D@tuxteam.de>
On Saturday, September 28th, 2024 at 5:26 PM, tomas@tuxteam.de <tomas@tuxteam.de> wrote:
> 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.
> >
> > 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 ()
> >
> > (interactive)
> >
> > (setq warn-alist nil)
I set the global to nil so that the push upon qwpanel will execute on
first call.
> ;; 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.
>
> > (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)
>
> > ;; Init flag to track if values have been added
> > (already-added nil) )
> >
> > ;; 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
>
> > (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).
Right, agreed
> > (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.
Inside the let scope I call the following function with qwpanel
(defun alcons (alist &optional bfrn)
"Print Associateed List ALIST to the buffer BFRN."
(let* ( (bfname (or bfrn "ALIST Cons"))
(dbuffer (get-buffer-create (concat "𒆳 " 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.
>
> Cheers
> --
> tomás
next prev parent reply other threads:[~2024-09-28 9:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-27 22:50 Alist remaining empty Heime
2024-09-28 5:26 ` tomas
2024-09-28 9:11 ` Heime [this message]
2024-09-28 9:14 ` tomas
2024-09-28 15:22 ` Heime
2024-09-28 15:16 ` Stefan Monnier via Users list for the GNU Emacs text editor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='ZJH4mdU_OVmmvvhD223huuxfE_3Z3-mhc5l6sB7XRl_6ldTn3VjX-AFhT4x-Atmti49lQLjFT86rNenQgohtygEnteNEsOjSkx05J8cxYhI=@protonmail.com' \
--to=heimeborgia@protonmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=tomas@tuxteam.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.