From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Emanuel Berg Newsgroups: gmane.emacs.help Subject: Re: Printing alist pairs to a dedicated buffur Date: Fri, 26 Apr 2024 02:27:17 +0200 Message-ID: <87jzkl9dei.fsf@dataswamp.org> References: <87bk65fpsz.fsf@ledu-giraud.fr> <87plukbbod.fsf@ledu-giraud.fr> <87jzkss5w8.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11941"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:ovhQpOIxs6Wgzxz4cuBt6NMbnNM= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Apr 26 12:39:00 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 1s0Iyq-0002p9-JE for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 26 Apr 2024 12:39:00 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s0Iyi-00013H-RL; Fri, 26 Apr 2024 06:38:52 -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 1s09R7-0002eL-GJ for help-gnu-emacs@gnu.org; Thu, 25 Apr 2024 20:27:34 -0400 Original-Received: from ciao.gmane.io ([116.202.254.214]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s09R3-0003eN-Md for help-gnu-emacs@gnu.org; Thu, 25 Apr 2024 20:27:32 -0400 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1s09R1-0006Sz-Ps for help-gnu-emacs@gnu.org; Fri, 26 Apr 2024 02:27:27 +0200 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: help-gnu-emacs@gnu.org Mail-Copies-To: never Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -15 X-Spam_score: -1.6 X-Spam_bar: - X-Spam_report: (-1.6 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.25, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 26 Apr 2024 06:38:51 -0400 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:146482 Archived-At: Heime wrote: >> Don't use `defvar' if it can be avoided as that creates >> global dynamic/special variables,` setq' creates global >> static/lexical variables which isn't much better - unless >> there is a variable by that name present, then that is used >> instead. That kind of `setq' use is not wrong, actually it >> is good. > > So it is actually good, but then still make a commotion > about it. This way of commenting in not productive at all. `setq' to set variables is good, to create global variables with it is often not necessary and for the compiler not to warn you also have to use `defvar', that is totally confusing. (defvar global-lexical) (setq global-lexical 10) (special-variable-p 'global-lexical) ; nil Also setq is error-prone as make a typo, the intended variable with not be set but instead a global one will be created. But the byte compiler will warn you about that if it happens. Another solution would be one function to set available variables, and one to create global ones. The "set available" one would signal if such a variable isn't present, the global one if there were already such a variable. But again, this is what makes Lisp interesting. > My defvar is used to store values that I need to access when > I am working on a buffer. I can add to it as I modify the > buffer, or delete from it. I cannot see why all this fuss > not to use global variables. Certainly they are there if you want to use them (pun). Lisp is a maximalist language, anything and everything included. Some people think global variables are okay, other people think they should be avoided if there isn't any good reason to have them. Why is a static/lexical global variable better than a dynamic/special? Good question, we must write some Elisp to test what happens if that name collides with other source. I wrote some Elisp that would show another option approach, so one would always have `let' for static/lexical variables to facilitate coding, and another construct for options to set the behavior of whatever was enclosed. Now I don't really understand it anymore 100%, but I yank it here [last] for your viewing pleasure :) But it will be the way it is now, this is just endless theorizing because Lisp is very powerful, but also very complicated compared to other languages. ;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/vars-opts.el (require 'cl-lib) (defun check-binders (binds) (cl-loop for (n _) in binds with no-opt do (unless (special-variable-p n) (push (symbol-name n) no-opt) ) finally (when no-opt (error "No option%s: %s" (if (< 1 (length no-opt)) "s" "") (mapconcat #'identity (reverse no-opt) ", ") )))) (defmacro opts (binds &rest body) (declare (indent 1) (debug let) ) (check-binders binds) `(let ,binds ,@body) ) ;; (opts ((fill-column 1) ;; (a 0) ) ;; u) ; No option: a ;; ;; (defvar dynavar 2000) ;; ;; (opts ((dynavar 3000) ;; (fill-column 1) ;; (a 0) ;; (y 2) ) ;; y) ; No options: a, y ;; ;; (opts ((dynavar 3000) ;; (fill-column 10) ) ;; (delete-char 2) ;; (fill-paragraph) ) ; eval me (provide 'vars-opts) -- underground experts united https://dataswamp.org/~incal