2012-01-04 00:03:07 -06:00
|
|
|
fn w_semi(v: [int]) -> int {
|
|
|
|
vec::foldl(0, v) {|x,y| x+y};
|
|
|
|
-10
|
|
|
|
}
|
|
|
|
|
|
|
|
fn wo_paren(v: [int]) -> int {
|
|
|
|
// Perhaps surprising: this is parsed equivalently to w_semi()
|
|
|
|
vec::foldl(0, v) {|x,y| x+y} - 10
|
|
|
|
}
|
2011-12-29 11:49:33 -06:00
|
|
|
|
2012-01-04 00:03:07 -06:00
|
|
|
fn w_paren(v: [int]) -> int {
|
|
|
|
// Here the parentheses force interpretation as an expression:
|
|
|
|
(vec::foldl(0, v) {|x,y| x+y}) - 10
|
|
|
|
}
|
2011-12-29 11:49:33 -06:00
|
|
|
|
|
|
|
fn main() {
|
2012-01-04 00:03:07 -06:00
|
|
|
assert wo_paren([0, 1, 2, 3]) == -10;
|
|
|
|
assert w_semi([0, 1, 2, 3]) == -10;
|
|
|
|
assert w_paren([0, 1, 2, 3]) == -4;
|
2011-12-29 11:49:33 -06:00
|
|
|
}
|
|
|
|
|