apply(3scm) Scheme Programmer's Manual apply(3scm)

apply - call a procedure with a list of arguments

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme base))              ;R7RS

(apply procedure obj ... pair)

The apply procedure calls procedure with the elements of the list

(append (list obj ...) pair)

as the actual arguments.

apply returns the values returned by procedure when procedure is called in the manner above.


apply is usually used to call a procedure where the set of arguments to give to the procedure is not known ahead of time. apply can also be used to perform a simple "fold" over a list of items if procedure can take an arbitrary number of arguments. For example:

(apply + (list 1 2 3 4)) => 10

This procedure can raise exceptions with the following condition types:
&assertion (R6RS)
The wrong number of arguments was passed or an argument was outside its domain.
R7RS
The assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

2022-02-01