# Tag Info

10

I can now offer a solution which leverages the full power of the code formatter, in its new, more robust form. Load the formatter: Import["https://raw.github.com/lshifr/CodeFormatter/master/CodeFormatter.m"] Some examples: CodeFormatterSpelunk[RunThrough] CodeFormatterSpelunk[PacletManagerCreatePaclet] In the last example, using MakeBoxes ...

9

Well, here is a suggestion: you can overload Needs using Villegas-Gayley trick. To do this safely, here is a generator for local environments, where Needs will be overloaded: createTraceEnvironment[context_String]:= Module[{inNeeds}, Function[ code, InternalInheritedBlock[ ...

9

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 ... 7 The iterator variable in the package lives in the context that your package sets (in this case, mypackagePrivate), but the call to ParallelTable from inside your package does not distribute the definitions in your package, because the parallel functions only distribute contexts that are listed in$DistributedContexts. This is by default set to $Context, ... 6 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 ...

6

Here is an alternative: ClearAll[f]; SetAttributes[f, HoldAll]; f[a_Symbol] := Block[{$ContextPath = {"Test"},$Context = "Test"}, ToString[Unevaluated@a] ]; It is based on the way Mathematica treats short and long names depending on the current settings of $Context and$ContextPath. The context "Test" must not exist for it to be ...

6

This works, though it'd be nicer to have a built-in way to do it: SetAttributes[fullyQualifiedName, {HoldAll, Listable}]; fullyQualifiedName[a_] := Context[a] <> SymbolName[Unevaluated@a] Some demonstrations: In[4]:= fullyQualifiedName[a] Out[4]= "Globala" In[5]:= foo = 3 Out[5]= 3 In[6]:= fullyQualifiedName[foo] Out[6]= "Globalfoo" In[7]:= ...

5

The problem is that if you pass a symbol, it will be created already during the parsing stage, when you pass it, in the current context. Therefore I suggest to pass its string name instead. This function will do the job: ClearAll[f]; f[symbolName_String, value_, context_] := Block[{$ContextPath}, BeginPackage[context]; ToExpression[ ... 5 It looks like FeynArts did not get patched. Please follow the instructions here, i.e., reinstall fc820.zip and then do :$LoadPhi=True; Needs["HighEnergyPhysicsFeynCalc"]; If I find time I update FeynCalc to include a patched FeynArts. The problem is that some examples in fcexamples do not work with FeynArts 3.7 and I need to have a look at how to fix ...

4

Mathematica packages are isolated, in the sense that ASub need not necessarily be a "sub-package" of A, unless you explicitly make it so. Note that when you call BeginPackage["ASub"], the context path is temporarily changed to just {"ASub", "System"}, meaning it has no idea about functions in A. To fix this, you need to load A in your sub-package ...

4

When you use DumpSave, it stores the expression in Notebook$xyzthedata where the$xyz part is a unique context for that notebook. When you load the file using Get, it restores the expression to the variable in that context. However, there is no guarantee that your notebook will have the same unique context in two different sessions. Your new thedata might ...

4

I often create styles using CellPrint: Once you have created the style definition go to Format > Edit Stylesheet and past this style definition cell into the private stylesheet: You should then see the docked cell in your notebook: But once you give values to your variables it should work You should probably also remove some unwanted stuff from ...

3

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 /. ...

3

I believe this is what you want: f[symname_String, value_, context_] := (Begin[context]; With[{s = Symbol[symname]}, Set[s, value]]; End[]) Then use it like this: f["myvar", 4, "MyContext"] Verify: ? MyContextmyvar Hope that helps

2

The Dump contexts appear to be loaded when .mx files are requested. These are in machine code for a specific system, and are in the same form as the file you will get if you use the function DumpSave. You will find the .mx files in the ../../SystemFiles/Kernel/SystemResources/YourSystem/ folder. These are generally not loaded until you request a function ...

2

Please Try adding AllowShortContext -> False to both InstallService functions. To both: InstallService["http://hpiers.obspm.fr/eop-pc/webservice/server_MATRICE_EOP.php?wsdl", AllowShortContext -> False] and InstallService["http://hpiers.obspm.fr/eop-pc/webservice/server_EOP2.php?wsdl", AllowShortContext -> False] Try the following hard coded ...

1

{context1x, context1y, context1z} = {1, 10, 100} f[input_String] := ( input <> "z" <> "=" <> ToString[ ToExpression[input <> "x"] + ToExpression[input <> "y"] ] ) //ToExpression f["context1"] context1z EDIT: now that we've established that we are trying to define methods on structures, let's create ...

1

Problem solved by restarting the Mathematica Kernel - it seems like an old version of the file was cached at some point and wasn't being reread. This appears to be a recurring problem, and restarting the kernel is the only way I've found to fix it. I'll leave this open for the moment, in case someone knows a good fix for this/reason why this occurred.

1

As Leonid Shifrin said in his comment, you can use SymbolName and ToExpression to get the values in each context. {Context1x, Context2x} = {"foo", 42}; contexttable = {"Context1", "Context2", "Context3"}; ToExpression[# <> SymbolName @ Unevaluated @ x] & /@ contexttable {"foo", 42, Context3`x}

1

I should mention that I eventually resolved this confusion. Fultz's answer (referenced above) said Separate the examples into cell groups. You can use, e.g., Section or Subsection cells to do this I was thinking of cell groups merely as any cells joined by the brackets on the right-side of the screen, and I was manually adjusting the grouping. This ...

1

Actually we do not need Manipulate to look at this issue. Manipulate just confuses things a little. Lets just simplify things more and just use standard Modules Lets make a global a1 symbol with the value -99. Then create a Module with a local a1 symbol of value 1 then display the value of a1 from applying ToExpression to the string "a1". We see the same ...

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