I have the following (minimized, but perhaps not minimal) code snippet which is intended to group nodes of graph components. The surprising thing is that it seems to imply that elements of a set are not in the set.
ns = [1,2,5,4,3]
cs = Set()
for n in ns
x = nothing
for c in cs
if !(c in cs)
println(c, " is not in ", cs)
end
for m in c
if abs(m-n) <=1
if isnothing(x)
push!(c,n)
x = c
else
union!(x,c)
delete!(cs,c)
end
break
end
end
end
if isnothing(x)
s = Set()
push!(s,n)
push!(cs,s)
end
end
cs
This outputs
Set(Any[2, 1]) is not in Set(Any[Set(Any[2, 1])])
Set(Any[2, 1]) is not in Set(Any[Set(Any[5, 4]), Set(Any[2, 1])])
Set(Any[5, 4]) is not in Set(Any[Set(Any[5, 4]), Set(Any[2, 1])])
Set(Any[2, 1]) is not in Set(Any[Set(Any[5, 4, 3]), Set(Any[2, 1])])
Can someone help me understand what is going on here? Is this some scoping or evaluation order issue?