ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 23 Mar 2019 18:51:23 +0100Is there any way to inject a variable in the local environment of a function ?https://ask.sagemath.org/question/45887/is-there-any-way-to-inject-a-variable-in-the-local-environment-of-a-function/Inspiration: in [this recent question](https://ask.sagemath.org/question/45870/3d-line-from-equations-to-parametric/), the author looked for a way to act on variables introduced by a function call (this happens in some Maxima or Sympy functions such as `solve` or `desolve`, which need to introduce constants, for example).
It is (relatively) easy to wrap such calls detecting and creating such "new" symbolic variables. It is also easy to inject them in the global namespace. See my answer for a first (somewhat awkward) proposal.
But the case may be thatr these variables are useful in the context of a function wrapping the call to a maxima- or Sympy-derived function, but irrelevant to the global context. Example : the solution to a variational problem might involve calls to `desolve`, in which such constants are created, the used later on to solve for boundary conditions. At this poiont, the created variables are no longer useful.
It would be therefore useful to inject the new variables in the calling function's local namespace. But I do not know how to do this.
Ultimately, I'd like to write a context for such variable-generating calls managing such new variables.
Any suggestions ?Sat, 23 Mar 2019 18:51:23 +0100https://ask.sagemath.org/question/45887/is-there-any-way-to-inject-a-variable-in-the-local-environment-of-a-function/