Comment seems to cause compiler error


#1

This is odd. Looks like commenting out an entry in the array causes a parse error. I found this trying to do exactly that in my code, i.e. commenting out an entry to replace it with a more up-to-date set of values.

julia version 1.0.0

x= [(:test,
     [("A",
       "B",
       "C")
      #,("Should",
      #  "not",
      #  "matter")
      ,("D",
        "E",
        "F")
      ,("G",
        "H",
        "I")
      ])]

println(x)

ERROR: LoadError: syntax: unexpected comma in matrix expression
Stacktrace:
 [1] include at .\boot.jl:317 [inlined]
 [2] include_relative(::Module, ::String) at .\loading.jl:1038
 [3] include(::Module, ::String) at .\sysimg.jl:29
 [4] exec_options(::Base.JLOptions) at .\client.jl:229
 [5] _start() at .\client.jl:421
in expression starting at C:\Users\denheyeb\Documents\khaleesi_pv\src\julia\test.jl:8

Now take the comment out…

x= [(:test,
     [("A",
       "B",
       "C")
      ,("D",
        "E",
        "F")
      ,("G",
        "H",
        "I")
      ])]

println(x)

Tuple{Symbol,Array{Tuple{String,String,String},1}}[(:test, [("A", "B", "C"), ("D", "E", "F"), ("G", "H", "I")])]

#2

ah. i should point out that shuffling the commas so that the are at the end of each tuple instead of at the beginning fixes the problem.


#3

This is because, within [], Julia has meaningful whitespace. For example

julia> [1 2
        3 4]
2×2 Array{Int64,2}:
 1  2
 3  4

I can’t tell you in detail what the parser has understood so far at the moment it throws the error, but I think this example should at least convince you that whitespace / comments do matter.


#4

oh, right, that makes sense. putting in the comment makes that region look like “whitespace”.

having the comma at the end of the tuple probably puts the parser into a state that makes it ignore whitespace until it sees the next expression, or something like that.