Sure, I think so. Should I assume the “state” is (or could/should be) a global const? If so, you could make it e.g. a mutable struct (or a dict, etc.) so that its parameters can be redefined if needed. For example
# inside General
const STATE = Dict(:g => 9.8)
some_calc(x) = 0.5 * x * STATE[:g]^2
# if you already have a version with st, like you said,
# you can have global state as the default, with optional
# second argument
some_calc(x, st = STATE) = 0.5 * x * st[:g]^2
Then General can also define a method for overwriting the state in case the user needs it to change.
function edit_global_state!(;kwargs...)
for (k, v) in kwargs
STATE[k] = v
end
end
# allows:
# edit_global_state!(g = 11.23)
# to set :g
By the way, the other paradigms I mentioned would still work just fine in the astrodynamics case. For example, a user could do
# let's say Earth is exported for user convenience:
some_calc(parameters, Earth)
# can also set Earth to be default positional:
some_calc(parameters)
some_calc(parameters, General.Jupiter) # not exported
some_calc(parameters, Planet(1,1,1,1)) # user-defined
As a final note, if nothing I’ve said so far is the right fit, (first of all, sorry!) then I really need to know more about the use case to see how it is unique (these are all the most standard and common approaches in Julia). I’m happy to look through source code if you care to post or link.