Improve the implementation of in-slice.

This commit is contained in:
Vincent St-Amour 2015-08-07 14:47:43 -05:00
parent 2d23ca1414
commit 1a7b71fb20

View File

@ -62,22 +62,18 @@
;; Added by stamourv (from David Vanderson (david.vanderson at gmail.com)):
(provide/contract
[in-slice (exact-positive-integer? any/c . -> . any)])
[in-slice (exact-positive-integer? sequence? . -> . any)])
(define (in-slice k seq)
;; ELI: what's the point of using `any/c' above and then checking it here?
(unless (sequence? seq) (raise-type-error 'in-slice "sequence" seq))
(make-do-sequence
(λ ()
(define-values (more? get) (sequence-generate seq))
(values
(λ (_)
;; ELI: Add an `in-range'
(for/list ([i k] #:when (more?))
(for/list ([i (in-range k)] #:when (more?))
(get)))
values
#f
#f
;; ELI: Use `pair?'
(λ (val) (0 . < . (length val)))
(λ (val) (pair? val))
#f))))