<RefEntry id="list-put">
<!-- This file is generated automatically from the DSSSL source. -->
<!-- Do not edit this file! -->
<?html-filename list-put.html>

<RefMeta>
  <RefEntryTitle>list-put</RefEntryTitle>
  <RefMiscInfo Role="file">dblib.dsl</RefMiscInfo>
</RefMeta>

<RefNameDiv>
  <RefName>list-put</RefName>
  <RefPurpose>Replace a specific member of a list</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(list-put vlist ordinal value #!optional (span 1))
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
Replaces the <literal>ordinal</literal>th value of <literal>vlist</literal> with <literal>value</literal>.  If <literal>span</literal> > 1,
replaces <literal>ordinal</literal> to <literal>ordinal+span-1</literal> values starting at <literal>ordinal</literal>.</para>


</RefSect1>

<RefSect1><Title>Example</Title>

<para>
<literal>(list-put (1 2 3 4 5) 2 0 2)</literal> returns <literal>(1 0 0 4 5)</literal>.
</para>


</RefSect1>

<RefSect1><Title>Author</Title>

<para>
Norman Walsh, &lt;ndw@nwalsh.com&gt;
</para>
</RefSect1>
<RefSect1><Title>Source Code</Title>

<ProgramListing>
(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))))))
</ProgramListing>
</RefSect1>

</RefEntry>
