Hey all. I just ran into this. I don't *think* I'm doing anything wrong here, but let me know if I did.
I modified the existing wiki example of removing an element of a map, to show the problem. If a map contains records, then the 'remove' function gives flaky results. The item shows as removed, unless you try to access it, in which case it is there.
produces output:
As you can see... when I loop through the entries, it is there. And the same print statement, after the loop, provides different results.
I modified the existing wiki example of removing an element of a map, to show the problem. If a map contains records, then the 'remove' function gives flaky results. The item shows as removed, unless you try to access it, in which case it is there.
Code:
void main() {
record my_type {
int num;
string str;
};
my_type rvar;
rvar.num=3; rvar.str='foo';
my_type rvar2;
rvar2.num=8;rvar2.str='bar';
my_type [int] map1;
item key;
map1[2] = rvar;
map1[5] = rvar2;
print( count( map1 ) + " " + map1 contains 2 + " " + map1[2] );
print( "remove: " + remove map1[2] );
print( count( map1 ) + " " + map1 contains 2 + " " + map1[2] );
foreach key in map1 {
print(key + " (" + map1[key] + ")");
}
print( count( map1 ) + " " + map1 contains 2 + " " + map1[2] );
}
produces output:
Code:
2 true record my_type
remove: record my_type
1 false record my_type
2 (record my_type)
5 (record my_type)
2 true record my_type
As you can see... when I loop through the entries, it is there. And the same print statement, after the loop, provides different results.