Questions about contexts, which are used in Mathematica to organize defined symbols and avoid conflict between symbols that would otherwise have the same name. They are created when packages are loaded.

learn more… | top users | synonyms

67
votes
6answers
3k views

What is the most convenient way to read definitions of in-memory symbols when we don't have the source files? (Spelunking tools)

Note: I put Simon's implementation on GitHub. Contributions welcome! When trying to read the definition of already defined (package or built-in) symbols using ...
26
votes
3answers
2k views

How to load a package without naming conflicts?

This question applies to any package, but I encountered this problem while working with graphs. There are symbols in the Combinatorica package (such as ...
37
votes
1answer
1k views

Local variables in Module leak into the Global context

From the Mathematica documentation on Module: Module allows you to set up local variables with names that are local to the module. But after using ...
15
votes
1answer
451 views

Is it possible to use Begin and End inside a Manipulate?

May be someone can explain why I can't use Begin["context`"] and End[] inside a Manipulate ...
20
votes
4answers
451 views

Result about Context is inconsistent with the description of “Power Programming with Mathematica”

x = 5; temp`x = 6; Begin["temp`"] {x, Global`x, temp`x} The result in my Mathematica session is {5,5,6}, but it's ...
21
votes
2answers
544 views

Context unique to each group at a specified level

Are there any new tools in v10 that might be applicable to this problem? Recent versions of Mathematica provide the option of having a unique $Context for each ...
22
votes
1answer
3k views

Why are some function names red?

I need to evaluate Needs["GraphUtilities`"] before I can use functions such as GraphPath[]. When I do so, some functions get ...
11
votes
1answer
4k views

How do I create and use Mathematica packages?

I have created a package following the tutorial in Mathematica 8 virtual book. However this tutorial is quite, let's call it, "short". I have a TestPackage.m file: ...
14
votes
1answer
267 views

Potential pollution of Global` context in fresh kernel

Bug introduced in 10.0.0 and fixed in 10.0.1 If I evaluate, with a fresh kernel Names["Global`*"] I get {"rhs", "z"} ...
14
votes
4answers
971 views

Strategies for avoiding and handling shadowing

When dealing with namespaces in Mathematica (BeginPackage, $ContextPath ...) one is unavoidably confronted with the problem of ...
10
votes
1answer
281 views

Context of localised (dynamic) symbols

When you localise a symbol with Module, the created unique symbol is usually in the current context. There seems to be an exception to this which has further ...
12
votes
2answers
236 views

Globally loading packages while using a CellGroup as the default context

I have a notebook I wish to set up where the sections are conceptually related to each other. But, I wish to isolate them from each other programmatically, so that they do not interfere with one ...
14
votes
3answers
263 views

How does $CellContext` work?

The only official info about $CellContext` I was able to find is: placeholder for the context of a symbol inside Dynamic ...
8
votes
2answers
764 views

How to properly handle mutual imports of multiple packages?

I'm new to the mathematica platform and I am developing a simulation framework as my first exercise and have been tearing my hair figuring how to make packages interact with each other. Ill explain a ...
7
votes
6answers
635 views

How can you give a Module a context and have its local variables and Modules belong to that context?

What would be the best way to give a module its own context and have its local variables and Modules belong to that context?
6
votes
3answers
303 views

Scope within Context

To define some package-wide functions/variables, what approach is recommended? I tried to use contexts with the Begin function, but this failed: ...
5
votes
1answer
104 views

Same name for functions in package and Global context

I am using a package that was written for Mathematica 3 while I am now working on Mathematica 8. I have issues with 2 functions in particular, Order and GraphComplement. They are a part of this ...
5
votes
1answer
103 views

Naming conflicts with Dummy variables in several packages conflicts

I'm using several packages in a notebook. In each packages there is functions defined with dummy variables. When I load the several packages in my session, i've got a warning message: ...
30
votes
3answers
372 views

How can I evaluate untrusted Mathematica code in a sandbox?

Is there any way to build a sandbox to evaluate untrusted Mathematica expressions in order to prevent them from having (malicious or accidental) harmful side effects? Context: I'm developing a system ...
15
votes
2answers
204 views

How to find out what files are touched when Get is called?

Is there a way to capture all package files touched whenever a package is called via Get, Needs, ...
11
votes
3answers
235 views

Creating a custom context with a Hold construct

I'm trying to create a function "InContext" to execute a piece of code inside a certain context (and to return the result of evaluating that piece of code). One approach is to place the code inside a ...
8
votes
3answers
799 views

How can I make private functions inside packages

I want to make private functions.for that purpose,I wrote the following code. BeginPackage["Test1`"] Begin["`Private`"] function1[x_]:=x End[] EndPackage[] I ...
10
votes
2answers
216 views

What are the purposes of functions in FrontEnd` context which are duplicates of those in System`?

I noticed that for notebook-related heads, there are usually a pair of same functions, one in System context, another in ...
10
votes
1answer
223 views

Importing an mx file into a context

Consider the following simple code which dumps the global context: var = 5; DumpSave["test.mx", "Global`"]; Now, in a new notebook, I would like to import var in ...
10
votes
2answers
266 views

The introduction for Context in Wagner's book is out of date? [duplicate]

In Section 8.1.1 (P230 of the book, P249 of the PDF) of Wagner's book, the following example is shown: x = 5; temp`x = 6; Begin["temp`"]; {x, Global`x} The ...
6
votes
2answers
232 views

Delete contexts from a string representation of a symbol

I want to delete the string representing the context of a symbol. For info I need such a functionality in my ShowIt function defined here I'd like to know how I ...
4
votes
1answer
336 views

Errors when using ParallelTable inside a package

I'm developing a package that contains a function that requires evaluation of an expensive Table, so I use ParallelTable ...
11
votes
2answers
157 views

Second argument of BeginPackage with nested package loading

I naively thought that the second argument of BeginPackage can simply be used to ensure the loading and availability in the ...
9
votes
2answers
204 views

How to define UpValues in a different context from within a package

I'm trying to create a function (in a package) to import a lot of data and create a symbol with UpValues to return specific results about the data. I've got it working fine in a regular notebook, but ...
8
votes
1answer
160 views

Organizing similar datasets using Contexts or otherwise

I often import several long time series to analyze something about a city. When I have multiple cities, I use contexts. As a simple example, ...
4
votes
1answer
102 views

Can a package append its context to $DistributedContexts?

I am writing a package (for reference, this one) which I use extensively in parallel computations, and to lighten the coding load on the 'run-time' notebook, I want my package to sit on the ...
1
vote
1answer
110 views

how to make cells independent with each other in notebook

If we open DocumentationCenter and then run code, we will find that the Cells are independent from each other. For example: ...
11
votes
2answers
217 views

For any symbol, how can I get the full context-qualified name of the symbol as a string?

I'd like to have a function, whether built-in or not, that when given a symbol, whether bound to a value or not, returns a string giving the context and name of the symbol. Example: ...
5
votes
3answers
96 views

How can I pass replacement rules to a package-defined function and have it understand their context?

I am writing a package where I would like to be able to pass replacement rules to a function inside the package and have the function manipulate its symbols using those replacement rules. However, I'm ...
3
votes
1answer
52 views

Behavior of Remove inside a Package

I have a notebook containing (in a Code cell, Initialization Group) ...
3
votes
1answer
193 views

automatically add Global` to $ContextPath for all notebooks when using CellContext->Notebook

I have some definitions in my init.m. E.g. my init.m contains this: ...
1
vote
1answer
51 views

Derivative in my package return 0

I'm writing my package (.m) in Mathematica and when I'll call the function returns 0 instead of right output. Here's my code: Package.m ...
0
votes
0answers
104 views

Setting individual CellContext for each notebook loses autocomplete suggestions

I'm running Mathematica 9.0.1 under OS X. In order to have separate contexts for each of my notebooks, I used the instructions in the last part of the accepted answer from the following link: Is ...