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

1
vote
0answers
30 views

How does Context work?

I thought when we type a symbol without specifying its Context, it will search all the Context in ...
39
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 ...
5
votes
1answer
55 views

Prevent autocompletion for symbols in contexts other than “`Private`”

I've been working on a Mathematica package (call it QuantumDot) that has become huge. Right now, all the back-end helper functions are in context ...
12
votes
2answers
168 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 ...
1
vote
1answer
52 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 ...
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 ...
3
votes
1answer
52 views

Behavior of Remove inside a Package

I have a notebook containing (in a Code cell, Initialization Group) ...
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 ...
21
votes
4answers
452 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 ...
1
vote
0answers
21 views

Global context seems to be shared between kernels when using Clear?

I am trying to understand the following behaviour, and determine if it's a bug in Mathematica 10. I am using Mathematica 10.3, and can't reproduce this behaviour under Mathematica 9. The test outlined ...
18
votes
2answers
238 views

How to find the package file that stores a certain symbol?

Is it possible to figure out in what file a certain packaged symbol lives in (assuming there is no shadowing between multiple identical symbol names)? I would like to have a function that if, given a ...
6
votes
2answers
94 views

How to store symbols in a package without being parsed?

I have a package file myPackage.m with the following content: BeginPackage["myPackage`"]; load[] := {a, b, c}; EndPackage[]; ...
9
votes
3answers
444 views

Why doesn't DumpSave work for elements created within a local notebook context?

I recently noticed that when dealing with notebooks with local context, I cannot successfully DumpSave variables, or, rather, when I call ...
30
votes
3answers
374 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 ...
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 ...
5
votes
1answer
105 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 ...
14
votes
3answers
265 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 ...
6
votes
1answer
88 views

Update/refresh notebook variable color on clear

By default, Mathematica displays variable names already assigned as black while new variables are displayed in blue. When executing Clear["Global`*"], variables ...
10
votes
0answers
155 views

Autocomplete of non-global functions

In Mathematica 9 and 10 they added autocompletion. Out of the box this works great, but when I set the CellContext to "Notebook" ...
1
vote
1answer
24 views
2
votes
1answer
99 views

Why must I specify the Global context for a symbol in a private package?

I have written two versions of the function below in a package. When I load the package and call the function, Why does the first version where the variable s has no explicit Context return the long ...
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 ...
4
votes
1answer
1k views

FeynCalc “May shadow or be shadowed by other definitions”

So I've downloaded the latest FeynCalc from this site and put the extracted folder in user/me/library/Mathematica/application, but when I write the command ...
4
votes
1answer
69 views
2
votes
1answer
42 views

Import variable assignments from external files into different contexts

(I use Mathematica 9.0.1 on OS X 10.10.5.) I have two text files. One is named file1.txt with the contents ...
6
votes
1answer
122 views

When I run multiple Mathematica programs from terminal, are they supposed to use different Kernel?

Since I found that when I using notebook interface, I need to assign different kernels to different notebooks (if I want to run them at the same time), I wonder if I run those *.m files from terminal ...
2
votes
0answers
98 views

Shadowing issue with DeleteDuplicatesBy

I have been running a function in Mathematica 10 with the command, DeleteDuplicatesBy. The function was working great until one day I started to get an error with ...
2
votes
1answer
75 views

Removing commands used before loading package

Original Question: I used the convert command before loading the Units package. Convert[20000. Feet, Mile] Since Convert ...
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"} ...
3
votes
0answers
37 views

Context is not clearable and does not reload [closed]

I'm just going crazy with Mathematica Contexts as they absolute do not work as intended. Simple Example: Begin["TEST`"] Hello[s_]:=s Bye[s_]:=s End[] Now using ...
14
votes
1answer
246 views

Global` context not empty at startup in v10.2.0

Bug introduced in 10.2 and persisting through 10.2 or later Note that the analysis of this problem revealed a different problem than in Potential pollution of Global` context in fresh kernel (see ...
3
votes
2answers
108 views
7
votes
2answers
139 views
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 ...
13
votes
2answers
365 views

Why does leaving and re-entering a context lose values defined in that context?

I'm getting unexpected behavior when beginning a new context, leaving it, and then re-entering it. Specifically, when re-entering the context, symbols that had been previously defined in that context ...
3
votes
0answers
38 views

Cross referencing symbols in different packages [duplicate]

I have problems with name space shadowing which I do not know how to resolve. I have two packages which depend on each other. Here is example of two files fooPackage.m: ...
11
votes
2answers
201 views

Why is a symbol still found after changing its context?

It seems that we can change the context of symbols: In[1]:= x = 1 Out[1]= 1 In[2]:= Context[x] = "foo`"; But then x is still ...
2
votes
1answer
115 views

Symbol not added to context

I have run into a problem that is currently stumping me. I'm running a WebMathematica server, and am trying to create a package to use on one of the pages. However, when I load the package, it appears ...
5
votes
0answers
50 views

How is CellContext->CellGroup supposed to work?

After reading the documentation on the subject, I still cannot get CellContext->CellGroup to work. Here's a simple example. (Unfortunately, I cannot easily ...
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 ...
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: ...
0
votes
1answer
74 views

How can I use private variables in different ways

How can I use some private variables/symbols in another sub contexts in different ways. Note: Please do not use code Cell Style for testing the codes. ...
-5
votes
1answer
136 views

Exporting data from different notebooks to a common file

I am doing some calculations from different notebooks. I need to export the results from all those notebooks in columns of the same file, like a1 b1 c1 a2 b2 c2 a3 b3 c3 . . . where a, b ...
3
votes
2answers
105 views

Rewriting symbol context?

I have some code that uses a list of replacement rules to inject values (physical constants for different materials) into a more complicated expression. This is convenient since I can tweak the values ...
5
votes
2answers
291 views

Package Loading: How to get rid of Needs::nocont?

I am trying to create a documentated application inside FileNameJoin[{$UserBaseDirectory, "Applications"}] I obviously dont fully understand the concept of the ...
4
votes
0answers
69 views

Variable not assigned to correct Context [duplicate]

I am trying to understand Mathematica's Context, but I do not understand why the short name of the variable defined in the temp` context (x) returns the Global definition. I am following the section ...
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 ...
3
votes
1answer
112 views
10
votes
1answer
285 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 ...
1
vote
0answers
119 views

NMaximize with matrix input

I defined function f[x_, fixed_] := {...}. Here x is an $M\times N$ matrix. I want to maximize $f$ with respect to $x$. I have ...