Implement range* as in-inclusive-range.

This commit is contained in:
Jonathan Chan 2021-12-10 22:24:45 -08:00
parent adf8ba4600
commit b49762c1b5
1 changed files with 2 additions and 8 deletions

10
lib.rkt
View File

@ -194,14 +194,8 @@
(define (snoc lst v) (define (snoc lst v)
(append lst (list v))) (append lst (list v)))
;; range* : number? -> (listof number?) ;; range* : number? -> number? -> [number?] -> (streamof number?)
;; range* : number? -> number? -> [number?] -> (listof number?) (define range* in-inclusive-range)
;; Like range, but with an inclusive right end
(define-syntax range*
(syntax-rules ()
[(_ n) (range (add1 n))]
[(_ from to) (range from (add1 to))]
[(_ from to step) (range from (add1 to) step)]))
;; scanl : (a -> a -> a) -> (listof a) -> (listof a) ;; scanl : (a -> a -> a) -> (listof a) -> (listof a)
;; foldl that accumulates partial results in a list ;; foldl that accumulates partial results in a list