2012-06-25 22:00:46 -05:00
|
|
|
fn w_semi(v: [int]/~) -> int {
|
2012-01-04 16:16:41 -06:00
|
|
|
// the semicolon causes compiler not to
|
|
|
|
// complain about the ignored return value:
|
2012-01-04 00:03:07 -06:00
|
|
|
vec::foldl(0, v) {|x,y| x+y};
|
|
|
|
-10
|
|
|
|
}
|
|
|
|
|
2012-06-25 22:00:46 -05:00
|
|
|
fn w_paren1(v: [int]/~) -> int {
|
2012-01-04 16:16:41 -06:00
|
|
|
(vec::foldl(0, v) {|x,y| x+y}) - 10
|
2012-01-04 00:03:07 -06:00
|
|
|
}
|
2011-12-29 11:49:33 -06:00
|
|
|
|
2012-06-25 22:00:46 -05:00
|
|
|
fn w_paren2(v: [int]/~) -> int {
|
2012-01-04 16:16:41 -06:00
|
|
|
(vec::foldl(0, v) {|x,y| x+y} - 10)
|
|
|
|
}
|
|
|
|
|
2012-06-25 22:00:46 -05:00
|
|
|
fn w_ret(v: [int]/~) -> int {
|
2012-01-04 16:16:41 -06:00
|
|
|
ret vec::foldl(0, v) {|x,y| x+y} - 10;
|
2012-01-04 00:03:07 -06:00
|
|
|
}
|
2011-12-29 11:49:33 -06:00
|
|
|
|
|
|
|
fn main() {
|
2012-06-25 22:00:46 -05:00
|
|
|
assert w_semi([0, 1, 2, 3]/~) == -10;
|
|
|
|
assert w_paren1([0, 1, 2, 3]/~) == -4;
|
|
|
|
assert w_paren2([0, 1, 2, 3]/~) == -4;
|
|
|
|
assert w_ret([0, 1, 2, 3]/~) == -4;
|
2011-12-29 11:49:33 -06:00
|
|
|
}
|
|
|
|
|