We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 198512b + bb63a77 commit 51b1e63Copy full SHA for 51b1e63
main.rkt
@@ -102,16 +102,16 @@
102
103
104
(define (sliding lst size [step 1])
105
- (define (tail-call lst)
106
- (if (>= size (length lst))
107
- (list lst)
108
- (cons (take lst size)
109
- (tail-call (drop lst step)))))
110
- (cond
111
- [(> step (length lst))
112
- (error "step has to be equal to or smaller than length of the list")]
113
- [(= step (length lst)) (list lst)]
114
- [else (tail-call lst)]))
+ (when (or (<= step 0) (> step (length lst)))
+ (error "step has to be equal to or smaller than the length of the list"))
+
+ (let recur [(lst lst)
+ (len (length lst))]
+ (if (>= len size)
+ (cons (take lst size)
+ (recur (drop lst step)
+ (- len step)))
+ empty)))
115
116
117
(define (scanl proc lst)
0 commit comments