(require (lib"1.ss""srfi"))
; sublist : list integer integer -> list
; (sublist (list x0 x1 ... xn) s e)
; => (list xs ... x_e-1)
(define (sublista-liststartend)
(take (dropa-listend)
(-endstart)))
; sublist! : list integer integer -> list
; the linear update version of sublist,
; sublist! may alter a-list to produce the result
(define (sublist!a-liststartend)
(take! (dropa-listend)
(-endstart)))
This uses the take and drop functions from SRFI 1. The function take takes the first n elements from a list, while drop takes everything after the first n elements. So you can see that we're dropping start elements from the front of the list and taking {- end start) elements from that result.
Example usage:
A call to sublist will a return a newly allocated list holding
the elements of the given segment.
The function sublist! will alter the given list, and will therefore not allocate a new list.
Note: The sublist function corrresponds to using the slice operator in Python.
-- GordonWeakliem - 29 Apr 2004, JensAxelSoegaard - 12 May 2004