Fibonacci
(def fib-seq
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
Powers of two
(def twopowers (lazy-seq (cons 1N (map #(* 2N %) twopowers))))
Factorial
(def fact (lazy-cat [1N] (map * (map #(+ % 2) (range)) fact)))
I decided to learn a functional language: I chose Clojure, because it runs on the JVM, and it seems more easy to digest for me, having some Java background. In this blog, I am going to write notes mainly for myself. However, since I already take the time to write them down, why not publish them? Maybe they will be useful for someone else too :) Please keep in mind, that I'm an absolute beginner in Clojure. So please use my blog only at your own responsibility. You have been warned ;)
(def fib-seq
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))
(def twopowers (lazy-seq (cons 1N (map #(* 2N %) twopowers))))
(def fact (lazy-cat [1N] (map * (map #(+ % 2) (range)) fact)))