MathGroup Archive 2005

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

Search the Archive

Re: Validating functions input

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58789] Re: Validating functions input
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Tue, 19 Jul 2005 04:10:00 -0400 (EDT)
  • Reply-to: hanlonr at cox.net
  • Sender: owner-wri-mathgroup at wolfram.com

In[1]:=
f::invalid="Invalid arguments";

In[2]:=
f[x_,y_ ]:= (Message[f::invalid];Null)/;x>2^y;

In[3]:=
f[2,2]

Out[3]=
f(2,2)

In[4]:=
f[5,2]

From In[4]:=
f::invalid: Invalid arguments

In[5]:=
f[x,y]

Out[5]=
f(x,y)


Bob Hanlon

> 
> From: "Nilton" <nilton.volpato at ig.com.br>
To: mathgroup at smc.vnet.net
> Date: 2005/07/18 Mon AM 03:21:21 EDT
> Subject: [mg58789]  Validating functions input
> 
> 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: Re: How to create a new Form
  • Next by Date: Re: Validating functions input
  • Previous by thread: Re: Validating functions input
  • Next by thread: Re: Validating functions input