Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a list "unlazy" in clojure

I recently noticed that there was a very clear implementation of insertion sort here :

Insertion sort in clojure throws StackOverFlow error

  • which suffers from a memory overflow, due to the fact that concat lazily joins lists. I was wondering :

What strategies can we apply to "de-lazying" a list when we want better performance on large collections ?

like image 373
jayunit100 Avatar asked Mar 25 '12 23:03

jayunit100


1 Answers

doall is certainly fine for forcing lazy evaluation.

Another useful thing to remember is that reduce is non-lazy. This can therefore be very useful in large computations for ensuring that intermediate results get evaluated and reduced to a single output value before the computation proceeds.

like image 192
mikera Avatar answered Nov 12 '22 23:11

mikera