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 0f71d9f commit dacfce1Copy full SHA for dacfce1
main.rkt
@@ -102,16 +102,17 @@
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)]))
+ (cond [(> step (length lst))
+ (error "step has to be equal to or smaller than length of the list")]
+ [(= step (length lst))
+ (list lst)]
+ [(let recur ([lst lst]
+ [len (length lst)])
+ (if (>= size len)
+ (if (empty? lst) empty (list lst))
+ (cons (take lst size)
+ (recur (drop lst step)
115
+ (- len step)))))]))
116
117
118
(define (scanl proc lst)
0 commit comments