list-head.ss

Scheme

Public Domain

Return an initial portion of a list

Download (right click, save as, rename as appropriate)

Embed

Tags:

list lists Scheme
1
2
3
4
; Returns the first `k' elements of `li' or, if `k' is negative, all but the
; last "(- k)" elements
(define (list-head li k)
 (reverse (list-tail (reverse li) (if (< k 0) (- k) (- (length li) k)))))