From: Jean Louis <bugs@gnu.support>
To: help-gnu-emacs@gnu.org
Subject: Re: How to get plist properties list?
Date: Tue, 12 Jan 2021 23:32:14 +0300 [thread overview]
Message-ID: <X/4HTrJI/cwMezCR@protected.rcdrun.com> (raw)
In-Reply-To: <jwvpn2edpb4.fsf-monnier+emacs@gnu.org>
* Stefan Monnier <monnier@iro.umontreal.ca> [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
next prev parent reply other threads:[~2021-01-12 20:32 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-07 7:58 How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'? Jean Louis
2021-01-07 10:03 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 11:00 ` Jean Louis
2021-01-07 10:07 ` Philipp Stephani
2021-01-07 10:07 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 11:06 ` Jean Louis
2021-01-07 11:23 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 11:12 ` Jean Louis
2021-01-07 11:33 ` Philipp Stephani
2021-01-07 11:35 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 16:05 ` FW: " Drew Adams
2021-01-08 1:04 ` Jean Louis
2021-01-08 2:26 ` Stefan Monnier
2021-01-08 2:39 ` Jean Louis
2021-01-08 2:45 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 2:50 ` Jean Louis
2021-01-08 3:36 ` Stefan Monnier
2021-01-08 2:52 ` Jean Louis
2021-01-08 3:08 ` Drew Adams
2021-01-08 3:31 ` Stefan Monnier
2021-01-08 2:19 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 0:58 ` Jean Louis
2021-01-08 1:08 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-07 15:38 ` Stefan Monnier
2021-01-08 1:03 ` Jean Louis
2021-01-08 2:21 ` Stefan Monnier
2021-01-08 2:21 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 2:38 ` Jean Louis
2021-01-08 3:39 ` Stefan Monnier
2021-01-08 4:09 ` Jean Louis
2021-01-08 5:13 ` Stefan Monnier
2021-01-08 5:38 ` Robert Thorpe
2021-01-08 6:22 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 7:10 ` Stefan Monnier
2021-01-09 18:57 ` Tomas Hlavaty
2021-01-09 19:01 ` Stefan Monnier
2021-01-10 9:20 ` Tomas Hlavaty
2021-01-10 14:52 ` Stefan Monnier
2021-01-11 22:23 ` Tomas Hlavaty
2021-01-08 5:40 ` Jean Louis
2021-01-08 7:14 ` Stefan Monnier
2021-01-08 8:28 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 11:07 ` tomas
2021-01-08 12:38 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 13:13 ` tomas
2021-01-08 13:31 ` Philipp Stephani
2021-01-08 13:35 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 13:47 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 13:15 ` Philipp Stephani
2021-01-08 13:31 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 14:03 ` tomas
2021-01-09 7:55 ` Jean Louis
2021-01-09 13:15 ` Leo Butler
2021-01-09 14:02 ` Philipp Stephani
2021-01-09 23:06 ` Leo Butler
2021-01-09 23:14 ` Stefan Monnier
2021-01-11 12:53 ` Leo Butler
2021-01-11 15:03 ` Stefan Monnier
2021-01-08 3:03 ` Drew Adams
2021-01-08 4:40 ` Stefan Monnier
2021-01-08 17:22 ` Drew Adams
2021-01-08 4:48 ` How to get plist properties list? Jean Louis
2021-01-08 5:20 ` Stefan Monnier
2021-01-08 5:46 ` Jean Louis
2021-01-08 6:50 ` Stefan Monnier
2021-01-09 7:54 ` Jean Louis
2021-01-09 9:27 ` tomas
2021-01-09 10:41 ` Jean Louis
2021-01-09 16:57 ` Stefan Monnier
2021-01-12 20:32 ` Jean Louis [this message]
2021-01-12 21:23 ` Stefan Monnier
2021-01-08 0:57 ` How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'? Jean Louis
2021-01-07 15:35 ` Stefan Monnier
2021-01-08 1:02 ` Jean Louis
2021-01-08 1:12 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-01-08 2:08 ` Jean Louis
2021-01-08 2:26 ` Emanuel Berg via Users list for the GNU Emacs text editor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=X/4HTrJI/cwMezCR@protected.rcdrun.com \
--to=bugs@gnu.support \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).