list-set!(3scm) Scheme Programmer's Manual list-set!(3scm)

list-set! - modify an element in a list

(import (scheme base))              ;R7RS

(list-set! list k obj)

Stores obj in element k of list.

Returns an unspecified value.

(let ((ls (list 'one 'two 'five!)))
  (list-set! ls 2 'three)
  ls)
          => (one two three)
(list-set! '(0 1 2) 1 "oops")
          error    ; constant list should not be mutated

This procedure was added in R7RS to round out the sequence operations.

This procedure is unique to R7RS. An alternative is to use set-car!(3scm) and list-tail(3scm).

It is an error if the wrong number of arguments was passed or an argument was outside its domain. In particular, it is an error if k is not a valid index of list. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

set-car!(3scm)

R7RS

This procedure first appeared 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