Julia has no static
keyboard. In C
, a static
variable inside a function has a value that persists over function calls.
One way to emulate this in Julia is with a global
variable. This has two limitations: first, this pollutes the global scope; second, a global variable should be const
for performance, since its type cannot be annotated. What if I want a non-const static variable?
Is there a way to emulate a local static variable in Julia?
Local in the sense that it should be visible only inside the scope of the function that uses it.