Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;; Constructor definition
- (defn make-fibonacci-seq
- ([] (concat '(0 1 2)
- (fibonacci-seq 1 2)))
- ([prev-prev prev]
- (lazy-seq (let [new-number (+ prev prev-prev)]
- (cons new-number
- (make-fibonacci-seq prev
- new-number))))))
- ;; Creation of an instance of a fibonacci seq inside
- ;; a do cycle that ends up by returning nil, so that
- ;; the repl doesn't try to print something infinite
- (do (def fb-seq (make-fibonacci-seq))
- nil)
- ;; Using the Infinite Seq
- (first fb-seq) ;=> 0
- (nth fb-seq 15) ;=> 987
- (nth (fibonacci-seq) 500) ;; => ;;2255915161619363308725126950360720720460113249137581905886388664
- ;;18474627738686883405015987052796968498626
Add Comment
Please, Sign In to add comment