[Python-Dev] Questions about about the DLS 2020

2020年11月16日 03:26:51 -0800

Hi Tobias,
A couple of questions about the DLS 2020 paper.
1. Why do you use the term "validate" rather than "test" for the process of selecting a match? It seems to me, that this is a test, not a validation, as no exception is raised if a case doesn't match. 2. Is the error in the ast matching example, an intentional "simplification" or just an oversight?
The example:
```
def simplify(node):
 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
```
is wrong.
The correct version is
```
def simplify(node):
 match node:
 case BinOp(Num(left), Add(), Num(right)):
 return Num(left + right)
 case BinOp(left, Add() | Sub(), Num(0)):
 return simplify(left)
 case UnaryOp(USub(), UnaryOp(USub(), item)):
 return simplify(item)
 case _:
 return node
```
Cheers,
Mark.
_______________________________________________
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/ETZGYRCF4DR6RJXTHGXIRZXINXJ76J2D/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to