Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-04 Thread Erik Max Francis
Antoon Pardon wrote: Maybe I'm going to be pedantic here, but I fear that your code won't work with matrices. The problem is that multiplication is not commutative with matrices. This means that matrices have two divisions a right and a left division. A far as I know the / operator usaly

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-04 Thread Antoon Pardon
On 2008-08-01, Terry Reedy [EMAIL PROTECTED] wrote: Nevertheless, I think this is probably the best example of the enhanced polymorphism of if x yet. I'm kind of surprised no one came up with it.) I think of Python code as 'generic' rather than 'polymorphic'. I am not sure if that is a

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-04 Thread Terry Reedy
Erik Max Francis wrote: Antoon Pardon wrote: [responding to me] Maybe I'm going to be pedantic here, but I fear that your code won't work with matrices. The problem is that multiplication is not commutative with matrices. This means that matrices have two divisions a right and a left

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Antoon Pardon
On 2008-08-01, Carl Banks [EMAIL PROTECTED] wrote: On Jul 31, 1:27 pm, Chris Mellon [EMAIL PROTECTED] wrote: I'm really not sure where you're going with this or what you're trying to prove. if x is a duck-type test for a boolean value. Obviously if you know the type and want a more *specific*

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Erik Max Francis
Antoon Pardon wrote: I now have the following question for people who argue that if x is more polymorphic. I could subclass list, so that instances of this new sequence would always behave as true, even if they are empty. I could then rewrite my loop as follows: while 1: extra = produce()

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Antoon Pardon
On 2008-08-01, Erik Max Francis [EMAIL PROTECTED] wrote: Antoon Pardon wrote: I now have the following question for people who argue that if x is more polymorphic. I could subclass list, so that instances of this new sequence would always behave as true, even if they are empty. I could then

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Matthew Fitzgibbons
Antoon Pardon wrote: On 2008-08-01, Erik Max Francis [EMAIL PROTECTED] wrote: Antoon Pardon wrote: I now have the following question for people who argue that if x is more polymorphic. I could subclass list, so that instances of this new sequence would always behave as true, even if they are

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Matthew Fitzgibbons
Carl Banks wrote: On Jul 31, 11:44 pm, Carl Banks [EMAIL PROTECTED] wrote: [snip excellent explanation of why it's hard to for if x to be extensively polymorphic] By the way, one thing I forgot to mention is Matt Fitzgibbons' filter example. As I said, it's hard to write code that works for

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Matthew Fitzgibbons
Matthew Fitzgibbons wrote: 'if x' strikes me as better for this case because you might want to accept a non-empty list (or some other objects) but reject non-empty lists. 'if x is None' would not work. It still may be susceptible to the empty iterator problem, depending on what prep_func does.

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Antoon Pardon
On 2008-08-01, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: Antoon Pardon wrote: On 2008-08-01, Erik Max Francis [EMAIL PROTECTED] wrote: Antoon Pardon wrote: I now have the following question for people who argue that if x is more polymorphic. I could subclass list, so that instances of

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Carl Banks
On Aug 1, 8:49 am, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: Carl Banks wrote: On Jul 31, 11:44 pm, Carl Banks [EMAIL PROTECTED] wrote: [snip excellent explanation of why it's hard to for if x to be extensively polymorphic] By the way, one thing I forgot to mention is Matt

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Terry Reedy
Nevertheless, I think this is probably the best example of the enhanced polymorphism of if x yet. I'm kind of surprised no one came up with it.) I think of Python code as 'generic' rather than 'polymorphic'. I am not sure if that is a real difference or not, since I am a bit fuzzy on the

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Matthew Fitzgibbons
Carl Banks wrote: On Aug 1, 8:49 am, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: Carl Banks wrote: On Jul 31, 11:44 pm, Carl Banks [EMAIL PROTECTED] wrote: [snip excellent explanation of why it's hard to for if x to be extensively polymorphic] By the way, one thing I forgot to mention is Matt

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Carl Banks
On Aug 1, 3:36 pm, Terry Reedy [EMAIL PROTECTED] wrote: Nevertheless, I think this is probably the best example of the enhanced polymorphism of if x yet. I'm kind of surprised no one came up with it.) I think of Python code as 'generic' rather than 'polymorphic'. I am not sure if that

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Carl Banks
On Aug 1, 4:45 pm, Carl Banks [EMAIL PROTECTED] wrote: On Aug 1, 3:36 pm, Terry Reedy [EMAIL PROTECTED] wrote: Nevertheless, I think this is probably the best example of the enhanced polymorphism of if x yet. I'm kind of surprised no one came up with it.) I think of Python code as

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-08-01 Thread Carl Banks
On Aug 1, 4:45 pm, Carl Banks [EMAIL PROTECTED] wrote: On Aug 1, 3:36 pm, Terry Reedy [EMAIL PROTECTED] wrote: In general, asking code to apply across numeric, container, and other classes is asking too much. Python code can be generic only within protocol/interface categories such as

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Russ P.
On Jul 30, 10:43 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: On Jul 30, 9:27 pm, Erik Max Francis [EMAIL PROTECTED] wrote: You're sure going on about a distinction without a difference for a guy who childishly likes to call other people names. A reasonable person would

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Iain King
On Jul 31, 7:08 am, Russ P. [EMAIL PROTECTED] wrote: On Jul 30, 10:43 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: On Jul 30, 9:27 pm, Erik Max Francis [EMAIL PROTECTED] wrote: You're sure going on about a distinction without a difference for a guy who childishly

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Chris Mellon
On Tue, Jul 29, 2008 at 3:37 AM, Carl Banks [EMAIL PROTECTED] wrote: On Jul 28, 8:15 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Mon, 28 Jul 2008 13:22:37 -0700, Carl Banks wrote: On Jul 28, 10:00 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote:

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Matthew Fitzgibbons
Steven D'Aprano wrote: On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote: If you're expecting a list (and only a list) then your point makes sense. 'if x' can get you into trouble if you _don't_ want its polymorphism. if x is hardly unique in that way. If you're expecting a list,

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Matthew Fitzgibbons
Steven D'Aprano wrote: On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote: If you're expecting a list (and only a list) then your point makes sense. 'if x' can get you into trouble if you _don't_ want its polymorphism. if x is hardly unique in that way. If you're expecting a list,

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Matthew Fitzgibbons
Matthew Fitzgibbons wrote: Steven D'Aprano wrote: On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote: If you're expecting a list (and only a list) then your point makes sense. 'if x' can get you into trouble if you _don't_ want its polymorphism. if x is hardly unique in that way.

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Matthew Woodcraft
Steven D'Aprano wrote: On Wed, 30 Jul 2008 20:55:03 +0100, Matthew Woodcraft wrote: On the other hand, iterators provide a clear example of problems with if x: __nonzero__ for iterators (in general) returns True even if they are 'empty'. How do you propose telling whether an iterator is

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Steven D'Aprano
On Thu, 31 Jul 2008 22:01:48 +0100, Matthew Woodcraft wrote: Steven D'Aprano wrote: On Wed, 30 Jul 2008 20:55:03 +0100, Matthew Woodcraft wrote: On the other hand, iterators provide a clear example of problems with if x: __nonzero__ for iterators (in general) returns True even if they are

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Matthew Woodcraft
Steven D'Aprano wrote: On Thu, 31 Jul 2008 22:01:48 +0100, Matthew Woodcraft wrote: The point is that if you tell people that if x is the standard way to check for emptiness, and also support a general principle along the lines of write your function using the interfaces you expect, and call

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Carl Banks
On Jul 31, 1:27 pm, Chris Mellon [EMAIL PROTECTED] wrote: I'm really not sure where you're going with this or what you're trying to prove. if x is a duck-type test for a boolean value. Obviously if you know the type and want a more *specific* test, then you can use an explicit one. Any time

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Carl Banks
On Jul 31, 12:13 am, Ethan Furman [EMAIL PROTECTED] wrote: Carl Banks wrote: So I stand by the point I was trying to make: for your average day-to- day programming, the main benefit of if x is to save keystrokes. It doesn't help your code become more polymophic in practice. A little

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Carl Banks
On Jul 30, 10:05 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: On Jul 30, 1:07 am, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: Oh, Lordy. I understand perfectly well how boolean tests, __len__, and __nonzero__ work in Python. It's very basic stuff. You can quit

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Carl Banks
On Jul 31, 11:44 pm, Carl Banks [EMAIL PROTECTED] wrote: [snip excellent explanation of why it's hard to for if x to be extensively polymorphic] By the way, one thing I forgot to mention is Matt Fitzgibbons' filter example. As I said, it's hard to write code that works for both numeric and

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-31 Thread Erik Max Francis
Carl Banks wrote: If you recall, I agreed with his statement. Would you like to claim that I don't understand the fundamentals of Python? Since you've invented this connection out of nowhere, not particularly. I've never said anything about _anyone_ not understanding the fundamentals of

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 29, 10:33 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 30, 1:15 am, Russ P. [EMAIL PROTECTED] wrote: Having said that, it would sure be nice to be able to write if myList is not empty: instead of if len(myList) != 0: I can agree with this. But I guess that could only work

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Carl Banks wrote: Bull. This is a request, that, if satisfied, would prove that if x is more polymorphic than a simple explicit test. I posed the question precisely to see if anyone could come up with a use case that shows this benefit of if x. Except you're the only one who's not convinced

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: All this discussion about if x has me wondering. I use it all the time because a fully explicit test just seems redundant. But maybe it does have some value in terms of readability and type checking. After all, it is possible to forget whether something is a number or a list.

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Carl Banks wrote: On Jul 30, 1:15 am, Russ P. [EMAIL PROTECTED] wrote: All this discussion about if x has me wondering. I use it all the time because a fully explicit test just seems redundant. But maybe it does have some value in terms of readability and type checking. After all, it is

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: On Jul 29, 10:33 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 30, 1:15 am, Russ P. [EMAIL PROTECTED] wrote: Having said that, it would sure be nice to be able to write if myList is not empty: instead of if len(myList) != 0: I can agree with this. But I guess that could

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 29, 11:09 pm, Erik Max Francis [EMAIL PROTECTED] wrote: I'm getting this sneaking suspicion that you guys are all putting us on. As I said in an earlier post, I realize that this would only work if there were only one copy of empty (as there is only one copy of None). I don't know off

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 29, 11:16 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: On Jul 29, 10:33 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 30, 1:15 am, Russ P. [EMAIL PROTECTED] wrote: Having said that, it would sure be nice to be able to write if myList is not empty: instead of

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: On Jul 29, 11:09 pm, Erik Max Francis [EMAIL PROTECTED] wrote: I'm getting this sneaking suspicion that you guys are all putting us on. As I said in an earlier post, I realize that this would only work if there were only one copy of empty (as there is only one copy of None).

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: Come to think of it, shouldn't the list type have an isempty method? Or does it? Yes. It's written: if not aList: ... -- Erik Max Francis [EMAIL PROTECTED] http://www.alcyone.com/max/ San Jose, CA, USA 37 18 N 121 57 W AIM, Y!M erikmaxfrancis The

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 29, 11:36 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: On Jul 29, 11:09 pm, Erik Max Francis [EMAIL PROTECTED] wrote: I'm getting this sneaking suspicion that you guys are all putting us on. As I said in an earlier post, I realize that this would only work if

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 29, 11:36 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: Come to think of it, shouldn't the list type have an isempty method? Or does it? Yes. It's written: if not aList: ... As you know, that is not quite exactly the same thing. An isempty

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Carl Banks
On Jul 30, 2:06 am, Erik Max Francis [EMAIL PROTECTED] wrote: Perhaps in the particular use case you're thinking of (numeric types vs. container types), there aren't any good examples. But who cares? You don't have to. I am trying to set the record straight on just how much polymophism if x

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Carl Banks
On Jul 30, 1:58 am, Russ P. [EMAIL PROTECTED] wrote: On Jul 29, 10:33 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 30, 1:15 am, Russ P. [EMAIL PROTECTED] wrote: Having said that, it would sure be nice to be able to write if myList is not empty: instead of if len(myList) != 0:

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Heiko Wundram
Am Mittwoch, 30. Juli 2008 08:30:48 schrieb Russ P.: On Jul 29, 11:09 pm, Erik Max Francis [EMAIL PROTECTED] wrote: I'm getting this sneaking suspicion that you guys are all putting us on. As I said in an earlier post, I realize that this would only work if there were only one copy of empty

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 30, 12:03 am, Heiko Wundram [EMAIL PROTECTED] wrote: Am Mittwoch, 30. Juli 2008 08:30:48 schrieb Russ P.: On Jul 29, 11:09 pm, Erik Max Francis [EMAIL PROTECTED] wrote: I'm getting this sneaking suspicion that you guys are all putting us on. As I said in an earlier post, I realize

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Heiko Wundram
Am Mittwoch, 30. Juli 2008 09:18:48 schrieb Russ P.: Oh, Lordy. I understand perfectly well how boolean tests, __len__, and __nonzero__ work in Python. It's very basic stuff. You can quit patronizing me (and Carl too, I'm sure). I'll stop repeating what the current state is (which might sound

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 30, 12:49 am, Heiko Wundram [EMAIL PROTECTED] wrote: Am Mittwoch, 30. Juli 2008 09:18:48 schrieb Russ P.: Oh, Lordy. I understand perfectly well how boolean tests, __len__, and __nonzero__ work in Python. It's very basic stuff. You can quit patronizing me (and Carl too, I'm sure).

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: On Jul 29, 11:36 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: Come to think of it, shouldn't the list type have an isempty method? Or does it? Yes. It's written: if not aList: ... As you know, that is not quite exactly the same thing. An

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Carl Banks wrote: I mean in general. I wouldn't spell it like that. I would prefer if empty(x), with an __empty__ method. (And support __nonzero__ aka __bool__ dropped completely.) So your argument is purely about style, then. You just wish it were written differently. -- Erik Max

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: Oh, Lordy. I understand perfectly well how boolean tests, __len__, and __nonzero__ work in Python. It's very basic stuff. You can quit patronizing me (and Carl too, I'm sure). You suggested a syntax for testing non-emptiness (`x is not empty`) which indicated a profound

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Ethan Furman
Russ P. wrote: Oh, Lordy. I understand perfectly well how boolean tests, __len__, and __nonzero__ work in Python. It's very basic stuff. You can quit patronizing me (and Carl too, I'm sure). The point that you seem to be missing, or refuse to acknowledge for some reason, is that if x can be

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Maric Michaud
Le Tuesday 29 July 2008 23:48:31 [EMAIL PROTECTED], vous avez écrit : Here's a function, print_members.  It's just something that takes some iterable and prints its members in XML.  It's special-cased so that an empty iterable gets an empty tag.  (This is a bit of a trivial example, I admit;

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread giltay
On Jul 30, 5:09 am, Maric Michaud [EMAIL PROTECTED] wrote: Le Tuesday 29 July 2008 23:48:31 [EMAIL PROTECTED], vous avez écrit : def print_members(iterable):     if not iterable:         print 'members /'         return     print 'members'     for item in iterable:         print

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Hyuga
On Jul 30, 3:53 am, Russ P. [EMAIL PROTECTED] wrote: Fair enough. I have no dog in this particular fight. I just think it wouldn't hurt to add an isempty() or isnonempty() method to the list type, and let people use it if they wish, or continue using if x if that's what they prefer. Go right

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Maric Michaud
Le Wednesday 30 July 2008 15:31:28 [EMAIL PROTECTED], vous avez écrit : class Signal:     [...]     def dc_offset(self, amount):         if amount == 0:             return         self.samples = [sample + amount for sample in self.samples] This function is also wrong assuming

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Terry Reedy
Carl Banks wrote: That's not what I was asking for. I was asking for a use case for if x that can't be replaced by a simple explicit test. Your example didn't satisfy that. But I believe my example of an iterator with __bool__ but not with __len__ does. --

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Matthew Fitzgibbons
Carl Banks wrote: On Jul 30, 1:58 am, Russ P. [EMAIL PROTECTED] wrote: On Jul 29, 10:33 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 30, 1:15 am, Russ P. [EMAIL PROTECTED] wrote: Having said that, it would sure be nice to be able to write if myList is not empty: instead of if len(myList)

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Matthew Fitzgibbons
Russ P. wrote: On Jul 30, 12:03 am, Heiko Wundram [EMAIL PROTECTED] wrote: Am Mittwoch, 30. Juli 2008 08:30:48 schrieb Russ P.: On Jul 29, 11:09 pm, Erik Max Francis [EMAIL PROTECTED] wrote: I'm getting this sneaking suspicion that you guys are all putting us on. As I said in an earlier

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Matthew Fitzgibbons
Carl Banks wrote: On Jul 29, 6:42 pm, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: Carl Banks wrote: Much like in Steven D'Aprano's example, still the only actual code snippet I've seen, it seems that this can easily be done with a simple explicit test by having all no-advance filters return

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Ethan Furman
Carl Banks wrote: On Jul 29, 6:42 pm, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: I don't have any postable code (it's in a half way state and I haven't touched it for a while), but I'll see if I can't find the time to bang something up to give you the gist. I wouldn't bother at this point.

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Matthew Woodcraft
Terry Reedy [EMAIL PROTECTED] wrote: Carl Banks wrote: That's not what I was asking for. I was asking for a use case for if x that can't be replaced by a simple explicit test. Your example didn't satisfy that. But I believe my example of an iterator with __bool__ but not with __len__

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 30, 1:07 am, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: Oh, Lordy. I understand perfectly well how boolean tests, __len__, and __nonzero__ work in Python. It's very basic stuff. You can quit patronizing me (and Carl too, I'm sure). You suggested a syntax for testing

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Carl Banks
On Jul 30, 11:07 am, Terry Reedy [EMAIL PROTECTED] wrote: Carl Banks wrote: That's not what I was asking for. I was asking for a use case for if x that can't be replaced by a simple explicit test. Your example didn't satisfy that. But I believe my example of an iterator with __bool__

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Carl Banks
On Jul 30, 3:56 am, Erik Max Francis [EMAIL PROTECTED] wrote: Carl Banks wrote: I mean in general. I wouldn't spell it like that. I would prefer if empty(x), with an __empty__ method. (And support __nonzero__ aka __bool__ dropped completely.) So your argument is purely about style,

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Carl Banks
On Jul 30, 4:49 am, Ethan Furman [EMAIL PROTECTED] wrote: Carl Banks wrote: On Jul 29, 6:42 pm, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: I don't have any postable code (it's in a half way state and I haven't touched it for a while), but I'll see if I can't find the time to bang

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: On Jul 30, 1:07 am, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: Oh, Lordy. I understand perfectly well how boolean tests, __len__, and __nonzero__ work in Python. It's very basic stuff. You can quit patronizing me (and Carl too, I'm sure). You suggested a syntax

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread castironpi
On Jul 30, 1:50 am, Carl Banks [EMAIL PROTECTED] wrote: On Jul 30, 1:58 am, Russ P. [EMAIL PROTECTED] wrote: On Jul 29, 10:33 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 30, 1:15 am, Russ P. [EMAIL PROTECTED] wrote: Having said that, it would sure be nice to be able to write

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 30, 7:05 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: On Jul 30, 1:07 am, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: Oh, Lordy. I understand perfectly well how boolean tests, __len__, and __nonzero__ work in Python. It's very basic stuff. You can quit

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Steven D'Aprano
On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote: If you're expecting a list (and only a list) then your point makes sense. 'if x' can get you into trouble if you _don't_ want its polymorphism. if x is hardly unique in that way. If you're expecting a list, and only a list,

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Steven D'Aprano
On Wed, 30 Jul 2008 20:55:03 +0100, Matthew Woodcraft wrote: On the other hand, iterators provide a clear example of problems with if x: __nonzero__ for iterators (in general) returns True even if they are 'empty'. How do you propose telling whether an iterator is empty? That's a generic

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: The reason I wrote that it would be nice to be able to write if x is not empty: is that it reads naturally. It was not an actual proposal, and the fact that you took it as such was *your* mistake. ... Now read carefully: I DID NOT CLAIM THAT THIS IS THE WAY TO DO IT!

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Ethan Furman
Carl Banks wrote: On Jul 30, 4:49 am, Ethan Furman [EMAIL PROTECTED] wrote: Even for those that did realize, and in fact hoped that that is what you were attempting to accomplish, I was not attempting to accomplish what you think I was. I was looking for it, but I didn't want to see it. I

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 30, 8:03 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: The reason I wrote that it would be nice to be able to write if x is not empty: is that it reads naturally. It was not an actual proposal, and the fact that you took it as such was *your* mistake. ...

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Steven D'Aprano
On Thu, 31 Jul 2008 02:41:08 +, Steven D'Aprano wrote: On Wed, 30 Jul 2008 09:23:05 -0600, Matthew Fitzgibbons wrote: ... Although, if my function is expecting a list, my preference is to do: if not isinstance(x, list): raise SomeMeaningfulException() # do stuff with the list I

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Ethan Furman
Russ P. wrote: [snippers] The reason I wrote that it would be nice to be able to write if x is not empty: is that it reads naturally. [and more snippers] Reads naturally? For whom? Readability counts does not mean make it sound like english as much as possible. There are good reasons

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 30, 8:24 pm, Russ P. [EMAIL PROTECTED] wrote: On Jul 30, 8:03 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: The reason I wrote that it would be nice to be able to write if x is not empty: is that it reads naturally. It was not an actual proposal, and the

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: I don't know if you can read minds, but you seem to have a lot of trouble reading words. Can you read it would be nice to be able to write ...? Can you understand what it means? Can you understand that it does *not* mean, one *should* be able to write ...? You're sure going on

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread alex23
Ethan Furman wrote: If that's really what you want, go join Dave Parker and Flaming Thunder. Best recommendation in this thread to date :) -- http://mail.python.org/mailman/listinfo/python-list

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Russ P.
On Jul 30, 9:27 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Russ P. wrote: I don't know if you can read minds, but you seem to have a lot of trouble reading words. Can you read it would be nice to be able to write ...? Can you understand what it means? Can you understand that it does

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-30 Thread Erik Max Francis
Russ P. wrote: On Jul 30, 9:27 pm, Erik Max Francis [EMAIL PROTECTED] wrote: You're sure going on about a distinction without a difference for a guy who childishly likes to call other people names. A reasonable person would have long ago moved on instead of blaming others for not immediately

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Carl Banks
On Jul 28, 8:15 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Mon, 28 Jul 2008 13:22:37 -0700, Carl Banks wrote: On Jul 28, 10:00 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: Cutting to the crux of the discussion... On Sun, 27 Jul 2008 23:45:26

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Heiko Wundram
Am Dienstag, 29. Juli 2008 10:37:45 schrieb Carl Banks: You keep bringing up this notion of more complex with no benefit, which I'm simply not interested in talking about that at this time, and I won't respond to any of your points. I am seeking the answer to one question: whether if x can

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Steven D'Aprano
On Tue, 29 Jul 2008 01:37:45 -0700, Carl Banks wrote: On Jul 28, 8:15 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Mon, 28 Jul 2008 13:22:37 -0700, Carl Banks wrote: On Jul 28, 10:00 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: Cutting to the crux

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Anders J. Munch
Steven D'Aprano wrote: On Tue, 29 Jul 2008 00:23:02 +, Steven D'Aprano wrote: Dude. Dude. Just... learn some Python before you embarrass yourself further. I'm sorry Anders, that was a needlessly harsh thing for me to say. I apologize for the unpleasant tone. Still, __nonzero__ is a

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Heiko Wundram
Am Dienstag, 29. Juli 2008 11:15:05 schrieb Heiko Wundram: I can't dig up a simple example from code I wrote quickly... Just to get back to that: an example I found where if x (the generic __nonzero__() test) will work to test for emptiness/non-emptiness of a container, whereas if len(x) 0

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Colin J. Williams
Heiko Wundram wrote: Am Dienstag, 29. Juli 2008 11:15:05 schrieb Heiko Wundram: I can't dig up a simple example from code I wrote quickly... Just to get back to that: an example I found where if x (the generic __nonzero__() test) will work to test for emptiness/non-emptiness of a container,

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Matthew Fitzgibbons
Carl Banks wrote: On Jul 28, 8:15 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Mon, 28 Jul 2008 13:22:37 -0700, Carl Banks wrote: On Jul 28, 10:00 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: Cutting to the crux of the discussion... On Sun, 27 Jul 2008

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Carl Banks
On Jul 29, 5:27 am, Steven D'Aprano [EMAIL PROTECTED] wrote: On Tue, 29 Jul 2008 01:37:45 -0700, Carl Banks wrote: I am looking for one that can't. If you are writing code that needs to do the right thing with arbitrary types, then your so-called simple explicit tests simply can't work. I

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Carl Banks
On Jul 29, 5:15 am, Heiko Wundram [EMAIL PROTECTED] wrote: I can't dig up a simple example from code I wrote quickly, but because of the fact that explicit comparisons always hamper polymorphism I'm not going to take your word for it. Do you have code that demonstrates how if x improves

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Carl Banks
On Jul 29, 11:12 am, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: Carl Banks wrote: On Jul 28, 8:15 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Mon, 28 Jul 2008 13:22:37 -0700, Carl Banks wrote: On Jul 28, 10:00 am, Steven D'Aprano [EMAIL PROTECTED]

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Carl Banks
On Jul 29, 1:30 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 29, 5:15 am, Heiko Wundram [EMAIL PROTECTED] wrote: I can't dig up a simple example from code I wrote quickly, but because of the fact that explicit comparisons always hamper polymorphism I'm not going to take your word for

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Carl Banks
On Jul 29, 5:27 am, Steven D'Aprano [EMAIL PROTECTED] wrote: On Tue, 29 Jul 2008 01:37:45 -0700, Carl Banks wrote: I would accept as evidence something that satisfies my criteria, which your example did not: it could have easily (and more robustly) been written with a simple explicit test.

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Erik Max Francis
Carl Banks wrote: On Jul 29, 1:30 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 29, 5:15 am, Heiko Wundram [EMAIL PROTECTED] wrote: I can't dig up a simple example from code I wrote quickly, but because of the fact that explicit comparisons always hamper polymorphism I'm not going to take

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Matthew Woodcraft
Steven D'Aprano [EMAIL PROTECTED] wrote: if x is completely type agnostic. You can pass an object of any type to it, and it will work. (Excluding objects with buggy methods, naturally.) There are many circumstances where if a parameter is None I'd rather get an exception than have the code

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Heiko Wundram
Am 29.07.2008, 18:30 Uhr, schrieb Carl Banks [EMAIL PROTECTED]: On Jul 29, 5:15 am, Heiko Wundram [EMAIL PROTECTED] wrote: I can't dig up a simple example from code I wrote quickly, but because of the fact that explicit comparisons always hamper polymorphism I'm not going to take your word

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Carl Banks
On Jul 29, 4:08 pm, Erik Max Francis [EMAIL PROTECTED] wrote: Carl Banks wrote: On Jul 29, 1:30 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 29, 5:15 am, Heiko Wundram [EMAIL PROTECTED] wrote: I can't dig up a simple example from code I wrote quickly, but because of the fact that

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Carl Banks
On Jul 29, 3:43 pm, Heiko Wundram [EMAIL PROTECTED] wrote: Am 29.07.2008, 18:30 Uhr, schrieb Carl Banks [EMAIL PROTECTED]: On Jul 29, 5:15 am, Heiko Wundram [EMAIL PROTECTED] wrote: I can't dig up a simple example from code I wrote quickly, but because of the fact that explicit

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread giltay
On Jul 29, 1:30 pm, Carl Banks [EMAIL PROTECTED] wrote: On Jul 29, 5:15 am, Heiko Wundram [EMAIL PROTECTED] wrote: I can't dig up a simple example from code I wrote quickly, but because of the fact that explicit comparisons always hamper polymorphism I'm not going to take your word for

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Heiko Wundram
Also, just a couple of points: Am 29.07.2008, 22:27 Uhr, schrieb Carl Banks [EMAIL PROTECTED]: 1. Any container type that returns a length that isn't exactly the number of elements in it is broken. I agree, but how do you ever expect to return an infinite element count? The direction I took

Re: Boolean tests [was Re: Attack a sacred Python Cow]

2008-07-29 Thread Matthew Fitzgibbons
Carl Banks wrote: On Jul 29, 11:12 am, Matthew Fitzgibbons [EMAIL PROTECTED] wrote: Carl Banks wrote: On Jul 28, 8:15 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Mon, 28 Jul 2008 13:22:37 -0700, Carl Banks wrote: On Jul 28, 10:00 am, Steven D'Aprano [EMAIL PROTECTED]

  1   2   >