From: Rupert Swarbrick <rswarbrick@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: What to use instead of find-if?
Date: Wed, 03 Dec 2008 00:29:34 +0000 [thread overview]
Message-ID: <gh4juo$vas$1@news.albasani.net> (raw)
In-Reply-To: mailman.1649.1228166673.26697.help-gnu-emacs@gnu.org
[-- Attachment #1: Type: text/plain, Size: 952 bytes --]
"Drew Adams" <drew.adams@oracle.com> writes:
>> So the code I'm thinking about does the following:
>> (let ((blah (find-if (lambda (elem)
>> (whopping-great-predicatey-thing))
>> some-list)))
>> (if blah (something using blah) (something else)))
>>
>> Can anyone suggest a vaguely idiomatic way to do this using
>> the built-in constructs of elisp?
>
> There are no doubt lots of ways to do it. Here's one:
>
> (defun my-find-if (pred xs)
> (catch 'my-found
> (dolist (x xs) (when (funcall pred x) (throw 'my-found x)))
> nil))
Ahah. That's neat! (And is indeed the semantics I had in mind when I
wrote the original).
Now, this really isn't relevant to the original question, but I was just
wondering: what are the performance costs of (catch ) in elisp? For
example, should one think twice before using it in syntax highlighting
code or the like?
Rupert
[-- Attachment #2: Type: application/pgp-signature, Size: 314 bytes --]
next prev parent reply other threads:[~2008-12-03 0:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-01 19:56 What to use instead of find-if? Rupert Swarbrick
2008-12-01 21:24 ` Drew Adams
[not found] ` <mailman.1649.1228166673.26697.help-gnu-emacs@gnu.org>
2008-12-03 0:29 ` Rupert Swarbrick [this message]
2008-12-03 0:58 ` Drew Adams
-- strict thread matches above, loose matches on Subject: below --
2008-12-01 19:54 Rupert Swarbrick
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='gh4juo$vas$1@news.albasani.net' \
--to=rswarbrick@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/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).