Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #65390
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.python |
| References | <mailman.4966.1388953508.18130.python-list@python.org> |
| Subject | Re: Postfix conditionals |
| Message-ID | <8SVHu.12417$MB1.2814@fx09.am4> (permalink) |
| Organization | virginmedia.com |
| Date | 2014-02-03 23:43 +0000 |
"Göktuğ Kayaalp" <self@gkayaalp.com> wrote in message news:mailman.4966.1388953508.18130.python-list@python.org... > AFAIK, we do not have "postfix conditionals" in Python, i.e. a condition > appended to a > statement, which determines whether the statement runs or not: > > py> for i in [False]: > ... break if not i > > The above piece of code is equivalent to this in Python: > > py> for i in [False]: > ... if not i > ... break > What are your thoughts on this? I develop my own language (not Python, but also dynamic and interpreted). I have this feature, and it's OK, but not indispensible. I varied it a bit by allowing 'if', 'when' and 'unless' as the conditionals, just to break it up a little. However, it just maps internally to a regular if-statement. In Python though, the normal way of writing 'break if not i' is about the same length (in my language it's somewhat longer), so I can't see it getting much support. What would be far more useful would be a proper 'switch' statement, but if that's not in, then I don't think your proposal will get far! (There are various clunky workarounds for switch - one idea is to use an if-elseif chain, but that's just what it tries to avoid. Switch is attractive for an interpreted language because - provided all cases are constants, a bit of a problem in Python, because as soon as you give a name to something, it's no longer constant - it can be implemented very efficiently.) -- Bartc
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-05 22:24 +0200
Re: Postfix conditionals Roy Smith <roy@panix.com> - 2014-01-05 15:41 -0500
Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-05 22:54 +0200
Re: Postfix conditionals Dan Stromberg <drsalists@gmail.com> - 2014-01-05 13:08 -0800
Re: Postfix conditionals "Rhodri James" <rhodri@wildebst.org.uk> - 2014-01-06 01:40 +0000
Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-01-06 09:51 +0200
Re: Postfix conditionals "Rhodri James" <rhodri@wildebst.org.uk> - 2014-01-07 00:48 +0000
Re: Postfix conditionals "BartC" <bc@freeuk.com> - 2014-02-03 23:43 +0000
Re: Postfix conditionals Göktuğ Kayaalp <self@gkayaalp.com> - 2014-02-04 07:16 +0200
Re: Postfix conditionals "BartC" <bc@freeuk.com> - 2014-02-04 10:00 +0000
Re: Postfix conditionals Chris Angelico <rosuav@gmail.com> - 2014-02-04 16:23 +1100
csiph-web