print-utils.scm 868 B

1234567891011121314151617181920212223242526272829
  1. (library (print-utils)
  2. (export print-limited)
  3. (import
  4. (except (rnrs base) let-values map error)
  5. (only (guile)
  6. lambda* λ
  7. current-output-port
  8. call-with-output-string
  9. simple-format)
  10. (ice-9 pretty-print)
  11. (ice-9 textual-ports)))
  12. (define print-limited
  13. (lambda* (object
  14. #:optional (output-port (current-output-port))
  15. #:key (max 1024))
  16. (let ([pretty-output
  17. (call-with-output-string
  18. (λ (port)
  19. (cond
  20. [(string? object) (put-string port object)]
  21. [else (pretty-print object #:port port)])))])
  22. (let ([limited-message
  23. (substring pretty-output
  24. 0
  25. (min max (string-length pretty-output)))])
  26. (simple-format output-port "~a\n" limited-message)))))