From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nikolaj Schumacher Newsgroups: gmane.emacs.help Subject: Re: "assoc" for returning ALL associations for a given key Date: Wed, 06 May 2009 12:10:58 +0200 Message-ID: References: <7b7011d7-2f03-4a08-ae58-6701999d637d@v4g2000vba.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1241604741 10975 80.91.229.12 (6 May 2009 10:12:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 6 May 2009 10:12:21 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: florian Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed May 06 12:12:11 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1M1e6e-0000zJ-TL for geh-help-gnu-emacs@m.gmane.org; Wed, 06 May 2009 12:12:05 +0200 Original-Received: from localhost ([127.0.0.1]:56008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M1e6e-00068x-4l for geh-help-gnu-emacs@m.gmane.org; Wed, 06 May 2009 06:12:04 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M1e5e-00063u-VE for help-gnu-emacs@gnu.org; Wed, 06 May 2009 06:11:03 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M1e5d-00063G-Dm for help-gnu-emacs@gnu.org; Wed, 06 May 2009 06:11:01 -0400 Original-Received: from [199.232.76.173] (port=53407 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M1e5d-00063D-7B for help-gnu-emacs@gnu.org; Wed, 06 May 2009 06:11:01 -0400 Original-Received: from dd18200.kasserver.com ([85.13.138.168]:57219) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M1e5c-0000et-Q2 for help-gnu-emacs@gnu.org; Wed, 06 May 2009 06:11:01 -0400 Original-Received: from thursday (e179056141.adsl.alicedsl.de [85.179.56.141]) by dd18200.kasserver.com (Postfix) with ESMTP id 96C05180972F2; Wed, 6 May 2009 12:11:02 +0200 (CEST) In-Reply-To: <7b7011d7-2f03-4a08-ae58-6701999d637d@v4g2000vba.googlegroups.com> (florian's message of "Tue, 5 May 2009 01:59:48 -0700 (PDT)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.92 (darwin) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 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-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:64204 Archived-At: florian wrote: > (defun assocs (key alist) > "Like `assoc', but return all elements of ALIST whose car is > `equal' to KEY. > In other words, return a subset of ALIST." > (delq nil > (mapcar '(lambda (cons-cell) > (if (equal (car cons-cell) key) > cons-cell)) > alist))) > > But I am wondering whether that would have been necessary - perhaps I > am overlooking something? Otherwise, would anybody care to comment > about the efficiency of the above function? A lot of temporary cons objects are created, so it's probably not the most efficient way of doing this. If efficiency is really critical, you should build the list yourself. Or maybe create no list at all, if appropriate... (dolist (el lst) (when (equal (car el) key) (do-stuff-here ... That's easier on the eyes, too. ;) regards, Nikolaj Schumacher