diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2023-08-05 17:07:28 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-05 17:07:28 +0100 |
| commit | 006bd2fe17d29d4f10f060567cad2f978978bb5f (patch) | |
| tree | 5473e361b0e682974e49b72b7f29b0f878756faf /examples | |
| parent | d252768ac5ea0e5f0259d831a8e108721f82c827 (diff) | |
| parent | 4b9afd787ca88c1c9b4cf38cb4290de76da8ae94 (diff) | |
Merge pull request #2696 from hwchen/hwchen/fix-parse-call-expr-ellipses
core:odin/parser allow args after varargs in parse_call_expr
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/demo/demo.odin | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index 6f2a6cf63..030446b1b 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -459,6 +459,27 @@ named_proc_return_parameters :: proc() { fmt.println("foo2 =", foo2()) // 567 321 } +variadic_procedures :: proc() { + fmt.println("\n# variadic procedures") + sum :: proc(nums: ..int, init_value:= 0) -> (result: int) { + result = init_value + for n in nums { + result += n + } + return + } + fmt.println("sum(()) =", sum()) + fmt.println("sum(1, 2) =", sum(1, 2)) + fmt.println("sum(1, 2, 3, 4, 5) =", sum(1, 2, 3, 4, 5)) + fmt.println("sum(1, 2, 3, 4, 5, init_value = 5) =", sum(1, 2, 3, 4, 5, init_value = 5)) + + // pass a slice as varargs + odds := []int{1, 3, 5} + fmt.println("odds =", odds) + fmt.println("sum(..odds) =", sum(..odds)) + fmt.println("sum(..odds, init_value = 5) =", sum(..odds, init_value = 5)) +} + explicit_procedure_overloading :: proc() { fmt.println("\n# explicit procedure overloading") @@ -2462,6 +2483,7 @@ main :: proc() { the_basics() control_flow() named_proc_return_parameters() + variadic_procedures() explicit_procedure_overloading() struct_type() union_type() |