Declaration of variables

How is a variable declared as a simple Float64, say, without initializing it?
Something like A= Array{Float64, 0}(undef), which works for vectors.

You don´t . A Float64 is an immutable value, meaning that there is nothing that is its “existence” except its value. What you can is define its scope without giving it a value:

function f()
    local a
    for i in 1:3
        if i == 1
            a = 1 
        end
        a = a + 1
    end
    return a
end

(the function above errors if you remove local a because then a is not initialized in the second iteration of the loop, as the scope of a would be limited to the first iteration).

ps: You could there also use local a::Float64 to specify the type of a).

1 Like

To nitpick I think isbits is a better abstraction than isimmutable here. Regardless a Float64 is represented by exactly eight bytes, and all those 2^64 possible values correspond to a double precision number, so there’s no space to encode the state of not being initialized.

1 Like