Alex Rivera | Logout

Explanation of "Lose your head" in lazy sequences

Asked 2011-04-18T03:08:57.313
20

In Clojure programming language, why this code passes with flying colors?

(let [r (range 1e9)] [(first r) (last r)])

While this one fails:

(let [r (range 1e9)] [(last r) (first r)])

I know it is about "Losing your head" advice but would you please explain it to me? I'm not able to digest it yet.

UPDATE:
It is really hard to pick the correct answer, two answers are amazingly informative.
Note: Code snippets are from "The Joy of Clojure".

Edit
Report

1 Answer

2

for a technical description, go to http://clojure.org/lazy. the advice is mentioned in the section Don't hang (onto) your head

answered 2011-04-19T09:56:12.210

Your Answer