view 6-Clojure/fibonaci.clj @ 89:7e4afb129bef

Add initial Day 2 notes with functions, partially applied, and currying
author IBBoard <dev@ibboard.co.uk>
date Sat, 15 Jun 2019 21:07:27 +0100
parents eccc649d49a2
children
line wrap: on
line source

; For a pair of (assumed) consecutive (assumed) Fibonacci numbers and generates the next pair
(defn fib-pair [[a b]] ; I *think* this a vector and not just two parameters so that we can iterate (because you can't return two values)
    [b (+ a b)])

(print (fib-pair [3 5]))

(print 
    (take 5
        (map first (iterate fib-pair [1 1]))))

(print 
    (nth 
        (map first (iterate fib-pair [1 1]))
        50)) ;The book says 500th, but even 100th gives java.lang.ArithmeticException: integer overflow!