I do not understand why my function to get the largest number does not want to work. If I am thinking about this correctly, if the first atom is smaller than the second atom the
First mistake is that you are returning list as output in base case. You need to return a number.
You can implement this procedure in recursive way by storing the max value in MaxVal accumulator as we recurse through list.
input : List of positive unique numbers inList
output : Maximum value in list MaxVal
Follow is the implementation for above specification:
(define (GetMaxVal MaxVal inList)
(cond ( (null? inList ) MaxVal )
( (> (car inList) MaxVal ) (GetMaxVal (car inList) (cdr inList)) )
( else ( GetMaxVal MaxVal (cdr inList)) ) ))
(define inList '(1 67 3 5 176 4745 34 575))
(display (GetMaxVal 0 inList) ) ; prints 4745 to screen
MaxValMaxVal than update MaxVal; pass MaxVal and (cdr inList) in argument in recursive call.else the first element is not greater so recurse by passing list without first element i.e. (cdr inList)