Re: Operator Precedence/Boolean Logic

2016-07-17 Thread Steven D'Aprano
On Mon, 18 Jul 2016 01:58 am, Steven D'Aprano wrote: > All objects > can be coerced to strings, using either str() or repr(). If you define > only one of __str__ or __repr__, Python will use the other. Er, sorry, that was incoherent. I hit Send too quick, without editing. What I meant to say was

Re: Operator Precedence/Boolean Logic

2016-07-17 Thread Steven D'Aprano
On Mon, 18 Jul 2016 01:00 am, Rustom Mody wrote: >> I'm still waiting to hear in what way it is not straightforward. You keep >> insisting that it isn't, but haven't told us in what way it is not. > > The re/automaton/graph examples were towards this only and I think we are > running in circles o

Re: Operator Precedence/Boolean Logic

2016-07-17 Thread Rustom Mody
On Sunday, July 17, 2016 at 4:32:36 PM UTC+5:30, Steven D'Aprano wrote: > On Sun, 17 Jul 2016 04:44 pm, Rustom Mody wrote: > > > My earlier statement (with emphasis in original): > >> You also have a bizarre notion that python's property: “Everything has > >> auto-bool-nature” IS STRAIGHTFORWARD.

Re: Operator Precedence/Boolean Logic

2016-07-17 Thread Steven D'Aprano
On Sun, 17 Jul 2016 04:44 pm, Rustom Mody wrote: > My earlier statement (with emphasis in original): >> You also have a bizarre notion that python's property: “Everything has >> auto-bool-nature” IS STRAIGHTFORWARD. I'm still waiting to hear in what way it is not straightforward. You keep insisti

Re: Operator Precedence/Boolean Logic

2016-07-17 Thread Steven D'Aprano
On Sun, 17 Jul 2016 05:44 pm, Lawrence D’Oliveiro wrote: > On Sunday, July 17, 2016 at 7:33:19 PM UTC+12, Chris Angelico wrote: >> 1) REXX and, I think, Pascal: there are two specific values that may >> be used in conditionals, and anything else is an error > > Worth comparing how two different l

Re: Operator Precedence/Boolean Logic

2016-07-17 Thread Lawrence D’Oliveiro
On Sunday, July 17, 2016 at 7:33:19 PM UTC+12, Chris Angelico wrote: > 1) REXX and, I think, Pascal: there are two specific values that may > be used in conditionals, and anything else is an error Worth comparing how two different languages deal with strict enforcement of booleans: * Modula-2 doe

Re: Operator Precedence/Boolean Logic

2016-07-17 Thread Chris Angelico
On Sun, Jul 17, 2016 at 4:44 PM, Rustom Mody wrote: > I am sure Chris you can distinguish between: > > - Python’s (bool) model is bizarre > - The model “Everything has auto-bool-nature” is bizarre > - The notion « “Everything has auto-bool-nature” is straightforward » is > bizarre > > > My earlie

Re: Operator Precedence/Boolean Logic

2016-07-17 Thread Rustom Mody
On Sunday, July 17, 2016 at 12:15:40 PM UTC+5:30, Rustom Mody wrote: > On Sunday, July 17, 2016 at 9:35:57 AM UTC+5:30, Chris Angelico wrote: > > On Sun, Jul 17, 2016 at 1:43 PM, Rustom Mody wrote: > > > Heh! A flurry of opinions! > > > No time right now… other than to say thank you (MRAB) for thi

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Rustom Mody
On Sunday, July 17, 2016 at 9:35:57 AM UTC+5:30, Chris Angelico wrote: > On Sun, Jul 17, 2016 at 1:43 PM, Rustom Mody wrote: > > Heh! A flurry of opinions! > > No time right now… other than to say thank you (MRAB) for this little gem: > > > > On Saturday, July 16, 2016 at 10:29:02 PM UTC+5:30, MRA

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Chris Angelico
On Sun, Jul 17, 2016 at 1:43 PM, Rustom Mody wrote: > Heh! A flurry of opinions! > No time right now… other than to say thank you (MRAB) for this little gem: > > On Saturday, July 16, 2016 at 10:29:02 PM UTC+5:30, MRAB wrote: >> On 2016-07-16 17:27, Steven D'Aprano wrote: >> > On Sat, 16 Jul 2016

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Rustom Mody
Heh! A flurry of opinions! No time right now… other than to say thank you (MRAB) for this little gem: On Saturday, July 16, 2016 at 10:29:02 PM UTC+5:30, MRAB wrote: > On 2016-07-16 17:27, Steven D'Aprano wrote: > > On Sat, 16 Jul 2016 10:33 pm, Rustom Mody wrote: > [snip] > > > And yes, Rustom,

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Chris Angelico
On Sun, Jul 17, 2016 at 2:27 AM, Steven D'Aprano wrote: > If you really mean your words, and don't wish to step back and make a less > extreme claim, then you ought to be easily able to show that Python's use > of bools hardly ever works. It's clearly a terrible idea, almost every use > of it is a

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread MRAB
On 2016-07-16 17:27, Steven D'Aprano wrote: On Sat, 16 Jul 2016 10:33 pm, Rustom Mody wrote: [snip] And yes, Rustom, I'm very familiar with the philosophical objections to the something/nothing distinction. "Is zero truly nothing, or is it some thing distinct from the absence of any number?" I

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Steven D'Aprano
On Sat, 16 Jul 2016 10:15 pm, Rustom Mody wrote: > Earlier you said: > >> > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a >> > graph..." >> >> I would make the empty graph (zero nodes) falsey, and non-empty graphs >> (one or more nodes) truthy. >> >> >> > 2. Automata w

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Steven D'Aprano
On Sat, 16 Jul 2016 10:33 pm, Rustom Mody wrote: > You also have a bizarre notion that python's property: “Everything has > auto-bool-nature” IS STRAIGHTFORWARD. That's a very strong claim. You're not just pointing out that there may be a few old corner cases here and there where Python's treatm

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Chris Angelico
On Sat, Jul 16, 2016 at 9:02 PM, Steven D'Aprano wrote: > On Sat, 16 Jul 2016 08:46 pm, Chris Angelico wrote: > >> As Steven says, >> the default is that they're all truthy, and onus is on the implementer >> to demonstrate that this object is functionally equivalent to 0 or an >> empty collection.

re: Operator Precedence/Boolean Logic

2016-07-16 Thread Gerald Britton
I'd say if |V| = |E| = 0, G has a boolean value of false. Maybe thusly?https://en.wikibooks.org/wiki/Sufism/Nasrudin#Of_any_two_options_choose_the_third -- - Previous message (by thread): Operator Precedence/Boolean Logic <https://mail.python.org/pipermail/python-list/

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Rustom Mody
On Saturday, July 16, 2016 at 4:16:34 PM UTC+5:30, Chris Angelico wrote: > On Sat, Jul 16, 2016 at 8:16 PM, Steven D'Aprano wrote: > >> If both you and Chris tripped up on a right definition of an “empty” > >> automaton and regex respectively, I believe it demonstrates that getting > >> boolishnes

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Rustom Mody
Earlier you said: > > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a > > graph..." > > I would make the empty graph (zero nodes) falsey, and non-empty graphs (one > or more nodes) truthy. > > > > 2. Automata which in a way are special kinds of graphs > > As above. No

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Steven D'Aprano
On Sat, 16 Jul 2016 08:46 pm, Chris Angelico wrote: > As Steven says, > the default is that they're all truthy, and onus is on the implementer > to demonstrate that this object is functionally equivalent to 0 or an > empty collection. (And it's possible for ANYONE to get that wrong - cf > timedelt

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Chris Angelico
On Sat, Jul 16, 2016 at 8:16 PM, Steven D'Aprano wrote: >> If both you and Chris tripped up on a right definition of an “empty” >> automaton and regex respectively, I believe it demonstrates that getting >> boolishness for an arbitrary type right is at least non-trivial. [FWIW My >> belief: In gen

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Steven D'Aprano
On Sat, 16 Jul 2016 03:48 pm, Rustom Mody wrote: > On Thursday, June 30, 2016 at 10:52:50 PM UTC+5:30, Steven D'Aprano wrote: >> Okay, if you think that automata cannot be empty, I'll accept that. In >> that case, then I'll change my answer and say that __bool__ for automata >> should simply retur

Re: Operator Precedence/Boolean Logic

2016-07-16 Thread Steven D'Aprano
On Sat, 16 Jul 2016 03:58 pm, Rustom Mody wrote: > > From other thread: > > On Saturday, July 16, 2016 at 9:50:13 AM UTC+5:30, Ethan Furman wrote: >> On 07/15/2016 09:04 PM, Rustom Mody wrote: >> >> > Just that suggesting that python's bool notion is straightforward is an >> > unnecessary lie –

Re: Operator Precedence/Boolean Logic

2016-07-15 Thread Rustom Mody
From other thread: On Saturday, July 16, 2016 at 9:50:13 AM UTC+5:30, Ethan Furman wrote: > On 07/15/2016 09:04 PM, Rustom Mody wrote: > > > Just that suggesting that python's bool notion is straightforward is an > > unnecessary lie – especially to newbies. > > Python's boolean concept is as si

Re: Operator Precedence/Boolean Logic

2016-07-15 Thread Rustom Mody
On Thursday, June 30, 2016 at 10:52:50 PM UTC+5:30, Steven D'Aprano wrote: > Okay, if you think that automata cannot be empty, I'll accept that. In that > case, then I'll change my answer and say that __bool__ for automata should > simply return True. All automata should be truthy. > I am not sur

Re: Operator Precedence/Boolean Logic

2016-06-30 Thread Steven D'Aprano
On Fri, 1 Jul 2016 02:01 am, Rustom Mody wrote: > On Thursday, June 30, 2016 at 5:10:41 AM UTC+5:30, Steven D'Aprano wrote: >> On Wed, 29 Jun 2016 11:30 pm, Rustom Mody wrote: >> >> > The other answers -- graphs and automata -- are questionable and/or >> > wrong >> > >> > You may wish to think a

Re: Operator Precedence/Boolean Logic

2016-06-30 Thread Rustom Mody
On Thursday, June 30, 2016 at 5:10:41 AM UTC+5:30, Steven D'Aprano wrote: > On Wed, 29 Jun 2016 11:30 pm, Rustom Mody wrote: > > > The other answers -- graphs and automata -- are questionable and/or wrong > > > > You may wish to think about them again? > > You may wish to justify your assertion.

Re: Operator Precedence/Boolean Logic

2016-06-29 Thread Steven D'Aprano
On Thu, 30 Jun 2016 01:00 am, Grant Edwards wrote: > On 2016-06-29, Steven D'Aprano wrote: > >> To Nick, having 1+True return 2 is an accident of implementation, > > My recollection is that it was not an accident of impliementation. It > was an intentional descision to provide compatibility wi

Re: Operator Precedence/Boolean Logic

2016-06-29 Thread Steven D'Aprano
On Wed, 29 Jun 2016 11:30 pm, Rustom Mody wrote: > The other answers -- graphs and automata -- are questionable and/or wrong > > You may wish to think about them again? You may wish to justify your assertion. -- Steven “Cheer up,” they said, “things could be worse.” So I cheered up, and sur

Re: Operator Precedence/Boolean Logic

2016-06-29 Thread Jon Ribbens
On 2016-06-29, Grant Edwards wrote: > On 2016-06-29, Steven D'Aprano wrote: >> To Nick, having 1+True return 2 is an accident of implementation, > > My recollection is that it was not an accident of impliementation. It > was an intentional descision to provide compatibility with many years > wor

Re: Operator Precedence/Boolean Logic

2016-06-29 Thread Grant Edwards
On 2016-06-29, Steven D'Aprano wrote: > To Nick, having 1+True return 2 is an accident of implementation, My recollection is that it was not an accident of impliementation. It was an intentional descision to provide compatibility with many years worth of programs that were written before there

Re: Operator Precedence/Boolean Logic

2016-06-29 Thread Rustom Mody
On Wednesday, June 29, 2016 at 6:38:16 PM UTC+5:30, Steven D'Aprano wrote: > On Wed, 29 Jun 2016 08:21 pm, Rustom Mody wrote: > > 3. Regular Expressions which mathematically are related to automata > > And pragmatically are (more) present in python than the first two > > Can you even have an emp

Re: Operator Precedence/Boolean Logic

2016-06-29 Thread Steven D'Aprano
On Wed, 29 Jun 2016 08:21 pm, Rustom Mody wrote: > So if we are in a link-pillow-fight here is a link > https://mail.python.org/pipermail/python-ideas/2016-June/040780.html > in which python-dev Nick Coghlan answers the question: > >> Q: ...supporting arithmetical operations (1+True==2) was a pri

Re: Operator Precedence/Boolean Logic

2016-06-29 Thread Chris Angelico
On Wed, Jun 29, 2016 at 8:21 PM, Rustom Mody wrote: > > Please show me how we would define __bool__ for > > 1. Graphs -- the kind mathematicians define with "Let G =(V,E) be a graph..." > > 2. Automata which in a way are special kinds of graphs > > 3. Regular Expressions which mathematically are r

Re: Operator Precedence/Boolean Logic

2016-06-29 Thread Rustom Mody
Moved from thread "Assignment Versus Equality" where this is less relevant On Wednesday, June 29, 2016 at 8:06:10 AM UTC+5:30, Steven D'Aprano wrote: > On Tue, 28 Jun 2016 12:10 am, Rustom Mody wrote: > > > Analogy: Python's bool as 1½-class because bool came into python a good > >

Re: Operator Precedence/Boolean Logic

2016-06-25 Thread Gregory Ewing
Marko Rauhamaa wrote: The pile originally had -4 coconuts. The first sailor threw one to the monkey, leaving -5 coconuts in the pile. He took his share (-1 coconut) out and put the remaining -4 coconuts back in the big pile. Sounds a bit like Hawking radiation. A coconut-anticoconut p

Re: Operator Precedence/Boolean Logic

2016-06-25 Thread Marko Rauhamaa
Steven D'Aprano : > So we have falsey values: > > - None > - zeroes (0, 0.0, 0j, etc) > - empty dict {} > - empty sets and frozensets > - empty strings '' and b'' (in Python 2: u'' and '') > - empty lists, tuples and other sequences > > and truthy values: > > - object > - non-zero numbers > - non-

Re: Operator Precedence/Boolean Logic

2016-06-24 Thread Jussi Piitulainen
Lawrence D’Oliveiro writes: > On Thursday, June 23, 2016 at 9:57:35 PM UTC+12, Marko Rauhamaa wrote: >> Lawrence D’Oliveiro: >> >>> On Thursday, June 23, 2016 at 9:11:05 PM UTC+12, Marko Rauhamaa wrote: The __len__ method is not guaranteed to execute in O(1). >>> >>> So what is? >> >> The _

Re: Operator Precedence/Boolean Logic

2016-06-24 Thread Lawrence D’Oliveiro
On Thursday, June 23, 2016 at 9:57:35 PM UTC+12, Marko Rauhamaa wrote: > Lawrence D’Oliveiro: > >> On Thursday, June 23, 2016 at 9:11:05 PM UTC+12, Marko Rauhamaa wrote: >>> The __len__ method is not guaranteed to execute in O(1). >> >> So what is? > > The __bool__ method is the appropriate place

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Steven D'Aprano
On Thu, 23 Jun 2016 11:26 pm, Random832 wrote: > On Thu, Jun 23, 2016, at 08:37, Steven D'Aprano wrote: >> You keep saying that, but I've never seen it happen. I've seen cases >> where people have been surprised by the unexpected truthiness of an >> object ("I expected an exhausted iterator to be

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Chris Angelico
On Thu, Jun 23, 2016 at 10:37 PM, Steven D'Aprano wrote: > I acknowledge, cheerfully, that there might be a mismatch between what you > expect and what the object actually does. "I expect empty containers to be > falsey, and non-empty ones to be truthy; but this RedBlackTree object is > always fal

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Random832
On Thu, Jun 23, 2016, at 08:37, Steven D'Aprano wrote: > You keep saying that, but I've never seen it happen. I've seen cases > where people have been surprised by the unexpected truthiness of an > object ("I expected an exhausted iterator to be false, but it was > true"), but that's not what you s

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 14:37 schreef Steven D'Aprano: > So I'm not really sure what you are trying to describe. I guess it might be > something like this: > > def spam(alist): > if alist: > process(alist) > else: > print("empty list") > > > If you pass 1 instead of an actual list,

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Random832
On Thu, Jun 23, 2016, at 02:34, Andreas Röhler wrote: > Indeed, why should the result of 4 - 4 have a different truth-value > than 4 - 3 ? This implementation seems to be a legacy from languages > without boolean types. A set which included Python until version 2.3. -- https://mail.python.org/mai

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Steven D'Aprano
On Thu, 23 Jun 2016 08:21 pm, Antoon Pardon wrote: > Op 23-06-16 om 11:39 schreef Steven D'Aprano: [...] >> To decide on a branch, you don't need an actual bool, anything capable of >> acting like a bool will do. As a language design, ALL objects are capable >> of acting like a bool. Python has a

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler
On 23.06.2016 14:08, Antoon Pardon wrote: Op 23-06-16 om 13:45 schreef Chris Angelico: On Thu, Jun 23, 2016 at 7:23 PM, Antoon Pardon wrote: I don't care. In modern mathematics, zero is usaly defined as the empty set. The empty set contains nothing, but it isn't nothing itself. Otherwise the

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Chris Angelico
On Thu, Jun 23, 2016 at 10:05 PM, Jussi Piitulainen wrote: > Is "sq" mnemonic for something? Presumably "sequence", which fits the other assumption that you noted: that calling 'iter' on it will produce a non-destructive iterator. I hope that code is never used on older Pythons that don't have e

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 13:45 schreef Chris Angelico: > On Thu, Jun 23, 2016 at 7:23 PM, Antoon Pardon > wrote: >> I don't care. In modern mathematics, zero is usaly defined as the >> empty set. The empty set contains nothing, but it isn't nothing >> itself. Otherwise the empty set would be the same as the

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Jussi Piitulainen
Antoon Pardon writes: > Op 23-06-16 om 12:59 schreef Marko Rauhamaa: >> Antoon Pardon : >> >>> Op 23-06-16 om 11:53 schreef Marko Rauhamaa: >>> Maybe something like this: >>> >>> def empty(sq): >>> try: >>> iter(sq).next() >>> except StopIteration: >>> return False >>>

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Chris Angelico
On Thu, Jun 23, 2016 at 7:23 PM, Antoon Pardon wrote: > I don't care. In modern mathematics, zero is usaly defined as the > empty set. The empty set contains nothing, but it isn't nothing > itself. Otherwise the empty set would be the same as the set > containing the empty set, since they both wou

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 12:59 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 23-06-16 om 11:53 schreef Marko Rauhamaa: >> Maybe something like this: >> >> def empty(sq): >> try: >> iter(sq).next() >> except StopIteration: >> return False >> except: >> raise TypeError >

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Marko Rauhamaa
Antoon Pardon : > Op 23-06-16 om 11:53 schreef Marko Rauhamaa: > Maybe something like this: > > def empty(sq): > try: > iter(sq).next() > except StopIteration: > return False > except: > raise TypeError > else: > return True That may or may not be a

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 11:53 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 23-06-16 om 11:10 schreef Marko Rauhamaa: >>> The __len__ method is not guaranteed to execute in O(1). See: >>> >>>https://docs.python.org/3/reference/datamodel.html?highlig >>>ht=__len__#object.__len__> >> As far as I c

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 11:39 schreef Steven D'Aprano: > On Thursday 23 June 2016 17:58, Antoon Pardon wrote: > >> Op 23-06-16 om 05:59 schreef Steven D'Aprano: >>> On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: >>> On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: [snip] > I feel that’s a

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler
On 23.06.2016 11:46, Marko Rauhamaa wrote: Ridiculous? It was this line of thinking that led Paul Dirac to predict the existence of antimatter. Marko Yeah. Maybe we could construct examples already using antagonistic charges of electrons? -- https://mail.python.org/mailman/listinfo/pytho

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Marko Rauhamaa
Antoon Pardon : > Op 23-06-16 om 11:10 schreef Marko Rauhamaa: >> The __len__ method is not guaranteed to execute in O(1). See: >> >>https://docs.python.org/3/reference/datamodel.html?highlig >>ht=__len__#object.__len__> > > As far as I can see, neither is the __bool__ method. Correct, bu

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Marko Rauhamaa
Lawrence D’Oliveiro : > On Thursday, June 23, 2016 at 9:11:05 PM UTC+12, Marko Rauhamaa wrote: >> The __len__ method is not guaranteed to execute in O(1). > > So what is? The __bool__ method is the appropriate place to implement an efficient emptiness check. It might not be O(1) but it will be th

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler
On 23.06.2016 11:17, Steven D'Aprano wrote: [ ... ] We can derive arithmetic from set theory. IMO not, resp. not really. But that would make a another item, pretty off-topic from Python. Should you know a place where to continue, would like to follow up. Thanks BTW. Zero is very speci

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Marko Rauhamaa
Steven D'Aprano : > On Thursday 23 June 2016 18:32, Andreas Röhler wrote: > >> There is a fundamental diff between zero and emptiness. > > In English, "emptiness" implies a container (real or figurative). The > container is not "something or nothing", it is the *contents* being > referred to. > >

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Lawrence D’Oliveiro
On Thursday, June 23, 2016 at 9:11:05 PM UTC+12, Marko Rauhamaa wrote: > Lawrence D’Oliveiro: > >> On Thursday, June 23, 2016 at 8:17:02 PM UTC+12, Marko Rauhamaa wrote: >>> if len(leftover) > 0:# no, I'd never write this >>> ... >> >> I regularly write “len(leftover) != 0”. Why no

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Steven D'Aprano
On Thursday 23 June 2016 17:58, Antoon Pardon wrote: > Op 23-06-16 om 05:59 schreef Steven D'Aprano: >> On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: >> >>> On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: >>> [snip] I feel that’s a needlessly complicated rule. It would have been simple

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 11:10 schreef Marko Rauhamaa: > Lawrence D’Oliveiro : > >> On Thursday, June 23, 2016 at 8:17:02 PM UTC+12, Marko Rauhamaa wrote: >>> if len(leftover) > 0:# no, I'd never write this >>> ... >> I regularly write “len(leftover) != 0”. Why not? > The __len__ method is no

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 10:48 schreef Steven D'Aprano: > On Thursday 23 June 2016 18:17, Antoon Pardon wrote: > >> No zero is not nothing. > I think you have just disagreed with about four thousand years of > mathematicians and accountants. I don't care. In modern mathematics, zero is usaly defined as the

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Steven D'Aprano
On Thursday 23 June 2016 18:32, Andreas Röhler wrote: > There is a fundamental diff between zero and emptiness. In English, "emptiness" implies a container (real or figurative). The container is not "something or nothing", it is the *contents* being referred to. "This shopping bag is empty" doe

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Marko Rauhamaa
Lawrence D’Oliveiro : > On Thursday, June 23, 2016 at 8:17:02 PM UTC+12, Marko Rauhamaa wrote: >> if len(leftover) > 0:# no, I'd never write this >> ... > > I regularly write “len(leftover) != 0”. Why not? The __len__ method is not guaranteed to execute in O(1). See: https://d

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 10:16 schreef Marko Rauhamaa: > I don't particularly like Python's falsey/truthy semantics, but I can > live with it. The biggest problem I have with it is the absence of an > emptiness predicate. I'd like to be able to write: > > if not leftover.empty(): > ... > > or eve

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Lawrence D’Oliveiro
On Thursday, June 23, 2016 at 8:17:02 PM UTC+12, Marko Rauhamaa wrote: > if len(leftover) > 0:# no, I'd never write this > ... I regularly write “len(leftover) != 0”. Why not? -- https://mail.python.org/mailman/listinfo/python-list

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Steven D'Aprano
On Thursday 23 June 2016 18:17, Antoon Pardon wrote: > No zero is not nothing. I think you have just disagreed with about four thousand years of mathematicians and accountants. In fact, mathematicians were so hung up about zero being nothing, that it took about three thousand years before they

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler
On 23.06.2016 10:17, Antoon Pardon wrote: Op 23-06-16 om 09:05 schreef Steven D'Aprano: On Thursday 23 June 2016 16:34, Andreas Röhler wrote: Indeed, why should the result of 4 - 4 have a different truth-value than 4 - 3 ? Because 4-4 is zero, which is "nothing", while 4-3 is one, which is

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Andreas Röhler
On 23.06.2016 09:05, Steven D'Aprano wrote: On Thursday 23 June 2016 16:34, Andreas Röhler wrote: Indeed, why should the result of 4 - 4 have a different truth-value than 4 - 3 ? Because 4-4 is zero, which is "nothing", Hmm, water freezes at zero degree celsius, because there is no temper

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Marko Rauhamaa
Antoon Pardon : > It is why I have sometime found the need to write: > > if flag is True: > > Because flag needed to be True, not truthy. Then, you have found the correct idiom for your rare need. You might even want to consider: if flag is UP: ... elif flag is DOWN: ...

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 09:05 schreef Steven D'Aprano: > On Thursday 23 June 2016 16:34, Andreas Röhler wrote: > >> Indeed, why should the result of 4 - 4 have a different truth-value than >> 4 - 3 ? > Because 4-4 is zero, which is "nothing", while 4-3 is one, which is > "something". No zero is not nothin

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Antoon Pardon
Op 23-06-16 om 05:59 schreef Steven D'Aprano: > On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: > >> On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: >> [snip] >>> I feel that’s a needlessly complicated rule. It would have been simpler >>> if boolean operators (and conditional expressions like

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Steven D'Aprano
On Thursday 23 June 2016 14:47, Lawrence D’Oliveiro wrote: > On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote: >> On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: >>> * boolean operators don’t have to operate on boolean values. The >>> language spec >>>

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Christian Gollwitzer
Am 23.06.16 um 05:12 schrieb Larry Hudson: On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: I feel that’s a needlessly complicated rule. It would have been simpler if boolean operators (and conditional expressions like in if-statements and while-statements) only allowed values of boolean types

Re: Operator Precedence/Boolean Logic

2016-06-23 Thread Steven D'Aprano
On Thursday 23 June 2016 16:34, Andreas Röhler wrote: > Indeed, why should the result of 4 - 4 have a different truth-value than > 4 - 3 ? Because 4-4 is zero, which is "nothing", while 4-3 is one, which is "something". You might as well ask why False and True have different truth values. Iron

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Marko Rauhamaa
Andreas Röhler : > Indeed, why should the result of 4 - 4 have a different truth-value > than 4 - 3 ? This implementation seems to be a legacy from languages > without boolean types. In Lisp, only nil (= the empty list) is accepted as false, everything else is considered true. In Scheme, only #f

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Andreas Röhler
On 23.06.2016 06:47, Lawrence D’Oliveiro wrote: On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote: On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: * boolean operators don’t have to operate on boolean values. The language spec

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Rustom Mody
On Thursday, June 23, 2016 at 10:17:16 AM UTC+5:30, Lawrence D’Oliveiro wrote: > On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote: > > On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: > >> * boolean operators don’t have to operate on boolean values. The > >> language spec > >

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Lawrence D’Oliveiro
On Thursday, June 23, 2016 at 3:12:52 PM UTC+12, Larry Hudson wrote: > On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: >> * boolean operators don’t have to operate on boolean values. The >> language spec >> >> says:

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Elizabeth Weiss
On Wednesday, June 22, 2016 at 11:59:44 PM UTC-4, Steven D'Aprano wrote: > On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: > > > On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: > > [snip] > >> I feel that’s a needlessly complicated rule. It would have been simpler > >> if boolean operators (a

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Elizabeth Weiss
On Wednesday, June 22, 2016 at 3:42:24 AM UTC-4, Lawrence D’Oliveiro wrote: > On Wednesday, June 22, 2016 at 3:40:22 PM UTC+12, Elizabeth Weiss wrote: > > I am a little confused as to how this is False: > > > > False==(False or True) > > > > I would think it is True because False==False is true.

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Elizabeth Weiss
On Wednesday, June 22, 2016 at 3:15:02 AM UTC-4, Jussi Piitulainen wrote: > Christian Gollwitzer writes: > > > Am 22.06.16 um 05:40 schrieb Elizabeth Weiss: > >> I am a little confused as to how this is False: > >> > >> False==(False or True) > >> > >> I would think it is True because False==False

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Elizabeth Weiss
On Tuesday, June 21, 2016 at 11:59:37 PM UTC-4, Ben Finney wrote: > Elizabeth Weiss > writes: > > > Hi There, > > Welcome! Your questions are fine here, but you may like to know that we > also have a beginner-specific forum for collaborative tutoring > https://mail.python.org/mailman/listinfo/tu

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Elizabeth Weiss
On Tuesday, June 21, 2016 at 11:59:37 PM UTC-4, Ben Finney wrote: > Elizabeth Weiss > writes: > > > Hi There, > > Welcome! Your questions are fine here, but you may like to know that we > also have a beginner-specific forum for collaborative tutoring > https://mail.python.org/mailman/listinfo/tu

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Steven D'Aprano
On Thu, 23 Jun 2016 01:12 pm, Larry Hudson wrote: > On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: > [snip] >> I feel that’s a needlessly complicated rule. It would have been simpler >> if boolean operators (and conditional expressions like in if-statements >> and while-statements) only allowe

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Larry Hudson via Python-list
On 06/22/2016 12:42 AM, Lawrence D’Oliveiro wrote: [snip] I feel that’s a needlessly complicated rule. It would have been simpler if boolean operators (and conditional expressions like in if-statements and while-statements) only allowed values of boolean types. But that’s one of the few warts

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Erik
On 22/06/16 04:40, Elizabeth Weiss wrote: I am a little confused as to how this is False: False==(False or True) Other people have explained why the expression evaluates as it does - the sub-expression "False or True" evaluates to True (as one of the operands is truthy). Your expression then

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Random832
On Tue, Jun 21, 2016, at 23:40, Elizabeth Weiss wrote: > Hi There, > > I am a little confused as to how this is False: > > False==(False or True) > > I would think it is True because False==False is true. "False or True" is True, and then it reduces to "False == True" which is false. There's

Fwd: Operator Precedence/Boolean Logic

2016-06-22 Thread Jorge Gimeno
On Tue, Jun 21, 2016 at 8:40 PM, Elizabeth Weiss wrote: > Hi There, > > I am a little confused as to how this is False: > > False==(False or True) > > I would think it is True because False==False is true. > > I think the parenthesis are confusing me. > > (False==False) or True > > This is True.

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Lawrence D’Oliveiro
On Wednesday, June 22, 2016 at 3:40:22 PM UTC+12, Elizabeth Weiss wrote: > I am a little confused as to how this is False: > > False==(False or True) > > I would think it is True because False==False is true. > > I think the parenthesis are confusing me. No, it is the meanings of the boolean

Re: Operator Precedence/Boolean Logic

2016-06-22 Thread Jussi Piitulainen
Christian Gollwitzer writes: > Am 22.06.16 um 05:40 schrieb Elizabeth Weiss: >> I am a little confused as to how this is False: >> >> False==(False or True) >> >> I would think it is True because False==False is true. >> >> I think the parenthesis are confusing me. > > Are you thinking, by any cha

Re: Operator Precedence/Boolean Logic

2016-06-21 Thread Christian Gollwitzer
Am 22.06.16 um 05:40 schrieb Elizabeth Weiss: I am a little confused as to how this is False: False==(False or True) I would think it is True because False==False is true. I think the parenthesis are confusing me. Are you thinking, by any chance, that "or" indicates a choice? Comparing Fals

Re: Operator Precedence/Boolean Logic

2016-06-21 Thread Steven D'Aprano
On Wednesday 22 June 2016 13:40, Elizabeth Weiss wrote: > Hi There, > > I am a little confused as to how this is False: > > False==(False or True) > > I would think it is True because False==False is true. Remember that parentheses are always evaluated first. So Python evaluates: False or Tru

Re: Operator Precedence/Boolean Logic

2016-06-21 Thread Ben Finney
Elizabeth Weiss writes: > Hi There, Welcome! Your questions are fine here, but you may like to know that we also have a beginner-specific forum for collaborative tutoring https://mail.python.org/mailman/listinfo/tutor>. > I am a little confused as to how this is False: > False==(False or True)

Operator Precedence/Boolean Logic

2016-06-21 Thread Elizabeth Weiss
Hi There, I am a little confused as to how this is False: False==(False or True) I would think it is True because False==False is true. I think the parenthesis are confusing me. (False==False) or True This is True. Is it because False==False? And True==False is not True but that does not