unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Jean Louis <bugs@gnu.support>
Cc: "help-gnu-emacs@gnu.org" <help-gnu-emacs@gnu.org>
Subject: RE: [External] : Re: Testing whether a list contains at least one non-nil element
Date: Thu, 27 Oct 2022 15:54:25 +0000	[thread overview]
Message-ID: <CO6PR10MB547389397A19A2B17B14D179F3339@CO6PR10MB5473.namprd10.prod.outlook.com> (raw)
In-Reply-To: <Y1oOta3pfdpRHyy1@protected.localdomain>

> >   ;; Why do the rest of this?
> >   ;; Search for a nil, after the non-nil car?
> >   ;; Then copy the entire list.  Then delete
> >   ;; all nils from it?  Why on earth do this?
> >   (if (memq elt list)
> >        ^^^^
> >       (delq elt (copy-sequence list))
> >                  ^^^^^^^^^^^^^
> >        ^^^^^^^^^
> >     list))
> 
> I get your reasoning. Maybe my function was not
> named correctly and then your logic jumps in.
> 
> > You certainly don't need to remove all nils
> > from the list.  If your list is 100,000,000
> > elements long and the first element is t, why
                     ^
                     IF
> > would you want to copy the entire list and
> > then remove all the nils from it?  Testing
> > the first element tells you the answer.
> 
> I get the reasoning, you are right, though maybe not in the context of
> testing if list has at least one non nil element. I am not sure, you
> know is not easy to grasp all.
> 
> What I know is that by testing the first element does not tell the
> answer if list has any non nil element:...
> So testing the first element did not give me the answer that
> my-list has one non-nil element.

No one said it did.  Please reread what I wrote.

In the worst case for your code, the first
element IS non-nil and you spend forever doing
useless stuff.  In no case is your code as
efficient as just testing each list element,
starting at the beginning, and STOPPING as
soon as you find a non-nil element.

> Maybe you can show in Emacs Lisp practically how do you mean it.

I think I did.  Please reread.  Try your code.
Try it in the debugger.  Try the code that
others have sent.  Look at that code: it just
tests till it finds a non-nil element, then
stops - that's the point.  And no list copying.

It's not important perhaps, if your use case
doesn't care about such things.  But it's not
a bad idea to look at the code that defines
functions you use - in this case `remq', to
see how it behaves.  That's the real point
here.

And yes, the `cl-*' functions can be, and
typically are, implemented in a performant
way.

If you find an Emacs implementation of a CL
function that's not as good as it could be,
please report that.

Emacs's `cl-*' emulation is not a real,
performant CL implementation, nor does it
pretend to be.  But in some cases it could
perhaps be improved.

  parent reply	other threads:[~2022-10-27 15:54 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 10:16 Testing whether a list contains at least one non-nil element Heime
2022-10-25 10:46 ` Jean Louis
2022-10-25 10:47 ` Jean Louis
2022-10-25 10:50 ` Jean Louis
2022-10-25 12:12   ` Emanuel Berg
2022-10-26 18:56     ` Jean Louis
2022-10-27  3:54       ` [External] : " Drew Adams
2022-10-27  4:53         ` Jean Louis
2022-10-27  5:30           ` Emanuel Berg
2022-10-27 15:54           ` Drew Adams [this message]
2022-10-27 17:47             ` Elisp and CL (was: Re: [External] : Re: Testing whether a list contains at least one non-nil element) Emanuel Berg
2022-10-27 20:38             ` [External] : Re: Testing whether a list contains at least one non-nil element Jean Louis
2022-10-28  0:22               ` Emanuel Berg
2022-10-28  4:48               ` tomas
2022-10-28  5:19                 ` Jean Louis
2022-10-28  6:20                 ` Michael Heerdegen
2022-10-28 13:09                   ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-29  6:10                     ` Michael Heerdegen
2022-10-29 15:25                       ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-10-30 12:49                         ` Emanuel Berg
2022-10-29  6:38                     ` tomas
2022-10-30 12:48                     ` Emanuel Berg
2022-10-29  9:20                   ` Emanuel Berg
2022-10-29  9:19                 ` Emanuel Berg
2022-10-27  4:01       ` Emanuel Berg
2022-10-25 12:05 ` Michael Heerdegen
2022-10-25 12:15   ` Emanuel Berg
2022-10-25 15:59   ` [External] : " Drew Adams
2022-10-25 17:44     ` Emanuel Berg
2022-10-26 15:39       ` Drew Adams
2022-10-26 17:43         ` Emanuel Berg
2022-10-25 17:25 ` Joost Kremers
2022-10-25 17:51   ` Emanuel Berg
2022-10-25 19:44   ` Heime
2022-10-25 20:08     ` Joost Kremers
2022-10-25 20:15     ` [External] : " Drew Adams
2022-10-25 20:19       ` Joost Kremers
2022-10-26  3:00         ` Stefan Monnier via Users list for the GNU Emacs text editor
  -- strict thread matches above, loose matches on Subject: below --
2022-10-28  5:07 Drew Adams

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=CO6PR10MB547389397A19A2B17B14D179F3339@CO6PR10MB5473.namprd10.prod.outlook.com \
    --to=drew.adams@oracle.com \
    --cc=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).