diff options
| author | gingerBill <bill@gingerbill.org> | 2019-10-26 14:36:28 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-10-26 14:36:28 +0100 |
| commit | a5e42a046531405e0b8830ae092470c2aa2e67a8 (patch) | |
| tree | 9495fea4cc28c6823f7988529b0bfc3288848f76 /examples | |
| parent | d808f9eccf961a63630d6751c7367d8dc375c4b9 (diff) | |
Add `ranged_fields_for_array_compound_literals`
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/demo/demo.odin | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/examples/demo/demo.odin b/examples/demo/demo.odin index cd6ac6bf5..fa970fa43 100644 --- a/examples/demo/demo.odin +++ b/examples/demo/demo.odin @@ -1194,13 +1194,43 @@ ranged_fields_for_array_compound_literals :: proc() { foo := [?]int{1, 4, 9, 16}; fmt.println(foo); } - i := 2; - foo := [?]int { - 0 = 123, - 5..9 = 54, - 10..<16 = i*3 + (i-1)*2, - }; - fmt.println(foo); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8] + { // Indexed + foo := [?]int{ + 3 = 16, + 1 = 4, + 2 = 9, + 0 = 1, + }; + fmt.println(foo); + } + { // Ranges + i := 2; + foo := [?]int { + 0 = 123, + 5..9 = 54, + 10..<16 = i*3 + (i-1)*2, + }; + #assert(len(foo) == 16); + fmt.println(foo); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8] + } + { // Slice and Dynamic Array support + i := 2; + foo_slice := []int { + 0 = 123, + 5..9 = 54, + 10..<16 = i*3 + (i-1)*2, + }; + assert(len(foo) == 16); + fmt.println(foo_slice); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8] + + foo_dynamic_array := [dynamic]int { + 0 = 123, + 5..9 = 54, + 10..<16 = i*3 + (i-1)*2, + }; + assert(len(foo) == 16); + fmt.println(foo_dynamic_array); // [123, 0, 0, 0, 0, 54, 54, 54, 54, 54, 8, 8, 8, 8, 8] + } } main :: proc() { |