I’m running a simple find_zero(), and to help me identify errors the core of the function being solved is inside a try/catch circuit:
function getA(input) # then main simulation println("Running 1982 onwards ") try results = S82to20(s82, input, state1981, k81); catch err print(err) println("with input ", input) throw(error()) end cap = results; return f(cap) end solution = find_zero(getA, iniInput)
However, I get the error “results not found”. I understand this is a scoping problem, and the easiest fix is to prefix “global” inside the try/catch. But I only want “results” to fall within function scope, not universal scope. So my questions are:
- If I prefix “global”, does that place results in function scope or top-level scope?
- If the former, how would I (hypothetically) place it in top-level scope instead?
- If the latter, is there an alternative to “global” that places it in function scope?