<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, <ndw@nwalsh.com> </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>