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


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

Re: Understanding patterns

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Understanding patterns
Date 2012-04-17 10:05 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jmjf9n$8aa$1@smc.vnet.net> (permalink)

Show all headers | View raw


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


Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web