[ prog / sol / mona ]

prog


Internal definitions vs letrec

1 2020-08-01 20:53

Which one do you prefer?

(define (fibonacci n)
  (define (fibi n a b)
    (cond
     ((zero? n) b)
     (else (fibi (- n 1) (+ a b) a))))
  (fibi n 1 0))

(define (fibonacci n)
  (letrec ((fibi (lambda (n a b)
                   (cond
                    ((zero? n) b)
                    (else (fibi (- n 1) (+ a b) a))))))
    (fibi n 1 0)))
13


VIP:

do not edit these