From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: [SOLVED with `eval']: Why I cannot use this variable in macro call from function? Date: Wed, 9 Jun 2021 09:42:00 +0300 Message-ID: References: <20210608183138.GA14693@tuxteam.de> <20210608200312.GE14693@tuxteam.de> <20210608202326.GG14693@tuxteam.de> <20210609060959.GA21706@tuxteam.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38005"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0.7+183 (3d24855) (2021-05-28) Cc: Help GNU Emacs To: tomas@tuxteam.de Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 09 08:46:38 2021 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 1lqrz4-0009i9-D3 for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 09 Jun 2021 08:46:38 +0200 Original-Received: from localhost ([::1]:58470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqrz3-0006HJ-Fb for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 09 Jun 2021 02:46:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56756) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqryi-0006H8-Ga for help-gnu-emacs@gnu.org; Wed, 09 Jun 2021 02:46:16 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:36269) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqryg-0001qg-Ah for help-gnu-emacs@gnu.org; Wed, 09 Jun 2021 02:46:16 -0400 Original-Received: from localhost ([::ffff:197.157.0.23]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000AE2EE.0000000060C063B2.00004BAB; Tue, 08 Jun 2021 23:46:10 -0700 Mail-Followup-To: tomas@tuxteam.de, Help GNU Emacs Content-Disposition: inline In-Reply-To: <20210609060959.GA21706@tuxteam.de> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_SORBS_WEB=1.5, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.help:130651 Archived-At: * tomas@tuxteam.de [2021-06-09 09:11]: > You'll see "43" in your minibuffer. We managed to set the dynamically > "defined" variable "that-other-var" to 43. Yay! Now enter > > that-other-var > > ...and again C-x e. Minibuffer says... 43. The variable escaped the > scope. Bad variable, but hey, that's how setq goes, no? Yes. I did it. > * Experiment 2 > > Make new lisp interaction buffer, as above. Make sure you have > lexical binding (when experimenting, always change at most one > thing at a time, right?). Now: > > (let ((some-var 42) > (that-other-var 44)) ; bind that-other-var locally > (eval '(setq that-other-var 43)) > (message "%S\n" that-other-var)) > > Again, minibuffer says 43. Now... > > that-other-var > > ...and C-x e. What does minibuffer say? Is that right or wrong? > Explain. The one bound locally got 44, it was protected from a global variable. That is so far expected. If I wish for example avoid case sensitive entries, I do: (let ((completion-ignore-case t) (collection '("One" "Two"))) (completing-read "Choice: " collection nil t)) In that case the global variable `completion-ignore-case' is nil, but I bind it temporarily globally to T, for better user experience. > I guess you'll need a more differentiated model than just "works". > Works how? Do you want it to "work" like that? If yes, then fine. Here is the function that just works, it asks for global variable. If I would know better way, I would do it and if you know some other way to dynamically assign global variable let me know: (defun rcd-db-completing-table-history (table) "Return symbol of history variable for TABLE. If TABLE is \"businesses\" the symbol will become `rcd-db-completing-table-history-businesses' and it will be used for functions `completing-read' and `read-from-minibuffer' history. If a dynamically generated variable does not exist, it will be generated on the fly." (let ((rcd-symbol (intern (concat "rcd-db-completing-table-history-" table))) (description (format "History for table `%s'" table))) (if (boundp rcd-symbol) rcd-symbol (eval (list 'defvar rcd-symbol nil description))))) Just like any code, the above (eval (list 'defvar rcd-symbol nil description)) is understandable only to people who know what eval, list, defvar and variables mean. We are now in collaboration and I am asking if there is better way to dynamically assign a global variable if it does not exist and return a symbol of it. What I don't know is why the function work as I am somehow expecting that new evaluation of (defvar ex-sting-variable nil) would make it nil, but it does not and history is remembered. > A very wise person [1] once said that he doesn't write programs > to get the computer to do what he wants, but to convince his > colleagues that the computer is doing the right thing. Fine, but that way I don't get my dynamically assigned global variables. (づ。◕‿‿◕。)づ -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/