I play with clojure, more precisely with lazyness. I tried this chunk of code:
(defn even-numbers
([] (even-numbers 0))
([n] (cons n (lazy-seq (even-numbers (+ n 2))))))
(take 1 (even-numbers 0))
It's quite idiomatic, I don't think there is something wrong with this.
The problem is I use cider within emacs. If I first evaluate the defn and afterwards evaluate the function call I get a stack overflow. Evaluating the whole buffer is OK.
I suspect that enlighten mode is to be blamed since I don't get the overflow when I disable it. I just want to understand what happens here.
[EDIT] I'm quite sure the issue is related to the enlighten mode of cider. disabling it I never get a stack overflow.
To dig a little bit into it, considering the slightly modified excerpt:
(ns clojure-noob.bizarerrie)
(defn even-numbers
([] (even-numbers 0))
([n] (do (println (even-numbers (+ n 2)))
(cons n (lazy-seq (even-numbers (+ n 2)))))))
(take 1 (even-numbers 0))
which also gives a stack overflow in every cases. Since enlighten mode try to resolves expression to output it during execution on the fly; Intuitively I'd say it tries to print the (even-numbers (+ n 2))
form (like the println I just added), which cause the stack overflow.