Register
Odin»Forums»Arrays and Slices
10 posts
Arrays and Slices
2 years, 9 months ago Edited by novus1044 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.
Ginger Bill
226 posts / 2 projects

I am ginger thus have no soul.

Arrays and Slices
2 years, 9 months 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.
10 posts
Arrays and Slices
2 years, 9 months ago Edited by novus1044 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.