[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: return first element in list with certain property
From: |
Drew Adams |
Subject: |
RE: return first element in list with certain property |
Date: |
Mon, 20 Nov 2017 14:59:19 -0800 (PST) |
> However the below tests seem to indicate no
> problems for any of the solutions suggested
> so far?
Certainly there will be no problem with any of them
when the list is small.
> (let ((test-list '(0 1 2 3 4 5)))
>
> (cl-dolist (e test-list)
> (message "cl-dolist processing: %s" e)
> (when (> e 1) (cl-return e) ))
>
> (cl-find-if (lambda (e) (and (message "cl-find-if processing: %s" e)
> (> e 1) ))
> test-list)
>
> (seq-find (lambda (e) (and (message "find-seq processing: %s" e)
> (> e 1) ))
> test-list)
> )
> ;; cl-dolist processing: 0
> ;; cl-dolist processing: 1
> ;; cl-dolist processing: 2
> ;; cl-find-if processing: 0
> ;; cl-find-if processing: 1
> ;; cl-find-if processing: 2
> ;; find-seq processing: 0
> ;; find-seq processing: 1
> ;; find-seq processing: 2
As I said, `cl-find-if' apparently traverses the list twice.
You see only one message for each element tested because your
predicate is called only once per element. `cl-find-if' is
implemented by first calling `cl-position', which uses your
predicate. And then, once a satisfactory element is found,
it calls `elt' to traverse the list again, to obtain that
element. The call to `elt' does not use your predicate, so
you see no messages for it.
As I said, I have not bothered to profile the different
suggestions, but a guess is that with a very large list
`cl-find-if' will be slower.
- Re: return first element in list with certain property, (continued)
- Re: return first element in list with certain property, John Mastro, 2017/11/24
- Re: return first element in list with certain property, Robert Thorpe, 2017/11/24
- Re: return first element in list with certain property, Alexis, 2017/11/24
- Re: return first element in list with certain property, tomas, 2017/11/25
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/25
- Re: return first element in list with certain property, Eli Zaretskii, 2017/11/25
- Re: return first element in list with certain property, tomas, 2017/11/25
- Re: return first element in list with certain property, John Mastro, 2017/11/25
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/25
- Re: return first element in list with certain property, Michael Heerdegen, 2017/11/26
- RE: return first element in list with certain property,
Drew Adams <=
- Re: return first element in list with certain property, Emanuel Berg, 2017/11/20
Re: return first element in list with certain property, Marco Wahl, 2017/11/19
Re: return first element in list with certain property, Marco Wahl, 2017/11/19