-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add FAQ with correct solution(s) for "static" variables in functions #20353
Comments
Agree this should be documented. But what is the correct solution? |
One is to use a julia> let a = 0
global function f()
a += 1
end
end
f (generic function with 1 method)
julia> f()
1
julia> f()
2
julia> a
UndefVarError: a not defined I am not sure how to make a |
Don't change its value :) |
What if the static variable depends on a type parameter of the function? In this case each specific method should get its own static variable. For example, suppose I want to write something like, global function f(x::T) where {T <: Real}
static a = zero(T)
return a + 1
end In this scenario the above approach of defining |
Why can't the compiler or even lowered code in Julia do the |
cf. #15056, #12627
The text was updated successfully, but these errors were encountered: