I’m a bit confused about the rules concerning tuples, parentheses, commas, and how Julia interprets them.
Could someone explain to me the following behavior?
julia> (1.0, 2.0) == (1.0, 2.0) # Nice
true
julia> (1.0, 2.0) .== (1.0, 2.0) # Charming 🤩
(true, true)
# Surprising perhaps:
julia> (1.0, 2.0) == 1.0, 2.0 # I get it, stuck at the comma
(false, 2.0)
julia> (1.0, 2.0) .== 1.0, 2.0 # Sum of the last previous, fine
((true, false), 2.0)
# I am completely lost in those two:
julia> 1.0, 2.0 == 1.0, 2.0 # WTF?
(1.0, false, 2.0)
julia> 1.0, 2.0 .== 1.0, 2.0 # Same?
(1.0, false, 2.0)
There are places where Julia is more pedantic than, e.g., Python when it comes to parentheses, and this seems to be the case. I’m used to assignments like
julia> a, b = 1, 2
(1, 2)
julia> a
1
julia> b
2
It is OK to use (...)
in for
loops like (Python won’t require them),
julia> for (i, a) in enumerate("confused by tuples")
println("$i: $a")
end
1: c
2: o
3: n
4: f
5: u
6: s
7: e
8: d
9:
10: b
11: y
12:
13: t
14: u
15: p
16: l
17: e
18: s
But the examples on tuple comparison above confuses me a bit. Julia’s parser seems a bit “greedier” than Python’s, if that makes sense. What are the exact rules concerning tuples, parentheses, commas, etc.?