Identifying Tail-Recursion

43 views Asked by At

Using Racket, I have written the following function, poly-eval, to compute the value of a polynomial given the coefficients and an integer:

(define (poly-eval coeffs x)
(letrec ([helper (lambda (coeffs x y)
    (if (empty? coeffs)
        0
        (+ (helper (cdr coeffs) x (- y 1)) (* (car coeffs) (iexpt x (- y 1))))))])
  (helper (reverse coeffs) x (length coeffs))))

From my understanding, this is a tail-recursive solution. Is this correct? Is there any way to manually check and identify a function as tail-recursive?

0

There are 0 answers