the documentation of math.combinatorics states that all functions return lazy sequences.
However if I try to run subsets with a lot of data
(last (combinatorics/subsets (range 20)))
;OutOfMemoryError Java heap space clojure.lang.RT.cons (RT.java:559)
I get an OutOfMemory Error.
Running
(last (range))
burns cpu but doesn't return an error.
Clojure doesn't seem to "hold on the head" like explained in this so question
Could someone explain me why this is happening and how I can use bigger ranges in subsets
Update
It seems to work on some peoples computers as the comments suggest. So I will post my system configuration
I run a Mac (10.8.3) and installed clojure (1.5.1) with homebrew.
My Java Version is
% java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06-451-11M4406)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01-451, mixed mode)
I didn't change any of the default settings.
I also reinstalled all dependencies, by deleting the ~/.m2
folder
My projects.clj
And the command I used was this
% lein repl
nREPL server started on port 61774
REPL-y 0.1.10
Clojure 1.5.1
=> (require 'clojure.math.combinatorics)
nil
=> (last (clojure.math.combinatorics/subsets (range 20)))
OutOfMemoryError Java heap space clojure.lang.RT.cons (RT.java:570)
or
OutOfMemoryError Java heap space clojure.math.combinatorics/index-combinations/fn--1148/step--1164 (combinatorics.clj:64)
I tested the problem on a colleagues laptop and he had the same issue, but he was on a mac, too.