# Tag Info

13

Here I offer the safe version of Get that can be used successively to collect all the source files and contexts of packages without polluting the memory (too much). What it does I have practically reverse-engineered all the necessary functions (Get, Needs, BeginPackage, Begin, EndPackage and End) so that I could inject the monitoring code for ...

13

It appears since version 3 shadowed variables are given priority, as demonstrated below. In the temp context x is taken as tempx unless Globalx exists. Remove[tempx, Globalx] tempx = 6; Begin["temp"]; {x, Globalx} End[]; {6, x} Remove[tempx, Globalx] tempx = 6; x = 5; Begin["temp"]; {x, Globalx} End[]; {5, 5}

11

This is because of $ContextPath. If the symbol outside the Begin/End is created in a context that is listed in$ContextPath, Mathematica will recognize it as belonging to that context even when called from a different context (even if Begin/End is put in a package file and called via Get): $ContextPath {"DocumentationSearch", "ResourceLocator", ... 11 Not an answer. Just screen shot. I booted up version 2.2 to verify the book result. And it does verify. Something changed since the book was written ! 11 Using Begin and End won't help, because .mx files are lower-level and the way they are loaded is different from normal packages. I was about to say that this isn't possible, but here is a hack which seems to work: ClearAll[loadInContext]; loadInContext[context_String,file_String/;FileExtension[file]==="mx"]:= Module[{tag}, ... 10 This is possible in the interactive session with$PreRead. I will adopt my solution to the same problem posted in this Mathgroup thread. To quote my explanation from there, the essence of the present solution is to delay the parsing of the code (body) that must be executed inside a given context until run-time, that is, replace code ...

10

Since nobody has mentioned it yet... V8 introduced the undocumented flag Debug$ExamineCode. When it is set to true, the information functions will display the definitions of ReadProtected symbols: Debug$ExamineCode = True ??BinLists It is sometimes useful to suppress some of the internal package names to make it easier to scan the definitions. Here ...

9

This behaviour has changed since that book was published. I am writing this additional answer to make it clear how Mathematica 9 searches contexts for symbols and that even the current version 9 documentation is incorrect in describing this. How symbol lookup actually works When you enter a symbol name such as x, Mathematica will check if a symbol with ...

7

As Leonid has explained the problem is that the symbols are created and get their context at parse time, so if you need to avoid generating them in the current (usually "Global") context, using $PreRead as he explained is the only possibility. If you don't care that the symbols you use are created in the current context AND the context you want to evaluate ... 4 Since it was mr. Leonid Shifrin who provided a proper solution, I feel less guilty of my brute-force, very limited try: it adds the context to the first symbol in every Set and SetDelayed. a =.; b =.; c =. context2a =.; context2b =.; context2c =. InContextSetAndSetDelayed := Function[{context, code}, code /. SetDelayed -> f /. ... 4 This is all covered in the documentation. To answer your specific questions: Yes, just call Needs or Get more than once. Yes, by setting up contexts correctly Yes, but in Mathematica they are called Contexts. The issue is likely to be that you did not use a standard package structure to write your packages, including the Begin["Private"]. See the ... 3 The standard way to expose a symbol which is defined within a private context is to define a usage string outside the private context, as in BeginPackage["MyPackage"]; Symbol1 = 1; Symbol2::usage = "Symbol2 is a test symbol"; Begin["MyContext"]; Symbol2 = 2; End[]; EndPackage[]; Actually, any mention of the symbol inside the package but outside the ... 3 For your second question this would define a global aContxt so that it can be used in other notebooks (to be evaluated in the notebook with the private context): GlobalaContext =$Context; Then you can define a new variable like this: SetDelayed @@ Join[Hold[varAnb], ToExpression[aContext <> "varA", InputForm, Hold]] the reason why this looks so ...

2

My previous answer had heavy shortcomings and errors, so I took a deeper breath and figured out a more robust way. The problem with FindFile["context"] is twofold. First, it can only return the first file in a possibly long list of files adding to the same context. Second, it might not work on a context extracted from a symbol because symbol contexts might ...

2

Interpolation is a built-in function located in the System context, which is the same for all Notebooks independently of $Context, hence any changes of Options of this function will be global. But you can define your own function in the local context and set local options for it (see here for explanations): Clear[interpolation]; Options[interpolation] = ... 2 It might be that this is due to dispatch, list and doStuff being completely owned by the frontend, since you wrapped them in a DynamicModule. Frontend variables cannot be shared between kernels. When you localize them in a Module, and therefore keep them as kernel variables, it works: Module[{dispatch, list, doStuff}, list = Range[8]; doStuff[a_] := ... 2 I reported this problem to Wolfram technical support, and I have received the following response (edited for brevity). I was able to reproduce the issue you have reported. I have forwarded an incident report to our developers with the information you provided. I have tagged the question with bugs. Update This bug appears to be fixed in V10.0.1 2 Not each Cell but each CellGroup has separate context. If you create new cell you will get In[2]: You can confirm this thesis with: nb = Select[Notebooks[], "Help" === ("DocumentType" /. NotebookInformation[#]) &][[1]] Options[#, CellContext] & /@ Cells[nb, GeneratedCell -> False, CellStyle -> "Input"] {{CellContext -> ... 2 This is not a complete answer, but here I will suggest a somewhat different way to extract the dependencies, than in Istvan's answer. I think my method is somewhat more economical. The idea is to load the package of interest in a dynamic environment where$Packages variable is reset to {} initially. This will automatically prompt all packages to be loaded ...

1

Just a really quick hack that is nevertheless useful sometimes: LocateFunction[f_]:=(SystemOpen[Context[f]];NotebookFind[SelectedNotebook[],f//ToString]) If applicable, this opens the package relating to the symbol´s context and primes the search (use F3 to search for subsequent locations of the symbol).

1

Problem Solved. If I start Mathematica 10 and immediately run Context["Classify"] it will says Context::notfound: Symbol Classify not found and if I run Context[Classify] note: without quote. Mathematica will tell you: "Global" But When I run Needs["MachineLearning"] and then run Context["Classify"] Mathematica gives System` ...

Only top voted, non community-wiki answers of a minimum length are eligible