(defn min-max-by-columns [s]
(reduce (fn [[smallest largest] y]
[(map min smallest y) (map max largest y)])
[(first s) (first s)]
s))
I'm trying to find out the max and min of each column of a large table (sequence of fixed length sequences)
The above code works fine for small tables, but for large tables I get a stackoverflow error
clojure.core/map/fn--3594 (core.clj:2370)
clojure.lang.LazySeq.sval (LazySeq.java:42)
clojure.lang.LazySeq.seq (LazySeq.java:60)
clojure.lang.RT.seq (RT.java:447)
clojure.core/seq (core.clj:133)
clojure.core/map/fn--3594 (core.clj:2371)
clojure.lang.LazySeq.sval (LazySeq.java:42)
clojure.lang.LazySeq.seq (LazySeq.java:60)
clojure.lang.RT.seq (RT.java:447)
clojure.core/seq (core.clj:133)
clojure.core/map/fn--3594 (core.clj:2371)
clojure.lang.LazySeq.sval (LazySeq.java:42)
clojure.lang.LazySeq.seq (LazySeq.java:60)
clojure.lang.RT.seq (RT.java:447)
clojure.core/seq (core.clj:133)
clojure.core/map/fn--3594 (core.clj:2371)
...
Am I holding on to the head because of the line [(first s) (first s)]? I need these values for the algorithm to work.
How can I fix this?
[(first s) (first s)]out of the equation, e.g.,(defn min-columns [s] (reduce (fn [x y] (map min x y)) s)).