From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Rupert Swarbrick Newsgroups: gmane.emacs.help Subject: Re: What to use instead of find-if? Date: Wed, 03 Dec 2008 00:29:34 +0000 Organization: albasani.net Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Trace: ger.gmane.org 1228264854 27834 80.91.229.12 (3 Dec 2008 00:40:54 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 3 Dec 2008 00:40:54 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 03 01:41:57 2008 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 1L7foT-00008H-En for geh-help-gnu-emacs@m.gmane.org; Wed, 03 Dec 2008 01:41:57 +0100 Original-Received: from localhost ([127.0.0.1]:35616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L7fnI-0000wj-Vt for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Dec 2008 19:40:45 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!goblin1!goblin.stu.neva.ru!news.albasani.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 44 Original-X-Trace: news.albasani.net eo3s57nm0/BXzOIzsfMNYw79kajNjHtZwJ9zk0bZKjB8cSA89WHllQWRCx0qUUMbkRcMW0TScsq31dUMKfp9TaAWKAkQ/YDf2/2DPbpSDMAFNJO46NpoqIvOdKwzRzdm Original-X-Complaints-To: abuse@albasani.net Original-NNTP-Posting-Date: Wed, 3 Dec 2008 00:30:19 +0000 (UTC) X-User-ID: 7Ubvj/BRuVxbARsL0kyVutFAA9zZ+92m69GEv5JUo4Q= Cancel-Lock: sha1:p1PoBGbqT4tFWFcvGRiglMiHIwI= User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux) X-NNTP-Posting-Host: QzZtItYmgsBL5Ku9s3lSN3ZUk+o0gjg6nooYe/iMp3A= Original-Xref: news.stanford.edu gnu.emacs.help:164998 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:60326 Archived-At: --=-=-= Content-Transfer-Encoding: quoted-printable "Drew Adams" 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))) >>=20 >> Can anyone suggest a vaguely idiomatic way to do this using=20 >> 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 --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iJwEAQECAAYFAkk10u4ACgkQRtd/pJbYVoYLowQAgPvEwS685FL9mO/SPuk2Oovl z9ZyCN+42Hr26w+g+y7cEdA49zOXbYzIB/Bfp7+reJ8itLypDLCCrYaykXsudNwj /ZL8bEM1w1VIkTOKl0VD4ADgdWWilP5EAGUKjBFrKrfv9u2bJXk60hD5DSgzpAv1 CtrZGqRyTadmMlcQrJA= =tHJs -----END PGP SIGNATURE----- --=-=-=--