string-helpers.scm 612 B

12345678910111213141516171819202122232425262728
  1. (library (string-helpers)
  2. (export display-to-string
  3. string-repeat)
  4. (import (except (rnrs base))
  5. (only (guile)
  6. lambda*
  7. λ
  8. call-with-output-string
  9. display
  10. when))
  11. (define (string-repeat str n)
  12. (define (iter port str n)
  13. (when (> n 0)
  14. (display str port)
  15. (iter port str (- n 1))))
  16. (call-with-output-string
  17. (λ (port)
  18. (iter port str n))))
  19. (define display-to-string
  20. (λ (sth)
  21. (call-with-output-string
  22. (λ (port)
  23. (display sth port))))))