Re: Case Statements

2016-03-20 Thread Antoon Pardon
Command line parsing is a case where switch >>>>>> statements are often used, e.g. in shell scripts. >>>>> >>>>> I've seen at least six different ways of simulating switches, so >>>>> those >>>>> people who want them, can h

Re: Case Statements

2016-03-20 Thread Mark Lawrence
On 16/03/2016 15:27, Antoon Pardon wrote: Op 16-03-16 om 15:02 schreef Mark Lawrence: On 16/03/2016 13:38, Antoon Pardon wrote: Op 16-03-16 om 12:07 schreef Mark Lawrence: Raise the item on the python-ideas mailing list for the umpteenth time then, and see how far you get. I don't care enou

Re: Case Statements

2016-03-20 Thread Mark Lawrence
On 20/03/2016 08:01, Rustom Mody wrote: On Wednesday, March 16, 2016 at 5:51:21 PM UTC+5:30, Marko Rauhamaa wrote: BartC : On 16/03/2016 11:07, Mark Lawrence wrote: but I still very much doubt we'll be adding a switch statement -- it's a "sexy" language design issue I did *NOT* write the

Re: Case Statements

2016-03-20 Thread Rustom Mody
and "==" (~ "equal?"). >The "case" form makes use of the operator "eqv?" that is missing from >Python ("eqv?" compares numbers numerically but is otherwise the same >as "eq?"). > > > Marko I think it needs to b

Re: Case Statements

2016-03-20 Thread Antoon Pardon
Op 16-03-16 om 18:24 schreef Mark Lawrence: > On 16/03/2016 15:27, Antoon Pardon wrote: >> Op 16-03-16 om 15:02 schreef Mark Lawrence: >>> On 16/03/2016 13:38, Antoon Pardon wrote: Op 16-03-16 om 12:07 schreef Mark Lawrence: > > Raise the item on the python-ideas mailing list for the u

Re: Case Statements

2016-03-19 Thread Steven D'Aprano
On Thursday 17 March 2016 16:45, Gregory Ewing wrote: > Steven D'Aprano wrote: >> On Thu, 17 Mar 2016 11:31 am, Chris Angelico wrote: >> >>>orig = globals()[cls.__name__] >> >> I wouldn't want to rely on it working with decorator syntax either. Even >> if it does now, I'm not sure that's a l

Re: Case Statements

2016-03-19 Thread Chris Angelico
On Thu, Mar 17, 2016 at 8:23 PM, Antoon Pardon wrote: > Op 17-03-16 om 03:02 schreef Chris Angelico: >> On Thu, Mar 17, 2016 at 12:54 PM, Steven D'Aprano >> wrote: >> >>> I wouldn't want to rely on it working with decorator syntax either. Even if >>> it does now, I'm not sure that's a language g

Re: Case Statements

2016-03-19 Thread Steven D'Aprano
On Thu, 17 Mar 2016 12:15 am, l0r0m0a0...@gmail.com wrote: > What hath I wrought? Dr Ray Stantz: Fire and brimstone coming down from the skies! Rivers and seas boiling! Dr Egon Spengler: Forty years of darkness! Earthquakes, volcanoes... Winston Zeddemore: The dead rising from the grave! Dr P

Re: Case Statements

2016-03-19 Thread l0r0m0a0i0l
What hath I wrought? -- https://mail.python.org/mailman/listinfo/python-list

Re: Case Statements

2016-03-19 Thread BartC
uot;==" (~ "equal?"). The "case" form makes use of the operator "eqv?" that is missing from Python ("eqv?" compares numbers numerically but is otherwise the same as "eq?"). Yes, a few scripting languages can do interesting things with swit

Re: Case Statements

2016-03-19 Thread Marko Rauhamaa
l0r0m0a0...@gmail.com: > Gratified to see that with all this back-and-forth this thread still > has a sense of humor. Perhaps, we can all just agree to disagree? :) I might agree with you if you tell me what we disagree about. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: Case Statements

2016-03-19 Thread Steven D'Aprano
On Wed, 16 Mar 2016 09:34 pm, BartC wrote: > (BTW why does Python have 'elif' when if-else is all that is really > needed?) To save indentation. if condition: block else: if other: block else: if third: block else: block versus: if

Re: Case Statements

2016-03-19 Thread Mark Lawrence
On 16/03/2016 19:41, BartC wrote: On 16/03/2016 09:51, Mark Lawrence wrote: On 16/03/2016 09:35, Antoon Pardon wrote: So I guess those who would like a case statement in Python can only hope a core developer gets bitten by a nasty bug while using one of those ways of simulating switches. S

Re: Case Statements

2016-03-19 Thread Steven D'Aprano
On Thu, 17 Mar 2016 10:14 am, Chris Angelico wrote: > On Thu, Mar 17, 2016 at 5:31 AM, Antoon Pardon > wrote: >> It can be yes. Look at decorators. They don't provide functionality >> we wouldn't have without them. > > Really? Okay, try implementing this without decorators: [...] > @monkeypatc

Re: Case Statements

2016-03-19 Thread Chris Angelico
On Thu, Mar 17, 2016 at 11:19 AM, Steven D'Aprano wrote: > On Thu, 17 Mar 2016 10:14 am, Chris Angelico wrote: > >> On Thu, Mar 17, 2016 at 5:31 AM, Antoon Pardon >> wrote: >>> It can be yes. Look at decorators. They don't provide functionality >>> we wouldn't have without them. >> >> Really? Oka

Re: Case Statements

2016-03-19 Thread Marko Rauhamaa
BartC : > On 16/03/2016 11:07, Mark Lawrence wrote: >> but I still very much doubt we'll be adding a switch statement -- >> it's a "sexy" language design issue > > That's the first time I've heard a language feature common in C > described as sexy. Scheme has a "switch" statement (a "case" form).

Re: Case Statements

2016-03-19 Thread BartC
On 16/03/2016 21:43, Mark Lawrence wrote: On 16/03/2016 19:41, BartC wrote: That article appears to try to do without using a new switch byte-code, as the author doesn't see the point. My code to implement a 'switch' byte-code (for integer expression and constant integer case-expressions) is b

Re: Case Statements

2016-03-19 Thread l0r0m0a0i0l
Gratified to see that with all this back-and-forth this thread still has a sense of humor. Perhaps, we can all just agree to disagree? :) -- https://mail.python.org/mailman/listinfo/python-list

Re: Case Statements

2016-03-19 Thread Gregory Ewing
Chris Angelico wrote: So maybe it's a language guarantee that hasn't been written down somewhere, The Language Reference says: [the decorator] is invoked with the function object as the only argument. The returned value is bound to the function name instead of the function object. The "

Re: Case Statements

2016-03-19 Thread Antoon Pardon
Op 17-03-16 om 03:02 schreef Chris Angelico: > On Thu, Mar 17, 2016 at 12:54 PM, Steven D'Aprano wrote: > >> I wouldn't want to rely on it working with decorator syntax either. Even if >> it does now, I'm not sure that's a language guarantee. > That's the thing, though. It's not a guarantee, yet i

Re: Case Statements

2016-03-19 Thread Mark Lawrence
On 16/03/2016 13:38, Antoon Pardon wrote: Op 16-03-16 om 12:07 schreef Mark Lawrence: Raise the item on the python-ideas mailing list for the umpteenth time then, and see how far you get. I don't care enough. I do care about people using valid arguments. Arguments have been made for and ag

Re: Case Statements

2016-03-19 Thread Antoon Pardon
Op 16-03-16 om 15:02 schreef Mark Lawrence: > On 16/03/2016 13:38, Antoon Pardon wrote: >> Op 16-03-16 om 12:07 schreef Mark Lawrence: >>> >>> Raise the item on the python-ideas mailing list for the umpteenth time >>> then, and see how far you get. >> >> I don't care enough. I do care about people

Re: Case Statements

2016-03-19 Thread Gregory Ewing
Steven D'Aprano wrote: On Thu, 17 Mar 2016 11:31 am, Chris Angelico wrote: orig = globals()[cls.__name__] I wouldn't want to rely on it working with decorator syntax either. Even if it does now, I'm not sure that's a language guarantee. The following idiom relies on similar behaviour:

Re: Case Statements

2016-03-19 Thread Mark Lawrence
On 16/03/2016 13:27, Steven D'Aprano wrote: On Thu, 17 Mar 2016 12:15 am, l0r0m0a0...@gmail.com wrote: What hath I wrought? Dr Ray Stantz: Fire and brimstone coming down from the skies! Rivers and seas boiling! Dr Egon Spengler: Forty years of darkness! Earthquakes, volcanoes... Winston Ze

Re: Case Statements

2016-03-19 Thread Marko Rauhamaa
Antoon Pardon : > Op 16-03-16 om 20:27 schreef Marko Rauhamaa: >> Antoon Pardon : >>> Look at decorators. They don't provide functionality we wouldn't have >>> without them. So we don't actually need them. Do you argue that >>> introducing them wasn't progress? >> I do. > > Way to miss the point.

Re: Case Statements

2016-03-19 Thread Steven D'Aprano
On Thu, 17 Mar 2016 11:31 am, Chris Angelico wrote: > Yes... in theory. But try rewriting my example to avoid decorator > syntax. It won't work, because of this line: > > orig = globals()[cls.__name__] That's a nasty, dirty piece of code, and I hope you are thoroughly ashamed of having writt

Re: Case Statements

2016-03-19 Thread Antoon Pardon
Op 17-03-16 om 01:31 schreef Chris Angelico: > On Thu, Mar 17, 2016 at 11:19 AM, Steven D'Aprano wrote: >> On Thu, 17 Mar 2016 10:14 am, Chris Angelico wrote: >> >>> On Thu, Mar 17, 2016 at 5:31 AM, Antoon Pardon >>> wrote: It can be yes. Look at decorators. They don't provide functionality

Re: Case Statements

2016-03-19 Thread BartC
On 16/03/2016 11:07, Mark Lawrence wrote: I don't want to discourage you too much, but I think that adding a switch statement comes *very* low on the list of improvements we would like to make in Python 3.5. We should probably focus on speed ... OK, you're coming round... but I still very m

Re: Case Statements

2016-03-19 Thread Chris Angelico
On Thu, Mar 17, 2016 at 5:31 AM, Antoon Pardon wrote: > It can be yes. Look at decorators. They don't provide functionality > we wouldn't have without them. Really? Okay, try implementing this without decorators: def monkeypatch(cls): orig = globals()[cls.__name__] print("Monkeypatch",id

Re: Case Statements

2016-03-19 Thread Marko Rauhamaa
BartC : > On 16/03/2016 14:31, Marko Rauhamaa wrote: >> Scheme has this: > >> (case (die10) >> ((1 3 5 7 9) >>=> (lambda (n) >> n)) >> (else >>=> (lambda (n) >> (/ n 2 >> >> which maps 1, 3, 5, 7 and 9 onto themselves but halves 2, 4, 6,

Re: Case Statements

2016-03-19 Thread Antoon Pardon
Op 16-03-16 om 20:27 schreef Marko Rauhamaa: > Antoon Pardon : > >> Look at decorators. They don't provide functionality we wouldn't have >> without them. So we don't actually need them. Do you argue that >> introducing them wasn't progress? > I do. Way to miss the point. Sure there will be people

Re: Case Statements

2016-03-19 Thread BartC
On 16/03/2016 09:51, Mark Lawrence wrote: On 16/03/2016 09:35, Antoon Pardon wrote: So I guess those who would like a case statement in Python can only hope a core developer gets bitten by a nasty bug while using one of those ways of simulating switches. So that core developers can waste th

Re: Case Statements

2016-03-19 Thread Steven D'Aprano
On Thu, 17 Mar 2016 05:48 pm, Chris Angelico wrote: > On Thu, Mar 17, 2016 at 5:29 PM, Steven D'Aprano > wrote: >> I don't think that property is a similar situation. I think what happens >> here is that the first call to property sets: >> >> # @property def x... >> x = property(x) >> >> Then the

Re: Case Statements

2016-03-19 Thread Mark Lawrence
On 16/03/2016 13:15, l0r0m0a0...@gmail.com wrote: What hath I wrought? The Comfy Chair :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list

Re: Case Statements

2016-03-19 Thread Chris Angelico
On Thu, Mar 17, 2016 at 12:54 PM, Steven D'Aprano wrote: > On Thu, 17 Mar 2016 11:31 am, Chris Angelico wrote: > >> Yes... in theory. But try rewriting my example to avoid decorator >> syntax. It won't work, because of this line: >> >> orig = globals()[cls.__name__] > > That's a nasty, dirty p

Re: Case Statements

2016-03-19 Thread Chris Angelico
On Thu, Mar 17, 2016 at 4:45 PM, Gregory Ewing wrote: > Steven D'Aprano wrote: >> >> On Thu, 17 Mar 2016 11:31 am, Chris Angelico wrote: >> >>>orig = globals()[cls.__name__] >> >> >> I wouldn't want to rely on it working with decorator syntax either. Even >> if >> it does now, I'm not sure tha

Re: Case Statements

2016-03-19 Thread Marko Rauhamaa
BartC : > Yes, a few scripting languages can do interesting things with switch or > case statements. Perl for example (where I think it is created out other > language features, but it looks a regular part of the syntax). > > Even Ruby has one. It doesn't do anything 's

Re: Case Statements

2016-03-19 Thread Chris Angelico
On Thu, Mar 17, 2016 at 5:29 PM, Steven D'Aprano wrote: > I don't think that property is a similar situation. I think what happens > here is that the first call to property sets: > > # @property def x... > x = property(x) > > Then the second decorator does: > > # @x.setter def x... > x = x.setter(

Re: Case Statements

2016-03-19 Thread Marko Rauhamaa
Antoon Pardon : > Look at decorators. They don't provide functionality we wouldn't have > without them. So we don't actually need them. Do you argue that > introducing them wasn't progress? I do. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: Case Statements

2016-03-18 Thread Antoon Pardon
Op 17-03-16 om 09:57 schreef Marko Rauhamaa: > Antoon Pardon : > >> Op 16-03-16 om 20:27 schreef Marko Rauhamaa: >>> Antoon Pardon : Look at decorators. They don't provide functionality we wouldn't have without them. So we don't actually need them. Do you argue that introducing them

Re: Case Statements

2016-03-18 Thread BartC
On 16/03/2016 14:31, Marko Rauhamaa wrote: BartC : Even Ruby has one. case when this when that That's a different topic. Yes but, if Ruby has it, why shouldn't Python? (Aren't they rivals or something?) which is exactly equivalent to if this... elif that... (when th

Re: Case Statements

2016-03-18 Thread Antoon Pardon
Op 17-03-16 om 00:14 schreef Chris Angelico: > def monkeypatch(cls): > orig = globals()[cls.__name__] > print("Monkeypatch",id(cls),"into",id(orig)) > for attr in dir(cls): > if not attr.startswith("_"): > setattr(orig,attr,getattr(cls,attr)) > return orig > > cl

Re: Case Statements

2016-03-18 Thread Chris Angelico
On Thu, Mar 17, 2016 at 9:53 PM, Steven D'Aprano wrote: > On Thu, 17 Mar 2016 05:48 pm, Chris Angelico wrote: > >> Okay. Let's try this. > [...] >> Decorators work. Now let's try NOT using decorators. > > You are still using a decorator. You're just not using @ decorator syntax. Oops, sorry. That

Re: Case Statements

2016-03-18 Thread Mark Lawrence
On 16/03/2016 11:16, BartC wrote: On 16/03/2016 11:07, Mark Lawrence wrote: I don't want to discourage you too much, but I think that adding a switch statement comes *very* low on the list of improvements we would like to make in Python 3.5. We should probably focus on speed ... OK, you're c

Re: Case Statements

2016-03-16 Thread Mark Lawrence
ython programmer. I have no interest what other languages use switch/case statements for, as we've on the PYTHON mailing list. There once were multiple ways to simulate a conditional expression. And it was generally thought that using if else statements instead of a conditional expression was u

Re: Case Statements

2016-03-16 Thread Antoon Pardon
those >>> people who want them, can have them. if-elif chains are not likely to >>> kill any Python programmer. >>> >>> I have no interest what other languages use switch/case statements >>> for, as we've on the PYTHON mailing list. >> >> There

Re: Case Statements

2016-03-16 Thread BartC
% of other languages, but is generally considered more flexible and readable than the if-elif, was missing in Python. (your link "Switch Statement Code Smell" not withstanding) Have a great day :) Switch and case statements are such a waste of time that, in order to understand them

Re: Case Statements

2016-03-16 Thread Mark Lawrence
statements are often used, e.g. in shell scripts. I've seen at least six different ways of simulating switches, so those people who want them, can have them. if-elif chains are not likely to kill any Python programmer. I have no interest what other languages use switch/case statements for, as

Re: Case Statements

2016-03-16 Thread Antoon Pardon
tatements are often used, e.g. in shell scripts. > > I've seen at least six different ways of simulating switches, so those > people who want them, can have them. if-elif chains are not likely to > kill any Python programmer. > > I have no interest what other languages

Re: Case Statements

2016-03-16 Thread Marko Rauhamaa
Christian Gollwitzer : > That happens indeed if one were to simulate polymorphism using switch > statements, but not for other cases. There are not many other cases. Decoding is the only generally valid case I can think of. > In Python, you need to go the other way round, you don't have a > swit

Re: Case Statements

2016-03-16 Thread Mark Lawrence
are the way to go. Command line parsing is a case where switch statements are often used, e.g. in shell scripts. I've seen at least six different ways of simulating switches, so those people who want them, can have them. if-elif chains are not likely to kill any Python programmer. I have

Re: Case Statements

2016-03-16 Thread Christian Gollwitzer
Am 16.03.16 um 05:26 schrieb Mark Lawrence: So you would rather write something like:- switch (x): case COW: moo() break case DUCK: quack() break default IDUNNO: panic() than:- x.makeNoise() No sane person would do that. But just because you selected the w

Re: Case Statements

2016-03-15 Thread Mark Lawrence
On 16/03/2016 01:55, jj0gen0i...@gmail.com wrote: You have apparently mistaken me for someone who's worried. I don't use Python, I was just curious as to why a construct that is found, not only to be useful in 95% of other languages, but is generally considered more flexible and readable than

Re: Case Statements

2016-03-15 Thread Mario R. Osorio
enerally considered more > flexible and readable than the if-elif, was missing in Python. (your link > "Switch Statement Code Smell" not withstanding) > > Have a great day :) Switch and case statements are such a waste of time that, in order to understand them you have to men

Re: Case Statements

2016-03-15 Thread jj0gen0info
You have apparently mistaken me for someone who's worried. I don't use Python, I was just curious as to why a construct that is found, not only to be useful in 95% of other languages, but is generally considered more flexible and readable than the if-elif, was missing in Python. (your link "Sw

Re: Case Statements

2016-03-15 Thread Mark Lawrence
On 16/03/2016 00:51, BartC wrote: On 15/03/2016 23:47, jj0gen0i...@gmail.com wrote: Thanks for the informative post. I've read it and disagree with the rational, it places Python in a decided minority of the major languages. And this proposal (3103) was by the guy who invented the language!

Re: Case Statements

2016-03-15 Thread BartC
On 15/03/2016 23:47, jj0gen0i...@gmail.com wrote: Thanks for the informative post. I've read it and disagree with the rational, it places Python in a decided minority of the major languages. And this proposal (3103) was by the guy who invented the language! Good thing he didn't have design-

Re: Case Statements

2016-03-15 Thread Mark Lawrence
On 15/03/2016 23:47, jj0gen0i...@gmail.com wrote: Thanks for the informative post. I've read it and disagree with the rational, it places Python in a decided minority of the major languages. https://en.wikipedia.org/wiki/Conditional_(computer_programming)#Case_and_switch_statements See secti

Re: Case Statements

2016-03-15 Thread jj0gen0info
Thanks for the informative post. I've read it and disagree with the rational, it places Python in a decided minority of the major languages. https://en.wikipedia.org/wiki/Conditional_(computer_programming)#Case_and_switch_statements See section "Choice system cross reference" Thanks again for

Re: Case Statements

2016-03-15 Thread Mark Lawrence
On 15/03/2016 20:46, jj0gen0i...@gmail.com wrote: Given that "Case Statements" are more compact and less redundant than a sequence of if-elif statements, and usually can contain embedded match lists: Is there any chance future versions of Python will adopt a case structure? Some

Case Statements

2016-03-15 Thread jj0gen0info
Given that "Case Statements" are more compact and less redundant than a sequence of if-elif statements, and usually can contain embedded match lists: Is there any chance future versions of Python will adopt a case structure? Something like select x case in [1,2,3,5,7,9] print ..