summaryrefslogtreecommitdiff
path: root/test/files/run/t3502.scala
diff options
context:
space:
mode:
authorAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-06-02 16:31:56 +0000
committerAleksandar Pokopec <aleksandar.prokopec@epfl.ch>2010-06-02 16:31:56 +0000
commitde67e153ee74427f98b4ea5c21afa8fb01fe374a (patch)
treee99e19aac6c6e72673f950605c8b338de012ba3f /test/files/run/t3502.scala
parenta708aa88f4b7d03fe272a8bfff8d42c389592964 (diff)
downloadscala-de67e153ee74427f98b4ea5c21afa8fb01fe374a.tar.gz
scala-de67e153ee74427f98b4ea5c21afa8fb01fe374a.tar.bz2
scala-de67e153ee74427f98b4ea5c21afa8fb01fe374a.zip
Partially solves the problem for #3502.
This commit reimplements filter for Streams, but does not reimplement map in StreamWithFilter. The problem is that GC can't collect instances of Streams residing on the stack if there are multiple references to the Stream (more than a single one on the stack on which a Stream method is invoked). In the case of a StreamWithFilter, being an inner class, there is always an `$outer` reference to the outer object, so there is little GC can do. Possible solution - change the return type of WithFilter to something else (in TraversableLike) to allow it to return objects that don't have to subclass TraversableLike.WithFilter, and reimplement the withFilter method in Stream to simply call `filter` method - in the case of Streams, `withFilter` has little sense in either case...
Diffstat (limited to 'test/files/run/t3502.scala')
-rw-r--r--test/files/run/t3502.scala24
1 files changed, 24 insertions, 0 deletions
diff --git a/test/files/run/t3502.scala b/test/files/run/t3502.scala
new file mode 100644
index 0000000000..cc78e54c86
--- /dev/null
+++ b/test/files/run/t3502.scala
@@ -0,0 +1,24 @@
+
+
+
+
+
+// ticket #3502
+object Test {
+
+ object GeneratePrimeFactorsLazy extends (Int => List[Int]) {
+ override def apply(n:Int) = {
+ val s = Stream.range(2, n / 2).filter(n % _ == 0)
+ //val s = for (i <- Stream.range(2, n / 2); if n % i == 0) yield i
+ s.headOption.map(x => x :: apply(n / x)).getOrElse(List(n))
+ }
+ }
+
+ def main(args:Array[String]) {
+ // a prime number
+ //val num = 623456789
+ val num = 2796203
+ assert(GeneratePrimeFactorsLazy(num) == List(num))
+ }
+
+}