Re: Function Works in Notebook NOT Package

*To*: mathgroup at smc.vnet.net*Subject*: [mg86565] Re: Function Works in Notebook NOT Package*From*: Szabolcs Horvát <szhorvat at gmail.com>*Date*: Thu, 13 Mar 2008 20:52:59 -0500 (EST)*Organization*: University of Bergen*References*: <fras5u$19s$1@smc.vnet.net>

What do you mean when you say "it does not work"? If you at least provided a sample input, and explained what kind of output you were expecting, then you would spare us the trouble of having to read a long and uncommented piece of code full misused ToStrings. I get the same output for random 2D matrices, no matter if I define the function in the front end or load it from a package. But I wouldn't be surprised if that MakeExpression caused trouble. Strings are converted to expressions with ToExpression, not MakeExpression. Andrew Beveridge wrote: > Any help would be appreciated. > > I am using Mathematica 5.2. > > I wrote a function that compares rows in a 2D array. If the > individual values of the rows are within some tolerance, for example > 15%, it is considered a match. Within 15% tolerance of what? What does the function return? Please provide an exact description of the problem. > > Since I do not know many elements will be in each row, I had to write > a conditional for any value of elements. There is probably a better > way of doing this, any suggestions welcomed. > > Anyway the following function works fine IF I evaluate it in a > Notebook. When I try to place it in a package file it does not work. > It appears the replacement rules are not working. > > Why does not it work in the package file? > > Function: > > PreliminaryAlignment[x_List, percentTolerance_] := > Module[ {ListLength,numLength, correctForm,numData, > blankTable,lowerLimit, upperLimit, conditionalTable,stringConditional}, > > correctForm =SameQ@@(Length/@x); > numData = Rest/@x; > ListLength=Length/@numData; > numLength = First[ListLength]; > lowerLimit = ToString[ 1 - percentTolerance]; > upperLimit = ToString[1 + percentTolerance]; > > If[correctForm=== False, Return[$Failed], > > blankTable = "z:Table[_, {"<>ToString[numLength]<>"}]"; > conditionalTable = > Table["LessEqual[Times["<>lowerLimit<>",Part[kkk, j, " <> ToString[i] <> > "]], Part[z," <> ToString[ > i] <> "], Times["<>upperLimit<>", Part[kkk, j, "<>ToString[i]<>"]]] > " , {i,1,numLength}] ; > > stringConditional = > MakeExpression[ blankTable <> "/; And[" <> \ > StringReplace[ToString[conditionalTable]<> "]", {"{"\[Rule] " ", > "}"\[Rule] ""} ] ] ; > > Union[ Table[Flatten[ > Position[numData, ReleaseHold[ > stringConditional/.{kkk\[Rule] numData,j\[Rule]l} ] ] ],{l,1, > Length[numData]} ] ] > > ] > > ] > > > > Andrew C Beveridge > MS M888 > Los Alamos National Laboratory > Los Alamos, NM 87545 > > 505-665-2092 > e-mail: acbev at lanl.gov