Take the 2-minute tour ×

So I have written this function that returns a list of numbers in this format:

'(1 2 5 6 7 2)

Now I need to find the maximum value of this list, but the max function doesn't seem to work with this type of list. How would I go about solving this problem?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

What you want is

> (max 1 2 5 6 7 2)

Since your arguments are in a list, use apply:

> (apply max '(1 2 5 6 7 2))

See also here.

share|improve this answer
What exactly does apply do? I'm a bit confused by it. –  Seeker Apr 21 at 17:41
max is a procedure that takes one or more parameters, so you code (max n1 ...). Simply put, apply transforms (max '(n1 ...)) into (max n1 ...) –  Le Petit Prince Apr 21 at 17:47
Thanks a bunch one again :) –  Seeker Apr 21 at 17:51
You're welcome ;-) –  Le Petit Prince Apr 21 at 17:53
@Seeker Do you know Python or Ruby, and their "splatting" operator? (foo(bar, *baz)) apply is the Scheme version of the same concept. –  Chris Jester-Young Apr 21 at 17:55

Your Answer


