list-put
dblib.dsl
list-put
Replace a specific member of a list
Synopsis
(list-put vlist ordinal value #!optional (span 1))
Description
Replaces the ordinalth value of vlist with value. If span > 1,
replaces ordinal to ordinal+span-1 values starting at ordinal.
Example
(list-put (1 2 3 4 5) 2 0 2) returns (1 0 0 4 5).
Author
Norman Walsh, <ndw@nwalsh.com>
Source Code
(define (list-put vlist ordinal value #!optional (span 1))
;; Replace a specific member of a list
(let loop ((result vlist) (count span) (k ordinal))
(if (equal? count 0)
result
(let ((head (list-head result (- k 1)))
(tail (list-tail result k)))
(loop (append head (list value) tail) (- count 1) (+ k 1))))))