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.
1 parent 51b1e63 commit 4e28d43Copy full SHA for 4e28d43
main.rkt
@@ -102,16 +102,16 @@
102
103
104
(define (sliding lst size [step 1])
105
- (when (or (<= step 0) (> step (length lst)))
106
- (error "step has to be equal to or smaller than the length of the list"))
107
-
108
- (let recur [(lst lst)
109
- (len (length lst))]
110
- (if (>= len size)
111
- (cons (take lst size)
112
- (recur (drop lst step)
113
- (- len step)))
114
- empty)))
+ (define (tail-call lst)
+ (if (>= size (length lst))
+ (list lst)
+ (cons (take lst size)
+ (tail-call (drop lst step)))))
+ (cond
+ [(> step (length lst))
+ (error "step has to be equal to or smaller than length of the list")]
+ [(= step (length lst)) (list lst)]
+ [else (tail-call lst)]))
115
116
117
(define (scanl proc lst)
0 commit comments