Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg58791] Re: Validating functions input
  • From: "David Park" <djmp at earthlink.net>
  • Date: Tue, 19 Jul 2005 04:10:02 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Nilton,

Strange. The usual procedure is to leave it unevaluated if the arguments are
not valid. In any case,

f::invalid = "Invalid arguments, `` > ``";
f[x_, y_] /; ¬ (x <= 2^y) := Message[f::invalid, x, 2y]

In[9]:=
f[1,3]

Out[9]=
f[1,3]

In[10]:=
f[3,1]

From In[10]:=
f::invalid: Invalid arguments, 3 > 2

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/



From: Nilton [mailto:nilton.volpato at ig.com.br]
To: mathgroup at smc.vnet.net


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: Validating functions input
  • Next by Date: Re: How to create a new Form
  • Previous by thread: Re: Validating functions input
  • Next by thread: Re: Validating functions input