Last active
July 16, 2018 22:06
-
-
Save dresswithpockets/49deacac0d9d7df211f5e25b5a6ae2a4 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
// chain matches to the first true case, and then continues to reiterate and match until no cases return true. | |
let x := chain { | |
true => 5, | |
x == 6 => x * 2, | |
x == 5 => x + 1, | |
x == 7 => 0 | |
} | |
assert!(x == 12) | |
// branch matches to the first true case, and then flows downard and will continue to match true cases until it leaves | |
// the control block | |
let y := branch { | |
true => 5, | |
y == 6 => y * 2, | |
y == 5 => y + 1, | |
y == 7 => 0 | |
} | |
assert!(y == 6) | |
// match works identically to Rust's match functionality. | |
let z := match(y) { | |
6 => x * y | |
_ => panic!() | |
} | |
assert!(z == x * y) | |
let a := | |
if false { | |
0 | |
} | |
else if true { | |
50 | |
} | |
else { | |
9 | |
} | |
assert!(a == 50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment