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

0 votes
in ClojureScript by

In Clojure, passing a nil as the first arg to range throws NPE, but in ClojureScript it doesn't and odd things can happen:

(range nil 0)
=> ()
(range nil 1)
=> (nil)
(range nil 2)
=> (nil 1)

What's worse is if you have the start and the step both being nil:

(range 0 0 0)
=> ()
(range nil 0 nil)
INTERNAL REPL ERROR: Got an unexpected reply from relay, check Inspect
Timeout while waiting for result.

This actually evaluates to an infinite seq of nils!

(take 10 (range nil 0 nil))
=> (nil nil nil nil nil nil nil nil nil nil)

:boom:

(also raised for discussion on the clojurians slack)

1 Answer

0 votes
by

The behavior of non-numeric args passed to range is undefined.

...