| apply(3scm) | Scheme Programmer's Manual | apply(3scm) |
NAME
apply - call a procedure with a list of arguments
LIBRARY
(import (rnrs)) ;R6RS (import (rnrs base)) ;R6RS (import (scheme r5rs)) ;R7RS (import (scheme base)) ;R7RS
SYNOPSIS
(apply procedure obj ... pair)
DESCRIPTION
The apply procedure calls procedure with the elements of the list
(append (list obj ...) pair)
as the actual arguments.
RETURN VALUES
apply returns the values returned by procedure when procedure is called in the manner above.
EXAMPLES
(apply + (list 3 4))
=> 7
(define compose
(lambda (f g)
(lambda args
(f (apply g args)))))
((compose sqrt *) 12 75)
=> 30
APPLICATION USAGE
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
COMPATIBILITY
This procedure works the same everywhere.
ERRORS
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.
SEE ALSO
map(3scm), for-each(3scm), call-with-current-continuation(3scm)
STANDARDS
R4RS, IEEE Scheme, R5RS, R6RS, R7RS
AUTHORS
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 |