DSSSL Library Reference: Part of the Modular DocBook Stylesheet distribution
Prev |  | Next

# list-head

## Name

list-head -- Return the head of a list

## Synopsis

    (list-head inputlist k)

## Description

Returns the list that contains the first `k` elements of `inputlist`.

## Example

`(list-head (1 2 3 4) 2)` returns `(1 2)`.

## Author

Norman Walsh, <ndw@nwalsh.com>

## Source Code

    (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)))))))

Prev | Home | Next
constant-list | Up | list-put