Tag Info

New answers tagged

4

I found, in the "Applications" section of the documentation of ClearAll, this authoritative recommendation: Unprotect and clear all symbols in a package, to allow it to be read twice: Begin["`Private`"]; Unprotect["`*"]; ClearAll["`*"]; f[x_] := x^2 Protect[f]; End[]; I don't see this advice in the guide here for Setting up Wolfram Packages, ...


3

This is messy and imperfect, but it will work in simple cases: Import the package contents: pack = ImportString[data, {"Package", "HeldExpressions"}] (* {HoldComplete[BeginPackage["Test`"]], HoldComplete[testFunction::usage = "-";], HoldComplete[Begin["`Private`"]], HoldComplete[testFunction[] := {123, explicitvalue, Hold[explicitvalue]};], ...


5

We can replace something, in all definitions associated with a symbol, using function like this: ClearAll[replaceExtendedDefinition] SetAttributes[replaceExtendedDefinition, HoldFirst] replaceExtendedDefinition[sym_, rules_] := Replace[ Language`ExtendedDefinition[sym] , (rule:Rule | RuleDelayed)[lhs_, rhs_] :> ...


3

When using automatically generated packages I am selective about which Cells I mark for Initialization and therefore transference to the package file. I don't find the need to include ClearAll in such cases. I do use a Unprotect / Protect paring which at least prevents additional definitions from accidentally being made elsewhere. A case where ClearAll ...


3

Another possibility with built-in functions: (* Define the process *) proc = ItoProcess[\[DifferentialD]s[t] == \[Mu] s[t] \[DifferentialD]t + \[Sigma] s[t] \[DifferentialD]w[t], s[t], {s, s0}, {t, 0}, w \[Distributed] WienerProcess[]] Now the process can be used as: Expectation[z, z \[Distributed] proc[t]] (* E^(t \[Mu]) s0 *) ...


2

A comment from @Diogo brought me on the right track: In[1]:= <<ItosLemma` In[2]:= dS=ItoMake[S[t],\[Mu] *S,\[Sigma]*S] Out[2]= dt S \[Mu]+S \[Sigma] Subscript[dB, 1] In[3]:= ItoD[Log[S[t]]] Out[3]= dt (\[Mu]-\[Sigma]^2/2)+\[Sigma] Subscript[dB, 1]


5

A Mathematica package is just a file with the .m or .wl extension that contains Mathematica expressions. Get will simply evaluate these expressions. The "Run Package" button will simply evaluate everything in the package file. It's equivalent to Get["/path/to/mypakcage.m"]. The "Update" button rebuilds the Function and Section menus just left of this ...



Top 50 recent answers are included