Global variable declaration


#1

Hi,
I am having following problem, I don’t understand why though.
Can anybody help

julia> let
       global d1, d2=3, d3::Int, d4::AbstractString = "ddd"
       end
ERROR: syntax: invalid assignment location "3"

#2

The message is somewhat confusing and there’s an open issue about it. The syntax for multiple assignment is a, b = 1, 2 rather than a = 1, b = 2.

In your case you can factor out the variables you want to assign to and use multiple assignment (global d2, d4 = 3, "ddd"), and declare the others separately without initial values as global d1, d3.

Note that at this time Julia doesn’t support type declarations on global variables, so the declarations for d3 and d4 would also not have succeeded here. I don’t think it’s a fundamental restriction, so it may be lifted in the future.