Re: Usefulness of the "not in" operator

2011-11-06 Thread DevPlayer
On Oct 16, 12:05 am, Steven D'Aprano wrote: > On Sat, 15 Oct 2011 15:04:24 -0700, DevPlayer wrote: > > I thought "x not in y" was later added as syntax sugar for "not x in y" > > meaning they used the same set of tokens. (Too lazy to check the actual > > tokens) Stated in response to OP wanting a

Re: Usefulness of the "not in" operator

2011-10-15 Thread Steven D'Aprano
On Sat, 15 Oct 2011 15:04:24 -0700, DevPlayer wrote: > 1. I thought "x not in y" was later added as syntax sugar for "not x in > y" > meaning they used the same set of tokens. (Too lazy to check the actual > tokens) Whether the compiler has a special token for "not in" is irrelevant. Perhaps it

Re: Usefulness of the "not in" operator

2011-10-15 Thread DevPlayer
On Oct 8, 8:41 am, Alain Ketterlin wrote: > candide writes: > > Python provides > > >     -- the not operator, meaning logical negation > >     -- the in operator, meaning membership > > > On the other hand, Python provides the not in operator meaning > > non-membership. However, it seems we can

Re: Usefulness of the "not in" operator

2011-10-15 Thread Alexander Kapps
On 10.10.2011 19:29, Nobody wrote: On Sun, 09 Oct 2011 02:25:27 +0200, Alexander Kapps wrote: Even if it's off-topic, could you add some similar explanations for Church numerals (maybe Lambda calculus it isn't too much?) The Church numeral for N is a function of two arguments which applies it

Re: Usefulness of the "not in" operator

2011-10-13 Thread Jussi Piitulainen
Chris Angelico writes: > On Sun, Oct 9, 2011 at 12:07 AM, Jussi Piitulainen wrote: > > But both negations can be avoided by modus tollens. > > > > "If you are able to start the car, the key is in the ignition." > > But this translation implies looking at the result and ascertaining > the state, wh

Re: Usefulness of the "not in" operator

2011-10-11 Thread Alec Taylor
As you see, this way of writing constants gives you much more poetic freedom than in other programming languages. On Tue, Oct 11, 2011 at 7:46 PM, Chris Angelico wrote: > On Tue, Oct 11, 2011 at 7:28 PM, Nobody wrote: >> It's useful insofar as it allows you to define "numbers" given nothing >> o

Re: Usefulness of the "not in" operator

2011-10-11 Thread Chris Angelico
On Tue, Oct 11, 2011 at 7:28 PM, Nobody wrote: > It's useful insofar as it allows you to define "numbers" given nothing > other than abstraction and application, which are the only operations > available in the lambda calculus. > Heh. This is why mathematicians ALWAYS make use of previously-defin

Re: Usefulness of the "not in" operator

2011-10-11 Thread Nobody
On Tue, 11 Oct 2011 04:33:43 +1100, Chris Angelico wrote: >> The Church numeral for N is a function of two arguments which applies its >> first argument N times to its second, i.e. (f^N)(x) = f(f(...(f(x))...)). >> > > Thanks - nice clear explanation. Appreciated. For an encore, can you > give an

Re: Usefulness of the "not in" operator

2011-10-10 Thread Steven D'Aprano
Tim Roberts wrote: > Westley Martínez wrote: >>On Sat, Oct 08, 2011 at 12:34:42PM -0400, Roy Smith wrote: >>> >>> Here's my take on parenthesis: If you need to look up whether they're >>> necessary or not, they are :-) >> >>So we don't need precedence charts in the bathroom? > > Yes, we do, be

Re: Usefulness of the "not in" operator

2011-10-10 Thread Tim Roberts
Westley Martínez wrote: >On Sat, Oct 08, 2011 at 12:34:42PM -0400, Roy Smith wrote: >> >> Here's my take on parenthesis: If you need to look up whether they're >> necessary or not, they are :-) > >So we don't need precedence charts in the bathroom? Yes, we do, because I'm always reading code f

Re: Usefulness of the "not in" operator

2011-10-10 Thread Terry Reedy
On 10/10/2011 1:55 PM, Ian Kelly wrote: On Mon, Oct 10, 2011 at 11:33 AM, Chris Angelico wrote: On Tue, Oct 11, 2011 at 4:29 AM, Nobody wrote: The Church numeral for N is a function of two arguments which applies its first argument N times to its second, i.e. (f^N)(x) = f(f(...(f(x))...)).

Re: Usefulness of the "not in" operator

2011-10-10 Thread Ian Kelly
On Mon, Oct 10, 2011 at 11:33 AM, Chris Angelico wrote: > On Tue, Oct 11, 2011 at 4:29 AM, Nobody wrote: >> >> The Church numeral for N is a function of two arguments which applies its >> first argument N times to its second, i.e. (f^N)(x) = f(f(...(f(x))...)). >> > > Thanks - nice clear explanat

Re: Usefulness of the "not in" operator

2011-10-10 Thread Chris Angelico
On Tue, Oct 11, 2011 at 4:29 AM, Nobody wrote: > > The Church numeral for N is a function of two arguments which applies its > first argument N times to its second, i.e. (f^N)(x) = f(f(...(f(x))...)). > Thanks - nice clear explanation. Appreciated. For an encore, can you give an example of where

Re: Usefulness of the "not in" operator

2011-10-10 Thread Nobody
On Sun, 09 Oct 2011 02:25:27 +0200, Alexander Kapps wrote: > Even if it's off-topic, could you add some similar explanations for > Church numerals (maybe Lambda calculus it isn't too much?) The Church numeral for N is a function of two arguments which applies its first argument N times to its se

Re: Usefulness of the "not in" operator

2011-10-10 Thread candide
Le 10/10/2011 10:06, John Ladasky a écrit : Who like that second one speaks? Yoda his name is. Programs in Forth he must. ;) We can add to the list : -- Tarzan -- Geronimo -- don Alexandro de la Vega dying in the arms of Zorro ... -- http://mail.python.org/mailman/listinfo/python-list

Re: Usefulness of the "not in" operator

2011-10-10 Thread Alec Taylor
Unfortunately I don't know lambda [or for that matter, regular] calculus... On Tue, Oct 11, 2011 at 12:01 AM, Alain Ketterlin wrote: > Alec Taylor writes: > >> On Sun, Oct 9, 2011 at 3:08 AM, Steven D'Aprano >> wrote: > >>> def true(x, y): >>>    return x >>> >>> def false(x, y): >>>    return

Re: Usefulness of the "not in" operator

2011-10-10 Thread Alain Ketterlin
Alec Taylor writes: > On Sun, Oct 9, 2011 at 3:08 AM, Steven D'Aprano > wrote: >> def true(x, y): >>    return x >> >> def false(x, y): >>    return y [...] >> def Nand(a, b): >>    return (lambda c: lambda x, y: c(y, x))(a(b, a)) >> >> and we're done. [...] > Awesome Yes, that's how Church d

Re: Usefulness of the "not in" operator

2011-10-10 Thread Alec Taylor
On Sun, Oct 9, 2011 at 3:08 AM, Steven D'Aprano wrote: > Roy Smith wrote: > >> If you want to take it one step further, all the boolean operators can >> be derived from nand (the dualists would insist on using nor). > > Let's define the boolean values and operators using just two functions: > > de

Re: Usefulness of the "not in" operator

2011-10-10 Thread John Ladasky
On Oct 8, 5:01 am, Steven D'Aprano wrote: > Who like that second one speaks? Yoda his name is. Programs in Forth he must. -- http://mail.python.org/mailman/listinfo/python-list

Re: Usefulness of the "not in" operator

2011-10-10 Thread Alexander Kapps
On 08.10.2011 18:08, Steven D'Aprano wrote: Let's define the boolean values and operators using just two functions: [SNIP] Have you just explained Church booleans in an understandable language? Awesome. I still have to chew on this, but I think this is the first time where I might understan

Re: Usefulness of the "not in" operator

2011-10-09 Thread Westley Martínez
On Sat, Oct 08, 2011 at 12:34:42PM -0400, Roy Smith wrote: > In article <4e906108$0$27980$426a3...@news.free.fr>, > candide wrote: > > > After browsing source code, I realize that parenthesis are not necessary > > ("not" has higher precedence than "in"). > > Here's my take on parenthesis: If

Re: Usefulness of the "not in" operator

2011-10-09 Thread Albert van der Horst
In article , Jussi Piitulainen wrote: >Mel writes: > >> Steven D'Aprano wrote: >> >> > candide wrote: >> > >> >> So what is the usefulness of the "not in" operator ? Recall what Zen of >> >> Python tells >> >> >> >> There should be one-- and preferably only one --obvious way to do it. >> > >> > A

Re: Usefulness of the "not in" operator

2011-10-08 Thread Roy Smith
In article , Chris Angelico wrote: > I sent this email twelve hours ago but to the wrong mailing list > *blush*. Since nobody else has raised the point, I'll repost it. > > On Sun, Oct 9, 2011 at 12:07 AM, Jussi Piitulainen > wrote: > > But both negations can be avoided by modus tollens. > > >

Re: Usefulness of the "not in" operator

2011-10-08 Thread Chris Angelico
I sent this email twelve hours ago but to the wrong mailing list *blush*. Since nobody else has raised the point, I'll repost it. On Sun, Oct 9, 2011 at 12:07 AM, Jussi Piitulainen wrote: > But both negations can be avoided by modus tollens. > > "If you are able to start the car, the key is in th

Re: Usefulness of the "not in" operator

2011-10-08 Thread Alexander Kapps
On 09.10.2011 01:35, Tim Roberts wrote: Roy Smith wrote: In article<4e906108$0$27980$426a3...@news.free.fr>, candide wrote: After browsing source code, I realize that parenthesis are not necessary ("not" has higher precedence than "in"). Here's my take on parenthesis: If you need to look

Re: Usefulness of the "not in" operator

2011-10-08 Thread Tim Roberts
Roy Smith wrote: >In article <4e906108$0$27980$426a3...@news.free.fr>, > candide wrote: > >> After browsing source code, I realize that parenthesis are not necessary >> ("not" has higher precedence than "in"). > >Here's my take on parenthesis: If you need to look up whether they're >necessary

Re: Usefulness of the "not in" operator

2011-10-08 Thread Roy Smith
In article , rusi wrote: > On Oct 8, 6:31 pm, Roy Smith wrote: > > In article <87ehyn8xlp@dpt-info.u-strasbg.fr>, > >  Alain Ketterlin wrote: > > > > > Sure, but note that you can also reformulate != using not and ==, < > > > using not and >=, etc. Operators like "not in" and "is not" sho

Re: Usefulness of the "not in" operator

2011-10-08 Thread Chris Angelico
On Sun, Oct 9, 2011 at 3:31 AM, rusi wrote: >> If you want to take it one step further, all the boolean operators can >> be derived from nand (the dualists would insist on using nor). >                         > > I'm not sure what you're questioning, but it's possible to derive

Re: Usefulness of the "not in" operator

2011-10-08 Thread rusi
On Oct 8, 6:31 pm, Roy Smith wrote: > In article <87ehyn8xlp@dpt-info.u-strasbg.fr>, >  Alain Ketterlin wrote: > > > Sure, but note that you can also reformulate != using not and ==, < > > using not and >=, etc. Operators like "not in" and "is not" should > > really be considered single token

Re: Usefulness of the "not in" operator

2011-10-08 Thread Roy Smith
In article <4e906108$0$27980$426a3...@news.free.fr>, candide wrote: > After browsing source code, I realize that parenthesis are not necessary > ("not" has higher precedence than "in"). Here's my take on parenthesis: If you need to look up whether they're necessary or not, they are :-) -- h

Re: Usefulness of the "not in" operator

2011-10-08 Thread Steven D'Aprano
candide wrote: > Le 08/10/2011 14:01, Steven D'Aprano a écrit : > > > And "not in" is the obvious way to do it. > > Obvious ? Not so. I performed some code mining and it appears that even > good sources make use of "not (foo in bar)" expressions. All that proves is that even expert Python dev

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 17:16, Dave Angel a écrit : You should say "... parenthesis are not necessary ("not" has LOWER precedence than "in")." I should, yes, I confess ;) In my defense, I must tell that Python document reference here : http://docs.python.org/reference/expressions.html#summary has

Re: Usefulness of the "not in" operator

2011-10-08 Thread Steven D'Aprano
Roy Smith wrote: > If you want to take it one step further, all the boolean operators can > be derived from nand (the dualists would insist on using nor). Let's define the boolean values and operators using just two functions: def true(x, y): return x def false(x, y): return y That's

Re: Usefulness of the "not in" operator

2011-10-08 Thread Grant Edwards
On 2011-10-08, Steven D'Aprano wrote: > candide wrote: > >> So what is the usefulness of the "not in" operator ? Recall what Zen of >> Python tells >> >> There should be one-- and preferably only one --obvious way to do it. > > And "not in" is the obvious way to do it. > > > "If the key is not in

Re: Usefulness of the "not in" operator

2011-10-08 Thread Chris Angelico
On Sun, Oct 9, 2011 at 2:16 AM, Dave Angel wrote: > You should say >    "... parenthesis are not necessary ("not" has LOWER precedence than > "in")." > Is "are not" an operator in English, or should this be "not parentheses are necessary"? ChrisA -- http://mail.python.org/mailman/listinfo/pytho

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 17:13, Thorsten Kampe a écrit : * candide (Sat, 08 Oct 2011 16:41:11 +0200) After browsing source code, I realize that parenthesis are not necessary ("not" has higher precedence than "in"). Lower precedence. Ooops, thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Usefulness of the "not in" operator

2011-10-08 Thread Dave Angel
On 01/-10/-28163 02:59 PM, candide wrote: Le 08/10/2011 12:42, candide a écrit : >>> not ('th' in "python") False >>> After browsing source code, I realize that parenthesis are not necessary ("not" has higher precedence than "in"). You should say "... parenthesis are not necessary

Re: Usefulness of the "not in" operator

2011-10-08 Thread Thorsten Kampe
* candide (Sat, 08 Oct 2011 16:41:11 +0200) > After browsing source code, I realize that parenthesis are not > necessary ("not" has higher precedence than "in"). Lower precedence. Thorsten -- http://mail.python.org/mailman/listinfo/python-list

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 12:50, Jon Clements a écrit : 10 - 5 as 10 + -5 (as obviously the - is redundant as an operation), and 10 / 2 as int(10 * .5) or something, who needs a divide!? OK, I see your point but I was supposing non-membershipness seldom needed and in fact one can suppose that test memb

Re: Usefulness of the "not in" operator

2011-10-08 Thread Chris Angelico
On Sun, Oct 9, 2011 at 1:40 AM, candide wrote: > A notin operator or isnot operator would be less confusing (at least in my > case ;) ). > Let's replace both of them. in --> foo extant bar not in --> foo extinct bar That would solve the problem, wouldn't it? *ducking for cover* ChrisA -- htt

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 12:42, candide a écrit : >>> not ('th' in "python") False >>> After browsing source code, I realize that parenthesis are not necessary ("not" has higher precedence than "in"). -- http://mail.python.org/mailman/listinfo/python-list

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 14:01, Steven D'Aprano a écrit : > And "not in" is the obvious way to do it. > > Obvious ? Not so. I performed some code mining and it appears that even good sources make use of "not (foo in bar)" expressions. begin examples *** from drpython/drPlugin

Re: Usefulness of the "not in" operator

2011-10-08 Thread candide
Le 08/10/2011 14:41, Alain Ketterlin a écrit : Operators like "not in" and "is not" should really be considered single tokens, even though they seem to use "not". And I think they are really convenient. I realize that I was confused by the lexical form of the "not in" operator : it is made by

Re: Usefulness of the "not in" operator

2011-10-08 Thread Roy Smith
In article <87ehyn8xlp@dpt-info.u-strasbg.fr>, Alain Ketterlin wrote: > Sure, but note that you can also reformulate != using not and ==, < > using not and >=, etc. Operators like "not in" and "is not" should > really be considered single tokens, even though they seem to use "not". > And I t

Re: Usefulness of the "not in" operator

2011-10-08 Thread Jussi Piitulainen
Mel writes: > Steven D'Aprano wrote: > > > candide wrote: > > > >> So what is the usefulness of the "not in" operator ? Recall what Zen of > >> Python tells > >> > >> There should be one-- and preferably only one --obvious way to do it. > > > > And "not in" is the obvious way to do it. > > >

Re: Usefulness of the "not in" operator

2011-10-08 Thread Mel
Steven D'Aprano wrote: > candide wrote: > >> So what is the usefulness of the "not in" operator ? Recall what Zen of >> Python tells >> >> There should be one-- and preferably only one --obvious way to do it. > > And "not in" is the obvious way to do it. > > > "If the key is not in the igniti

Re: Usefulness of the "not in" operator

2011-10-08 Thread Alain Ketterlin
candide writes: > Python provides > > -- the not operator, meaning logical negation > -- the in operator, meaning membership > > On the other hand, Python provides the not in operator meaning > non-membership. However, it seems we can reformulate any "not in" > expression using only "not"

Re: Usefulness of the "not in" operator

2011-10-08 Thread Steven D'Aprano
candide wrote: > So what is the usefulness of the "not in" operator ? Recall what Zen of > Python tells > > There should be one-- and preferably only one --obvious way to do it. And "not in" is the obvious way to do it. "If the key is not in the ignition, you won't be able to start the car."

Re: Usefulness of the "not in" operator

2011-10-08 Thread Stefaan Himpe
So what is the usefulness of the "not in" operator ? Recall what Zen of Python tells There should be one-- and preferably only one --obvious way to do it. the zen of python also says (amongst other things): ... Readability counts. ... Although practicality beats purity ... Best regards, St

Re: Usefulness of the "not in" operator

2011-10-08 Thread Jon Clements
On Oct 8, 11:42 am, candide wrote: > Python provides > >      -- the not operator, meaning logical negation >      -- the in operator, meaning membership > > On the other hand, Python provides the not in operator meaning > non-membership. However, it seems we can reformulate any "not in" > express