On 11 Jul 2020, at 21:03, Eric Nieuwland <eric.nieuwl...@gmail.com> wrote:

> What I meant to say is that as I read the current PEP text there would be a 
> confusing difference between
> 
>       match poly:
>               case Polygon(Point(x0, y0), Point(x1, y1), Point(x2, y2)):
>                       ...
> 
> and
> 
>       p0 = Point(x0, y0)
>       p1 = Point(x1, y1)
>       p2 = Point(x2, y2)
>       match poly:
>               case Polygon(p0, p1, p2):
>                       ...
> 
> This would be especially clumsy if I need to match parts in a deep structure.
> It would require me to either write the whole construction as part of the 
> ‘match’ or use ‘match’ nested to drill down to the parts I need.
> 

Just after I hit ‘send’ it dawned on me it might be preferable to make that

        match poly:
                p0 = Point(x0, y0)
                p1 = Point(x1, y1)
                p2 = Point(x2, y2)
        case Polygon(p0, p1, p2):
                        …

so the part preceded by ‘match’ is the preparation phase for matching.

This could also resolve the discussion on indentation of the ‘case’ parts and 
the placement of the default matching:

        match <expression> [as <var>]:
                <preparation statements>
        case <pattern> [<guard>]:
                <statements>
        …
        [else:
                <statements>]

within the preparation statements it would then be allowed to use undefined 
variables as receivers of matched parts.
_______________________________________________
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/DOGIGJRL2RBHNGXXH2LZG6QMWTPLHU5J/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to