Re: Options for a function
- To: mathgroup at smc.vnet.net
- Subject: [mg18128] Re: Options for a function
- From: paulh at wolfram.com (P.J. Hinton)
- Date: Fri, 18 Jun 1999 00:51:36 -0400
- Organization: Wolfram Research, Inc.
- References: <7ka6ub$ins@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In article <7ka6ub$ins at smc.vnet.net>, Virgil Stokes <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? Try using SameQ[] rather than Equal[] as the test in the If[] statement. Here is what your function is doing. Equal[] does not consider this to be either True or False. In[1]:= TEST == BoxCar Out[1]= TEST == BoxCar SameQ[] will give you the False result. In[2]:= TEST === BoxCar Out[2]= False -- P.J. Hinton Mathematica Programming Group paulh at wolfram.com Wolfram Research, Inc. Disclaimer: Opinions expressed herein are those of the author alone.