I have run into a problem that is currently stumping me. I'm running a WebMathematica server, and am trying to create a package to use on one of the pages. However, when I load the package, it appears to only load some of the public functions, and loads the rest of the public functions as belonging to the Private page, and the functions in the Private functions that are not revealed don't seem to be loaded at all.
I'm including the entirety of the code here, because I honestly can't tell where my mistake could be... (I should note that this is running on Mathematica 5.2)
BeginPackage["UtilitiesTest`"]
revToIrrev::usage = "Takes a reaction string,
and if it is a reversible reaction returns a list
in the form {forward, backward}
Otherwise, it returns the reaction.";
getSpecies::usage = "Takes a reaction and
returns a list containing every species within that reaction.";
isValidRxnStr::usage = "Takes a reaction and
returns true if the reaction is correctly formatted.";
replaceWithVars::usage ="test";
getRxnSide::usage = "Test2";
generateVars::usage = "Generates a list of {species, variable}
pairs.";
Begin["`Private`"]
generateVars[specs_] := Module[{specList = specs},
specList = specList /. spec_ -> {spec, "Elem"};
Return[Table[{specList[[1]], Append[specList[[2]], i]}, {i, specList//Length}]];
];
replaceWithVars[exprStr_, vars_] := Module[{repExpr = exprStr, varList = vars, repRules},
repRules = Table[{varList[[i,1]]->varList[[i,2]]}, {i, varList//Length}];
Return[StringReplace[repExpr, repRules]];
];
replaceVars[expr_, vars_] := Module[{repExprStr = expr, varList = vars, repRules},
repRules = Table[{varList[[i,2]]->varList[[i,1]]}, {1, varList//Length}];
Return[StringReplace[repExprStr, repRules]];
];
revToIrrev[rxn_] := Module[{rxnParser},
rxnParser[react__ ~~ "" ~~ prod__] := Module[{},
Return[{react ">" prod, prod ">" react}];];
rxnParser[react__] := Module[{}, Return[react]];
Return[{rxnParser[rxn]}];
];
getIrrevRxnList[rxns_, seperator_:"|"] := Module[{splitRxns},
splitRxns = StringSplit[rxns, seperator];
Return[Flatten[Map[revToIrrev, splitRxns]]];
];
getSpecies[rxn_] := Return[Union[getReactants[rxn], getProducts[rxn]]];
getRxnSide[front__ ~~ "" ~~ back__, "front"] := Return[front];
getRxnSide[front__ ~~ "" ~~ back__, "back"] := Return[back];
getRxnSide[Except[__ ~~ "" ~~ __, front__ ~~ ">" ~~ back__], "front"] := Return[front];
getRxnSide[Except[__ ~~ "" ~~ __, front__ ~~ ">" ~~ back__], "back"] := Return[back];
getSumSpeciesWithCoeffs[sum_] := Return[StringSplit[sum, "+"]];
getSpeciesWithCoeffs[rxn_, type_] := Module[{rxnString = rxn, specString, specs},
specString = getRxnSide[rxnString, type];
specs = getSumSpeciesWithCoeffs[specString];
Return[specs];
];
splitCoeff[coeff:(NumberString||"") ~~ spec:(LetterCharacter ~~ WordCharacter...)] :=
If[coeff === "", Return[{1, spec}], Return[{ToExpression[coeff], spec}]];
getReactantsWithCoeffs[rxn_] := Return[Map[splitCoeff, getSpeciesWithCoeffs[rxn, "front"]]];
getProductsWithCoeffs[rxn_] := Return[Map[splitCoeff, getSpeciesWithCoeffs[rxn, "back"]]];
getReactants[rxn_] := Return[Map[getSpec, getSpeciesWithCoeffs[rxn, "front"]]];
getProducts[rxn_] := Return[Map[getSpec, getSpeciesWithCoeffs[rxn, "back"]]];
getSpecPattern[] := Return[NumberString|"" ~~ LetterCharacter ~~ WordCharacter...];
getSpecPattern[spec_] := Return[NumberString ~~ spec];
getSpec[specStr_] := Module[{spec},
specStr /. ((NumberString|"") ~~ spec: (LetterCharacter ~~ WordCharacter...)) -> spec;
Return[spec];
];
getSidePattern[spec_:getSpecPattern[]] := Module[{speciesPat, sidePat},
speciesPat = getSpecPattern[];
sidePat = (speciesPat ~~ "+")...~~ getSpecPattern[spec] ~~("+" ~~ speciesPat)...;
Return[sidePat[]];
];
isValidRxnStr[rxn_] := Module[{sidePat, posPat},
sidePat = getSidePattern[];
posPat = sidePat ~~ (""|">") ~~ sidePat;
Return[StringMatchQ[rxn, posPat]];
];
removeInvalidRxns[rxns_] := Module[{rxnList = rxns, goodPos},
goodPos = Position[rxnList, {_?isValidRxnStr,_NumberString,(_NumberString)|NULL}];
rxnList = Extract[rxnList, goodPos];
Return[rxnList];
];
isReactant[rxn_, spec_] := Module[{fullPat},
fullPat = getSidePattern[spec] ~~ (""|">") ~~ getSidePattern[];
Return[StringMatchQ[rxn, fullPat]];
];
isProduct[rxn_, spec_] := Module[{fullPat},
fullPat = getSidePattern[] ~~ (""|">") ~~ getSidePattern[spec];
Return[StringMatchQ[rxn, fullPat]];
];
decomposeRxnInfo[rxns_] := Module[{rxnList = rxns, parseRxn},
rxnList = removeInvalidRxns[rxnList];
rxnList = Flatten[Map[revToIrrev, rxnList]];
Return[NULL];
];
End[]
EndPackage[]
In the webMathematica page I have the following (The msp:evaluate tags seem to get hidden, but each line is enclosed by them:
Needs["UtilitiesTest`"]
?UtilitiesTest`*
The output from loading this page is
General KernelData0:: getSpecies isValidRxnStr revToIrrev
If I change ?UtilitiesTest to ?UtilitiesTest`Private
The output is
General KernelData0:: UtilitiesTest`Private`generateVars