Sophie

Sophie

distrib > Mageia > 7 > i586 > media > core-release > by-pkgid > 6b3585ea67ce3e79c9049b5b33294cdd > files > 651

docbook-style-dsssl-doc-1.79-16.mga7.noarch.rpm

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

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

<RefNameDiv>
  <RefName>list-head</RefName>
  <RefPurpose>Return the head of a list</RefPurpose>
</RefNameDiv>

<RefSynopsisDiv><Title>Synopsis</Title>
<Synopsis>
(list-head inputlist k)
</Synopsis>
</RefSynopsisDiv>

<RefSect1><Title>Description</Title>

<para>
Returns the list that contains the first <literal>k</literal> elements of <literal>inputlist</literal>.</para>


</RefSect1>

<RefSect1><Title>Example</Title>

<para>
<literal>(list-head (1 2 3 4) 2)</literal> returns <literal>(1 2)</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-head inputlist k)
  ;; Return the head of a list
  (let loop ((l inputlist) (count k) (result '()))
    (if (<= count 0)
	result
	(loop (cdr l) (- count 1) (append result (list (car l)))))))
</ProgramListing>
</RefSect1>

</RefEntry>