[Date Index] [Thread Index] [Author Index]
Re: package impasse?
> In previous postings, I described in more or less detail a problem I > have with implementing a package. Please tell me if my conclusion > about this is correct. > > A user defines a certain function f, which in turn may reference other > user-defined objects g and c. These _other_ names are unknown to the package > designer (me)! > > The package doesn't export anything. What it does do is evaluate the > user's f at certain arguments supplied within the package. > > Since the user-defined objects upon which f depends have names unknown > to the package, the StartPackage expression must be of the form > > StartPackage["thepackage`", "Global`"] > > Hence (and this is what I'm asking about): there is NO WAY to prevent > name clashes between objects created within the package and objects > created by the user -- other than the package's trying to use very > cryptic and obscure names, of course. > > If the user's f was self-contained, or depended only upon objects > whose names were known in advance to the package designer, then of > course there's no problem: avoid including "Global`" in StartPackage > and instead refer to f within the package as Global`f. But that's not > the realistic situation here. > > If I am correct, then this seems a fatal shortcoming of Mathematica's > implementation of namespaces via contexts. > > If I am incorrect, then I anxiously await a solution! > > -- > Murray Eisenberg Internet: murray at math.umass.edu > Mathematics & Statistics Dept. Voice: 413-545-2859 (W) > University of Massachusetts 413-549-1020 (H) > Amherst, MA 01003 Fax: 413-545-1801 ======================================================================= I'd afraid that I don't understand the question. I gave it a good effort, reading your message a couple of times and everything, and I still wasn't able to figure it out. Perhaps the following question will help to illustrate my lack of understanding: If the function f is self-contained, then why does the package designer care about symbols that are used within the definition of f? The context system certainly isn't perfect, but I'm not aware of anything that might qualify as a "fatal shortcoming", or of any situations where I can't get what I want by using some variant of package design or through manipulation of the context search path. One discussion of this (including an alternate package design) can be found in "Mathematica: A Practical Approach" by Nancy Blachman. Dave Withoff Wolfram Research