Re: simple pattern match question
- To: mathgroup at smc.vnet.net
- Subject: [mg91185] Re: simple pattern match question
- From: Steven Siew <stevensiew2 at gmail.com>
- Date: Fri, 8 Aug 2008 07:17:32 -0400 (EDT)
- References: <g7ed78$2po$1@smc.vnet.net>
You should use the query (?) In[1]:= f[x_?NumberQ] := x ^ 2 In[2]:= f[3] Out[2]= 9 In[3]:= f[3.3] Out[3]= 10.89 In[4]:= f[r] Out[4]= f[r] This means function f only works on things that return True on the NumberQ[expr_] function Steven Siew On Aug 7, 6:54 pm, congruentialumina... at yahoo.com wrote: > Hello UG: > > I am trying to understand simple pattern rule evaulation. The > following trivial examples baffles me: > > --------------------------------------------------- > In[1]:= f[x_Number] := x ^ 2 > In[2]:= f[3] > Out[2]= f[3] > > In[3]:= f[3.3] > Out[3]= f[3.3] > > In[4]:= NumberQ[3.3] > Out[4]= True > -------------------------------------------------- > Why is it that f[3.3] does not evaluate?? > > TIA. > > Regards..RogerW