From: Nikolaj Schumacher <me@nschum.de>
To: florian <lorian@fsavigny.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: "assoc" for returning ALL associations for a given key
Date: Wed, 06 May 2009 12:10:58 +0200 [thread overview]
Message-ID: <m23abisfrh.fsf@nschum.de> (raw)
In-Reply-To: <7b7011d7-2f03-4a08-ae58-6701999d637d@v4g2000vba.googlegroups.com> (florian's message of "Tue, 5 May 2009 01:59:48 -0700 (PDT)")
florian <lorian@fsavigny.de> 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
prev parent reply other threads:[~2009-05-06 10:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-05 8:59 "assoc" for returning ALL associations for a given key florian
2009-05-05 10:07 ` Juanma Barranquero
2009-05-05 10:15 ` Pascal J. Bourguignon
2009-05-06 10:10 ` Nikolaj Schumacher [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m23abisfrh.fsf@nschum.de \
--to=me@nschum.de \
--cc=help-gnu-emacs@gnu.org \
--cc=lorian@fsavigny.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).