On 11 May 2011 13:36:02 GMT, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: : > In this case, the interpretation of an arbitrary object as a boolean is : > peculiar for python. : : Incorrect. It is widespread among many languages. Programmers have been : writing conditional tests using arbitrary values since 1958 when Lisp : introduced the concept.
The fact that you need to list language by language which objects evaluate as false or equivalent to false illustrates that this has to be learnt language by language. Allowing arbitrary objects is one thing, the particular interpretation is peculiar. The fact that if and while accepts any object for the condition may be chapter 1 stuff, but the memorisation of exactly how the interpretation does not come early (unless you learn it by rote of course). : C, Forth and Visual Basic treat any non-zero number as true, and zero as : false; that's not quite arbitrary objects, but it's arbitrary integer : values. Similarly, Objective C has two different boolean types, "BOOL" : which is a C char where 0 is false and everything else is true, and : "bool" which is more like the Java boolean type. Mentioning C, with no Boolean type at all, in this context is a bit absurd. Understanding boolean evaluation in C is very little help when you want to understand it in python. : > An empty list is a real, existing object, and the : > supposition that [] be false is counter-intuitive. : : Not to me, nor to anyone who has an intuition about "something" versus : "nothing". I believe this distinction is fundamental to the universe, and : that nearly every person understands this intuitively. The distinction : between something and nothing is so strong that it took centuries of : argument for the finest minds in Europe[1] to finally decide that, yes, : zero is a number -- and they only did it because the Arabs and Indians : had proven how useful it was, and Roman numerals really do suck for doing : calculations. Exactly. By now we have gotten past that old-fashioned idea that 0 is not a number. Computer scientists even tend to count 0 as a natural number. When 0 is a number as real and existent as any other, one would think that the empty list is also as real and existent as any other list. : In my experience, it does not confuse newbies or beginners. The only : people it confuses are those who are over-educated into thinking that the : One Correct Way of doing truth testing is with a dedicated boolean type, : and anything else is heresy. What kind of beginners are you talking about? Beginners to python or beginners to programming. The audience I am concerned about is the ones who are over-educated into using and having used a score of different meanings of the same symbols. They will be used to their intuition being wrong when they move into a new context. Being explicit will help them. -- :-- Hans Georg -- http://mail.python.org/mailman/listinfo/python-list