From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.help Subject: Re: [External] : Re: Testing whether a list contains at least one non-nil element Date: Sat, 29 Oct 2022 08:38:00 +0200 Message-ID: References: <87r0yw85la.fsf@dataswamp.org> <87lep031vm.fsf@web.de> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="sJVcron6y7t51r3A" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16577"; mail-complaints-to="usenet@ciao.gmane.io" To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Oct 29 08:38:43 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oofUR-000494-Ia for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 29 Oct 2022 08:38:43 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oofTv-0005mn-Ct; Sat, 29 Oct 2022 02:38:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oofTo-0005mD-Kw for help-gnu-emacs@gnu.org; Sat, 29 Oct 2022 02:38:04 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oofTm-0002Eb-KY for help-gnu-emacs@gnu.org; Sat, 29 Oct 2022 02:38:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tuxteam.de; s=mail; h=From:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:Date:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=yKSV8a+raPx/0N9cjA2RPDELvAdr8SosGqV4jFcQTCQ=; b=a5OBNtUQL0FPOcMuUITgpwfHfQ LxuXLUMBHbo3yKu6Red5bS8IrY4eLFFOpQg0qQnFDE3aBVd3TZjiVgxSr/Zk35FvhFp4Id0WudfJm NpfJdS05vNjsSaDKkQ6U0MD+Y6zKVknEXrQ4R/OqvvBvCK+Wm3mhCFDvbizIilLWz2yv4IfFiJklb ptuGbGlyfjQYcDjr0N5W2hPmCyrza8U6oSdy13iljYb5nk+mYB0UArwmSwmC7A/g68ALNKXT4tmfL B6nRFzS7XGu5G7D2t/V4KcMyRmEF6BeuT7HiKlkeYDoHGjDG0N3+eQmiXUgcjmtDO/D68yoXf+hl+ l+v6l6kw==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1oofTk-0002XG-5r for help-gnu-emacs@gnu.org; Sat, 29 Oct 2022 08:38:00 +0200 Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=5.199.139.25; envelope-from=tomas@tuxteam.de; helo=mail.tuxteam.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "help-gnu-emacs" Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:140489 Archived-At: --sJVcron6y7t51r3A Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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: > > 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. >=20 > 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. >=20 > Luckily, since Emacs-28 you can have your cake and eat it too: >=20 > (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 --=20 t --sJVcron6y7t51r3A Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCY1zKQQAKCRAFyCz1etHa Rj0FAJ4koHJOMieinto4s8aV2lVHr2Du3ACfeg/KL7yMZuQhTEsM6t9ydTXnorU= =trN7 -----END PGP SIGNATURE----- --sJVcron6y7t51r3A--