Closed isaacsas closed 3 years ago
We can make the @variables
macro take the runtime value when write it like @variables $t
.
I really like that proposal.
How would I do that in a loop?
term = "par1 + par2/par1"
pars = ["par1", "par2"]
for par in pars
sym = Symbol(par)
@variables $sym
end
ex = eval(Meta.parse(term)) # UndefVarError: par2 not defined
(cc @axla-io)
Sorted. Variables can be defined in a custom module to evaluate symbolic expression as is done in ReactionNetworkImporters.jl here.
Just a proposal; from the perspective of questions like https://github.com/SciML/Catalyst.jl/issues/281 and my own the other day, the current notation for building Syms and Terms programmatically seems complicated:
Would there be objections to adding a few helper functions to simplify this for common use cases? I know @ChrisRackauckas prefers to keep the API smaller, but I suspect this is going to lead to many user questions in the future as understanding the typing here requires going in and reading the SymbolicUtils docs too. (Not to mention it is much more complicated than just remembering
Operation
andVariable
with appropriate args.) Any thoughts?