I don't understand what the differences are between (sorry for the contrived example):
(define average
  (lambda (elems)
   (define length
     (lambda (xs)
      (if (null? xs)
          0
          (+ 1 (length (cdr xs))))))
   (define sum
     (lambda (xs)
      (if (null? xs)
          0
          (+ (car xs) (sum (cdr xs))))))
   (define total (sum elems))
   (define count (length elems))
   (/ total count)))
and
(define average
  (lambda (elems)
   (letrec ((length
              (lambda (xs)
               (if (null? xs)
                   0
                   (+ 1 (length (cdr xs))))))
            (sum
              (lambda (xs)
               (if (null? xs)
                   0
                   (+ (car xs) (sum (cdr xs))))))
            (total (sum elems))
            (count (length elems)))
     (/ total count))))
As far as I can tell, they both create a new scope, and in that scope create 4 local variables that refer to each other and to themselves, and evaluate and return a body.
Am I missing something here, or is letrec synonymous with scoped defines?
I know this may be implementation dependent; I'm trying to get an understanding of the fundamentals of Lisps.
 
     
    