123456789101112131415161718192021222324252627282930 |
- (library (iter-utils)
- ;; export all non-terminal symbols for testing and usage
- ;; elsewhere in the code
- (export range)
- (import
- (except (rnrs base) let-values map error)
- (only (guile) lambda* λ)))
- (define range
- (lambda* (start end #:key (end-inclusive #f) (start-inclusive #t) (step 1))
- (cond
- [(> start end) '()]
- [(= start end)
- (cond [end-inclusive (cons end '())]
- [else '()])]
- [else
- (cond [start-inclusive
- (cons start
- (range (+ start step)
- end
- #:end-inclusive end-inclusive
- #:step step))]
- [else
- (range (+ start step)
- end
- #:end-inclusive end-inclusive
- #:start-inclusive #t ; change after first element
- #:step step)])])))
|