On Tue, 17 Nov 2020 at 03:52, Steven D'Aprano <[email protected]> wrote:
> Here is a more representative example, borrowed from here: > > https://gvanrossum.github.io//docs/PyPatternMatching.pdf > > > match node: > case BinOp(Num(left), '+', Num(right)): > return Num(left + right) > case BinOp(left, '+' | '-', Num(0)): > return simplify(left) > case UnaryOp('-', UnaryOp('-', item)): > return simplify(item) > case _: > return node > > > which becomes this with the "as" proposal: > > > match node: > case BinOp(Num(as left), '+', Num(as right)): > return Num(left + right) > case BinOp(as left, '+' | '-', Num(0)): > return simplify(left) > case UnaryOp('-', UnaryOp('-', as item)): > return simplify(item) > case _: > return node > Well, I like the idea to have a keyword instead of a sigil, but `as` does not sounds good in English IMO. For example, in the `with` statement, it's with x as y: [code] I see the pattern matching code and I ask myself: where is the x? PS: pattern matching, for a mere mortal like me, seems to be something very exotical. That's why an explicit, even if verbose, additional keyword seems to me better for reading and understanding the code. For my eyes, it's the same difference between x = y ? z : w and x = y if z else w
_______________________________________________ Python-Dev mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/6HPPFZNEEAWVPHC5XRA7TVPXKASF7AXW/ Code of Conduct: http://python.org/psf/codeofconduct/
