Rhodri James wrote:

> Eric Nieuwland wrote:
> 
>> 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.
>> 
> Are you intending p0, p1 and p2 to be subpatterns rather than object 
> instantiations? That makes me a little twitchy; the difference between what 
> you wrote and:
> 
> match poly:
>       p0 = Point(x0, y0)
>       p1 = Point(x1, y1)
> case Polygon(p0, p1, p2):
>       ... 
> is very easy to miss.
> 

You are perfectly right.
That is why I prefer explicit marking of variables to be bound by matching.
Your example could then become:

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

and IMHO it would be very clear what to expect.

An alternative would be to ‘declare’ variables that are to be bound to make 
things even more explicit, like:

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

where a better name than ‘to_be_bound_by_matching’ would certainly be needed.

—eric
_______________________________________________
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/W6VILFGBO4HJLEAUTSW6SJMNZN352KTJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to