aboutsummaryrefslogtreecommitdiff
path: root/rosetta/lev.neb
blob: 03db260450271ede699b6cd0b2ad8c0ea0d10749 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
; this should be in the stdlib
(func min (lst)
    (reduce
        (lambda (acc x)
            (if (< x acc)
                x
                acc))
        (rest lst)
        (first lst)))

(func lev (s t)
    (branch
        ((eq? 0 (length s)) (length t))
        ((eq? 0 (length t)) (length s))
        ((eq? (first s) (first t))
            (lev (rest s) (rest t)))
        (#true
            (+ 1
                (min
                    (list
                        (lev s (rest t))
                        (lev (rest s) t)
                        (lev (rest s) (rest t))))))))