Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdearman committed Apr 15, 2024
1 parent 27d3994 commit eccef11
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/mvp.scm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@
(def (fib 1) 1)
(def (fib n) (+ (fib (- n 1)) (fib (- n 2))))

(def (fib (n : Int) : Int)
(if (<= n 1)
n
(+ (fib (- n 1)) (fib (- n 2)))))

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

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

0 comments on commit eccef11

Please sign in to comment.