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: [mg87268] Re: Help with Check Function Arguments & Options
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Sun, 6 Apr 2008 06:42:04 -0400 (EDT)
  • References: <ft7gkq$bve$1@smc.vnet.net>

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
> 
> 
By far the best answer to this is to use the new OptionsPattern and 
OptionValue features introduced at 6.0 - look them up in the help 
system. This will separate options from other arguments and check that 
the options used are actually valid.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: running a program
  • Next by Date: Re: mathematica on macbook... hangs on 5-4
  • Previous by thread: Re: Help with Check Function Arguments & Options
  • Next by thread: Re: Help with Check Function Arguments & Options