Re: Function in a package
- To: mathgroup at smc.vnet.net
- Subject: [mg42502] Re: [mg42493] Function in a package
- From: jmt <jmt at dxdydz.net>
- Date: Sat, 12 Jul 2003 05:19:04 -0400 (EDT)
- Organization: dxdydz
- References: <200307110657.CAA17172@smc.vnet.net>
- Reply-to: jmt at dxdydz.net
- Sender: owner-wri-mathgroup at wolfram.com
Names and possible values for options in a package function must be declared in the package. On Friday 11 July 2003 08:57, Roger Mason wrote: > Hello, > > I have written and tested successfully a function in a notebook. On > putting the function in a package it ceases to work. > > Here is the package: > > BeginPackage["FredNoEDA`"] > > TestPkgNoEDA::usage = "a test function."; > > Begin["`Private`"] > > TestPkgNoEDA[dat_, opts___?OptionQ] := Module[ > {n, Tow, Tow0}, > n = norm /. Flatten[{opts}] /. {norm -> fst}; > Tow = dat; > If[ > n == fst, Tow0 = First[Tow] > ]; > If[ > n == max, Tow0 = Tow[[ > Position[Tow, Max[Tow] ][[1, 1]] > ]] > ]; > Tow0 > ] > > End[] > > Protect[TestPkgNoEDA] > > EndPackage[]; > > Here is the identical function (under a different name) from a notebook: > > TestPkg[dat_, opts___?OptionQ] := Module[ > {n, Tow, Tow0}, > n = norm /. Flatten[{opts}] /. {norm -> fst}; > Tow = dat; > If[ > n == fst, Tow0 = First[Tow] > ]; > If[ > n == max, Tow0 = Tow[[ > Position[Tow, Max[Tow] ][[1, 1]] > ]] > ]; > Tow0 > ] > > Here are some test data: > > In[2]:= > tst = Table[x, {x, 1, 10}] > > Out[2]= > {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} > > Here are the results of a test: > > Needs["FredNoEDA`"] > > In[6]:= > TestPkgNoEDA[tst, norm -> max] > > Out[6]= > 1 > > In[11]:= > TestPkg[tst, norm -> max] > > Out[11]= > 10 > > Can anyone explain why the version of the function in the package returns > an incorrect result? > > Thanks, > Roger Mason
- References:
- Function in a package
- From: Roger Mason <rmason@sparky2.esd.mun.ca>
- Function in a package