"Göktuğ Kayaalp" <s...@gkayaalp.com> wrote in message
news:mailman.4966.1388953508.18130.python-l...@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
--
https://mail.python.org/mailman/listinfo/python-list