Order of cons in tri*
In the Peg Thing Example, tri* is defined as follows:
(defn tri*
"Generates lazy sequence of triangular numbers"
([] (tri* 0 1))
([sum n]
(let [new-sum (+ sum n)]
(cons new-sum (lazy-seq (tri* new-sum (inc n)))))))
What I don't understand: why does the lazy sequence end up in the right order? cons inserts at the beginning...
No comments:
Post a Comment