On Sun, 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))]
Right here ^^^ you're trying to use `>` as an infix operator, but
that's not how Racket syntax works. What you want is:
[(> (car lst) max) <...>]
The way you wrote it, it means: "If the first element of `lst` isn't
#f, then evaluate `>` for side-effects (which does nothing), then
evaluate `max` for side-effects (which does nothing), then return the
value of `(aux (cdr lst) (car lst))`."
> [#t (aux (cdr lst) max)]))
Preferred Racket style is to use `else` here instead of `#t`.
- Jon
--
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.