Clojure

(vec (range)) causes REPL to hang (infinite loop?)

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: Release 1.5
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    LightTable and CoutnerClockWise
    Windows7

Description

I just typed

(vec (range))

in LightTable and it stop working while CPU went to 100%
the same behavior is in Eclipse/Couterclockwise REPL

Activity

Hide
Andy Fingerhut added a comment -

Rene, this is expected to cause an infinite loop. (range) returns a lazy infinite sequence of integers. vec tries to cause the entire infinite sequence to be realized so it can put all elements into a vector. This is not a bug. You asked for an infinite loop, and you got one

Show
Andy Fingerhut added a comment - Rene, this is expected to cause an infinite loop. (range) returns a lazy infinite sequence of integers. vec tries to cause the entire infinite sequence to be realized so it can put all elements into a vector. This is not a bug. You asked for an infinite loop, and you got one
Hide
Alex Miller added a comment -

(range) will yield an infinite sequence. vec will walk the sequence, conj'ing each item onto the vector ... which will do bad things.

While Clojure works well with infinite sequences (an abstraction), the collections like vector support only a finite number of elements.

Show
Alex Miller added a comment - (range) will yield an infinite sequence. vec will walk the sequence, conj'ing each item onto the vector ... which will do bad things. While Clojure works well with infinite sequences (an abstraction), the collections like vector support only a finite number of elements.
Alex Miller made changes -
Field Original Value New Value
Resolution Declined [ 2 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: