File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 102
102
103
103
104
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)]))
105
+ (when (> step (length lst))
106
+ (error "step has to be equal to or smaller than length of the list " ))
107
+
108
+ (cond [(= step (length lst))
109
+ (list lst)]
110
+ [(let recur ([lst lst]
111
+ [len (length lst)])
112
+ (if (>= size len)
113
+ (if (empty? lst) empty (list lst))
114
+ (cons (take lst size)
115
+ (recur (drop lst step)
116
+ (- len step)))))]))
115
117
116
118
117
119
(define (scanl proc lst)
You can’t perform that action at this time.
0 commit comments