named optional parameters
- To: mathgroup at smc.vnet.net
- Subject: [mg37909] named optional parameters
- From: doris.siegl at gmx.at (Doris S.)
- Date: Tue, 19 Nov 2002 03:51:23 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Hello NG! I've got a problem using named optional parameters for a function in a package: Like described in chapter 2.3.10 of the Mathematica Help I created a list of default values for my parameters "DrawCh" and "DrawG". Then I wrote a function with optional parameters opts___ and evaluated them using the list. When I put all this (my function "ParamTest" and de Options for "ParamTest") into a Package and call the function from a notebook the given parameters are not evaluated correctly. The parameters just have the (default) values given in the Options list and don´t change as I defined them when calling the function. The source code of the function, nevertheless, seems to be correct, because putting the function outside a package and using it there works correctly. So do I have to define something else in the package so I can use named optional parameters? Additional Information: OS: Win2000 Version: Mathematica 4.0 I appreciate any help! Doris S. The source: (*****************************TestPackage.m:***************************) BeginPackage["TestPackage`TestPackage`"] Unprotect[ParamTest]; Begin["TestPackage`TestPackage`Private`"] (**********************************************************************) Options[ParamTest]={DrawCh->True,DrawG->True}; ParamTest[opts___]:=Block[{dc,dg}, dc=DrawCh/.{opts}/.Options[ParamTest]; dg=DrawG/.{opts}/.Options[ParamTest]; Return[{dc,dg}]; ]; (**********************************************************************) End[] Protect[ParamTest]; EndPackage[] (************* Using the function in a notebook ***********************) In[1]:= << TestPackage`TestPackage` In[2]:= Names["TestPackage`TestPackage`*"] Out[2]= {"ParamTest"} In[3]:= ParamTest[] (*default values*) Out[3]= {True, True} In[4]:= ParamTest[DrawCh -> False] (*result should be {False,True}*) Out[4]= {True, True} In[5]:= ParamTest[DrawG -> False] (*result should be {True,False}*) Out[5]= {True, True} (*putting the function code of the package in a notebook and evaluating it gives the correct result*) In[6]:= Options[ParamTest1] = {DrawCh -> True, DrawG -> True}; ParamTest1[opts___] := Block[{dc, dg}, dc = DrawCh /. {opts} /. Options[ParamTest1]; dg = DrawG /. {opts} /. Options[ParamTest1]; Return[{dc, dg}];]; In[8]:= ParamTest1[DrawG -> False] Out[8]= {True, False}