Questions tagged [contexts]

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.

Filter by
Sorted by
Tagged with
2
votes
2answers
77 views

How to make a contextual variable?

I have a question that would be trivial in OOP, but I am a newbie to programming in Mathematica, so I'm wondering how to deal with it. Basically, I want to create a package which basically involves a ...
1
vote
1answer
42 views

Context issues when using NDSolve and rule substitutions in a package [duplicate]

I have a .wl package and a demo .nb notebook. The package file is testPackage.wl and it ...
10
votes
4answers
535 views

What is the accessibility of a package's `Private` context variables?

I've been reading up on how Mathematica handles contexts, $Context, $ContextPath, and a few of the tutorials they have on ...
7
votes
0answers
43 views

Dealing with over eager shadowing messages

...
3
votes
1answer
42 views

Difference between $Context and Evaluate[Context[]] using DumpSave

If I were to type both individually with // FullForm, It would seem that both are the same: However, in the context for example of a dumpsave: ...
4
votes
1answer
54 views

DumpSave and Notation package

I tried to follow the answer in How to save/load (export/import) symbolized variables?. In my case, I would add the code: ...
8
votes
0answers
82 views

Current $Context of a given notebook

nb = CreateDocument[{Dynamic@$Context}, CellContext -> Notebook] It will show Notebook$$22$93500` or something similar. How ...
6
votes
1answer
182 views

Symbol appears in multiple contexts when loading package

I'm building a Mathematica application "APPStestI" that contains three packages: SUBappsA.m, SUBappsB.m, SUBappsC.m and APPStestI.m. Where APPStestI.m is the main package; SUBappsA.m and SUBappsB.m ...
2
votes
1answer
44 views

What's the difference between $Context<>“*” and “`*”?

When set context unique to this notebook: ClearAll @@ { $Context<>"*" } Clear["`*"] can both clear the variables I assigned. I just wonder what's the ...
2
votes
1answer
75 views

Loading MultivariateStatistics` changes colour of some multivariate distributions to red in notebook. Should I be worried?

I need to use the pdf of a Wishart distribution which is only defined in the package MultivariateStatistics`. However, after loading the package, some or all of the ...
3
votes
1answer
302 views

How to list all user-defined symbols?

I create a lot of symbols, and then I move on to my next set of manipulations. I noticed that symbols from prior sessions are still around. I have no idea how many symbols are in my context, but there ...
5
votes
1answer
74 views

Why does my Package not work when I use ParallelEvaluate?

I am developing a package in Mathematica for finding the conductivity of magnetic materials. The most important and time consuming processes are EigenSystem[] calls. I want to make the code modular so ...
0
votes
0answers
22 views

How can I Get[] a file and keep it in a given context? [duplicate]

I have a large MX file, which I need to Get before running my analysis. The following code puts the symbol in the ...
10
votes
1answer
129 views

Attempts at backwards compatibility

I have written a package in Mathematica 11, and I would like to provide some backwards compatibility to earlier versions. An example is the function Echo. ...
3
votes
0answers
28 views

Problem with contexts [duplicate]

Starting a fresh kernel and writing the following set of commands: Define a new context temp and a variable name x in it. <...
1
vote
0answers
31 views

NotebookEvaluate within cell with CellContext->Notebook

I've encountered the following issue with NotebookEvaluate (note the grouping into 3 distinct cells): ...
8
votes
1answer
89 views

How can I use CurrentValue in packages as it generates symbols in current context?

I just found that CurrentValue[$FrontEnd,"ScreenInformation"] will generate (some of) the symbols it uses as keys in the current context of the first evaluation (it ...
3
votes
1answer
83 views

ThrowAway Environment and Scoping

I want to be able to Get a .wl file. Run some functions (who will do their job working on some separate files that are being written away). And then return to some clean slate so that I can repeat ...
2
votes
1answer
126 views

How to set default for Notebook's Default Context

Every time I create a new notebook, I have to go into the settings and click Evaluation > Notebook's Default Context > Unique to This Notebook. Is there any way to make Mathematica do this ...
1
vote
2answers
56 views

Assigning variables whilst in a context

When working in a context, I would like all variable assignments to happen on symbols in the new context. This doesn't normally happen. For example, ...
2
votes
1answer
80 views

Returning a list of replacement rules from a package function

I am having a go at writing my first package and would like to do something similar to the following. Its a basically a very thin wrapper around NonlinearModelFit. ...
1
vote
1answer
41 views

Unexpected behavior of NotebookDirectory

The following code prints a message about a symbol in multiple contexts (MMAv9). ...
5
votes
1answer
117 views

How to save a context into an expression?

BeginPackage["foo`"]; bar; Begin["`Private`"]; bar[] := bar[ $Context, $ContextPath]; End[]; EndPackage[]; So I'd like to have all information ...
0
votes
1answer
49 views

Unexpected context change

I have a strange problem with Mathematica (10.1.0 for Microsoft Windows (64-bit) (March 24, 2015)). Namely when I evaluate expression ...
4
votes
1answer
69 views

Context of SQLBinary in Package

I have the following code for a simple key value store for binary data: ...
2
votes
0answers
90 views

Get context from notebook

The function Context[] returns the context of the Notebook the function is called in. Is there a function where we can specify e.g a Notebook object and retrieve ...
1
vote
0answers
206 views

Context not created when Needs was evaluated [duplicate]

I'm encountering a problem when trying to write and load my own packages. As a test case, I created a very simple package, TestPackage.m, which contains ...
5
votes
1answer
51 views

De-expose top-level symbols

I have an package with a bunch of symbols, many of which I exposed during development and which are now referenced in other subpackages. At this point, though, I don't want to expose these symbols to ...
2
votes
1answer
117 views

Why is my variable Lambda defined but not the others?

I would like to understand why in the following code, my variable Λ is recognized by the system but not n. In fact for me ...
1
vote
1answer
88 views

Can contexts be used to reuse functions with different variables?

So, I'm trying to create two sets of similar variables, for example: a, b, c. This would be ...
13
votes
1answer
322 views

How to automatically do a computation, Quit[], restart and do a new computation

Related questions have been asked before (eg Where does a package have to be loaded?, https://stackoverflow.com/questions/6152023/quit-kernel-in-mathematica-by-a-command-not-using-evaluation-menu, ...
4
votes
2answers
139 views

How to find variables set through Get[“/some/path/dump.mx”]? [duplicate]

(NB: I could not find any good tags for this post. Please feel free to add better ones.) Suppose that the file /some/path/dump.mx was generated during an earlier ...
6
votes
1answer
378 views

Begin[“`Private`”] vs Module

So, if you have a package formatted like so: ...
3
votes
0answers
61 views

Is the package documentation buggy? [duplicate]

At https://reference.wolfram.com/language/tutorial/SettingUpWolframLanguagePackages.html we read: BeginPackage["Package`"] set Package` to be the current ...
4
votes
1answer
159 views

Context inside Do[…]-loop

Consider the following code: Begin["mycontext`"]; myvar = 7; Print[Context[]]; Print[Context[myvar]]; End[]; with the output mycontext` mycontext` Now ...
-1
votes
1answer
161 views

Using different master kernel in the same notebook

In my notebook, I have to call another file, let's say 'program.m' that defines functions, let's say F[] of whom result c I need ...
30
votes
2answers
1k views

How to make Mathematica variables declarative instead of just-in-time?

Is there a way to have Mathematica at the notebook level (SetOptions[EvaluationNotebook[], CellContext -> Notebook]) only uses a set of declared variables in the ...
10
votes
1answer
190 views

NotebookEvaluate breaks notebook's context

Bug introduced in 10.4.1 or earlier and persists through 11.3 A support case with the identification [CASE:3813108] was created [...] I have forwarded an incident report to our developers with ...
1
vote
0answers
61 views

What can we do with the Dump contexts? [closed]

So we know from here what the *Dump contexts signify and here Rojo found a very useful goody that involves them: ...
3
votes
0answers
93 views

How to resolve a context shadow problem (revised) [duplicate]

I have developed a notebook of 30+ functions for Geometric Algebra, all of which involved using the symbol e with subscripts like Subscript[e,1]. I write them here as e1, e2, e3 ... for readability. ...
4
votes
0answers
47 views

Building the $Context from a stack of Begin and BeginPackage

Assume I'm reading a package file and want to know the current $Context while going serially through the file. I want to do this by inspecting the arguments of each ...
5
votes
3answers
229 views

How does Needs[“foo`”] find the file that defines context “foo`”?

The post's title says it all, but if more detail is needed: Suppose I have the following in some file /path/to/foo.m: ...
0
votes
0answers
127 views

How can I cleanly distribute definitions of system functions?

I have a package that redefines a system symbol, and I am struggling to find a clean solution that will ensure that those redefinitions will still work inside a parallelized environment. The core ...
8
votes
1answer
154 views

Pass symbols through MathLink with full context information

How can I ensure that symbols passed through MathLink retain their full context information? When using MathLink naively, they do not. Demonstration, controlling another kernel: ...
1
vote
1answer
60 views

Organizing Localized Variables and using Context

I have been developing a program that requires me to use LocalizedVariables->False for some variables. However, I am having a difficult time redirecting these ...
6
votes
2answers
218 views

Contexts and parallelization

This question is related to my previous one here. I opened a new question because I think that the root cause is different though. BTW I use MMA 9 on a mac OS X 10.11 (El Capitan). I put here a ...
3
votes
1answer
151 views

Using a Global symbol inside a package [duplicate]

Part I - Without package I have created a function to compute a bridge score. ...
1
vote
1answer
91 views

LeviCivita::shdw when I am loading FeynCalc

I have downloaded FeynArts-3.9 and put it in Applications already. Then, I downloaded FeynCalc using Import[]. After that, I used ...
1
vote
1answer
39 views

Why doesn't Get work on Image`?

Is there another way to get this package to load?
0
votes
0answers
36 views

Using Begin to return to a previously defined context [duplicate]

I am trying to understand how contexts in Mathematica work. Suppose I want to write a block of code in which all newly defined symbols are in a particular context. If I input the following code <...