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: Fri, 28 Oct 2022 06:48:44 +0200 Message-ID: References: <87r0yw85la.fsf@dataswamp.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="2NKDTdOb5NUy5k34" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12782"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Drew Adams To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 28 06:50:38 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 1ooHKH-00039S-RL for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 28 Oct 2022 06:50:37 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooHIa-0001IR-NB; Fri, 28 Oct 2022 00:48:52 -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 1ooHIZ-0001IJ-Dx for help-gnu-emacs@gnu.org; Fri, 28 Oct 2022 00:48:51 -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 1ooHIX-0000qW-Aa for help-gnu-emacs@gnu.org; Fri, 28 Oct 2022 00:48:51 -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:Cc:To:Date:Sender:Reply-To: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=s4ge8IT/M45BkPAX0q/+zafiEw9AMvmDjFIZ0IpzsMU=; b=qKnvP4CTmHzLHHSDLRQguRodGE bReHsUd/rhMftlKH3f3pkBhNJLP+rqc6AAzNTCN+KB94X2KB0G71wQlyZ0x+dSMszGc+Il3PJQFTe 8vTvLQaaCmCZKMIiSC9a6U1btBjxrjVzE41RQ9wG3WWtjVq9me0bQpSBtxUMfUNAuFcil6iC7ZqtB oOxfhDNrP5ZG9Ko3+/MLu8/bjDpf0rmzBf3BygfXfvxqlVZ8DQq7ydCDa+pajPutWu0RbqOQBDGBb t9DkMxwgdBU1T7jm/+HBbi2kBRXFjhcRO1oxcK/zZJ7faOsfxyvoVIw+Nnm2St/7rWV1aAMHjm74I It7NORuA==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.94.2) (envelope-from ) id 1ooHIS-000740-4B; Fri, 28 Oct 2022 06:48:44 +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:140446 Archived-At: --2NKDTdOb5NUy5k34 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Oct 27, 2022 at 11:38:57PM +0300, Jean Louis wrote: > * Drew Adams [2022-10-27 18:54]: > > 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. >=20 > Of course I agree with the thought in general. >=20 > Is it this below? >=20 > (defun check-if-any-elt-is-non-nil (list) > (let (there-is) > (while (and list (not there-is)) > (when (car list) (setq there-is t)) > (setq list (cdr list))) > there-is)) If you are doing it "by hand", why not indulge in Lisp's "classic elegance", like so: (defun has-non-nil (lst) (cond ((null lst) nil) ((consp lst) (or (not (null (car lst))) (has-non-nil (cdr lst)))) (t (error "Not a proper list! You cheater!")))) Cheers --=20 t --2NKDTdOb5NUy5k34 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EABECAB0WIQRp53liolZD6iXhAoIFyCz1etHaRgUCY1tfJAAKCRAFyCz1etHa Rt7EAJ4g7gtiiiFZ2SFzVmX+qRxFmU8yFACdEdZl0CcdiIu7ItbSZpvVpV9IHgs= =5Iv3 -----END PGP SIGNATURE----- --2NKDTdOb5NUy5k34--