list-helpers.scm 521 B

123456789101112131415161718192021222324252627
  1. (library (list-helpers)
  2. (export flatten
  3. make-list)
  4. (import
  5. (except (rnrs base) let-values map error)
  6. (only (guile)
  7. lambda* λ))
  8. (define flatten
  9. (λ (lst)
  10. (cond [(null? lst) '()]
  11. [(pair? lst)
  12. (append (flatten (car lst))
  13. (flatten (cdr lst)))]
  14. [else
  15. (list lst)])))
  16. (define make-list
  17. (λ (val count)
  18. (cond
  19. [(> count 0)
  20. (cons val (make-list val (- count 1)))]
  21. [else '()]))))