| 1 | fn multi(a i16) i64 { |
| 2 | one, two := a, 10 |
| 3 | return one + two |
| 4 | } |
| 5 | |
| 6 | pub fn multireturn(a int) (int, i64, i64) { |
| 7 | return 2, a + 2, 10 - a |
| 8 | } |
| 9 | |
| 10 | pub fn test() (int, int) { |
| 11 | return 25, 15 |
| 12 | } |
| 13 | |
| 14 | pub fn accept() int { |
| 15 | mut a, _ := test() |
| 16 | a += 20 |
| 17 | return a |
| 18 | } |
| 19 | |
| 20 | pub fn side_effect() int { |
| 21 | return 22 |
| 22 | } |
| 23 | |
| 24 | pub fn run_side_effect() int { |
| 25 | mut a := 15 |
| 26 | |
| 27 | _, a = side_effect(), 10 |
| 28 | |
| 29 | return a |
| 30 | } |
| 31 | |
| 32 | fn run_normal_stuff() { |
| 33 | println(multi(2)) |
| 34 | { |
| 35 | a, b, c := multireturn(20) |
| 36 | println(a) |
| 37 | println(b) |
| 38 | println(c) |
| 39 | } |
| 40 | println(accept()) |
| 41 | println(run_side_effect()) |
| 42 | } |
| 43 | |
| 44 | fn if_cond(cond bool) (int, int) { |
| 45 | return if cond { 10, 15 } else { 30, 35 } |
| 46 | } |
| 47 | |
| 48 | struct AA { |
| 49 | a int |
| 50 | b int |
| 51 | } |
| 52 | |
| 53 | fn take_struct(test AA) int { |
| 54 | return test.a |
| 55 | } |
| 56 | |
| 57 | fn give_two_struct(cond bool) (AA, AA) { |
| 58 | return if cond { |
| 59 | AA{ |
| 60 | a: 15 |
| 61 | }, AA{ |
| 62 | a: 15 |
| 63 | } |
| 64 | } else { |
| 65 | AA{ |
| 66 | a: 20 |
| 67 | }, AA{ |
| 68 | a: 592 |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | fn give_struct() int { |
| 74 | return take_struct(AA{ a: 15 }) |
| 75 | } |
| 76 | |
| 77 | fn if_struct_test(cond bool) AA { |
| 78 | a := if cond { |
| 79 | AA{} |
| 80 | } else { |
| 81 | AA{ |
| 82 | a: 125 |
| 83 | } |
| 84 | } |
| 85 | return a |
| 86 | } |
| 87 | |
| 88 | fn run_stmt_exprs() { |
| 89 | mut a := 0 |
| 90 | mut b := 0 |
| 91 | a, b = if_cond(true) |
| 92 | println(true) |
| 93 | println(a) |
| 94 | println(b) |
| 95 | a, b = if_cond(false) |
| 96 | println(false) |
| 97 | println(a) |
| 98 | println(b) |
| 99 | println(give_struct()) |
| 100 | mut struc := if_struct_test(false) |
| 101 | println(struc.a) |
| 102 | struc = if_struct_test(true) |
| 103 | println(struc.a) |
| 104 | c, d := give_two_struct(false) |
| 105 | println(c.a) |
| 106 | println(d.a) |
| 107 | } |
| 108 | |
| 109 | fn main() { |
| 110 | println('--- normal multi exprs') |
| 111 | run_normal_stuff() |
| 112 | println('--- struct based multi exprs/stmt exprs') |
| 113 | run_stmt_exprs() |
| 114 | } |
| 115 | |