[Python-ideas] Inline assignment expression

Guido van Rossum guido at python.org
Sat Mar 14 15:57:25 CET 2009

If we're going to allow unconstrained assignments inside expressions
why don't we use the same syntax as C, C++, Java, JavaScript etc.?

But I left this out intentionally for a reason. We would need to have
a great deal of evidence that it was a mistake for making a U-turn.

Have a happy discussion,

--Guido <extricates himself>

On Sat, Mar 14, 2009 at 6:47 AM, Jervis Whitley <jervisau at gmail.com> wrote:
> http://bugs.python.org/issue1714448 had an interesting proposal that I thought
> might be worthwhile discussing here.
> if something as x:
> however, of greater use would be assignment expressions that allow:
> if (something as x) == other:
>    # can now use x.
> I propose that we implement assignment expressions that would allow assignments
> to be made any place that expressions are currently valid. The
> proposal uses the
> (nominal) right arrow (RARROW) '->' to indicate the assignment. The
> form would look
> like this:
>    EXPR -> VAR
> which translates to
>    VAR = EXPR
>    (EXPR)
> Expression (EXPR) is evaluated and assigned to target VAR. The value of EXPR is
> left on the top of stack.
> another toy example to think about:
>    while len(expensive() -> res) == 4:
>        dosomething(res)
> A patch has been uploaded to the named issue in the bug tracker. I encourage
> you to try it out (py3k at the moment). As I mentioned earlier the
> exact syntax is only nominal. We needn't use the RARROW if consensus
> is against that, it is a simple operation to change this to any of
> ('becomes', 'into', 'assigns' ...
> I look forward to your comments.
> Cheers,
> Jervis
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-ideas mailing list