From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Joost Kremers Newsgroups: gmane.emacs.help Subject: Re: [External] : Re: Testing whether a list contains at least one non-nil element Date: Tue, 25 Oct 2022 22:19:18 +0200 Message-ID: <87lep3fy3s.fsf@fastmail.fm> References: <87r0yvst2a.fsf@fastmail.fm> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6209"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.8.3; emacs 28.1.91 Cc: Heime , help-gnu-emacs@gnu.org To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 25 22:31:55 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 1onQaZ-0001PQ-Bv for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 25 Oct 2022 22:31:55 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onQW2-00029f-Ba; Tue, 25 Oct 2022 16:27:14 -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 1onQW0-0001yJ-6V for help-gnu-emacs@gnu.org; Tue, 25 Oct 2022 16:27:12 -0400 Original-Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onQVy-0005Sr-1P for help-gnu-emacs@gnu.org; Tue, 25 Oct 2022 16:27:11 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 81AD132005D8; Tue, 25 Oct 2022 16:27:06 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Tue, 25 Oct 2022 16:27:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.fm; h= cc:cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1666729626; x=1666816026; bh=28bBn/LHsn HmnpnGEeGXxhC/EbMl2tr255Ee42eVv7k=; b=j7r0Mgsr90tFwmJakTw6bBFZJd J8+VPh228/INpQs1w1GgWD6KZEgZ0utKD1EpXD3DoA+Lf+0ukyQ1cXdEuvj++3iE h6+sIZ9+iuNtq3up9E0ZIFUN9+Wg0A/9IamE0Fy6oo/uch7I0JNqIWMFeyy6ts2B mcEdPvBJ2umx+JcGTU+nFrKFlIj2K0Ds8OVvYqmRlKxwxrSYxX0PLn8hwwxIlG+d DwRcmrbxy6dTyXt1TZCKvEAVa48tlyuJbgLZAsVH+HDesoO9uJWEn5m+Hko82VW6 eMb7wgSwL+Vikf7CxSfc/3U5BNgYnzVS0x/Q/XhHihaVTWH20EHABw574r4w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1666729626; x=1666816026; bh=28bBn/LHsnHmnpnGEeGXxhC/EbMl 2tr255Ee42eVv7k=; b=Q035113QHOHfmhFMfiQisTFW+pC3yEARVdCko4v/05tE /C0VvesrTiqLzEixRJ1BDWZTYT7vMHC6GGdu0JgcLIkM+3ucUONuWqffsiIuIt7Z wmFqfapkIHBsyDUdalhDrIon/gXQ6Tr2Nn3EEImEH/7jgCqehc7PX53KX/oNV49n Vm6qIqFFVOcUV4LTH1oK2pRuIpDBks+uAKNrOtFIyvjlCgfVH/kVnRtgwGqYOdst 8PblDqR9aY/2lbuFDM8ecqsPWXyN8RQBxinYjIGTOEMLPsdFoqYum5GvHF3Py9jK VYskCcgXVU52AvCzoiDXvjUvFqHuXEVHMlypPgOHYw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrtddtgdduvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfhgfhffvvefuffgjkfggtgesthdtredttdertdenucfhrhhomheplfhoohhs thcumfhrvghmvghrshcuoehjohhoshhtkhhrvghmvghrshesfhgrshhtmhgrihhlrdhfmh eqnecuggftrfgrthhtvghrnhepgfeihfdutdetleejheevkeejtdffueehfffhffefteei teefhedtkedtiedtkeffnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomhepjhhoohhsthhkrhgvmhgvrhhssehfrghsthhmrghilhdrfhhm X-ME-Proxy: Feedback-ID: ie15541ac:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 25 Oct 2022 16:27:05 -0400 (EDT) In-reply-to: Received-SPF: pass client-ip=64.147.123.19; envelope-from=joostkremers@fastmail.fm; helo=wout3-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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:140382 Archived-At: On Tue, Oct 25 2022, Drew Adams wrote: >> > > I would like to test whether a list contains at least one >> > > non-nil element? If I do that, then I would be able to >> > > continue a loop where a non-nil element would mean >> > > that a match was found. >> > >> > (seq-some (lambda (e) (not (null e))) mylist) >> > >> > or shorter: >> > >> > (not (seq-every-p #'null mylist)) >> >> How does your implementation (not (seq-every-p #'null mylist)) compared to >> >> (elt (delq nil mylist) 0) > > `delq' is a "destructive" operation. Oops, I didn't realise that when I wrote my reply... Should've checked... So hopefully this gives a better idea: ``` (benchmark 100000 '(let ((mylist (list nil nil nil nil nil nil nil nil nil t))) (elt (delq nil mylist) 0))) "Elapsed time: 0.493742s (0.379511s in 2 GCs)" (benchmark 100000 '(let ((mylist (list nil nil nil nil nil nil nil nil nil t))) (not (seq-every-p #'null mylist)))) "Elapsed time: 0.923503s (0.566131s in 3 GCs)" (benchmark 100000 '(let ((mylist (list nil t nil nil nil nil nil nil nil nil t))) (elt (delq nil mylist) 0))) "Elapsed time: 0.496120s (0.377506s in 2 GCs)" (benchmark 100000 '(let ((mylist (list nil t nil nil nil nil nil nil nil nil t))) (not (seq-every-p #'null mylist)))) "Elapsed time: 0.823751s (0.566227s in 3 GCs)" ``` -- Joost Kremers Life has its moments