I am writing a package in which I have some constants defined inside a With
block, which are then used by various functions defined inside that block.
Separate to this, I have an .mt
file which contains tests for these various functions.
However, on occasion, I need access to those constants in my test file. Is there some way of referring to them directly rather than having to redefine them in my .mt
file, which is what I am doing currently.
many thanks for your help
With[]
. $\endgroup$With
block, assigning to them the values those constants have. You can do that conditionally using some variable like$debugMode
to control that. You can have those variables private to your package (which will naturally happen if they are in the implementation part of the package). You will then be able to access those variables from outside. However, any need to access them from outside may indicate that perhaps you should make them generally globally accessible, or reconsider your design. $\endgroup$Cases[ImportString["With[{c = 42,g=9.81}, Block[{bla}, bla = const]]", "HeldExpressions"], With[a_List, __] :> Inactivate[a, Set], -1] // Flatten
$\endgroup$