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: Tue, 12 Jan 2021 23:32:14 +0300 Message-ID: References: <7eec4142-3c37-4084-9ea1-73df5df2c821@default> 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="31753"; 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 Tue Jan 12 21:37:34 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 1kzQQ1-0008A0-IU for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 12 Jan 2021 21:37:33 +0100 Original-Received: from localhost ([::1]:38548 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kzQQ0-0004A7-KJ for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 12 Jan 2021 15:37:32 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:56964) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzQOe-00046j-Rd for help-gnu-emacs@gnu.org; Tue, 12 Jan 2021 15:36:09 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:36725) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kzQOc-00073C-Be for help-gnu-emacs@gnu.org; Tue, 12 Jan 2021 15:36:08 -0500 Original-Received: from localhost ([::ffff:197.157.0.38]) (AUTH: PLAIN securesender, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 000000000001E078.000000005FFE0833.00002AEC; Tue, 12 Jan 2021 13:36:03 -0700 Mail-Followup-To: help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: 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:127208 Archived-At: * Stefan Monnier [2021-01-09 20:03]: > > If I wish to get the element like number 17th I do not know what I > > If you need that, it's "too late" to do something else. I see. Example is here: (defun mutt-identity-signature (identity) (let* ((sql (format "SELECT * FROM identities WHERE identities_id = %s" identity)) (list (first (rcd-sql-list sql *cf*))) (identity-id (elt list 0)) (identity-name (elt list 1)) (identity-first-name (elt list 2)) (identity-last-name (elt list 3)) ...snip... As if I do not do like that above, then to construct hash from SQL, I would need to make little more complex SQL query like: SELECT 'identities_id', identities_id, 'identities_name', identities_name, 'identities_firstname', identities_firstname, 'identities_lastname', identities_lastname AND SO ON. I could automate it, and now I see I have a function to automate it. (defun rcd-db-table-id-hash-values (table id pg) "Returns hash for TABLE by its table ID with its expanded foreign key values." (let* ((oid (rcd/table-oid table pg)) (attributes (rcd-table-full-attributes oid pg)) (foreign-keys (rcd/table-foreign-keys table pg)) (hash (make-hash-table))) (dolist (col attributes hash) (let* ((column (aref col 0)) (foreign-key (rcd/column-foreign-key column foreign-keys)) (bvalue (rcd-db-get-entry table column id pg)) (value (if (and foreign-key bvalue) (rcd/combo-query (car foreign-key) bvalue pg) bvalue))) (puthash (intern column) value hash))))) then instead of the initial SQL query that requires using `elt' to fetch values, I get bunch of various functions that need to construct a hash. Then I can use instead of: (format "SELECT * FROM identities WHERE identities_id = %s" identity) with `elt' complexity, the new complexity: (rcd-db-table-id-hash-values "identities" identity *cf*) but underlying functions are many. I get the hash but I doubt I get the speed up. In this example it is selection of the identity that selects signature for the email being composed. I cannot visually see any difference. You were very right that it is probably too late, so I can put attention in future. But not that I need to change much of functionality for sake of speed when no delay is sensible. > The question is "if I wish to do something over all (or most of) the > elements of a list". And for that the answer is "don't use dotimes + > nth" but use `dolist` or `mapcar` or `while + cdr`. That is my conclusion now as well. > Needing the N'th element of a list is actually rare (just like it's > rare to need to go to kilometer N of a road compared to the frequency > of having to walk along that road doing this along its way). I do not know if it is rare as I cannot count and see easily what other people are doing I know that I often use it like this, (defun mapping/map-locations-point-kml-placemark (p) (mapping/kml-placemark (elt p 3) (elt p 4) (list (elt p 0) (elt p 1) (elt p 2)))) (defun mapping/map-locations-point-marble (p) (mapping/kml-marble-bookmark (elt p 3) (elt p 4) (list (elt p 0) (elt p 1) (elt p 2)))) using it in different manner would complicate the code more I think. If I do some grep in ~/.emacs.d/elpa/* I see many packages using it as well. In general I understood that one could think of speed in certain situations, but in other situations where speed is not important using lists is fine. Jean