New set class

Michiel nomail at please.com
Mon Feb 26 05:49:57 PST 2007


Stephan Diehl wrote:

> the python people have 'set' and 'frozenset'
> (http://docs.python.org/lib/types-set.html). The main difference between
> these two is basicly, that a 'set' can't be the key to a dict (and
> therefore not being a member of a set. To make it short: every member of
> a set must be immutable, or, to be more technical, must always produce
> the same hash value. This really makes sense, if one thinks about it a
> bit (and one wants to model sets in the more mathematical sense)

Yes, this does make sense. But my set implementation doesn't provide any
write access to its members anyway, so you could say that everything you
put into it automatically becomes 'frozen'.

Now that I think about it, I suppose it's possible to have another
reference to an object that you are going to put into a set and change
it through that reference. I'm not quite sure what to do with that.

How does D handle this with its associative arrays?

You know, I liked C++ better in that regard. If you do an assignment or
pass something as an argument it's automatically a copy. In Java and in
D you have to explicitly copy something, except if it's a base type. I
don't like exceptions like that.

-- 
Michiel



More information about the Digitalmars-d mailing list