chickadee » srfi-116 » itake

itake x iprocedure
idrop x iprocedure
ilist-tail x iprocedure

itake returns the first i elements of ilist x. idrop returns all but the first i elements of ilist x. ilist-tail is either the same procedure as idrop or else a procedure with the same behavior.

(itake (iq a b c d e)  2) ;=> (a b)
(idrop (iq a b c d e)  2) ;=> (c d e)

x may be any value — a proper or dotted ilist:

(itake (ipair 1 (ipair 2 (ipair 3 'd)))    ;=> (1 2)
(idrop (ipair 1 (ipair 2 (ipair 3 'd))) 2) ;=> (3 . d)
(itake (ipair 1 (ipair 2 (ipair 3 'd))) 3) ;=> (1 2 3)
(idrop (ipair 1 (ipair 2 (ipair 3 'd))) 3) ;=> d

For a legal i, itake and idrop partition the ilist in a manner which can be inverted with iappend:

(iappend (itake x i) (idrop x i)) = x

idrop is exactly equivalent to performing i icdr operations on x; the returned value shares a common tail with x.