MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

conditional pattern question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15687] conditional pattern question
  • From: dreissBLOOP at bloop.earthlink.net (David Reiss)
  • Date: Sun, 31 Jan 1999 03:06:09 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

I don't understand the following behavior: could someone educate  me
here?  ...or is it a bug?

First clear the functions and variables.


In[1]:=
ClearAll[NumericWithMessageQ,f];


Now define a message:


In[2]:=
Test::testmessage="The argument `1` has generated this message.";


Introduce a boolian test that has the added side effect of generating  a
message when the test yields False (I am using NumericQ as an  example,
but the problem that I am illustrating is independent of this):


In[3]:=
NumericWithMessageQ[z_]:=
   If[NumericQ[z],
      True,
      Message[Test::testmessage,z];False]
      
      
Now give a function definition for numeric values of the argument


In[4]:=
f[y_?NumericWithMessageQ]:=1;


Also give a definition for all other cases: the message defind a bove is
generated when this is executed-- I didn't expect this to  happen. That
the message is generated at this point puzzels me.   I don't understand
why this happens.


In[5]:=
f[y_]:=2;

Test::"testmessage": "The argument \!\(y_\) has generated this message."


Note though that the function works properly.  Here is a numeric case:


In[6]:=
f[4]

Out[6]=
1


And here is a non-numeric case (and the message is generated as  per the
design).


In[7]:=
f[a]

Test::"testmessage": "The argument \!\(a\) has generated this message."

Out[7]=
2


If the function is specified as follows, the message is not  generated 
unexpectedly when the function is defined.


In[8]:=
ClearAll[f]

In[9]:=
f[y_]/;NumericWithMessageQ[y]:=1;

In[10]:=
f[y_]:=2;


And the function works as above.


In[11]:=
f[4]

Out[11]=
1

In[12]:=
f[a]

Test::"testmessage": "The argument \!\(a\) has generated this message."

Out[12]=
2

-- 


   
----------------------------------------  Scientific Arts:
Creative Services and Consultation 
for the Applied and Pure Sciences 

David Reiss 
Email: dreiss at !SPAMscientificarts.com 
----------------------------------------
 


Remove the !SPAM to send email


  • Prev by Date: 4th order DE, NDSolve no solution, why?
  • Next by Date: Re: speed
  • Previous by thread: 4th order DE, NDSolve no solution, why?