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

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

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


From: yagnesh
Subject: elisp: how to find an ELT is present an ARRAY or not?
Date: Wed, 07 Dec 2011 22:39:50 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

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




reply via email to

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