Function in a package
- To: mathgroup at smc.vnet.net
- Subject: [mg42493] Function in a package
- From: Roger Mason <rmason at sparky2.esd.mun.ca>
- Date: Fri, 11 Jul 2003 02:57:54 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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
- Follow-Ups:
- Re: Function in a package
- From: Dr Bob <drbob@bigfoot.com>
- Re: Function in a package
- From: jmt <jmt@dxdydz.net>
- Re: Function in a package