If you evaluate the following code twice, results will be different. Can anyone explain what’s going on?
findHull[points_] := Module[{},
Needs["ComputationalGeometry`"];
ConvexHull[points]
];
findHull[RandomReal[1, {10, 2}]];
Remove["Global`ConvexHull"];
findHull[RandomReal[1, {10, 2}]]
The problem is that even though the module is not evaluated untill you call
findHull, the symbols are resolved when you definefindHull(i.e.: The new downvalue forfindHullis stored in terms of symbols, not text).This means that during the first round,
ConvexHullresolves toGlobal`ConvexHullbecause theNeedsis not evaluated.During the second round,
ComputationalGeometryis on$ContextPathand soConvexHullresolves as you intended.If you really cannot bear to load
ComputationalGeometrybeforehand, just refer toConvexHullby its full name:ComputationalGeometry`ConvexHull. See also this related answer.HTH