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 divisi

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 imple

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

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 su

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 th

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 > su

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

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 m

Re: Boolean tests

2008-08-01 Thread Ethan Furman
Anders J. Munch wrote: Ethan Furman wrote: > Even if we find out that C.__nonzero__ is called, what was it that > __nonzero__ did again? reinforce the impression that he is unaware of the double-underscore functions and what they do and how they work. Only if your newsreader malfunctio

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 M

Re: Boolean tests

2008-08-01 Thread Anders J. Munch
Ethan Furman wrote: > Even if we find out that C.__nonzero__ is called, what was it that > __nonzero__ did again? reinforce the impression that he is unaware of the double-underscore functions and what they do and how they work. Only if your newsreader malfunctioned and refused to let you

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

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 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 fo

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 a

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.

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, 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 mo

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 Py

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 c

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 > &g

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 li

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. An

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, an

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

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 iterato

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 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 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>

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 >

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

2008-07-30 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 pers

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-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 t

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 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

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 pr

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 rea

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

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 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 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 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 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 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 > &g

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

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 su

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 b

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

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

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

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

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 Fitzgibbons
s. They are instead a very well-defined language mechanism that isn't perfect for every circumstance, but is pretty good for the most part. I wanted to do meaningful boolean tests on various objects, so I used the mechanism that my language gave me. The natural, obvious way for a filte

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

2008-07-30 Thread Matthew Fitzgibbons
ent" would come at a much greater price than its worth, and he's absolutely right in that, as it's an abuse of the "is" operator, but again, that's a somewhat different point. It changes nothing about the fact that all this discussion centers around something that is a non-

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(

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. -- http://mail.python.org/mailm

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 i

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 prefe

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 '' > >         return > >     print '' > >     for item in iterable: > >         print '%s

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 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 &qu

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

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 Franc

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.

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 >

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 curre

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

2008-07-30 Thread Russ P.
ely right in that, as > it's an abuse of the "is" operator, but again, that's a somewhat different > point. It changes nothing about the fact that all this discussion centers > around something that is a non-point, but simply a matter of personal taste. > > -- >

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

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

2008-07-29 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 >

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

2008-07-29 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

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

2008-07-29 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

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

2008-07-29 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 w

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

2008-07-29 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 erikmaxfranci

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

2008-07-29 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 "Non

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

2008-07-29 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 e

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

2008-07-29 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

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

2008-07-29 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 co

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

2008-07-29 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 p

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

2008-07-29 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. H

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

2008-07-29 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 convin

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

2008-07-29 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 th

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

2008-07-29 Thread Carl Banks
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 possible to for

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

2008-07-29 Thread Carl Banks
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 None and

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

2008-07-29 Thread Russ P.
On Jul 29, 9:52 pm, Carl Banks <[EMAIL PROTECTED]> wrote: > On Jul 29, 11:17 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > > > > > Carl Banks wrote: > > >> As I wrote in the second reply email I sent, check out my integer set > > >> recipe on ASPN (and to save you the search: > > >> http://code.ac

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

2008-07-29 Thread Carl Banks
On Jul 29, 11:17 pm, Terry Reedy <[EMAIL PROTECTED]> wrote: > Carl Banks wrote: > >> As I wrote in the second reply email I sent, check out my integer set > >> recipe on ASPN (and to save you the search: > >> http://code.activestate.com/recipes/466286/). > > > Couple points: > > > 1. Any containe

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

2008-07-29 Thread Carl Banks
On Jul 30, 12:22 am, Erik Max Francis <[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. > > It's a completely artificial request.

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

2008-07-29 Thread Carl Banks
On Jul 29, 7:30 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > On Tue, 29 Jul 2008 10:30:43 -0700, Carl Banks 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 tha

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

2008-07-29 Thread Erik Max Francis
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. It's a completely artificial request. "if x" _is_ a completely simple test. Simpler, in fact, than the ones you we

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

2008-07-29 Thread Carl Banks
On Jul 29, 10:23 pm, Erik Max Francis <[EMAIL PROTECTED]> wrote: > Carl Banks wrote: > > Bzzt. "if len(x)!=0" is a simple explicit that would work for this > > class and all built-in containers. (Or should--Steven D'Aprano's > > objections notwithstanding, any reasonable container type should > >

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

2008-07-29 Thread Terry Reedy
Carl Banks wrote: As I wrote in the second reply email I sent, check out my integer set recipe on ASPN (and to save you the search: http://code.activestate.com/recipes/466286/). Couple points: 1. Any container type that returns a length that isn't exactly the number of elements in it is b

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

2008-07-29 Thread Erik Max Francis
Carl Banks wrote: Bzzt. "if len(x)!=0" is a simple explicit that would work for this class and all built-in containers. (Or should--Steven D'Aprano's objections notwithstanding, any reasonable container type should support this invariant. From a language design standpoint, an "empty" builtin c

Re: Boolean tests

2008-07-29 Thread Matthew Woodcraft
Steven D'Aprano <[EMAIL PROTECTED]> wrote: >Anders wrote: >> "But then you decide to name the method "__nonzero__", instead of some >> nice descriptive name?" > That suggests to me that Anders imagined that __nonzero__ is something I > just made up, instead of a standard Python method. What do

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

2008-07-29 Thread Steven D'Aprano
On Tue, 29 Jul 2008 13:53:07 -0700, Carl Banks wrote: > Bzzt. "if len(x)!=0" is a simple explicit that would work for this > class and all built-in containers. (Or should--Steven D'Aprano's > objections notwithstanding, any reasonable container type should support > this invariant. What's the le

Re: Boolean tests

2008-07-29 Thread Ethan Furman
Matthew Woodcraft wrote: Ben Finney <[EMAIL PROTECTED]> wrote: No, he retracted the *insult* and restated the *advice* as a distinct statement. I think it's quite worthwhile to help people see the difference. Ben, it was quite clear from Anders' post that he knows about __nonzero__ . That's

Re: Boolean tests

2008-07-29 Thread Steven D'Aprano
On Tue, 29 Jul 2008 21:25:44 +0100, Matthew Woodcraft wrote: > Ben Finney <[EMAIL PROTECTED]> wrote: >> No, he retracted the *insult* and restated the *advice* as a distinct >> statement. I think it's quite worthwhile to help people see the >> difference. > > Ben, it was quite clear from Anders'

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

2008-07-29 Thread Steven D'Aprano
On Tue, 29 Jul 2008 21:15:12 +0100, Matthew Woodcraft wrote: > 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 w

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

2008-07-29 Thread Steven D'Aprano
On Tue, 29 Jul 2008 10:42:50 -0700, Carl Banks wrote: > On Jul 29, 11:12 am, Matthew Fitzgibbons <[EMAIL PROTECTED]> wrote: ... >> My use case involves a DAG of filters that pass data (of a variety of >> types--filters just pass on data types they don't understand) between >> them. I can also drop

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

2008-07-29 Thread Steven D'Aprano
On Tue, 29 Jul 2008 10:30:43 -0700, Carl Banks 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 fo

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 PROTECTE

  1   2   >