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
1
vote
0answers
50 views

Begin[] again (V12.1)

Some questions related to $Context and $ContextPath have already been asked and answered, but I still cannot fully grasp the ...
0
votes
0answers
42 views

wrong syntax in very short package

Here is a very short package ...
1
vote
0answers
43 views

How to understand BeginPackage and Begin properly?

Using Get to evaluate these three .wl: First: ...
1
vote
1answer
31 views

What is my current scope if I change `Inspector>Cell options>Evaluation options>CellContext` to “Notebook”?

I mean I made this change: Now, Clear["Global`*"] and Names["Global`*"] are not working anymore. I tried ...
6
votes
1answer
129 views

What is the correct to have package A use package B in its private section without making B visible to the user?

V 12.1 on windows. I am loading pkg2, which in its Private section loads pkg1 in order to call one of its function. After ...
4
votes
2answers
56 views

Move definition from one context to Global`

Suppose we have the following package ABC.wl. BeginPackage["ABC`"] Begin["DEF`"] f1 = 0; f2[x_] := x + 1 End[] EndPackage[] ...
0
votes
1answer
37 views

How to load expressions into a notebook with a different context

So because I wanted my multiple notebooks to not interfere with each other, I start them with: SetOptions[EvaluationNotebook[], CellContext -> Notebook] ...
3
votes
0answers
23 views

Details about using packages with Wolfram Player

Is there a definitive document that describes the differences between what's allowed in Mathematica and Wolfram Player? I'm seeing differences in behavior between references to variables in packages (...
2
votes
0answers
38 views

Is there a function that reverts or undoes the effects of Needs? [duplicate]

Needs is used to load packages. Is there a function that cleans all the Definitions and ...
1
vote
0answers
42 views

Numerical Derivative ND doesn't work [closed]

I have entered the following code from the ND documentation, and get the wrong answer. ...
2
votes
0answers
45 views

Share package functions without sharing context

I'm trying to find a solution to a problem that I've been struggling with for a while. I asked a variant of the question here: Automatically load init.m without sharing CellContext, but think I've ...
5
votes
1answer
51 views

What is the proper way of setting ` CellContext -> CellGroup` in the Wolfram Cloud Notebook?

I want a different evaluation context for different sections of my Notebook.Mike Honeychurch suggested to me than changing the CellContext to ...
1
vote
2answers
63 views

How to keep symbol bindings local to a Notebook section?

I'm using the Notebook on Wolfram-Cloud as a ... well ... notebook to keep notes about the topic I'm studying and to answer exercises. I usually keep one notebook file per chapter, with course notes ...
6
votes
2answers
120 views

Operators without built-in meaning are incompatible with parallel evaluation

Mathematica has a useful set of Operators Without Built-In Meanings. For example: CenterDot, CircleDot, ...
1
vote
0answers
45 views

ClassifierFunction output dependent on current $ContextPath

I'm trying to use Classify to predict heads in a Mathematica expression from the heads of its arguments, which may be functions whose heads are not on the current <...
2
votes
2answers
98 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
68 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 ...
11
votes
4answers
681 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 ...
8
votes
0answers
53 views

Dealing with over eager shadowing messages

...
4
votes
1answer
61 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
72 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
97 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
524 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
50 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
79 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 ...
5
votes
1answer
656 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
94 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
26 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
148 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
39 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
94 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 ...
4
votes
1answer
89 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 ...
5
votes
1answer
208 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
57 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
95 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
47 views

Unexpected behavior of NotebookDirectory

The following code prints a message about a symbol in multiple contexts (MMAv9). ...
5
votes
1answer
142 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
51 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
81 views

Context of SQLBinary in Package

I have the following code for a simple key value store for binary data: ...
2
votes
0answers
105 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
601 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
53 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
143 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
124 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 ...
12
votes
1answer
467 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
181 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
561 views

Begin[“`Private`”] vs Module

So, if you have a package formatted like so: ...
4
votes
0answers
68 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
185 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 ...