       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:=
ClearAll[NumericWithMessageQ,f];

Now define a message:

In:=
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:=
NumericWithMessageQ[z_]:=
If[NumericQ[z],
True,
Message[Test::testmessage,z];False]

Now give a function definition for numeric values of the argument

In:=
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:=
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:=
f

Out=
1

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

In:=
f[a]

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

Out=
2

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

In:=
ClearAll[f]

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

In:=
f[y_]:=2;

And the function works as above.

In:=
f

Out=
1

In:=
f[a]

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

Out=
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?