Re: Limiting the number of messages

• To: mathgroup at smc.vnet.net
• Subject: [mg103867] Re: Limiting the number of messages
• From: Albert Retey <awnl at gmx-topmail.de>
• Date: Fri, 9 Oct 2009 07:19:49 -0400 (EDT)

```Hi,
>
> I realise it's a bit amateur to be re-writing the input as a string for
> the output (well, actually the whole thing feels more like a work-around
> than a proper solution), but it's achieving what I'm after I guess?!?
>

I think it is not the question whether this is a bit amateur or not, the
question is why you want to return something that looks like the
unevaluated form of the input. I think the reason Mathematica functions
do return unevaluated expression is because then it is possible to still
work with the unevaluated expression (pattern matching etc.). This can
not be done when you just return a string that looks like the
unevaluated expression and thus is not worth more than just returning
e.g. \$Failed. In fact these strings might even confuse the users. The
following uses a (documented) trick which lets you return the
unevaluated expression even when the original pattern does match and
achieves what you intend in a simpler and more robust way:

ClearAll[f, t]

f::aerror = "a is too small";
f::berror = "b is too small";

f[a_?NumericQ, b_?NumericQ] := Module[{check = True},
If[a <= 0, Message[f::aerror]; check = False];
If[b <= 2, Message[f::berror]; check = False];
a + b /; check
];

t[a_, b_] := Block[{res = (f[a, b])}, res^2 /; Head[res] =!= f];

In part I think that Leonid is right: you might want to rethink the
design of your functions. The question is really why you want to defer
the argument check to the subroutines. And after all: Using the above
scenario will still potentially create as many Messages as possibly
might occur. Can you reformulate more clearly what you want to achieve
and especially why you want it that way? Maybe that will lead you to
find a better solution yourself or at least create more useful answers...

hth,

albert

```

• Prev by Date: Re: AxesLabel from expression
• Next by Date: Re: For interest: oil prices with FX for comparison
• Previous by thread: Re: Limiting the number of messages
• Next by thread: Re: Re: Limiting the number of messages