From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.devel Subject: Re: Is there already an alist function which gets all matching elements, not just the first? Date: Thu, 6 Oct 2022 18:34:58 +0000 Message-ID: References: <87y1tum8z8.fsf@posteo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19978"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Philip Kaludercic Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Thu Oct 06 20:44:14 2022 Return-path: Envelope-to: ged-emacs-devel@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 1ogVqw-0004wi-6T for ged-emacs-devel@m.gmane-mx.org; Thu, 06 Oct 2022 20:44:14 +0200 Original-Received: from localhost ([::1]:44674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ogVqu-0001Ek-RH for ged-emacs-devel@m.gmane-mx.org; Thu, 06 Oct 2022 14:44:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogViD-0006IG-4v for emacs-devel@gnu.org; Thu, 06 Oct 2022 14:35:15 -0400 Original-Received: from mx3.muc.de ([193.149.48.5]:56621) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ogVi9-0003XT-96 for emacs-devel@gnu.org; Thu, 06 Oct 2022 14:35:12 -0400 Original-Received: (qmail 67925 invoked by uid 3782); 6 Oct 2022 20:35:00 +0200 Original-Received: from acm.muc.de (p4fe1585e.dip0.t-ipconnect.de [79.225.88.94]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Thu, 06 Oct 2022 20:34:59 +0200 Original-Received: (qmail 8403 invoked by uid 1000); 6 Oct 2022 18:34:58 -0000 Content-Disposition: inline In-Reply-To: <87y1tum8z8.fsf@posteo.net> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de Received-SPF: pass client-ip=193.149.48.5; envelope-from=acm@muc.de; helo=mx3.muc.de X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:297110 Archived-At: Hello, Philip. On Wed, Oct 05, 2022 at 18:16:43 +0000, Philip Kaludercic wrote: > Alan Mackenzie writes: > > Hello, Emacs. > > I want to be able to get all matching elements from an alist (thinking > > about extending imenu). Something like > > (assoc-all key list) > > which would return a list of matches. After all, we have functions > > which _delete_ all matches from an alist. > > Does such a function already exist, perhaps in cl-*.el? > This appears to do the right thing > (map-filter (lambda (k _v) (eq k '3)) > '((3 . 4) > (2 . 4) > (1 . 2) > (3 . 1))) > ;; => ((3 . 4) (3 . 1)) The doc string for map-filter doesn't actually describe the function, sadly. It talks about key/value pairs whilst giving no clue where the key and the value come from. I suppose one might guess, but really there's no alternative to studying the source code for map-filter. > Perhaps a `map-member' could be implemented that would do something like > what you are looking for? Or does this already exist by some other name > (I don't really use map.el). I've certainly wanted something like this > more than a few times. It seems like one of these things which quite a lot of people want, but nobody wants it enough to be bothered to implement it. ;-) > > Thanks! -- Alan Mackenzie (Nuremberg, Germany).