(define min
(lambda (l m c)
(cond ((null? l) (print m))
(else ((c (car l))
if((< c m) (m c))
min((cdr l) m c))))))
I want to use the tail-recursive method to do it,but it doesn’t work. I’m very very new in Scheme, hope you can help me. Thank you!
This looks like homework, I’ll give you some pointers so you can solve it by yourself. Fill-in the blanks:
In the above code, we’re implementing a two-parameter tail-recursive procedure called
mymin(don’t use the namemin, that’s a built-in procedure.) The first parameter is the list to traverse; the second parameter stores the minimum value found so far, and when the recursion ends, it will hold the answer.Call it like this, noticing that for the first call we need to pass in the second argument a number so big that all the other numbers are smaller: