On Wed, Jul 08, 2020 at 07:53:00AM -0000, Kerwin Sun wrote:
> I tried with this code:
> ```
> from dataclasses import dataclass
>
> @dataclass
> class Point:
> x: int
> y: int
>
> z = 41
>
> def whereis(point):
> w = 23
> match point:
> case Point(0, 0):
> print("Origin")
> case Point(0, y):
> print(f"Y={y}")
> case Point(x, 0):
> print(f"X={x}")
> case Point():
> print("Somewhere else")
> case 23:
> print("Not the answer")
> case w:
> print("Not the answer, local w")
> case z:
> print("The answer")
> case _:
> print("other")
> whereis(42)
> ```
>
> It retuend:
> ```
> Not the answer, local w
That looks like the correct answer, "w" is a new binding. This is the same in
Standard ML and OCaml:
# let whereis point =
let w = 23 in
match point with
23 -> "Not the answer"
| w -> "Correct answer"
| _ -> "Unreachable";;
Warning 26: unused variable w.
Warning 11: this match case is unused.
val whereis : int -> string = <fun>
# whereis 42;;
- : string = "Correct answer"
#
Stefan Krah
_______________________________________________
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/TH5NYQ2KF36MS7IKILOSMYDW3QZXFIZC/
Code of Conduct: http://python.org/psf/codeofconduct/