Re: if the else short form

2010-10-13 Thread John Nagle
On 10/10/2010 6:46 PM, Lawrence D'Oliveiro wrote: Languages that insisted on being able to do proper compiler-level cross checks between separately-compiled modules (e.g. Modula-2, Ada) never really became that popular. This saddened me. It's an sad consequence of a UNIX mindset that "you c

Re: if the else short form

2010-10-11 Thread Neville Dempsey
On Oct 11, 11:46 am, Lawrence D'Oliveiro wrote: > Nowadays we take it for granted that the core language should be a strong > and compact basis to build on, rather than providing lots of built-in > features, and all the rest should come from run-time libraries. Fast forward to 1972... In 1972 Bri

Re: if the else short form

2010-10-10 Thread Lawrence D'Oliveiro
In message , NevilleDNZ wrote: > Not having LIST and DICT as part of the base language would make sense > if user contributions were encouraged. Unfortunately, they neglected to include any kind of module/package system to make this kind of thing easy to do. But then again, the state of the ar

Re: if the else short form

2010-10-10 Thread NevilleDNZ
On Oct 10, 6:02 pm, Lawrence D'Oliveiro wrote: > As for DICT, I think table lookups were still a sufficiently novel concept > for people to disagree on how they should best be implemented. I then stumbled over this paper: Title: List processing in Algol 68 - V. J. Rayward-Smith International Jour

Re: if the else short form

2010-10-10 Thread Hrvoje Niksic
Antoon Pardon writes: > Personaly I don't see a reason to declare in advance that someone > who wants to treat "True" differently from non-zero numbers or > non-empty sequences and does so by a test like: > > if var == Trueorif var is True > > to have written incorrect code. I wouldn't

Re: if the else short form

2010-10-10 Thread Lawrence D'Oliveiro
In message <45368e8d-3b4f-4380-974d-bf9cd5d68...@w9g2000prc.googlegroups.com>, NevilleDNZ wrote: > I do ponder why (given that linked lists can easily be created in Algol68) > useful types like LIST and DICT were left out of the standard prelude. I guess a list type wasn’t seen as primitive enou

Re: if the else short form

2010-10-09 Thread saeed.gnu
>>> True == 1 True >>> False == 0 True >>> int(True) 1 >>> int(False) 0 >>> bool(1) True >>> bool(0) False ‌But: str(fill==True)+',' is simpler than: ("False,", "True,")[fill==True] -- http://mail.python.org/mailman/listinfo/python-list

Re: if the else short form

2010-10-09 Thread NevilleDNZ
On Oct 9, 6:55 pm, Lawrence D'Oliveiro wrote: > In message , BartC wrote: > > > "NevilleDNZ" wrote in message > >news:ad9841df-49a1-4c1b-95d0-e76b72df6...@w9g2000prc.googlegroups.com... > > >> In Algol68 this would be: > >> x:=(i|"One","Two","Three"|"None Of The Above") > > > The point is, the co

Re: if the else short form

2010-10-09 Thread Lawrence D'Oliveiro
In message , BartC wrote: > "NevilleDNZ" wrote in message > news:ad9841df-49a1-4c1b-95d0-e76b72df6...@w9g2000prc.googlegroups.com... > >> In Algol68 this would be: >> x:=(i|"One","Two","Three"|"None Of The Above") > > The point is, the construction works well when the syntax fully supports > it.

Re: if the else short form

2010-10-08 Thread BartC
"NevilleDNZ" wrote in message news:ad9841df-49a1-4c1b-95d0-e76b72df6...@w9g2000prc.googlegroups.com... On Oct 7, 9:23 am, Lawrence D'Oliveiro wrote: x = {1 : "One", 2 : "Two", 3 : "Three"}.get(i, "None Of The Above") More like: x = {1:lambda:"One", 2:lambda:"Two", 3:lambda:"Three"}.get(i,

Re: if the else short form

2010-10-08 Thread NevilleDNZ
On Oct 7, 10:36 am, "BartC" wrote: > i=16 > x = {1 : fna(), 2 : fnb(), 3 : fnc()}.get(i, "None Of The Above") > print x > > Other than efficiency concerns, sometimes you don't want the extra > side-effects. > > Probably there are workarounds here too, but I suspect the syntax won't be > quite as p

Re: if the else short form

2010-10-08 Thread NevilleDNZ
On Oct 7, 9:23 am, Lawrence D'Oliveiro wrote: > x = {1 : "One", 2 : "Two", 3 : "Three"}.get(i, "None Of The Above") More like: x = {1:lambda:"One", 2:lambda:"Two", 3:lambda:"Three"}.get(i, lambda:"None Of The Above")() i.e. deferred evaluation of selected case. In Algol68 this would be: x:=(i|"

Re: if the else short form

2010-10-07 Thread BartC
On Thu, 07 Oct 2010 01:36:33 +0100, BartC wrote: However, as I mentioned, one problem here is having to evaluate all the items in the list before selecting one: ... x = {1 : fna(), 2 : fnb(), 3 : fnc()}.get(i, "None Of The Above") "Mel" wrote in message news:i8j56e$ub...@speranza.aioe.org

Re: if the else short form

2010-10-06 Thread Steven D'Aprano
On Thu, 07 Oct 2010 01:36:33 +0100, BartC wrote: > However, as I mentioned, one problem here is having to evaluate all the > items in the list before selecting one: > > def fna(): > print "FNA CALLED" > return "One" > def fnb(): > print "FNB CALLED" > return "Two

Re: if the else short form

2010-10-06 Thread Mel
BartC wrote: > > > "Lawrence D'Oliveiro" wrote in message > news:i8j0dg$lh...@lust.ihug.co.nz... >> In message , BartC wrote: > >>> x = ("One","Two","Three") [i-1] >>> >>> While this works for i = 1,2,3, it goes funny for i=0,-1,-2, and >>> generates >>> an error for the rest ... >> >> x = {1

Re: if the else short form

2010-10-06 Thread BartC
"Lawrence D'Oliveiro" wrote in message news:i8j0dg$lh...@lust.ihug.co.nz... In message , BartC wrote: x = ("One","Two","Three") [i-1] While this works for i = 1,2,3, it goes funny for i=0,-1,-2, and generates an error for the rest ... x = {1 : "One", 2 : "Two", 3 : "Three"}.get(i, "No

Re: if the else short form

2010-10-06 Thread Lawrence D'Oliveiro
In message , BartC wrote: > I use this syntax where there are two possibilities chosen according to > condition 'a': > > (a | b | c) Algol 68! > x = ("One","Two","Three") [i-1] > > While this works for i = 1,2,3, it goes funny for i=0,-1,-2, and generates > an error for the rest ... x = {1 :

Re: if the else short form

2010-10-06 Thread BartC
"James Harris" wrote in message news:e8b46ea8-8d1e-4db9-91ba-501fd1a44...@g18g2000yqk.googlegroups.com... On 29 Sep, 18:20, Seebs wrote: On 2010-09-29, Tracubik wrote: > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > button = gtk.Button(("False,", "True,")[fill==T

Re: if the else short form

2010-10-06 Thread Antoon Pardon
On Wed, Oct 06, 2010 at 09:31:48PM +1300, Lawrence D'Oliveiro wrote: > In message , Antoon > Pardon wrote: > > > A lot of times someone comes with code like the following: > > > > if len(lst) != 0: > > ... > > > > > > and than gets the advise to write it as follows: > > > > if lst: >

Re: if the else short form

2010-10-06 Thread James Harris
On 5 Oct, 06:52, Lawrence D'Oliveiro wrote: > In message > , James > > Harris wrote: > > On 29 Sep, 18:20, Seebs wrote: > > >> On 2010-09-29, Tracubik wrote: > > >>> button = gtk.Button(("False,", "True,")[fill==True]) > > >> Oh, what a nasty idiom. > > > I'm surprised you don't like this constr

Re: if the else short form

2010-10-06 Thread Lawrence D'Oliveiro
In message , Antoon Pardon wrote: > A lot of times someone comes with code like the following: > > if len(lst) != 0: > ... > > > and than gets the advise to write it as follows: > > if lst: > ... > > Do you mean that this second piece of code is incorrectly written ... Yes. --

Re: if the else short form

2010-10-05 Thread Antoon Pardon
On Wed, Oct 06, 2010 at 01:45:51PM +1300, Lawrence D'Oliveiro wrote: > In message , Antoon > Pardon wrote: > > > On Tue, Oct 05, 2010 at 06:55:33PM +1300, Lawrence D'Oliveiro wrote: > > > >> In message , Antoon > >> Pardon wrote: > >> > >> > On Wed, Sep 29, 2010 at 01:38:48PM +0200, Hrvoje Niksi

Re: if the else short form

2010-10-05 Thread Lawrence D'Oliveiro
In message <20101005223520.3f5d9...@geekmail.invalid>, Andreas Waldenburger wrote: > On Tue, 05 Oct 2010 18:54:42 +1300 Lawrence D'Oliveiro > wrote: > >> “boolnoob” > > Bwahahahah! Nice! And of course, an instance of such boolnoobery can be referred to as a boolnoobism. :) -- http://mail.p

Re: if the else short form

2010-10-05 Thread Andreas Waldenburger
On Tue, 05 Oct 2010 18:54:42 +1300 Lawrence D'Oliveiro wrote: > “boolnoob” Bwahahahah! Nice! I'd love to say that I'll add this to my active vocabulary, but I don't think there will be enough opportunities to use it. :-/ /W -- INVALID? DE! -- http://mail.python.org/mailman/listinfo/python-

Re: if the else short form

2010-10-05 Thread Lawrence D'Oliveiro
In message , Antoon Pardon wrote: > On Tue, Oct 05, 2010 at 06:55:33PM +1300, Lawrence D'Oliveiro wrote: > >> In message , Antoon >> Pardon wrote: >> >> > On Wed, Sep 29, 2010 at 01:38:48PM +0200, Hrvoje Niksic wrote: >> > >> >> BTW adding "==True" to a boolean value is redundant and can even br

Re: if the else short form

2010-10-05 Thread Antoon Pardon
On Tue, Oct 05, 2010 at 06:55:33PM +1300, Lawrence D'Oliveiro wrote: > In message , Antoon > Pardon wrote: > > > On Wed, Sep 29, 2010 at 01:38:48PM +0200, Hrvoje Niksic wrote: > > > >> BTW adding "==True" to a boolean value is redundant and can even break > >> for logically true values that don't

Re: if the else short form

2010-10-04 Thread Lawrence D'Oliveiro
In message <4ca96440$0$1674$742ec...@news.sonic.net>, John Nagle wrote: > Yes, "bool" is a subtype of "int" in Python. This was > because the original design of Python didn't have "bool" > (a rather strange mistake for a language designed this late) > and the retrofit had to have some backwa

Re: if the else short form

2010-10-04 Thread Lawrence D'Oliveiro
In message , Antoon Pardon wrote: > On Wed, Sep 29, 2010 at 01:38:48PM +0200, Hrvoje Niksic wrote: > >> BTW adding "==True" to a boolean value is redundant and can even break >> for logically true values that don't compare equal to True (such as the >> number 10 or the string "foo"). > > But lea

Re: if the else short form

2010-10-04 Thread Lawrence D'Oliveiro
In message <877hi44w53@xemacs.org>, Hrvoje Niksic wrote: > BTW adding "==True" to a boolean value is redundant and can even break > for logically true values that don't compare equal to True (such as the > number 10 or the string "foo"). I wonder if there’s a name for this sort of thing: “boo

Re: if the else short form

2010-10-04 Thread Lawrence D'Oliveiro
In message , Philip Semanchuk wrote: > Does Python make any guarantee that int(True) == 1 and int(False) == 0 > will always hold, or are their values an implementation detail? There has never been a rationally-designed language where this was merely “an implementation detail”. -- http://mail.p

Re: if the else short form

2010-10-04 Thread Lawrence D'Oliveiro
In message , James Harris wrote: > On 29 Sep, 18:20, Seebs wrote: > >> On 2010-09-29, Tracubik wrote: >> >>> button = gtk.Button(("False,", "True,")[fill==True]) >> >> Oh, what a nasty idiom. > > I'm surprised you don't like this construct. I hadn't seen it until I > read the OP's question ju

Re: if the else short form

2010-10-04 Thread James Harris
On 29 Sep, 18:20, Seebs wrote: > On 2010-09-29, Tracubik wrote: > > > Hi all, > > I'm studying PyGTK tutorial and i've found this strange form: > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > the label of button is True if fill==True, is False otherwise. > > > i have googled for

Re: if the else short form

2010-10-04 Thread John Nagle
On 10/1/2010 10:19 PM, Paul Rubin wrote: Steven D'Aprano writes: Incorrect. bools *are* ints in Python, beyond any doubt. Python 2.6.2 (r262:71600, Jun 4 2010, 18:28:58) >>> type(3)==type(True) False Yes, "bool" is a subtype of "int" in Python. This was because the ori

Re: if the else short form

2010-10-03 Thread Andreas Waldenburger
On Fri, 1 Oct 2010 00:42:34 -0700 (PDT) "bruno.desthuilli...@gmail.com" wrote: > On 30 sep, 19:22, Andreas Waldenburger > wrote: > > On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) > > > > "bruno.desthuilli...@gmail.com" > > wrote: > > > On 29 sep, 19:20, Seebs wrote: > > > > On 2010-09-29, Tracubik

Re: if the else short form

2010-10-02 Thread Ian
On Oct 1, 11:19 pm, Paul Rubin wrote: > Steven D'Aprano writes: > > Incorrect. bools *are* ints in Python, beyond any doubt. > >     Python 2.6.2 (r262:71600, Jun  4 2010, 18:28:58) >     >>> type(3)==type(True) >     False >>> -1 < False < True < 2 True >>> True + True 2 >>> hex(True) '0x1'

Re: if the else short form

2010-10-01 Thread Arnaud Delobelle
Paul Rubin writes: > Steven D'Aprano writes: >> Incorrect. bools *are* ints in Python, beyond any doubt. > > Python 2.6.2 (r262:71600, Jun 4 2010, 18:28:58) > >>> type(3)==type(True) > False Of course, but it's the wrong thing to ask if you want know if bools are ints. To find ou

Re: if the else short form

2010-10-01 Thread Steven D'Aprano
On Fri, 01 Oct 2010 22:19:14 -0700, Paul Rubin wrote: > Steven D'Aprano writes: >> Incorrect. bools *are* ints in Python, beyond any doubt. > > Python 2.6.2 (r262:71600, Jun 4 2010, 18:28:58) > >>> type(3)==type(True) > False So? Instances of a subclasses are still instances of the

Re: if the else short form

2010-10-01 Thread Paul Rubin
Steven D'Aprano writes: > Incorrect. bools *are* ints in Python, beyond any doubt. Python 2.6.2 (r262:71600, Jun 4 2010, 18:28:58) >>> type(3)==type(True) False -- http://mail.python.org/mailman/listinfo/python-list

Re: if the else short form

2010-10-01 Thread Steven D'Aprano
On Fri, 01 Oct 2010 11:23:25 -0700, John Nagle wrote: >> Why so ? The doc clearly states that booleans are integers with True == >> 1 and False == 0, so there's nothing implicit here. > > Python "bool" values are NOT integers. They can be coerced to > integers for historical reasons. Inc

Re: if the else short form

2010-10-01 Thread Ethan Furman
John Nagle wrote: On 10/1/2010 12:42 AM, bruno.desthuilli...@gmail.com wrote: On 30 sep, 19:22, Andreas Waldenburger wrote: >>> But it does violate the "explicit is better than implicit" tenet, don't you think? Why so ? The doc clearly states that booleans are integers with True == 1 and Fal

Re: if the else short form

2010-10-01 Thread John Nagle
On 10/1/2010 12:42 AM, bruno.desthuilli...@gmail.com wrote: On 30 sep, 19:22, Andreas Waldenburger wrote: On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) "bruno.desthuilli...@gmail.com" wrote: On 29 sep, 19:20, Seebs wrote: On 2010-09-29, Tracubik wrote: button = gtk.Button(("False,", "True,")[f

Re: if the else short form

2010-10-01 Thread Antoon Pardon
On Wed, Sep 29, 2010 at 05:58:16AM -0700, bruno.desthuilli...@gmail.com wrote: > On 29 sep, 13:38, Hrvoje Niksic wrote: > > Tracubik writes: > > > > > button = gtk.Button(("False,", "True,")[fill==True]) > > (snip) > > > BTW adding "==True" to a boolean value is redundant and can even break > >

Re: if the else short form

2010-10-01 Thread Antoon Pardon
On Wed, Sep 29, 2010 at 01:38:48PM +0200, Hrvoje Niksic wrote: > Tracubik writes: > > > Hi all, > > I'm studying PyGTK tutorial and i've found this strange form: > > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > > the label of button is True if fill==True, is False otherwise. >

Re: if the else short form

2010-10-01 Thread bruno.desthuilli...@gmail.com
On 30 sep, 19:22, Andreas Waldenburger wrote: > On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) > > "bruno.desthuilli...@gmail.com" wrote: > > On 29 sep, 19:20, Seebs wrote: > > > On 2010-09-29, Tracubik wrote: > > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > > Oh, what a nasty idiom

Re: if the else short form

2010-09-30 Thread Andreas Waldenburger
On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) "bruno.desthuilli...@gmail.com" wrote: > On 29 sep, 19:20, Seebs wrote: > > On 2010-09-29, Tracubik wrote: > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > Oh, what a nasty idiom. > > > > Well, it's not very different from dict-based di

Re: if the else short form

2010-09-30 Thread Emile van Sebille
On 9/30/2010 3:21 AM Sion Arrowsmith said... Andreas Waldenburger wrote: [ ... ] Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that wh

Re: if the else short form

2010-09-30 Thread bruno.desthuilli...@gmail.com
On 29 sep, 19:20, Seebs wrote: > On 2010-09-29, Tracubik wrote: > > button = gtk.Button(("False,", "True,")[fill==True]) > Oh, what a nasty idiom. > Well, it's not very different from dict-based dispatch , which is the core of OO polymorphic dispatch in quite a few dynamic OOPLs. Anyway, it's

Re: if the else short form

2010-09-30 Thread Sion Arrowsmith
Andreas Waldenburger wrote: > >[ ... ] >Boolean values behave like the values 0 and 1, respectively, in >almost all contexts, the exception being that when converted to a >string, the strings

Re: if the else short form

2010-09-29 Thread Seebs
On 2010-09-29, Tracubik wrote: > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. > > i have googled for this form but i haven't found nothing, so can

Re: if the else short form

2010-09-29 Thread Andreas Waldenburger
On Wed, 29 Sep 2010 08:53:17 -0400 Philip Semanchuk wrote: > Does Python make any guarantee that int(True) == 1 and int(False) == > 0 will always hold, or are their values an implementation detail? > Bool

Re: if the else short form

2010-09-29 Thread Emile van Sebille
On 9/29/2010 5:53 AM Philip Semanchuk said... Does Python make any guarantee that int(True) == 1 and int(False) == 0 will always hold, or are their values an implementation detail? I had exactly this same question occur to me yesterday, and yes, I believe it does. From http://docs.python.

Re: if the else short form

2010-09-29 Thread Philip Semanchuk
On Sep 29, 2010, at 7:19 AM, Tom Potts wrote: > This is just a sneaky shorthand, which is fine if that's what you want, but > it makes it harder to read. The reason it works is that 'fill==True' is a > boolean expression, which evaluates to True or False, but if you force a > True into being an

Re: if the else short form

2010-09-29 Thread Alex Willmer
On Sep 29, 12:38 pm, Hrvoje Niksic wrote: > Tracubik writes: > > Hi all, > > I'm studying PyGTK tutorial and i've found this strange form: > > > button = gtk.Button(("False,", "True,")[fill==True]) > > > the label of button is True if fill==True, is False otherwise. > > The tutorial likely predat

Re: if the else short form

2010-09-29 Thread bruno.desthuilli...@gmail.com
On 29 sep, 13:38, Hrvoje Niksic wrote: > Tracubik writes: > > > button = gtk.Button(("False,", "True,")[fill==True]) (snip) > BTW adding "==True" to a boolean value is redundant and can even break > for logically true values that don't compare equal to True (such as the > number 10 or the strin

Re: [Python-list] if the else short form

2010-09-29 Thread Brendan Simon (eTRIX)
On 29/09/10 9:20 PM, python-list-requ...@python.org wrote: > Subject: > if the else short form > From: > Tracubik > Date: > 29 Sep 2010 10:42:37 GMT > > To: > python-list@python.org > > > Hi all, > I'm studying PyGTK tutorial and i've found t

Re: if the else short form

2010-09-29 Thread Hrvoje Niksic
Tracubik writes: > Hi all, > I'm studying PyGTK tutorial and i've found this strange form: > > button = gtk.Button(("False,", "True,")[fill==True]) > > the label of button is True if fill==True, is False otherwise. The tutorial likely predates if/else expression syntax introduced in 2.5, which w

Re: if the else short form

2010-09-29 Thread Tom Potts
This is just a sneaky shorthand, which is fine if that's what you want, but it makes it harder to read. The reason it works is that 'fill==True' is a boolean expression, which evaluates to True or False, but if you force a True into being an integer, it will be 1, and a False will become 0. Try w

Re: if the else short form

2010-09-29 Thread Joost Molenaar
Hi Nico, it's converting fill==True to an int, thereby choosing the string "False," or "True," by indexing into the tuple. Try this in an interpreter: >>> ['a','b'][False] 'a' >>> ['a','b'][True] 'b' >>> int(False) 0 >>> int(True) 1 Joost On 29 September 2010 12:42, Tracubik wrote: > > Hi all,

if the else short form

2010-09-29 Thread Tracubik
Hi all, I'm studying PyGTK tutorial and i've found this strange form: button = gtk.Button(("False,", "True,")[fill==True]) the label of button is True if fill==True, is False otherwise. i have googled for this form but i haven't found nothing, so can any of you pass me any reference/link to thi