You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
var st = Stream(0)
for (i <- 1 to 10000) st = i +: st
st.take(10000).print
results in:
....
7360, 7359, 7358, 7357, 7356, 7355, 7354, 7353, 7352, 7351, 7350, 7349, 7348, 7347, 7346, 7345java.lang.StackOverflowError
at scala.collection.immutable.List.toStream(List.scala:245)
at scala.collection.immutable.List$$anonfun$toStream$1.apply(List.scala:246)
at scala.collection.immutable.List$$anonfun$toStream$1.apply(List.scala:246)
at scala.collection.immutable.Stream$Cons.tail(Stream.scala:630)
at scala.collection.immutable.Stream$Cons.tail(Stream.scala:622)
at scala.collection.immutable.Stream$$anonfun$flatMap$1.apply(Stream.scala:217)
at scala.collection.immutable.Stream$$anonfun$flatMap$1.apply(Stream.scala:217)
at scala.collection.immutable.Stream.append(Stream.scala:80)
at scala.collection.immutable.Stream$$anonfun$append$1.apply(Stream.scala:80)
at scala.collection.immutable.Stream$$anonfun$append$1.apply(Stream.scala:80)
....
Creating a stream of the same size with Stream.cons works fine:
var st = Stream(0)
for (i <- 1 to 10000) { val st2 = st; st = Stream.cons(i,st2) }
st.take(10000).print
I haven't traipsed through the builder mechanism to figure out what's going on with +:, but I would have hoped it could construct a less fragile stream.
The text was updated successfully, but these errors were encountered:
Commit Message Bot (anonymous) said:
(extempore in r25130) Routed Stream.+: through cons to avoid some truly pathological
performance. Closes #4697, no review.
Typing this into the REPL:
var st = Stream(0)
for (i <- 1 to 10000) st = i +: st
st.take(10000).print
results in:
7360, 7359, 7358, 7357, 7356, 7355, 7354, 7353, 7352, 7351, 7350, 7349, 7348, 7347, 7346, 7345java.lang.StackOverflowError
at scala.collection.immutable.List.toStream(List.scala:245)
at scala.collection.immutable.List$$anonfun$toStream$1.apply(List.scala:246)
at scala.collection.immutable.List$$anonfun$toStream$1.apply(List.scala:246)
at scala.collection.immutable.Stream$Cons.tail(Stream.scala:630)
at scala.collection.immutable.Stream$Cons.tail(Stream.scala:622)
at scala.collection.immutable.Stream$$anonfun$flatMap$1.apply(Stream.scala:217)
at scala.collection.immutable.Stream$$anonfun$flatMap$1.apply(Stream.scala:217)
at scala.collection.immutable.Stream.append(Stream.scala:80)
at scala.collection.immutable.Stream$$anonfun$append$1.apply(Stream.scala:80)
at scala.collection.immutable.Stream$$anonfun$append$1.apply(Stream.scala:80)
....
Creating a stream of the same size with Stream.cons works fine:
var st = Stream(0)
for (i <- 1 to 10000) { val st2 = st; st = Stream.cons(i,st2) }
st.take(10000).print
I haven't traipsed through the builder mechanism to figure out what's going on with +:, but I would have hoped it could construct a less fragile stream.
The text was updated successfully, but these errors were encountered: