chickadee » list-utils » split-at+

split-at+ LIST COUNT #!optional PADSprocedure

Returns 2 values, the leading COUNT elements from LIST as a new list, and the remaining elements from LIST. Should there be fewer than COUNT elements available padding is attempted.

Padding is performed by trying to complete the remaining elements from the list PADS.

COUNT is a natural fixnum. PADS is a list or #f. Default is '().

A negative COUNT is treated as 0.

When PADS is #f then an incomplete leading sublist is treated as '(). The very odd treatment of PADS = #f can safely be ignored since this is not the default behavior.

(split-at+ '(1 2 3) 3) ;=> '(1 2 3) '()
(split-at+ '(1 2 3) 2) ;=> '(1 2) '(3)
(split-at+ '(1 2 3) 4) ;=> '(1 2 3) '()
(split-at+ '(1 2 3) 4 #f) ;=> '() '()