3 ms·
In Clojure you can generate the Fibonacci sequence with (def fibs (lazy-cat [0N 1N] (map + fibs (rest fibs)))) which is an example of (memory consuming) corec
by leephillips 13y ago
In Clojure you can generate the Fibonacci sequence with
(def fibs (lazy-cat [0N 1N] (map + fibs (rest fibs))))
which is an example of (memory consuming) corecursion that I managed to sneak into two recent articles:
http://arstechnica.com/science/2014/05/scientific-computings-future-can-any-coding-language-top-a-1950s-behemoth/ http://arstechnica.com/science/2014/05/scientific-computings...
and
http://lee-phillips.org/lispmath/ http://lee-phillips.org/lispmath/
(I did not come up with this.)
- gamegoblin 13y agoSimilarly in Haskell: fibs = 1:1:zipWith (+) fibs (tail fibs)