help-gnu-emacs
[Top][All Lists]
Advanced

[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: Sat, 9 Jan 2021 13:41:19 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* tomas@tuxteam.de <tomas@tuxteam.de> [2021-01-09 12:28]:
> On Sat, Jan 09, 2021 at 10:54:17AM +0300, Jean Louis wrote:
> > * Stefan Monnier <monnier@iro.umontreal.ca> [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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]