MathGroup Archive 1997

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

Search the Archive

Re: Functions and evaluation, returning themselves

  • To: mathgroup at
  • Subject: [mg7265] Re: Functions and evaluation, returning themselves
  • From: Paul Abbott <paul at>
  • Date: Tue, 20 May 1997 02:59:15 -0400 (EDT)
  • Organization: University of Western Australia
  • Sender: owner-wri-mathgroup at

Red wrote:

> I am trying to write a function in Mathematica
> that can give a message and return the
> expression entered.
> For example
> In[1] :=  Sin[]
> ``Sin::"argx":
>  "Sin called with 0 arguments; 1 argument is expected.
> Out[1]=  Sin[]

The following rule issues an error message (using the built-in Message
mechanism) if f is called with an incorrect number (i.e. != 1) of

	f[args___]:= Null/; Length[{args}] != 1 &&

As a side-effect of evaluating the Condition -- entered using the infix 
shorthand /; which can be read as such that -- the rule on the
right-hand side computes the number of arguments using Length and
(denoted here by &&) prints a message when it is not equal to one (i.e., 
Length[{args}] != 1):


	f::"argx": "f called with 2 arguments; 1 argument is expected."



Paul Abbott
Department of Physics                       Phone: +61-8-9380-2734 
The University of Western Australia           Fax: +61-8-9380-1014
Nedlands WA  6907                         paul at 

          God IS a weakly left-handed dice player

  • Prev by Date: Re: Re: How to clear all definitions?
  • Next by Date: Re: Bugs in Mathematica ver: 3.0 ?
  • Previous by thread: Functions and evaluation, returning themselves
  • Next by thread: Comparison of Mathematica on Various Computers