Re: Understanding patterns

*To*: mathgroup at smc.vnet.net*Subject*: [mg126101] Re: Understanding patterns*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Tue, 17 Apr 2012 06:04:33 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com

On 4/16/12 at 6:10 AM, sam.takoy at yahoo.com (Sam Takoy) wrote: >I hoping to get some pointers on understanding patterns. For >example, I can't quite make sense of the following: >f[p : {__?NumericQ}] := >What is the meaning of "{", the double underscore, and the question >mark? The { and } make the pattern match a list The double underscore matches one or more items the ? combined with NumbericQ defines a pattern test that returns true when the argument is numeric So, the pattern shown should match a list of one or more numeric items which can be verified by: In[1]:= MatchQ[{1, Pi, .3}, {__?NumericQ}] Out[1]= True In[2]:= MatchQ[{1}, {__?NumericQ}] Out[2]= True In[3]:= MatchQ[1, {__?NumericQ}] Out[3]= False In[4]:= MatchQ[{x}, {__?NumericQ}] Out[4]= False In[5]:= MatchQ[{1, x}, {__?NumericQ}] Out[5]= False