Prev: First nonzero in list
Next: change $UserBaseDirectory ?
From: telefunkenvf14 on 8 Jul 2010 03:13 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
From: Leonid Shifrin on 8 Jul 2010 06:53 Hi Ryan, 1. How about this: MatchQ[{1, 2, 2.2}, _?(MatchQ[N[#], { ___Real}] &)] 2. { ___Symbol} 3. Sounds like a good idea, but the hardest part will be to categorize them so that they can be searched efficiently. Some kind of tagging system may be needed for that. Regards, Leonid On Thu, Jul 8, 2010 at 11:13 AM, telefunkenvf14 <rgorka(a)gmail.com> wrote: > 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 > > >
From: Sir Bob Knight on 8 Jul 2010 06:50 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(a)gmail.com] > Inviato: gioved=EC 8 luglio 2010 9.14 > A: mathgroup(a)smc.vnet.net > Oggetto: 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
From: Leonid Shifrin on 8 Jul 2010 07:40 Hi Ryan, 1. How about this: MatchQ[{1, 2, 2.2}, _?(MatchQ[N[#], { ___Real}] &)] 2. { ___Symbol} 3. Sounds like a good idea, but the hardest part will be to categorize them so that they can be searched efficiently. Some kind of tagging system may be needed for that. Regards, Leonid On Thu, Jul 8, 2010 at 11:13 AM, telefunkenvf14 <rgorka(a)gmail.com> wrote: > 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 > > >
From: Peter Breitfeld on 8 Jul 2010 20:34
telefunkenvf14 wrote: > 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 > > The answer to question 1 could be: realpatt={_Real..} Question 2 could be done by: vectorpatt=v:{_Symbol..}/;VectorQ[v] There is a plethora of combinations of patterns, but in my opinion some of the fundamental ones are included in the examples above. Mostly it's possible to achieve the same goal in different ways. -- _________________________________________________________________ Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de |