Problem 2: Slice (100 pts)
Write a function slice
which takes in a stream s
, a non-negtive integer start
, and a non-negtive integer end
. It should return a Scheme list that contains the elements of s
between index start
and end
, not including end. If the stream ends before end
, you can return the whole part after start
; if the stream ends before start
, return nil
. You can assume end
may not less than start
.
(define (slice s start end)
'YOUR-CODE-HERE
)
;;; Tests
; scm> (define nat (naturals 0)) ; See naturals procedure defined earlier
; nat
; scm> (slice nat 4 12)
; (4 5 6 7 8 9 10 11)
; scm> (define a (cons-stream 1 (cons-stream 2 nil)))
; a
; scm> (slice a 1 114514)
; (2)