math.scm 736 B

123456789101112131415161718192021222324252627282930
  1. (add-to-load-path (dirname (current-filename)))
  2. (define-module (math)
  3. #:export (number-range-inclusive
  4. number-range
  5. number-range-exclusive))
  6. (define (number-range-inclusive a b)
  7. (define (iter low high)
  8. (cond [(> high low)
  9. (cons low
  10. (iter (+ low 1) high))]
  11. [else (list high)]))
  12. (cond [(< a b) (iter a b)]
  13. [(< b a) (iter b a)]
  14. [else '()]))
  15. (define (number-range a b)
  16. (define (iter low high)
  17. (cond [(> high low)
  18. (cons low
  19. (iter (+ low 1) high))]
  20. [else '()]))
  21. (cond [(< a b) (iter a b)]
  22. [(< b a) (iter b a)]
  23. [else '()]))
  24. (define (number-range-exclusive a b)
  25. (cdr (number-range a b)))