Clojure

GC Issue 29: Range sometimes yields wrong sequence (with patch)

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Reported by olov.lassus, Jan 02, 2009
The clojure.lang.Range type is implemented with integer type start and end
indices. The core.clj range function should detect when an index doesn't
fit inside an int and create an increasing sequence using iterate instead.
The current implementation detects too large positive, but not too large
negative ranges. The overflow occurs silently without throwing an exception.

Before:
user=> (take 1 (range -2147483649 0))
(2147483647)


After applying the patch which apply cleanly against trunk r1195:
user=> (take 1 (range -2147483649 0))
(-2147483649)


I also made the range function slightly less conservative < vs <= wise.
This shouldn't affect correctness but (range 0 2147483647) will now return
a Range (after patch) instead of a LazyCons (before).

 support_large_negative_range.patch
918 bytes Download
Comment 1 by richhickey, Jan 07, 2009
Patch applied - svn 1204 - thanks!
Status: Fixed

People

  • Assignee:
    Unassigned
    Reporter:
    Anonymous
Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: