MathGroup Archive 2010

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

Search the Archive

Re: Proper style for argument checking?

  • To: mathgroup at
  • Subject: [mg111955] Re: Proper style for argument checking?
  • From: James Stein <mathgroup at>
  • Date: Sat, 21 Aug 2010 04:18:43 -0400 (EDT)

I use this cell in my notebooks:

ClearAll[abort, abortLog, fail, failLog];
abortLog = failLog = {};
abort[s__] := (Beep[];
   AppendTo[abortLog, {s}];
   Print["Aborting: ", s];
fail[s__] := (Beep[];
   AppendTo[failLog, {s}];
   Print["Fail: ", s]

Neither abort' nor 'fail' does exactly what you request, but why
return the function unevaluated in case of failure?  My preference is
either to abort on failure (normal case) or report and continue
(regression testing).  In my experience, a function that returns
unevaluated merely wreaks havoc higher in the calling chain.

I'm eager to hear other responses to your query.

On Fri, Aug 20, 2010 at 4:06 AM, Yaroslav Bulatov <yaroslavvb at> wrote:
> I have a function, and I'd like to do several checks on arguments
> before evaluating it. If some check fails, I want the function to
> return unevaluated and print corresponding error message, what's the
> proper style of doing it?
> Help for "Message" gives an example for a single check, but it seems
> awkward to use same form for multiple checks.

  • Prev by Date: Re: NonLinearModelFit crash (restart) the mathematica (v7.0) kernel.
  • Next by Date: Re: Hanging indent in Print[] output?
  • Previous by thread: Proper style for argument checking?
  • Next by thread: Re: Proper style for argument checking?