From: <tomas@tuxteam.de>
To: help-gnu-emacs@gnu.org
Subject: Re: [External] : Re: Testing whether a list contains at least one non-nil element
Date: Sat, 29 Oct 2022 08:38:00 +0200 [thread overview]
Message-ID: <Y1zKSK3dgE00OISQ@tuxteam.de> (raw)
In-Reply-To: <jwvy1t0m7c2.fsf-monnier+emacs@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1449 bytes --]
On Fri, Oct 28, 2022 at 09:09:12AM -0400, Stefan Monnier via Users list for the GNU Emacs text editor wrote:
> Michael Heerdegen [2022-10-28 08:20:45] wrote:
> > <tomas@tuxteam.de> writes:
> >> If you are doing it "by hand", why not indulge in Lisp's
> >> "classic elegance", like so:
[...]
> > You don't want to implement such functions in Emacs with recursion
> > because you'll easily hit `max-lisp-eval-depth' when they are called.
>
> Indeed (and it's significantly slower than the corresponding loop
> without function calls).
I /knew/ I was missing something. The back of my brain mumbled
"does Emacs have tail recursion elimination or doesn't it?"
> > Sorry to tell you, but a loop is the preferable way in Elisp.
>
> Luckily, since Emacs-28 you can have your cake and eat it too:
>
> (defun has-non-nil (lst)
> (named-let loop ((lst lst))
> (cond
> ((null lst) nil)
> ((consp lst) (or (not (null (car lst))) (loop (cdr lst))))
> (t (error "Not a proper list! You cheater!")))))
Thanks for that :)
> Admittedly, here the `named-let` construct gives you only the
> elimination of tail-recursion, but in many other circumstances it
> also leads to quite elegant code.
Now I think of it, I saw something flashing past emacs-devel; back
then I must have thought "oh, nice, I've got to play with this..."
Now it sank in. So thanks :)
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
next prev parent reply other threads:[~2022-10-29 6:38 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
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 [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y1zKSK3dgE00OISQ@tuxteam.de \
--to=tomas@tuxteam.de \
--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.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.