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: Is there equivalent internal function for this list-has-elements? Date: Sun, 18 Oct 2020 22:58:50 +0200 Message-ID: <20201018205850.GA13219@tuxteam.de> References: Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZGiS0Q5IWpPtfppv" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39257"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/1.5.21 (2010-09-15) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 18 22:59:40 2020 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 1kUFmF-000A43-8g for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 18 Oct 2020 22:59:39 +0200 Original-Received: from localhost ([::1]:43418 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kUFmE-0001J3-Ah for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 18 Oct 2020 16:59:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42072) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kUFlZ-0001Gz-PB for help-gnu-emacs@gnu.org; Sun, 18 Oct 2020 16:58:57 -0400 Original-Received: from mail.tuxteam.de ([5.199.139.25]:57967) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.90_1) (envelope-from ) id 1kUFlX-00046J-L5 for help-gnu-emacs@gnu.org; Sun, 18 Oct 2020 16:58:57 -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; bh=vKTBqqiYbBRZjEFgNSDcaj3IIHHXF3zYvJHb6vDV8LM=; b=bUO779sLMFqawgbEC9BW1FYoYPhfq5yJU71Hr6ZK4j5rxvGuJziDB/KlR4Bj73d33g+ZbcH3gy7xQauOrZ2vUt/e3QgY6PSL3A1vBdzuSuy+iJpPmuZAZJZQrTjgFhpUg4GyYO8qehBAEv5S1zE3UlVIFrf9pst+Nusw0NvcqXnAwtQ9pzC8lHHIlXMuRVCLPd8ac27GoVC8kUoUfLenUrSYbvnuAOSs72r3WA5AlAmcQs2onSI2bfqaxNVTKwCRzaVdGaQhOKPwAQkQa5K03aLNBL9klUWwqBjOKDqwNmpIevIs5CW9zJaATVxSFv7ilgI6z7yRC/k2m8G+whT4YA==; Original-Received: from tomas by mail.tuxteam.de with local (Exim 4.80) (envelope-from ) id 1kUFlS-0004Y7-D3 for help-gnu-emacs@gnu.org; Sun, 18 Oct 2020 22:58:50 +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-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/18 16:58:47 X-ACL-Warn: Detected OS = Linux 3.1-3.10 [fuzzy] 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.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:124559 Archived-At: --ZGiS0Q5IWpPtfppv Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Oct 18, 2020 at 10:37:01PM +0300, Jean Louis wrote: >=20 > For the below function `list-has-elements' maybe there exist some > internal Emacs function that checks for list that elements that are > contained in the haystak? Is there any? >=20 > Other question is, if there is any function other than pushnew, if I > do not wish to use the pushnew? I can maybe just make a check if > element is in the list and then simply push? >=20 > (defun list-has (needle haystack) > "Returns elements of haystack that contain needle, case insensitive" > (let ((nlist)) > (dolist (element haystack (reverse nlist)) > (when (string-match needle element) > (pushnew element nlist))))) If I understand this one correctly, it can be expressed as: (seq-filter (lambda (elt) (string-match needle elt)) haystack) > (defun list-has-elements (needles haystack) > "Returns elements of haystack that contain needle, case insensitive" > (if needles > (let* ((needle (pop needles)) > (haystack (list-has needle haystack))) > (list-has-elements needles haystack)) > haystack)) The doc string sent me off to the weeds ;-D You want to filter out those elements in haystack which match *all* the needles? Then something like (Careful! untested!) (seq-reduce (lambda (red-haystack needle) (list-has needle red-haystack)) needles haystack) See elisp manual "6.1 Sequences" All untested. Cheers - t --ZGiS0Q5IWpPtfppv Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEARECAAYFAl+MrIoACgkQBcgs9XrR2kbDVgCdEi/3hTSCaNa1UJH/RPASpXTl L/8An2W5TzrJskybpwH91ljTY+QBCWce =BOhn -----END PGP SIGNATURE----- --ZGiS0Q5IWpPtfppv--