math.scm 641 B

1234567891011121314151617181920212223242526272829
  1. (library (math)
  2. (export circular-remainder
  3. next-in-circle
  4. previous-in-circle)
  5. (import
  6. (except (rnrs base) error)
  7. (only (guile)
  8. lambda* λ
  9. remainder)))
  10. (define circular-remainder
  11. (λ (num mod)
  12. "Return the circular remainder of the division of NUM by
  13. MOD."
  14. (remainder (+ num mod) mod)))
  15. (define next-in-circle
  16. (λ (num circle-length)
  17. "Return the next number in the circle."
  18. (circular-remainder (+ num 1) circle-length)))
  19. (define previous-in-circle
  20. (λ (num circle-length)
  21. "Return the next number in the circle."
  22. (circular-remainder (- num 1) circle-length)))