boolean true and false values.

Tim Rowe digitig at cix.co.uk
Sun Jun 25 18:07:00 EDT 2000


In article <slrn8l69kp.geg.hat at se-46.wpa.wtb.tue.nl>, 
hat at se-46.wpa.wtb.tue.nl (Albert Hofkamp) wrote:

>      I personally use the idea of 'first statement on a line messes up 
> an
>      invariant, the remainder of the line restores the invariant' in 
> C++, which
>      works great.

It works well in very simple cases. In more complicated cases you need 
something like Eiffel's structures for maintaining contracts and 
invariants. Basically where there's a lot of work to be done between 
breaking the invariant and having it fully fixed.

> Yes, I know, but why is it not in the language ?
> Quite a lot of algorithms rely on having sets. If you put them in a 
> list, there
> is an order which is not always wanted.

There is always an order, but you don't always know what it is. When you 
write your set class you just document that if the user iterates over the 
elements then the order in which they will be returned is undefined -- 
that's what happens in the C++ STL. The fact that the implementation has a 
natural ordering is no longer any use to the user. If you want to ram that 
home you can always shuffle the list from time to time :-)

> Also, implementing a set in anything else than a set is conceptually 
> not clean.
> (to be fair, the list operations are quite extensive, so living without 
> sets is
> doable).

I would consider implementing a set as a bag ("A set is a bag with no 
element duplicated") is conceptually clean. Of course, Python doesn't have 
bags as such, though they're easy to build...

Seriously, how do you think Python could implement it if not as a list or 
a tree or some ordered data structure? Even the Pascal set type is usually 
represented as a bit vector, which is every bit as ordered as a list...

> >delimiters on my keyboard are already used -- what would you delimit 
> it >with? :-)
> 
> {x,y,z} ?

That's going to get me confused...



More information about the Python-list mailing list