From mboxrd@z Thu Jan 1 00:00:00 1970 From: Adam Porter Subject: Re: lisp: scoping vars in repetitive defuns Date: Wed, 18 Sep 2019 16:42:32 -0500 Message-ID: <87v9tp703b.fsf@alphapapa.net> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:51961) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAhim-0004tW-80 for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 17:42:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAhil-0004n0-6H for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 17:42:44 -0400 Received: from 195-159-176-226.customer.powertech.no ([195.159.176.226]:36128 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iAhil-0004kt-00 for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 17:42:43 -0400 Received: from list by blaine.gmane.org with local (Exim 4.89) (envelope-from ) id 1iAhih-000prP-Bl for emacs-orgmode@gnu.org; Wed, 18 Sep 2019 23:42:39 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org Matt Price writes: > This is fun, thanks John. I really like the plist version put would > also like to loop through the variables in a let statement somehow. > > I think what I'm missing is the equivalent of a javascript implicit > destructuring construct: > > let { } = object; > > which will define new variables prop1, prop2... forever enumerable > property of the object. Is thre away to do that kind of destructuring > bind -- which binds *everything* in the plist, without knowing the > symbol names in advance? that would be really great. In fact, he has written an article about that sort of thing, which you can find linked here, along with some other destructuring tools: https://github.com/alphapapa/emacs-package-dev-handbook#a-callable-plist-data-structure-for-emacs https://github.com/alphapapa/emacs-package-dev-handbook#with-dict-with-plist-vals-1 Note that automatically binding variables named according to plist keys which are not known in advance would have to happen at runtime and would require use of eval, as well as potentially overriding variables that you're already using. Instead, I recommend using -let, which has a &plist keyword, which you can use like: (-let* (((&plist :query :preamble :preamble-case-fold) (org-ql--query-preamble query))) (list query preamble preamble-case-fold))