(no title)
robochat | 3 years ago
So python:
a = [0,1,2,3,4,5]
a[0:5] => [0,1,2,3,4] - half closed interval
a[0:-1] => [0,1,2,3,4] - negative indexing
a[:5] => [0,1,2,3,4] - skipping start index
a[3:] => [3,4,5] - skipping end index
nim: var a = [0,1,2,3,4,5]
a[0..5] = [0,1,2,3,4,5] - closed interval
a[0..^1] = [0,1,2,3,4,5] - closed interval with negative indexing
a[..4] = [0,1,2,3,4] - skipping start index
a[..<5] - Error - doesn't work
a[3..] - Error - doesn't work
a[0..<5] = [0,1,2,3,4] - half closed interval
a[0..< ^1] = [0,1,2,3,4] - half closed interval with negative indexing
(Important - the white space is required, it will crash otherwise!)
I'm sure that there are good reasons for this behaviour and that if you use nim a lot, you just get used to it but I find the python syntax just nicer.
ElegantBeef|3 years ago