Reputation: 4006
Is it possible to define multiple variables with type information in a single line in Julia v0.5+? One can define untyped variables, like so (let's assume the variables are within some function),
x1, x2 = 0.01, 0.5
but adding type information,
local x1 :: Float64, x2 :: Float64 = 0.01, 0.5
fails with an invalid syntax in "local" declaration
error. Am I doing something wrong, or is this kind of syntax not supported at all? TIA.
Upvotes: 3
Views: 342
Reputation: 12051
local
isn't needed in most situations, such as a plain function at top-level.
julia> function f()
x1::Float64, x2::Float64 = 1, 5
x1, x2
end
f (generic function with 1 method)
julia> f()
(1.0,5.0)
Where local
is needed (that is, where the name would otherwise be bound to an outer function), this syntax won't work as far as I know. See #7314.
Upvotes: 3