Postfix conditionals

Göktuğ Kayaalp self at gkayaalp.com
Tue Feb 4 00:16:07 EST 2014


[comments inline]

"BartC" <bc at freeuk.com> writes:

> "Göktuğ Kayaalp" <self at gkayaalp.com> wrote in message
> news:mailman.4966.1388953508.18130.python-list at 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).

Would love to see that, if possible!

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

I do not really think that string length is not of much significance.
The actual fact that disallows my proposal from being favoured/implemented
is that in Python, `break', `return' and `continue' are statements and the
community encourages having one statement per line, so that the source code
is easily understandable.  With my proposal implemented, the language would
would be encouraging having multiple statements in one line, that looks
like a single statement, but is indeed a composition of two.

I rather dislike the statement-orientedness of Python, but still, it is
a good device of easening for the language developers and beginners when
the fact that we use indentation to denote blocks is considered.

> 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 





More information about the Python-list mailing list