[plt-scheme] Why does this code pause at the end
Running this in Advanced Student. It's a fast version of Pascals
Triangle implemented by computing each row before it returns a result.
The program returns it's result but a (relatively) long pause ensues
before the scheme prompt appears. Wondering why.
(define (pascal-row row)
(cons 1
(local [(define (sum-neighbours row)
(if (or (empty? row)
(empty? (rest row)))
row
(cons (+ (first row) (second row))
(sum-neighbours (rest row)))))]
(sum-neighbours row))))
(define (pascal n k)
(cond
[(> k n) (pascal k n)]
[else (local [(define (pascal m previous-row)
(cond
[(= m n) (+ (list-ref previous-row (sub1 k))
(list-ref previous-row k))]
[else (pascal (add1 m) (pascal-row previous-
row))]))]
(pascal 0 empty))]))
(pascal 345 235)