[Python-Dev] Is PEP 572 really the most effective way to solve the problems it's targeting?
Paul G
paul at ganssle.io
Thu Apr 26 21:23:47 EDT 2018
Rust has a few syntactic ways to accomplish the same thing, though. I think match expressions are used for the equivalent of conditionals that carry the condition value into the body of the expression, and all blocks return the result of the last statement, so you can do things like:
let mut x;
while { x = foo(); x } {
bar(x);
}
I don't know if that's idiomatic Rust (and I wrote it on a phone and didn't check to be sure it compiles), but it does more or less solve the problem of assignment in a control flow condition.
On April 27, 2018 12:58:16 AM UTC, Steven D'Aprano <steve at pearwood.info> wrote:
>On Thu, Apr 26, 2018 at 09:36:48AM -0700, Mike Miller wrote:
>
>> However, there were two good questions in this message which I
>haven't seen
>> addressed yet:
>>
>> - How are other modern languages solving this issue?
>> - How does this new construct intersect with typing
>functionality?
>
>What counts as a modern language? Less than five years old? Less than
>fifty years old? Are Javascript, Ruby and R modern? They all support
>assignment as expressions.
>
>I think Koitlin, Rust and Go prohibit assignment as expressions.
>
>Swift assignment evaluates as Void (equivalent to None in Python, I
>guess), so you can use assignment in an expression but it returns
>nothing and only operates by side-effect.
>
>As far as type hints go, I think that if you need explicit type hints
>in
>the middle of an expression, it's a bad idea and you ought to pull it
>out as a separate statement. That applies regardless of whether that
>expression involves binding or not.
>
>
>--
>Steve
>_______________________________________________
>Python-Dev mailing list
>Python-Dev at python.org
>https://mail.python.org/mailman/listinfo/python-dev
>Unsubscribe:
>https://mail.python.org/mailman/options/python-dev/paul%40ganssle.io
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20180427/6cd98753/attachment.html>
More information about the Python-Dev
mailing list