Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Help with Check Function Arguments & Options

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87288] Re: Help with Check Function Arguments & Options
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Sun, 6 Apr 2008 06:45:51 -0400 (EDT)
  • References: <ft7gkq$bve$1@smc.vnet.net>

Hi,

f[x_, y_, opts : OptionsPattern[]] := x + y
f[args___, opts : OptionsPattern[]] :=
  If[Length[{args}] != 2, Message[f::"argrx", f, Length[{args}], 2];
   Return[$Failed]]

??

Regards
   Jens

Andrew Beveridge wrote:
> I would like to thank everyone who has previously responded to my 
> posts. Your advice has helped greatly.
> 
> I have a couple of final questions.
> 
> I am writing a package file and would like to do some argument and 
> option checking if possible; that is check the number of arguments 
> and see if there are unknown options.
> 
> If my function has no options I think I can do this.
> 
> f[x_,y_] := x + y
> f[args___] := If[Length[{args}] != 2, Message[f::"argrx", f, 
> Length[{args}], 2]; Return[$Failed]]
> 
> This type of check has been posted to the message board before.
> 
> My question is assume that f[x,y] has multiple options, that is
> Options[f] = {opt1 -> 1, opt2 -> True}, etc
> 
> How do I check if the user entered the correct options?
> 
> Thanks again for all of your help.
> 
> Regards,
> Andrew
> 
> Andrew C Beveridge
> MS M888
> Los Alamos National Laboratory
> Los Alamos, NM  87545
> 
> 505-665-2092
> e-mail: acbev at lanl.gov
> 
> 


  • Prev by Date: Re: Help with Check Function Arguments & Options
  • Next by Date: Re: Inconsistent behavior?
  • Previous by thread: Re: Help with Check Function Arguments & Options
  • Next by thread: Re: Help with Check Function Arguments & Options