Odin » Forums » Arrays and Slices
novus1044
9 posts
#10826 Arrays and Slices
3 months, 2 weeks ago Edited by on Feb. 8, 2017, 6 p.m.

Hey Bill,

I recently began playing around with Odin and noticed that you have incorporated slices into the language. Do you plan on having arrays automatically coerce into slices when they are passed to procedures? I know Rust does this, and I think it really helps the overall ergonomics of the language.
gingerBill
Ginger Bill
193 posts
2 projects

I am ginger thus have no soul.

#10827 Arrays and Slices
3 months, 2 weeks ago Edited by Ginger Bill on Feb. 8, 2017, 6:16 p.m.

No. To slice an array, it's really simple:

1
2
3
4
5
a: [12]int;
s: []int;
// These too are equivalent
s = a[:];
s = a[0:a.count-1];


I should note, I may change the syntax eventually from the colon `:`, to use the same as the for loops: `...` and `..<`.

This minor syntax difference isn't that important to worry about yet.
novus1044
9 posts
#10829 Arrays and Slices
3 months, 2 weeks ago Edited by on Feb. 8, 2017, 6:23 p.m.

Okay, that makes sense. Without documentation I just wasn't sure how to go about getting a slice from an array.

Thanks for the quick response. Really digging the language so far.