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: [mg15706] Re: [mg15687] conditional pattern question
  • From: David Withoff <withoff>
  • Date: Mon, 1 Feb 1999 14:54:21 -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?
> >
> In[1]:= ClearAll[NumericWithMessageQ,f];
> 
> In[2]:= Test::testmessage="The argument `1` has generated this message.";
> 
> In[3]:= NumericWithMessageQ[z_]:=
>              If[NumericQ[z],
>                 True,
>                 Message[Test::testmessage,z];False]
> 
> In[4]:= f[y_?NumericWithMessageQ]:=1;
> 
> In[5]:= f[y_]:=2;
> 
> Test::"testmessage": "The argument \!\(y_\) has generated this message."
> 
> Note though that the function works properly.
> 
> In[6]:= f[4]
> 
> Out[6]= 1
> 
> In[7]:= f[a]
> 
> Test::"testmessage": "The argument \!\(a\) has generated this message."
> 
> Out[7]= 2

The message here (after In[5]) is a result of the way that the part of
Mathematica that orders definitions works.  This is the part of
Mathematica that implements the behavior described in section 2.4.7,
"The Ordering of Definitions", in the Mathematica book.  The procedure
used for ordering rules does some evaluations.  Those evaluations can
have effects such as the one that you observed in this example.

Although this isn't really a bug, your concern is certainly valid.   As
you point out, the definitions work properly anyway, and since 
examples of this behavior are quite rare, this is mostly just a
curiousity.  If you have an example where the consequences seem more
serious, we would be very interested in looking at it. 

Dave Withoff
Wolfram Research


  • Prev by Date: Re(2): Re: Bug in Det[ ], once more
  • Next by Date: no kernel?
  • Previous by thread: Re(2): Re: Bug in Det[ ], once more
  • Next by thread: Re: conditional pattern question