This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (range start . args) | |
(let-optionals* args ((stop #f) (step 1)) | |
(define (rangei start stop ls) | |
(if (or (and (> step 0) (>= start stop)) (and (< step 0) (<= start stop))) | |
ls (rangei (+ start step) stop (cons start ls)))) | |
(cond ((= step 0) (error "Step cannot take 0")) | |
((not (integer? start)) (error "Integer required for 1st argument, but got:" start)) | |
((and stop (not (integer? stop))) (error "Integer required for 2nd argument, but got:" stop)) | |
((not (integer? step)) (error "Integer required for 3rd argument, but got:" step)) | |
((not stop) (reverse (rangei 0 start '()))) |
NewerOlder