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

append - append an object to one or multiple lists

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

(append)
(append list ... obj)

Returns a possibly improper list consisting of the elements of the first list followed by the elements of the other lists, with obj as the cdr of the final pair.

An improper list results if obj is not a list. Returns the empty list if called with no arguments.

The return value is made from new pairs for all arguments but the last; the last is merely placed at the end of the new structure.

Returns a single value. An improper list results if obj is not a proper list.

(append '(x) '(y))         =>  (x y)
(append '(a) '(b c d))     =>  (a b c d)
(append '(a (b)) '((c)))   =>  (a (b) (c))
(append '(a b) '(c . d))   =>  (a b c . d)
(append '() 'a)            =>  a
(append)                   =>  ()
(append 'a)                =>  a

Except for differences in error behavior, this procedure works the same everywhere.

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.

cons*(3scm), cons(3scm), list-tail(3scm)

R4RS, IEEE Scheme, R5RS, R6RS, R7RS

The append procedure has existed in LISP since at least 1959. The variants before R3RS only accepted proper lists. Scheme before R2RS running on MacLISP accepted any number of arguments, while in LISP 1.5 the procedure only accepted two arguments.

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/.

2023-02-08