In Julia, is there a way to pass a variable from a local scope to the enclosing local scope?
- 阅读更多 关于 In Julia, is there a way to pass a variable from a local scope to the enclosing local scope?
问题 I am writing some Julia code, wrapped in a function for performance. I need to pass a variable created in a loop to an outer loop but would like to avoid globals for performance reasons: function f() for i=1:1 for j=1:1 a=2 end println(a) end end f() This throws an error since the scope of the i-loop does not know about the variable a . Definining a first within the scope in question works: function f() for i=1:1 a=0 for j=1:1 a=2 end println(a) end end f() I am not super happy with that