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)


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}


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]];

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];


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;


getSidePattern[spec_:getSpecPattern[]] := Module[{speciesPat, sidePat},
    speciesPat = getSpecPattern[];
    sidePat = (speciesPat ~~ "+")...~~ getSpecPattern[spec] ~~("+" ~~ speciesPat)...;   


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]; 


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]];


In the webMathematica page I have the following (The msp:evaluate tags seem to get hidden, but each line is enclosed by them:



The output from loading this page is

General KernelData0:: 

If I change ?UtilitiesTest to ?UtilitiesTest`Private

The output is

General KernelData0:: 

1 Answer 1


Problem solved by restarting the Mathematica Kernel - Once a package has been loaded, the kernel that loaded it will not clear the defined symbols, even if the package file has changed. Useful for a production environment, but annoying when developing. Some changing of configuration might alleviate this, though I have not tested these:

  • Set KernelAcquireLimit to 1, so that the kernel is released after every page loads
  • Clear all the symbols in the package in either KernelAcquireCode or in KernelReleaseCode

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.