|
|
|
|
|
by minihoster
122 days ago
|
|
> arr[n..=m] so you just need to overload the syntax of intervals even more to make it work > arr[0..m], arr[m..] now `m` refers to different things depending on which side of the interval it's on. less characters doesn't mean nicer I get it though, I was skeptical about 1-based indexing when I started Julia. By the nature of indices vs length there will always be an off-by-one problem: either you have elements [n, m - 1] with length (m - n) or [n, m] with length (m - n + 1). Unless you're doing a bunch of pointer arithmetic type stuff, I find the symmetry of a inclusive-inclusive interval to be a better default. As a final rebuttal I offer: range(n - 1, -1, -1) |
|
As a neat bonus, in Julia 1:5 is just the iterator for the numbers 1 to 5. So slicing is typically not some special syntax either. It all works rather nicely.