Guest User

Untitled

a guest
Jun 15th, 2018
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;; Constructor definition
  2. (defn make-fibonacci-seq
  3.   ([] (concat '(0 1 2)
  4.             (fibonacci-seq 1 2)))
  5.   ([prev-prev prev]
  6.      (lazy-seq (let [new-number (+ prev prev-prev)]
  7.                  (cons new-number
  8.                        (make-fibonacci-seq prev
  9.                                       new-number))))))
  10.  
  11. ;; Creation of an instance of a fibonacci seq inside
  12. ;; a do cycle that ends up by returning nil, so that
  13. ;; the repl doesn't try to print something infinite
  14. (do (def fb-seq (make-fibonacci-seq))
  15.     nil)
  16.  
  17. ;; Using the Infinite Seq
  18. (first fb-seq) ;=> 0
  19. (nth fb-seq 15) ;=> 987
  20. (nth (fibonacci-seq) 500) ;; => ;;2255915161619363308725126950360720720460113249137581905886388664
  21. ;;18474627738686883405015987052796968498626
Add Comment
Please, Sign In to add comment