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

Re: if the else short form

2010-10-11 Thread Neville Dempsey
On Oct 11, 11:46 am, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand 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.

Re: if the else short form

2010-10-10 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-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 enough.

Re: if the else short form

2010-10-10 Thread Hrvoje Niksic
Antoon Pardon antoon.par...@rece.vub.ac.be 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

Re: if the else short form

2010-10-10 Thread NevilleDNZ
On Oct 10, 6:02 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand 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.

Re: if the else short form

2010-10-10 Thread Lawrence D'Oliveiro
In message e8a79f5b-a16b-4b33-a116-93cbd07a7...@u5g2000prn.googlegroups.com, 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

Re: if the else short form

2010-10-09 Thread Lawrence D'Oliveiro
In message i8o1ij$ro...@news.eternal-september.org, BartC wrote: NevilleDNZ neville...@gmail.com 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

Re: if the else short form

2010-10-09 Thread NevilleDNZ
On Oct 9, 6:55 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message i8o1ij$ro...@news.eternal-september.org, BartC wrote: NevilleDNZ neville...@gmail.com wrote in message news:ad9841df-49a1-4c1b-95d0-e76b72df6...@w9g2000prc.googlegroups.com... In Algol68 this would

Re: if the else short form

2010-10-08 Thread NevilleDNZ
On Oct 7, 9:23 am, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand 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

Re: if the else short form

2010-10-08 Thread NevilleDNZ
On Oct 7, 10:36 am, BartC b...@freeuk.com 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

Re: if the else short form

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

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 mwil...@the-wire.com wrote in message

Re: if the else short form

2010-10-06 Thread Antoon Pardon
On Wed, Oct 06, 2010 at 01:45:51PM +1300, Lawrence D'Oliveiro wrote: In message mailman.1339.1286268545.29448.python-l...@python.org, Antoon Pardon wrote: On Tue, Oct 05, 2010 at 06:55:33PM +1300, Lawrence D'Oliveiro wrote: In message

Re: if the else short form

2010-10-06 Thread Lawrence D'Oliveiro
In message mailman.1384.1286348190.29448.python-l...@python.org, 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

Re: if the else short form

2010-10-06 Thread James Harris
On 5 Oct, 06:52, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand wrote: In message e8b46ea8-8d1e-4db9-91ba-501fd1a44...@g18g2000yqk.googlegroups.com, James Harris wrote: On 29 Sep, 18:20, Seebs usenet-nos...@seebs.net wrote: On 2010-09-29, Tracubik affdfsdfds...@b.com wrote:

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 mailman.1384.1286348190.29448.python-l...@python.org, 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

Re: if the else short form

2010-10-06 Thread BartC
James Harris james.harri...@googlemail.com wrote in message news:e8b46ea8-8d1e-4db9-91ba-501fd1a44...@g18g2000yqk.googlegroups.com... On 29 Sep, 18:20, Seebs usenet-nos...@seebs.net wrote: On 2010-09-29, Tracubik affdfsdfds...@b.com wrote: Hi all, I'm studying PyGTK tutorial and i've found

Re: if the else short form

2010-10-06 Thread Lawrence D'Oliveiro
In message i8i1h8$dc...@news.eternal-september.org, 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

Re: if the else short form

2010-10-06 Thread BartC
Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote in message news:i8j0dg$lh...@lust.ihug.co.nz... In message i8i1h8$dc...@news.eternal-september.org, 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

Re: if the else short form

2010-10-06 Thread Mel
BartC wrote: Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote in message news:i8j0dg$lh...@lust.ihug.co.nz... In message i8i1h8$dc...@news.eternal-september.org, 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

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 def fnc():

Re: if the else short form

2010-10-05 Thread Lawrence D'Oliveiro
In message e8b46ea8-8d1e-4db9-91ba-501fd1a44...@g18g2000yqk.googlegroups.com, James Harris wrote: On 29 Sep, 18:20, Seebs usenet-nos...@seebs.net wrote: On 2010-09-29, Tracubik affdfsdfds...@b.com wrote: button = gtk.Button((False,, True,)[fill==True]) Oh, what a nasty idiom. I'm

Re: if the else short form

2010-10-05 Thread Lawrence D'Oliveiro
In message mailman.1166.1285774349.29448.python-l...@python.org, 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

Re: if the else short form

2010-10-05 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: “boolnoob”,

Re: if the else short form

2010-10-05 Thread Lawrence D'Oliveiro
In message mailman.1232.1285927634.29448.python-l...@python.org, 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

Re: if the else short form

2010-10-05 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 backwards

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 mailman.1232.1285927634.29448.python-l...@python.org, 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

Re: if the else short form

2010-10-05 Thread Lawrence D'Oliveiro
In message mailman.1339.1286268545.29448.python-l...@python.org, Antoon Pardon wrote: On Tue, Oct 05, 2010 at 06:55:33PM +1300, Lawrence D'Oliveiro wrote: In message mailman.1232.1285927634.29448.python-l...@python.org, Antoon Pardon wrote: On Wed, Sep 29, 2010 at 01:38:48PM +0200,

Re: if the else short form

2010-10-05 Thread Andreas Waldenburger
On Tue, 05 Oct 2010 18:54:42 +1300 Lawrence D'Oliveiro l...@geek-central.gen.new_zealand 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! --

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 l...@geek-central.gen.new_zealand wrote: “boolnoob” Bwahahahah! Nice! And of course, an instance of such boolnoobery can be referred to as a

Re: if the else short form

2010-10-04 Thread John Nagle
On 10/1/2010 10:19 PM, Paul Rubin wrote: Steven D'Apranost...@remove-this-cybersource.com.au 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

Re: if the else short form

2010-10-04 Thread James Harris
On 29 Sep, 18:20, Seebs usenet-nos...@seebs.net wrote: On 2010-09-29, Tracubik affdfsdfds...@b.com 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

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 bruno.desthuilli...@gmail.com wrote: On 30 sep, 19:22, Andreas Waldenburger use...@geekmail.invalid wrote: On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) bruno.desthuilli...@gmail.com bruno.desthuilli...@gmail.com wrote:

Re: if the else short form

2010-10-02 Thread Steven D'Aprano
On Fri, 01 Oct 2010 22:19:14 -0700, Paul Rubin wrote: Steven D'Aprano st...@remove-this-cybersource.com.au 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

Re: if the else short form

2010-10-02 Thread Arnaud Delobelle
Paul Rubin no.em...@nospam.invalid writes: Steven D'Aprano st...@remove-this-cybersource.com.au 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

Re: if the else short form

2010-10-02 Thread Ian
On Oct 1, 11:19 pm, Paul Rubin no.em...@nospam.invalid wrote: Steven D'Aprano st...@remove-this-cybersource.com.au 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

Re: if the else short form

2010-10-01 Thread bruno.desthuilli...@gmail.com
On 30 sep, 19:22, Andreas Waldenburger use...@geekmail.invalid wrote: On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) bruno.desthuilli...@gmail.com bruno.desthuilli...@gmail.com wrote: On 29 sep, 19:20, Seebs usenet-nos...@seebs.net wrote: On 2010-09-29, Tracubik affdfsdfds...@b.com wrote:

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 affdfsdfds...@b.com 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 Antoon Pardon
On Wed, Sep 29, 2010 at 05:58:16AM -0700, bruno.desthuilli...@gmail.com wrote: On 29 sep, 13:38, Hrvoje Niksic hnik...@xemacs.org wrote: Tracubik affdfsdfds...@b.com writes: button = gtk.Button((False,, True,)[fill==True]) (snip) BTW adding ==True to a boolean value is redundant and

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 Waldenburgeruse...@geekmail.invalid wrote: On Thu, 30 Sep 2010 03:42:29 -0700 (PDT) bruno.desthuilli...@gmail.combruno.desthuilli...@gmail.com wrote: On 29 sep, 19:20, Seebsusenet-nos...@seebs.net wrote:

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 Waldenburgeruse...@geekmail.invalid 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

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

Re: if the else short form

2010-10-01 Thread Paul Rubin
Steven D'Aprano st...@remove-this-cybersource.com.au 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-09-30 Thread Sion Arrowsmith
Andreas Waldenburger use...@geekmail.invalid wrote: http://docs.python.org/release/3.1/reference/datamodel.html#the-standard-type-hierarchy [ ... ] Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the exception being that when converted to a

Re: if the else short form

2010-09-30 Thread bruno.desthuilli...@gmail.com
On 29 sep, 19:20, Seebs usenet-nos...@seebs.net wrote: On 2010-09-29, Tracubik affdfsdfds...@b.com 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

Re: if the else short form

2010-09-30 Thread Emile van Sebille
On 9/30/2010 3:21 AM Sion Arrowsmith said... Andreas Waldenburgeruse...@geekmail.invalid wrote: http://docs.python.org/release/3.1/reference/datamodel.html#the-standard-type-hierarchy [ ... ] Boolean values behave like the values 0 and 1, respectively, in almost all contexts, the

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 bruno.desthuilli...@gmail.com wrote: On 29 sep, 19:20, Seebs usenet-nos...@seebs.net wrote: On 2010-09-29, Tracubik affdfsdfds...@b.com wrote: button = gtk.Button((False,, True,)[fill==True]) Oh, what a nasty idiom.

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 this

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 affdfsdfds...@b.com wrote: Hi

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

Re: if the else short form

2010-09-29 Thread Hrvoje Niksic
Tracubik affdfsdfds...@b.com 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

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 affdfsdfds...@b.com Date: 29 Sep 2010 10:42:37 GMT To: python-list@python.org Hi all, I'm studying PyGTK tutorial and i've found this strange form: button = gtk.Button((False

Re: if the else short form

2010-09-29 Thread bruno.desthuilli...@gmail.com
On 29 sep, 13:38, Hrvoje Niksic hnik...@xemacs.org wrote: Tracubik affdfsdfds...@b.com 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

Re: if the else short form

2010-09-29 Thread Alex Willmer
On Sep 29, 12:38 pm, Hrvoje Niksic hnik...@xemacs.org wrote: Tracubik affdfsdfds...@b.com 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

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

Re: if the else short form

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

Re: if the else short form

2010-09-29 Thread Seebs
On 2010-09-29, Tracubik affdfsdfds...@b.com 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,