Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9674 > unrolled thread

Re: Understanding patterns

Started byBill Rowe <readnews@sbcglobal.net>
First post2012-04-17 10:05 +0000
Last post2012-04-17 10:05 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: Understanding patterns Bill Rowe <readnews@sbcglobal.net> - 2012-04-17 10:05 +0000

#9674 — Re: Understanding patterns

FromBill Rowe <readnews@sbcglobal.net>
Date2012-04-17 10:05 +0000
SubjectRe: Understanding patterns
Message-ID<jmjf9n$8aa$1@smc.vnet.net>
On 4/16/12 at 6:10 AM, sam.takoy@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


[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web