Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdearman committed Apr 28, 2024
1 parent eccef11 commit f52a245
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions examples/mvp.scm
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,24 @@
;; def declarations
(def x 42)

;; def declarations with pattern matching
(: fib Int Int)
(def (fib 0) 0)
(def (fib 1) 1)
(def (fib n) (+ (fib (- n 1)) (fib (- n 2))))

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

(def (fib-iter (n : Int) : Int)
(def (fib-iter n)
(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)
(match n
Expand Down

0 comments on commit f52a245

Please sign in to comment.