Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdearman committed May 17, 2024
1 parent 4bbc90d commit ccdb49d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions examples/mvp.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
n
(+ (fib (- n 1)) (fib (- n 2)))))

(def (fib-iter n)
(defn fib (n)
"Compute the nth Fibonacci number."
(if (<= n 1)
n
(+ (fib (- n 1)) (fib (- n 2)))))

(defn fib-iter (n)
"Compute the nth Fibonacci number iteratively."
(let loop ((a 0) (b 1) (i n))
(if (= i 0)
a
(loop b (+ a b) (- i 1)))))

(def (fib-iter n)
(let (fn loop (a b i))
(if (= i 0)
a
(loop b (+ a b) (- i 1)))
(loop 0 1 n)))

;; this could also be done with a `match` expression
(def (fib n)
Expand Down

0 comments on commit ccdb49d

Please sign in to comment.