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: How to get plist properties list? Date: Sat, 9 Jan 2021 13:41:19 +0300 Message-ID: References: <7eec4142-3c37-4084-9ea1-73df5df2c821@default> <20210109092733.GB20537@tuxteam.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25587"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0 (3d08634) (2020-11-07) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jan 10 08:02:29 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 1kyUk8-0006Wu-2z for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 10 Jan 2021 08:02:28 +0100 Original-Received: from localhost ([::1]:40344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kyUk7-0002R8-3T for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 10 Jan 2021 02:02:27 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34102) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyUjP-0002Qp-HN for help-gnu-emacs@gnu.org; Sun, 10 Jan 2021 02:01:43 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:54617) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kyUjN-0004om-EB for help-gnu-emacs@gnu.org; Sun, 10 Jan 2021 02:01:42 -0500 Original-Received: from localhost ([::ffff:41.210.154.252]) (AUTH: PLAIN securesender, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000002DFDD.000000005FFAA633.000058BC; Sun, 10 Jan 2021 00:01:06 -0700 Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <20210109092733.GB20537@tuxteam.de> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, DATE_IN_PAST_12_24=1.049, 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:127157 Archived-At: * tomas@tuxteam.de [2021-01-09 12:28]: > On Sat, Jan 09, 2021 at 10:54:17AM +0300, Jean Louis wrote: > > * Stefan Monnier [2021-01-08 09:51]: > > > > I would like to understand what is the problem. I don't. You tell me > > > > that `elt' is problem, that is how I understand it. > > > > > > > > Could I maybe rather use `nth' to replace `elt'? > > > > > > No, same problem. > > > Think of it this way: consider your list of N elements as a road that's > > > N kilometers long [...] > > (nice explanation, BTW :) > > > So far I have seen from similar discussion on `length' on emacs-devel > > mailing list [...] > > When you have a toolbox (a language & library), you usually develop > a set of "ways of doing things", corresponding to the properties > your tools have. > > > If I wish to get the element like number 17th I do not know what I > > should do. > > (nth 17 my-list) > > Unless... you are doing it very often. Then you do something > different (unless, again, you don't care that your program is > slow; if you are giving your program to other people, you should > care, somewhat, at least. And so on. > > Lists are very flexible data structures. But they have one downside: > accessing a random element in them takes as long as walking through > half of it, in the average. > > If you plan to access elements by index, Emacs Lisp has arrays. > They aren't as flexible, but faster for random access. If you > want more flexibility, there are hash tables. And so on. > > It's like with tools. You use the screwdriver to drive screws. > In a pinch, you can use it to poke dirt out of a hole. I've > seen people using it to hit a hole in a wall (hm.) or even to > drive a nail into a piece of wood (ouch!). The comparison of different types of data structure does give me better explanation. I do use hashes. Recently I have switched from using list collections in completing read to using hashes. But I have not measured speed. Sometimes I have 20000 elements to choose from. This function provides sql in form COLUMN_ID, COLUMN_TEXT (where by COLUMN_TEXT can be concatenated from various multiple columns) and then the SQL result is converted to hash and used with completing read. (defun rcd-completing-read-sql-hash (prompt sql &optional history) (let* ((hash (rcd-sql-hash sql *cf*)) (values (hash-table-values hash)) (length (length values))) (if (= length 1) (car values) (let* ((completion-ignore-case t) (choice (completing-read prompt hash nil t nil history)) (choice (string-trim choice)) (id (gethash choice hash))) id)))) I should maybe measure it against the other one that was using lists to see the difference. Jean