[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to get plist properties list?
From: |
Jean Louis |
Subject: |
Re: How to get plist properties list? |
Date: |
Tue, 12 Jan 2021 23:32:14 +0300 |
User-agent: |
Mutt/2.0 (3d08634) (2020-11-07) |
* 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
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, (continued)
- How to get plist properties list?, Jean Louis, 2021/01/07
- Re: How to get plist properties list?, Stefan Monnier, 2021/01/08
- Re: How to get plist properties list?, Jean Louis, 2021/01/08
- Re: How to get plist properties list?, Stefan Monnier, 2021/01/08
- Re: How to get plist properties list?, Jean Louis, 2021/01/09
- Re: How to get plist properties list?, tomas, 2021/01/09
- Re: How to get plist properties list?, Jean Louis, 2021/01/10
- Re: How to get plist properties list?, Stefan Monnier, 2021/01/09
- Re: How to get plist properties list?,
Jean Louis <=
- Re: How to get plist properties list?, Stefan Monnier, 2021/01/12
- Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Jean Louis, 2021/01/07
Re: How to avoid compiler warning `unused lexical variable' for `dolist' or `dotimes'?, Stefan Monnier, 2021/01/07