MathGroup Archive 2004

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

Search the Archive

Re: Re: Length of actual parameters in a function call.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47130] Re: [mg47124] Re: Length of actual parameters in a function call.
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 27 Mar 2004 01:34:33 -0500 (EST)
  • References: <c3udpe$9om$1@smc.vnet.net> <200403260856.DAA23010@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 26 Mar 2004, at 08:56, Paul Abbott wrote:

> In article <c3udpe$9om$1 at smc.vnet.net>,
>  "E. Martin-Serrano" <eMartinSerrano at houston.rr.com> wrote:
>
>> A few weeks ago, reviewing some tutorials on pattern matching and 
>> error
>> handling, I came across an undocumented function to monitor the 
>> number of
>> parameters submitted to a function in a call; but somehow I lost its 
>> track
>> later. I guess that it must be something well-known by our 
>> specialists. Any
>> help about where to locate it?
>>
>> The undocumented feature helps in tracking situations as when we 
>> define
>> "MyFunction[a_,b_,c_]:= something" and then it is called as 
>> "myFunction[a]"
>> leaving the function unevaluated.
>
>   MyFunction[a_, b_, c_] := something
>
>   MyFunction[args___] := Null /; Length[{args}] != 3 &&
>     Message[MyFunction::argx, MyFunction, Length[{args}]]
>
>   MyFunction[a]
>
> Cheers,
> Paul
>
> -- 
> Paul Abbott                                   Phone: +61 8 9380 2734
> School of Physics, M013                         Fax: +61 8 9380 1014
> The University of Western Australia      (CRICOS Provider No 00126G)
> 35 Stirling Highway
> Crawley WA 6009                      mailto:paul at physics.uwa.edu.au
> AUSTRALIA                            http://physics.uwa.edu.au/~paul
>
>
>

This does not seem to produce the correct message; I think you need 
something like:

  MyFunction[a_, b_, c_] := something

MyFunction::"argx" = "MyFunction called with `1` arguments, 3 arguments 
are \
expected."

MyFunction[args___] := Null /; Length[{args}] != 3 &&
     Message[MyFunction::argx, Length[{args}]]


MyFunction[a]

Andrzej Kozlowski
Chiba, Japan
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: Yet another Mathematica docs whopper
  • Next by Date: Re: Disappearing Help Browser Categories
  • Previous by thread: Re: Length of actual parameters in a function call.
  • Next by thread: Re: Re: Length of actual parameters in a function call.