Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1999
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1999

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

Search the Archive

Re: conditional pattern question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg15695] Re: [mg15687] conditional pattern question
  • From: Jurgen Tischer <jtischer at col2.telecom.com.co>
  • Date: Mon, 1 Feb 1999 14:54:14 -0500 (EST)
  • Organization: Universidad del Valle
  • References: <199901310806.DAA14392@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

David,
I think first of all you should read (again) 2.5.6 Evaluation in
Patterns, Rules and Definitions (as I did after quite a while of
guessing about in your example). I don't say it explains everything,
but at least the guesses should become more educated. Now I make your
example worse (after I read 2.5.6 and I thought I understood what's
going on.)

With your first definition of f, define now 

In[5']:= f[y]:=3

and no evaluation with NumericWithMessageQ is taking place!

Jurgen

David Reiss wrote:
> 
> 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: RE: Help to clarify 'Map', 'Apply', and 'Thread'.
  • Next by Date: Re: conditional pattern question
  • Previous by thread: Re: conditional pattern question
  • Next by thread: Re: conditional pattern question