chickadee » srfi-116 » itake-right

itake-right dilist iprocedure
idrop-right dilist iprocedure

itake-right returns the last i elements of dilist. idrop-right returns all but the last i elements of dilist.

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

The returned ilist may share a common tail with the argument ilist.

dilist may be any ilist, either proper or dotted:

(itake-right (iq ipair 1 (ipair 2 (ipair 3 'd))) 2) ;=> (2 3 . d)
(idrop-right (ipair 1 (ipair 2 (ipair 3 'd))) 2)    ;=> (1)
(itake-right (ipair 1 (ipair 2 (ipair 3 'd))) 0)    ;=> d
(idrop-right (ipair 1 (ipair 2 (ipair 3 'd))) 0)    ;=> (1 2 3)

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

(iappend (itake dilist i) (idrop dilist i)) ;=> dilist

itake-right's return value is guaranteed to share a common tail with dilist.