Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

Problem
There are a number of bugs with Range which occur when the step size is 0 or where negative.

Examples

`
cljs.user=> (count (range 10 0 0))
-Infinity ;Expect Infinity

cljs.user=> (nth (range 10 0 -1) -1)
11 ; Expected IndexOutOfBounds

cljs.user=> (take 5 (sequence identity (range 0 10 0)))
() ; Expected (0 0 0 0 0)

cljs.user=> (into [] (take 5) (range 0 10 0))
[] ; Expected [0 0 0 0 0]
`

4 Answers

0 votes
by

Comment made by: dnolen

This patch is headed in the right direction but it needs to be more vigilant about performance. I'm more than happy to talk it over via IRC or Slack. Thanks!

0 votes
by

Comment made by: tmulvaney

Updated patch with performance tweaks.

  • Added the ^boolean annotation to the some-range? helper.
  • Removed calls to methods of Range where possible.
  • Improved 2-arity reduces performance over master significantly by replacing the call to ci-reduce.
0 votes
by

Comment made by: mfikes

Patch no longer applies; needs re-baseline.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-1846 (reported by tmulvaney)
...