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) ;; 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). > (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 -- tomás