Created
October 10, 2013 15:52
-
-
Save zaltoprofen/6920704 to your computer and use it in GitHub Desktop.
This file contains 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 '()))) | |
(else (reverse (rangei start stop '()))) | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment