1234567891011121314151617181920212223242526272829 |
- (library (print-utils)
- (export print-limited)
- (import
- (except (rnrs base) let-values map error)
- (only (guile)
- lambda* λ
- current-output-port
- call-with-output-string
- simple-format)
- (ice-9 pretty-print)
- (ice-9 textual-ports)))
- (define print-limited
- (lambda* (object
- #:optional (output-port (current-output-port))
- #:key (max 1024))
- (let ([pretty-output
- (call-with-output-string
- (λ (port)
- (cond
- [(string? object) (put-string port object)]
- [else (pretty-print object #:port port)])))])
- (let ([limited-message
- (substring pretty-output
- 0
- (min max (string-length pretty-output)))])
- (simple-format output-port "~a\n" limited-message)))))
|