debug.scm 1.1 KB

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