Re: how call a function by same name in 2 different contexts?
- To: mathgroup at smc.vnet.net
- Subject: [mg56849] Re: how call a function by same name in 2 different contexts?
- From: "steve" <nma124 at hotmail.com>
- Date: Sat, 7 May 2005 15:35:09 -0400 (EDT)
- References: <200505040434.AAA06268@smc.vnet.net><d5f5is$6d9$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Omega Consulting wrote: > On May 3, 2005, at 11:34 PM, steve wrote: > > > > I was expecting this output > > > > Context["FourierTransform"] > > SignalProcessing`Support`SigProc` > > System` > > Names["*`FourierTransform"] > or > ?*`FourierTransform > Thanks, this helps. Interesting is that the first command above does not show the full contexts: Names["*`FourierTransform"] {FourierTransform, System`FourierTransform} But the second one (the ?* command) does, which is what I wanted, but I am having hard time cutting/pasting the context string shown from that command output to use in the notebook as it is formatted in different font/display (bold inside a pink box) which means I need to type the context shown by hand and make typos. I need to figure how to make output of ?* command show up as plain text to make it easier to copy. > > Any idea how to handle all of this stuff? I do not think it is nice > > that one package hides away another function of the same name in > > different package. The whole idea of using packages is so that this > > sort of thing should not happen ! > > I cannot see a good way to avoid this. How is Mathematica supposed to > know which function you want to use at any particular point? > By using the full contexts path to each function. I understand this. I was asking how to find these paths, which you showed me, But this is was only part of the question. I am now talking about one name hiding another name. > What the package mechanism should ensure is that the packages aren't > confused. That is if 2 packages have the same symbol, then package A > should never use package B's symbol. > Yes offcourse, but there is more to it. The problem is that in Mathematica, loading package A with function named 'foo' has hidden away function 'foo' in package B. This is the problem What should happen is the following: load package A; (which contain function named 'foo') load package B; (which also contain a function name 'foo' with same signature as A.foo) now if I type foo[]; Then this is ambiguous, which 'foo' to call? A's or B's ? the user must type B.foo[] or A.foo[] What Mathematica is now doing is calling B.foo becuase B just happened to be loaded after A. This is wrong. in a later session if I happen to load package B before A, then I will get different results, assuming both functions 'foo' accept same arguments, and I would have hard time figuring what changed and why the results are now different. In my example, foo was in the System space. I loaded package B (which is the signal processing), then typed 'foo' (which is the FourierTransform functin). Mathematica decided to call foo inside the Signal processing package. This is wrong. do you now see the problem? Mathematica should generate an error saying the call is ambiguous and print the different contexts leading to a function called foo. This is what happens in languages that support packages. This is the whole point of using packages. > You can add new, unambiguous symbols that point to these definitions. > Something like: > > SigTransForm = SignalProcessing`Support`SigProc`FourierTransform > SysTransForm = System`FourierTransform > Ok, that helps. But this does not solve core problem being discussed. thanks, Steve
- References:
- how call a function by same name in 2 different contexts?
- From: "steve" <nma124@hotmail.com>
- how call a function by same name in 2 different contexts?