Re: Options for a function
- To: mathgroup at smc.vnet.net
- Subject: [mg18148] Re: [mg18116] Options for a function
- From: BobHanlon at aol.com
- Date: Fri, 18 Jun 1999 00:51:47 -0400
- Sender: owner-wri-mathgroup at wolfram.com
Virgil, You need to use SameQ (===) instead of Equal (==) x == y x == y It is unevaluated because the answer is unknown; whereas, x === y False For the If statement this results in If[x == y, a, b, c] c If[x === y, a, b, c] b Options[g] = {Opt1 -> BoxCar}; g[n_, opts___?OptionQ] := Module[{opt1, ans}, opt1 = Opt1 /. {opts} /. Options[g]; If[opt1 === BoxCar, ans = yes, ans = no]; {n, ans, opt1} ]; g[3] {3, yes, BoxCar} g[3, Opt1 -> TEST] {3, no, TEST} Bob Hanlon In a message dated 6/17/99 3:31:59 PM, virgil.stokes at neuro.ki.se writes: >The following simple function for testing >options does not work the way I expect >(Vers. 3.0.1). > > >Options[g] = {Opt1->BoxCar}; >g[n_,opts___?OptionQ] := > Module[{opt1,ans}, > opt1 = Opt1 /. {opts} /. Options[g]; > If[opt1 == BoxCar, ans = yes, ans = no]; > {n,ans,opt1} > ]; > >If I use > > g[3] > >then it returns > >{3,yes,BoxCar} > >which is of course correct. However, if I use > >g[3,Opt1->TEST] > >then it returns > >{3,ans$7,TEST} > >And, this is not what I would expect. In fact, I am >unable to get the > > ans = no > >part of the If statement to execute. Why? >