Because, if you have a vector of 10 elements, (and your language
starts indexing from 0) you can use (range 10) for the indexes,
instead of (range (- 10 1)). Or at least that makes sense to me.
It also makes sense to me that (range 10) gives you 10 numbers. Of
course if range started at 1 by default then I would expect (range 10)
to produce (1 2 3 4 5 6 7 8 9 10), but since it starts at 0 by
default, I think it is correct the way it is.
--
Michael Wood <esio...@gmail.com>
I wouldn't call it a bad habit just because it's not what you expected.
The definition of range used in Clojure (and elsewhere) has some nice
properties:
(= n (count (range n)))
(= (- b a) (count (range a b)))
(= (concat (range a b) (range b c)) (range a c))
Their utility may not be obvious immediately, but if you write code
that works a lot on indices, you will learn to appreciate them.
Konrad.
Edsger Dijkstra wrote up his opinion, why it should be like that:
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
Sincerely
Meikel