I was shadowing the clojure.core\range
function with my [lower upper :as range]
destructuring
Below is the version that didn't work
(generate-keystream [_ {:keys [ss] :as initmap} [lower upper :as range]]
(let [ns (conj ss [])]
(reduce rabbit-round ns (range 3))))
The following works as expected (note the change to :as rng
instead of :as range
)
(generate-keystream [_ {:keys [ss] :as initmap} [lower upper :as rng]]
(let [ns (conj ss [])]
(reduce rabbit-round ns (range 3))))
This explains why (range 3)
and (vec (range 3))
both didn't work, but [0 1 2]
did. The first two were evaluating to ([0 0] 3)
and (vec ([0 0] 3))
in my original code, while [0 1 2]
was evaluating to [0 1 2]
and succeeding.
Lesson learned. Don't shadow functions
As a side note, this works too...
(generate-keystream [_ {:keys [ss] :as initmap} [lower upper :as range]]
(let [ns (conj ss [])]
(reduce rabbit-round ns (clojure.core/range 3))))