Sets

Michiel nomail at hotmail.com
Mon Feb 5 11:48:48 PST 2007


Sean Kelly wrote:

> The behavior for sets was cleaner before their behavior was changed such
> that an opIndex lookup throws an exception if the lookup fails.
> Previously, it would return the default value, which for bool would be
> 'false'.  Insertions were still a bit messy as setName[key] = true, but
> it was better than nothing.  Personally, I'm not fond of how AA indexing
> and 'in' works now.  It feels like a kludge.

Ah, I see. I understand how the old behavior was handy for faking sets. But to be
honest, I like the new behavior better in general. That old behavior was much more
ambiguous. And the 'in' notation is more intuitive for people with a background in
basic set theory.

My problems are:
* Declaring the set: You have to give a value type, even though you don't really
need it.
* Adding to the set: You have to assign a dummy value, which isn't very elegant.

I think the void[KeyType] notation for sets is very intuitive. All it further
needs is an add(KeyType element) function. I think it can be well defined and
would be a nice addition to the D language.

Do the D developers read this newsgroup? Or should I mail them with this suggestion?



More information about the Digitalmars-d mailing list