all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* elisp: how to find an ELT is present an ARRAY or not?
@ 2011-12-07 13:39 yagnesh
  2011-12-07 13:44 ` Valentin Baciu
  0 siblings, 1 reply; 3+ messages in thread
From: yagnesh @ 2011-12-07 13:39 UTC (permalink / raw
  To: help-gnu-emacs


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




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: elisp: how to find an ELT is present an ARRAY or not?
  2011-12-07 13:39 elisp: how to find an ELT is present an ARRAY or not? yagnesh
@ 2011-12-07 13:44 ` Valentin Baciu
  2011-12-08 20:20   ` Yagnesh Raghava Yakkala
  0 siblings, 1 reply; 3+ messages in thread
From: Valentin Baciu @ 2011-12-07 13:44 UTC (permalink / raw
  To: yagnesh; +Cc: help-gnu-emacs

On Wed, Dec 7, 2011 at 3:39 PM,  <yagnesh@live.com> 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"))



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: elisp: how to find an ELT is present an ARRAY or not?
  2011-12-07 13:44 ` Valentin Baciu
@ 2011-12-08 20:20   ` Yagnesh Raghava Yakkala
  0 siblings, 0 replies; 3+ messages in thread
From: Yagnesh Raghava Yakkala @ 2011-12-08 20:20 UTC (permalink / raw
  To: help-gnu-emacs

Valentin Baciu <valentin@syntactic.org> writes:

> On Wed, Dec 7, 2011 at 3:39 PM,  <yagnesh@live.com> 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"))
>

thats the one I wanted (which is in cl package)

Thanks. more questions to come
-- 
YYR




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-12-08 20:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-07 13:39 elisp: how to find an ELT is present an ARRAY or not? yagnesh
2011-12-07 13:44 ` Valentin Baciu
2011-12-08 20:20   ` Yagnesh Raghava Yakkala

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.