Re: Pattern: x_List with conditions on elements
- To: mathgroup at smc.vnet.net
- Subject: [mg110845] Re: Pattern: x_List with conditions on elements
- From: "Sir Bob Knight" <sir.bob.knight at gmail.com>
- Date: Thu, 8 Jul 2010 06:50:21 -0400 (EDT)
What about the followings? In[2]:== MatchQ[{1, 2, 2.2, 5, 6, 4, 3, 3.}, {(_Real | _Integer) ..}] Out[2]== True In[3]:== MatchQ[{1 + I, 2, 2.2, 5, 6, 4, 3, 3.}, {(_Real | _Integer) ..}] Out[3]== False In[4]:== MatchQ[N[{1, 2, 2.2, 5, 6, 4, 3, 3.}], {_Real ..}] Out[4]== True In[5]:== MatchQ[N[{1 + I, 2, 2.2, 5, 6, 4, 3, 3.}], {_Real ..}] Out[5]== False In[6]:== MatchQ[{1, 2, 2.2, 5, 6, 4, 3.}, {_?(# \[Element] Reals &) ..}] Out[6]== True In[7]:== MatchQ[{1 + I, 2, 2.2, 5, 6, 4, 3.}, {_?(# \[Element] Reals &) ..}= ] Out[7]== False In[8]:== MatchQ[{a, b, c, d, e, f}, {_Symbol ..}] Out[8]== True In[9]:== MatchQ[{1, a, b, c, d, e, f}, {_Symbol ..}] Out[9]== False -Bob- > -----Messaggio originale----- > Da: telefunkenvf14 [mailto:rgorka at gmail.com] > Inviato: gioved=EC 8 luglio 2010 9.14 > A: mathgroup at smc.vnet.net > Oggetto: [mg110829] Pattern: x_List with conditions on elements > > Group: > > 1. Can someone provide a clearer way of implementing the following > example? (Goal: I want a pattern that accepts only a list of real > numbers and what I have seems hacky.) > > MatchQ[{1, 2, 2.2},x_?(VectorQ[#,(NumericQ[#]&&Im[#]====0)&]&)] > > 2. Could someone show me how to create a second pattern which accepts > only a list (vector) of symbols? I feel like I'm spinning my wheels a > bit on this one... > > 3. Does anyone else think it would be nice to compile a list of > favorite/useful patterns, along with a very brief explanation of the > intent? (And yes, I know there are a bunch of examples in the > documentation(!), but I'm thinking more in terms of assembling a list > of recipes.) I guess I'm just craving more guided examples. > > -RG