utils.scm 801 B

1234567891011121314151617181920212223242526272829
  1. (library (commands utils)
  2. (export process-input-port)
  3. (import (except (rnrs base) error map)
  4. (only (guile)
  5. lambda* λ
  6. ;; control flow
  7. when
  8. unless
  9. ;; ports
  10. current-input-port
  11. current-output-port
  12. current-error-port
  13. with-input-from-port
  14. with-output-to-port
  15. with-error-to-port
  16. call-with-input-file
  17. eof-object?)
  18. (ice-9 textual-ports))
  19. (define process-input-port
  20. (λ (port proc)
  21. (let next-line ([line (get-line port)])
  22. (cond
  23. [(eof-object? line) '()]
  24. [else
  25. (cons (proc line)
  26. (next-line (get-line port)))])))))