I am trying to run (someone else's code) that looks like
function f{T<:Number}(n::Int, alpha::T, beta::T)
...
end
When "using" that file I get
UndefVarError: T not defined
Stacktrace:
[1] top-level scope at [file location]:[line number of function definition above]
From what I've read in the documentation (https://docs.julialang.org/en/v1/base/numbers/), it looks like the syntax above is correct. Any idea why I'm getting this error?
This is old Julia syntax. This function should be re-written as follows, or you will need to switch to Julia 0.6 or one of the versions that came before it.
function f(n::Int, alpha::T, beta::T) where {T<:Number}
...
end
I ran the following on Julia 0.7 and here is what I got:
julia> function f{T<:Number}(n::Int, alpha::T, beta::T)
print("Test")
end
┌ Warning: Deprecated syntax `parametric method syntax f{T <: Number}(n::Int, alpha::T, beta::T)` around REPL[1]:2.
│ Use `f(n::Int, alpha::T, beta::T) where T <: Number` instead.
└ @ REPL[1]:2
f (generic function with 1 method)
Here is the link to the general syntax for the where
keyword.
Here is the link to a similar StackOverflow post explaining what the where
keyword does.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With