math.scm 496 B

1234567891011121314151617181920212223242526272829
  1. (library (math)
  2. (export sum
  3. product
  4. divisible-by?
  5. n-highest)
  6. (import
  7. (except (rnrs base) let-values map error)
  8. (only (guile)
  9. lambda* λ
  10. remainder
  11. sort)
  12. (srfi srfi-1))
  13. (define sum
  14. (λ (lst)
  15. (apply + lst)))
  16. (define product
  17. (λ (lst)
  18. (apply * lst)))
  19. (define divisible-by?
  20. (λ (num divisor)
  21. (= (remainder num divisor) 0)))
  22. (define n-highest
  23. (λ (lst n)
  24. (take (sort lst >) n))))