From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Valentin Baciu Newsgroups: gmane.emacs.help Subject: Re: elisp: how to find an ELT is present an ARRAY or not? Date: Wed, 7 Dec 2011 15:44:28 +0200 Message-ID: References: <87r50gijq1.fsf@live.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1323265490 5797 80.91.229.12 (7 Dec 2011 13:44:50 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 7 Dec 2011 13:44:50 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: yagnesh@live.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 07 14:44:46 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RYHnh-0005q8-30 for geh-help-gnu-emacs@m.gmane.org; Wed, 07 Dec 2011 14:44:45 +0100 Original-Received: from localhost ([::1]:45112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYHnf-0004wO-Vj for geh-help-gnu-emacs@m.gmane.org; Wed, 07 Dec 2011 08:44:43 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:42582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYHnW-0004w0-UZ for help-gnu-emacs@gnu.org; Wed, 07 Dec 2011 08:44:40 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RYHnR-0008Iw-8x for help-gnu-emacs@gnu.org; Wed, 07 Dec 2011 08:44:34 -0500 Original-Received: from mail-gy0-f169.google.com ([209.85.160.169]:62315) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RYHnR-0008Is-47 for help-gnu-emacs@gnu.org; Wed, 07 Dec 2011 08:44:29 -0500 Original-Received: by ghbg19 with SMTP id g19so598544ghb.0 for ; Wed, 07 Dec 2011 05:44:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntactic.org; s=syntacticorg; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=L6usRoS55agTVpwpP9B4MCJsbSfOCOQaMaohTrQRiFM=; b=mSfH9sDk6hdp+RuBY99c4G+paN0+5zTqD3LcpdazH/Vb9L3hlpW2qy87x5PJhG7GfX 9yIggxFxLPCvHrbhRC8uO84jZHDit/0PHKquTDWpITVMc72Zwk5doz6pGFPnTIznQvLO 3nvDBmd0DyIUlvYqAMuoJOpsoyPPasOhXyVbw= Original-Received: by 10.236.108.233 with SMTP id q69mr27655731yhg.120.1323265468036; Wed, 07 Dec 2011 05:44:28 -0800 (PST) Original-Received: by 10.146.131.17 with HTTP; Wed, 7 Dec 2011 05:44:28 -0800 (PST) In-Reply-To: <87r50gijq1.fsf@live.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.160.169 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83153 Archived-At: On Wed, Dec 7, 2011 at 3:39 PM, wrote: > > I am just trying to verify if an element is present in an array or not. > > here is what I tried, > > (let ((arr '[AAA BBB CCC])) > =A0(mapc (lambda (s) > =A0 =A0 =A0 =A0 =A0(if (string=3D "AAA" s) > =A0 =A0 =A0 =A0 =A0 =A0 =A0(insert "AAA is a member of arr"))) > =A0 =A0 =A0 =A0arr)) > > if I eval the above > return value is: [AAA BBB CCC] and inserts =A0"AAA is a member of arr" in > the buffer > > But the approach seems wrong to me. Because it loops over all the > elements no matter ELT is in it or not and the return value is useless > (at least in this case) > > here is what I really want to achieve: > > 1) search the array if the element is present > 2) if the element is present return "t" otherwise "nil" > 3) Since the number of elements in my array will be huge, break the loop > =A0and return "t", if it the function find the first occurrence of ELT > > Thanks > -- > YYR > > (when (find "AAA" '[AAA BBB CCC] :test 'string=3D) (insert "Found"))