• Clojure
  • 17 lines
  • 17 views
  • Pasted by anonymous on October 25, 2012
; Example for lazy concat causing a stack overflow
; Also shows how using doall can eliminate the stack overflow issues
; http://stackoverflow.com/questions/13072094/combining-2-lists-in-clojure


(first
  (loop [acc '(1), i 10000]
    (if (zero? i) acc
      (recur (concat acc nil) (dec i)))))
; => StackOverflowError


(first
  (loop [acc '(1), i 10000]
    (if (zero? i) acc
      (recur (doall (concat acc nil)) (dec i)))))
; => 1

Did you know? CLOSE

  • There are keyboard shortcuts!
    • When Creating A Paste
      • ALT+P Toggle Private
      • CTRL+Enter Create Paste
      • ALT+W Toggle word wrap
    • When Viewing A Paste
      • ALT+G Go to a line
      • ALT+CTRL+E Edit the paste
      • ALT+R Show the raw code
  • There are URL options!
    • When Creating A Paste
      • ?lang=Javascript to default to javascript
    • When Viewing A Paste
      • #L-N Jump to line number N
?