(define (min-cos i j) (if (= i j) (cos i) (min (cos i) (min-cos (+ i 1) j))))Now this isn't tail-recursive, so I can't compute something like (min-cos 1 10000000). Here is a tail-recursive version, along with a redefinition of (min-cos i j) that simply calls the tail-recursive version:
(define (min-cos-tr i j m)
(if (> i j)
m
(min-cos-tr (+ i 1) j (min (cos i) m))))
(define (min-cos i j) (min-cos-tr (+ i 1) j (cos i)))
Study this. Understand this. Love this. Your job is to
redefine this as a single function (min-cos i j) that uses
a letrec to define the tail-recursive version
internally. Read the "More functions creating functions:
letrec" section of Scheme Lab XX to see
how this is done.
(winner
beats? L) function from
Scheme Lab 4.
If you can't get a working version of(winner beats? L), do a tail-recursive implementation of "sum-of-absolute-valuse":(define (sabs L) (if (null? L) 0 (+ (abs (car L)) (sabs (cdr L)))))... that returns the sum of the absolute values of the elements of a list of numbers.
NOTE: Whichever you do, provide an example of calling the function in your file. The user should be able to call this function as before, without having to explicitly pass an extra argument to support the tail recursion (just like you did for the min-cos-tr function above).