debug.scm 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. (library (debug)
  2. (export debug-peek
  3. pretty-peek)
  4. (import
  5. (except (rnrs base)
  6. let-values
  7. map
  8. error
  9. vector-map)
  10. (only (guile)
  11. lambda* λ
  12. simple-format
  13. current-output-port
  14. call-with-output-string)
  15. (ice-9 pretty-print))
  16. (define debug-peek
  17. (lambda* (sth #:optional (message ""))
  18. (let ([as-string
  19. (call-with-output-string
  20. (λ (port)
  21. (simple-format port "~a" sth)))])
  22. (simple-format (current-output-port)
  23. "~a~a\n"
  24. message
  25. as-string)
  26. sth)))
  27. (define pretty-peek
  28. (lambda* (thing
  29. #:optional (port (current-output-port))
  30. #:key
  31. (width 80)
  32. (max-expr-width 80)
  33. (display? #t)
  34. (per-line-prefix "")
  35. (select (λ (thing) thing)))
  36. (pretty-print (select thing)
  37. #:port port
  38. #:width width
  39. #:max-expr-width max-expr-width
  40. #:display? display?
  41. #:per-line-prefix per-line-prefix)
  42. thing)))