Re: How do I test for existence of a list element?
- To: mathgroup at smc.vnet.net
- Subject: [mg112702] Re: How do I test for existence of a list element?
- From: "andre.robin3" <andre.robin3 at wanadoo.fr>
- Date: Mon, 27 Sep 2010 05:48:31 -0400 (EDT)
- References: <i7k4d7$lha$1@smc.vnet.net>
I recently had the same problem, but for a more general case : How to test
the existence of a deeply embedded element in a ragged structure ?
Say that the position of the element is specified by : list={i,j,k ..}
my solution was something like :
existenceTestQ[exp_, list_] := Module[{res},
res = False;
ReplacePart[exp, list :> (res = True)];
res
]
may be not elegant, but sufficient
"Joseph Gwinn" <joegwinn at comcast.net> a écrit dans le message de news:
i7k4d7$lha$1 at smc.vnet.net...
>I have an application where I am bouncing around in a list, and may
> accidentally ask for an element beyond the end of the list, which causes
> Mathematica to complain and balk, preventing completion.
>
> Is there any way to test for the existence of a list element without
> provoking complaint or balking should the list item fail to exist?
>
> Thanks,
>
> Joe Gwinn
>