> On Feb 12, 2017, at 3:00 PM, Angus <[email protected]> wrote: > > I am a beginner Racket developer by the way. > > Here is my maxval function which is supposed to take a list and return the > largest integer in the list. > > (define (maxval lst) > (define (aux lst max) > (cond [(null? lst) max] > [(car lst) > max (aux (cdr lst) (car lst))] > [#t (aux (cdr lst) max)])) > (aux lst 0)) > > > Using the function always returns the last value in the list > >> (maxval (list 1 2 3 5 6 1)) > 1 > > The code looks correct to me, but I must be missing something. What have I > done wrong?
Your code is 100% correct, conceptually. Sadly, it’s suffering from a mistake that I saw many many times in the 90s and before. And that’s precisely why we get beginners started on Beginning Student Language in DrRacket instead of plain Racket. Try it out for your next few exercises or even this one, to see whether the error message would have helped. — Matthias -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

