MathGroup Archive 2006

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

Search the Archive

Re: Checking function syntax

  • To: mathgroup at smc.vnet.net
  • Subject: [mg64582] Re: [mg64555] Checking function syntax
  • From: jmt <jmt at dxdydz.net>
  • Date: Thu, 23 Feb 2006 00:34:19 -0500 (EST)
  • References: <200602221058.FAA23476@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On Wednesday 22 February 2006 11:58, Chris Rodgers wrote:
> Hi,
>
> How can I make my own functions give an error if they are called with
> the wrong syntax?


Try this :

Here is your standard definition :
MyFunc1[x_, y_] := Tuples[{x, y}, 2]

Define your error message :
MyFunc1::"WrongInput" = "A sensible error message for incorrect input `1`"

Create the rule that match wrong input :
MyFunc1[u___] := Message[MyFunc1::"WrongInput", u]


Check normal function call :
Map[MyFunc2, MyFunc1[a, b]]

And incorrect one :
Map[MyFunc2, MyFunc1[a, b, c]]

Mind the fact that in some situations some rules might have equal priorities, 
in which case rule definition ordering defines which rule will be called.


  • Prev by Date: Re: Combining ContourPlot and Plot
  • Next by Date: Re: Matrix multiplication problem fixed via dot operation.
  • Previous by thread: Checking function syntax
  • Next by thread: Re: Checking function syntax