Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Validating functions input

  • To: mathgroup at
  • Subject: [mg58795] Re: Validating functions input
  • From: dh <dh at>
  • Date: Tue, 19 Jul 2005 04:10:04 -0400 (EDT)
  • References: <dbflkk$n0p$>
  • Sender: owner-wri-mathgroup at

Hi Nilton,
You want a function that returns unevaluated if the input fullfills some 
condition and does something if the condition is not fulfilled.
Well, this calls for negation: !

f[x_, y_] /; ! x <= 2^y := (Print["invalid Input"]; Null)

This will print an error message and return Null if the condition: x <= 
2^y is not (!) fulfilled.

sincerely, Daniel
Nilton wrote:
> I have a function that must have its input validated.
> f[x,y]
> I want to validate if x <= 2^y. If it's valid, then just return the
> symbol f[x,y] unevaluated. If it's not valid, I want to return some
> symbol, Null for instance, and issue an error message.
> The following is a try, but it doesn't work, because it's definition is
> recursive:
> f::invalid = "Invalid arguments"
> f[x_,y_] := If[x <= 2^y, f[x,y], Message[f::invalid]]
> Is there any way to implement this?
> Thanks,
> -- Nilton

  • Prev by Date: an Integrate question
  • Next by Date: Re: Validating functions input
  • Previous by thread: Re: Validating functions input
  • Next by thread: Re: Validating functions input