[Python-ideas] PEP 572: Statement-Local Name Bindings, take three!
BrenBarn
brenbarn at brenbarn.net
Mon Mar 26 19:09:39 EDT 2018
On 03/26/2018 04:18 AM, Steven D'Aprano wrote:
> On Mon, Mar 26, 2018 at 11:14:43AM +0300, Kirill Balunov wrote:
>> Hi Chris, would you mind to add this syntactic form `(expr -> var)` to
>> alternative syntax section, with the same semantics as `(expr as var)`. It
>> seems to me that I've seen this form previously in some thread (can't find
>> where), but it does not appear in alt. syntax section.
>
> That was probably my response to Nick:
>
> https://mail.python.org/pipermail/python-ideas/2018-March/049472.html
>
> I compared four possible choices:
>
> target = default if (expression as name) is None else name
> target = default if (name := expression) is None else name
> target = default if (expression -> name) is None else name
> target = default if (name <- expression) is None else name
>
>
> The two arrow assignment operators <- and -> are both taken from R.
>
> If we go down the sublocal scope path, which I'm not too keen on, then
> Nick's earlier comments convince me that we should avoid "as". In that
> case, my preferences are:
>
> (best) -> := <- as (worst)
>
> If we just bind to regular locals, then my preferences are:
>
> (best) as -> := <- (worst)
>
> Preferences are subject to change :-)
Obviously we're bikeshedding here, but personally I detest these kinds
of operators. To me - is a minus sign and < and > are less-than and
greater-than. Trying to re-use these characters in ways that depend on
their visual form strikes me as very ugly. <= makes sense because its
meaning is a combination of the *meanings* of < and =, but <- as
assignment is not a combination of the meanings of < and -. If we need
a two-character operator, I prefer something like := that doesn't try to
be a picture.
More information about the Python-ideas
mailing list