help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: elisp: how to find an ELT is present an ARRAY or not?


From: Valentin Baciu
Subject: Re: elisp: how to find an ELT is present an ARRAY or not?
Date: Wed, 7 Dec 2011 15:44:28 +0200

On Wed, Dec 7, 2011 at 3:39 PM,  <address@hidden> 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]))
>  (mapc (lambda (s)
>          (if (string= "AAA" s)
>              (insert "AAA is a member of arr")))
>        arr))
>
> if I eval the above
> return value is: [AAA BBB CCC] and inserts  "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
>  and return "t", if it the function find the first occurrence of ELT
>
> Thanks
> --
> YYR
>
>

(when (find "AAA" '[AAA BBB CCC] :test 'string=)
  (insert "Found"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]