El viernes, 28 de febrero de 2014 16:41:20 UTC-6, Pierre-Yves Gérardy 
escribió:
>
> To realize what you want to do, you can add the elements to be removed to 
> another set.
>
> On each iteration, verify that the current element isn't already in the 
> set of elements to be removed, and after the loop, clean the first set 
> using the elements of the second one.
>
>
Ah, that's a neat solution, thanks! 

David.
 

> —Pierre-Yves
>
> On Thursday, February 27, 2014 4:54:58 PM UTC+1, David P. Sanders wrote:
>>
>> I need to iterate over a Set whose elements will be deleted in the 
>> process.
>> However, some deleted elements are included in the iteration, e.g. the 
>> element 4 in the code below.
>>
>> Is this a bug, or am I misunderstanding?
>>
>> Thanks.
>>
>> julia> s = Set(5, 3, 4, 6)
>> Set{Int64}({5,4,6,3})
>>
>> julia> for i in s
>>        println("i=$i  s=$s")
>>        delete!(s, i-1)
>>        println("now s=$s\n")
>>        end
>> i=5  s=Set{Int64}({5,4,6,3})
>> now s=Set{Int64}({5,6,3})
>>
>> i=4  s=Set{Int64}({5,6,3})
>> now s=Set{Int64}({5,6})
>>
>> i=6  s=Set{Int64}({5,6})
>> now s=Set{Int64}({6})
>>
>>
>>
>>

Reply via email to