list-copy(3scm) Scheme Programmer's Manual list-copy(3scm)

list-copy - copy a list

(import (scheme base))              ;R7RS

(list-copy obj)

Returns a newly allocated copy of the given obj if it is a list. Only the pairs themselves are copied; the cars of the result are the same (in the sense of eqv?(3scm)) as the cars of list. If obj is an improper list, so is the result, and the final cdrs are the same in the sense of eqv?(3scm). An obj which is not a list is returned unchanged.

Returns a single value

(define a '(1 8 2 8))    ; a may be immutable
(define b (list-copy a))
(set-car! b 3)           ; b is mutable
b  =>  (3 8 2 8)
a  =>  (1 8 2 8)

This procedure is unique to R6RS. An alternative is to write (map values obj).

It is an error if the wrong number of arguments was passed or an argument was outside its domain. It is an error if obj is a circular list. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

map(3scm), vector-copy(3scm)

R7RS

This procedure is new in 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/.

2023-08-13