boolean true and false values.
Tim Rowe
digitig at cix.co.uk
Thu Jun 22 18:17:00 EDT 2000
In article <slrn8l1oc2.3c1.hat at se-46.wpa.wtb.tue.nl>,
hat at se-46.wpa.wtb.tue.nl (Albert Hofkamp) wrote:
> I read a number of replies, but didn't read an answer that seems
> satisfactory.
> I ran in the same problem, and was also not able to find a elegant
> solution.
> Using 0 and 1 or `true` and None is not correct imho, there should be a
> native
> way to use true and false for indicating boolean values.
There is not an elegant solution, short of making very fundamental changes
to the language that would IMHO break its nature. There is no problem with
assignment, but there is a serious danger with testing. You would have the
situation that
if foo:
could follow the true branch, but
if foo == true:
would follow the false branch. This has been a perennial C/C++ issue, and
there are still a lot of programmers who insist on using the latter form.
C++ now has boolean types, and that problem has been largely resolved, but
that's only been possible because C++ is (fairly) strongly typed and will
do implicit casts to boolean. I don't think that's a sensible route for
Python.
> Also, I am missing the data type 'set'. It can be faked with a
> dictionary, but it
> is just not the same. Any one else got this problem ?
It can be implemented very easily as a class wrapper around a list, that
checks for presence before adding an element, and defines union,
intersection, &c. It raises interesting questions of how deep the equality
test should be, and I suspect different applications would need different
answers, so I'm not sure it should be a built in. Anyway, all the paired
delimiters on my keyboard are already used -- what would you delimit it
with? :-)
More information about the Python-list
mailing list