Package import problem in mathematica?

As belisarius points out, your question as it stands is a bit v5-centric. The problem, however, still exists in current versions. As an example.

As belisarius points out, your question as it stands is a bit v5-centric. The problem, however, still exists in current versions. As an example Needs"Combinatorica`" ToCycles{3, 4, 1, 2} works fine, while (after restarting the kernel), Needs"Combinatorica`"; ToCycles{3, 4, 1, 2} fails with an error that "ToCycles::shdw: Symbol ToCycles appears in multiple contexts {Combinatorica`,Global`}; definitions in context Combinatorica` may shadow or be shadowed by other definitions."

In Mathematica terms, the reason the one-liner doesn't work is that Mathematica tries to resolve all symbols in the line before evaluating Needs (this was a surprise to me). This resolves ToCycles to Global`ToCycles (thus entering this symbol in the symbol table), before Needs gets a chance to load the definition of Combinatorica`ToCycles and add Combinatorica to the $ContextPath. To make the one-liner work, you must use the full name of ToCyles: Needs"Combinatorica`"; Combinatorica`ToCycles{3, 4, 1, 2} To understand the error, you need to know that all Symbols in Mathematica have a full name of the form context`name.

A context is similar to a namespace in many other languages. Now, if a symbol (such as ToCycles) is referenced without a context, Mathematica will look through the contexts currently in $ContextPath and see if the symbol is defined in any of those contexts. If not, the symbol is resolved in the current context, $Context which is Global in normal use.

When you load a package, the symbols of that package are defined in a package context (e.g. Combinatorica), and when the package is fully loaded this context is added to the $ContextPath so that you can access the symbols by their short name. Now, you can see what the error means: Since the Combinatorica has not yet been loaded when the symbols are resolved, ToCycles resolves to Global`ToCycles. After the package loads, Mathematica helpfully checks that all short names are unique, and finds in this case that the short name ToCycles is now defined in two contexts on $ContextPath one thus "shadowing" the other.

To refer to a specific of these symbols, you must use the full name, e.g. Combinatorica`ToCycles.To resolve a shadow conflict, simply Remove the unwanted symbol: RemoveGlobal`ToCycles Don't know how readable this was, but hope it helps a bit...

Many thanks! – Qiang Li Jan 12 at 2:19 Well explained! It is a bit surprising that the naive 1-liner doesn't work.

– Simon Jan 12 at 2:19 1 @Quang Li: It has to be a "backtick" between Combinatorica and ToCycles, but it took me a while to figure out how to enter a literal backtick in my answer. Should be ok now? Also, I added the correct one-liner before I even saw your comment :) – Janus Jan 12 at 2:26 @Simon: Thanks!

It surprised me as well. Always thought that semicolons and line breaks were completely interchangeable... – Janus Jan 12 at 2:28 +10 Never happened to me ... just because I always use Needs in a line on its own ... Good to know why! – belisarius Jan 12 at 3:21.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send