On Mon, Aug 17, 2020 at 10:04 AM Jean Abou Samra <j...@abou-samra.fr> wrote:

[Jean]

> Finally, was as-based syntax considered as an alternative to walrus
>> patterns, that is, PATTERN as NAME instead of NAME := PATTERN, as we have
>> in the try statement? Given the extensive discussion, I guess it might have
>> been rejected, so it could deserve a place under "Rejected ideas" -- this
>> holds for all the above too, which I'm sorry about if it's dumb.
>>
>
[Guido]

> I don't recall it was discussed. A very early draft (that wasn't
> published) used `as` instead of `case`, and that draft used `:=` for this
> purpose. It's always made sense to use that, so I've never considered `as`.
> Do you think there are situations where `as` has a clear advantage over
> `:=`?
>
>
[Jean]

> Let's see: it probably avoids some uglinesses that occur with the use of =
> in class patterns.
>
> case Expr(value=(add := BinOp(op=Add()))):
> vs.
> case Expr(value=(BinOp(op=Add()) as add))
>
> There is also
> case Line(start := Point(x, y), end):
> which might be confused with
> case Line(start=Point(x, y), end):
>
> However, the main reason why I was asking is that 'as' parallels well with
> the current context that is closest to pattern matching, namely the try
> statement. The walrus parallels with assignment expressions, so this is in
> fact a story of wether patterns should look more like expressions or the
> LHS of an assignment, as I see it.
>
> The walrus highlights the structure that you're trying to fit in: "This is
> an Expr, having as a value an addition, which looks like ...". By contrast,
> having the name after the pattern makes you think like the interpreter:
> "Try to fit this into BinOp(op=Add()), and if that succeds, put it in
> 'add'." Both are defendable. I think the latter would be a little easier to
> teach, so I'd encourage considering it.
>

Okay, I opened an issue in the PEP team's internal tracker about this:
https://github.com/gvanrossum/patma/issues/140


-- 
--Guido van Rossum (python.org/~guido)
*Pronouns: he/him **(why is my pronoun here?)*
<http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/Q55YSICYDK5Z5DXSTVKL5IIH3BUVHYHH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to