I am trying to call a reverse function I wrote (that works when called alone) inside another function, but it outputs incorrect results.
I'm writing a program to take the derivative, with respect to x, of a bivariate polynomial. I have a main function called poly_derx which will call my two helper functions reverse_list and mult_by_index.
(define (mult_by_index list_1)
(if (null? list_1)
list_1
(map * list_1 (range (length list_1)))))
(define (reverse_list list_1)
(if (null? list_1)
list_1
(append(reverse (cdr list_1)) (list (car list_1)))))
(define (poly_derx list_1)
(if (null? list_1)
list_1
(reverse_list(cons (mult_by_index (car list_1)) (poly_derx (cdr list_1))))))
(poly_derx `( (1) (1 2 3) () (3)))
Again, my 3 functions work fine until I add the reverse_list in poly_derx. Also, I know there is a built in reverse but I face the same issue.
At this point, the only thing I know to do is try calling reverse at different points in the function but nothing I know of works.