Prev Up Next

The Scheme procedure apply lets us call a procedure on a list of its arguments.

(define x '(1 2 3))

(apply + x)
=> 6

In general, apply takes a procedure, followed by a variable number of other arguments, the last of which must be a list. It constructs the argument list by prefixing the last argument with all the other (intervening) arguments. It then returns the result of calling the procedure on this argument list. Eg,

(apply + 1 2 3 x)
=> 12

Prev Up Next