Last active
May 31, 2022 09:20
-
-
Save metatoaster/8b36dc0f9f95bd8366addc08c3f276e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def match_value(number: int) -> str: | |
| three = 3 | |
| match number: | |
| case 1: | |
| return "Yay you are number wan" | |
| case 2: | |
| return "Second mouse gets the cheese" | |
| case three: | |
| return "You came third" | |
| case 42: | |
| return "The answer to life, the universe, and everything" | |
| case _: | |
| return "You are too late" | |
| print(match_value(3)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[allow(unreachable_patterns,unused_variables)] | |
| fn main() { | |
| fn match_value(number: i64) -> String { | |
| let three = 3; | |
| match number { | |
| 1 => "Yay you are number wan", | |
| 2 => "Second mouse gets the cheese", | |
| three => "You came third", | |
| 42 => "The answer to life, the universe, and everything", | |
| _ => "You are too late", | |
| }.to_string() | |
| } | |
| println!("{}", match_value(3)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ python3.10 match_expr.py | |
| File "/tmp/match_expr.py", line 8 | |
| case three: | |
| ^^^^^ | |
| SyntaxError: name capture 'three' makes remaining patterns unreachable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ cargo run | |
| Compiling match_expr v0.1.0 (/tmp/match_expr) | |
| Finished dev [unoptimized + debuginfo] target(s) in 0.16s | |
| Running `target/debug/match_expr` | |
| You came third |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment