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