diff --git a/collects/unstable/pretty.rkt b/collects/unstable/pretty.rkt new file mode 100644 index 0000000000..5a544428ff --- /dev/null +++ b/collects/unstable/pretty.rkt @@ -0,0 +1,16 @@ +#lang racket/base +(require racket/pretty) + +(provide pretty-format/write + pretty-format/display + pretty-format/print) + +(define ((pretty-format/pretty f) v [columns (pretty-print-columns)]) + (parameterize ([current-output-port (open-output-string)] + [pretty-print-columns columns]) + (f v) + (get-output-string (current-output-port)))) + +(define pretty-format/write (pretty-format/pretty pretty-write)) +(define pretty-format/display (pretty-format/pretty pretty-display)) +(define pretty-format/print (pretty-format/pretty pretty-print)) diff --git a/collects/unstable/scribblings/pretty.scrbl b/collects/unstable/scribblings/pretty.scrbl new file mode 100644 index 0000000000..0883e9e22f --- /dev/null +++ b/collects/unstable/scribblings/pretty.scrbl @@ -0,0 +1,59 @@ +#lang scribble/manual +@(require scribble/eval "utils.rkt" (for-label racket unstable/pretty)) + +@title{Pretty-Printing} + +@defmodule[unstable/pretty] + +This module provides tools for pretty-printing. + +@unstable[@author+email["Carl Eastlund" "cce@racket-lang.org"]] + +@defproc[(pretty-format/write [x any/c] + [columns + (or/c exact-nonnegative-integer? 'infinity) + (pretty-print-columns)]) + string?]{ + +This procedure behaves like @scheme[pretty-format], but it formats values +consistently with @scheme[write] instead of @scheme[print]. + +@examples[#:eval (eval/require 'racket/pretty 'unstable/pretty) +(struct both [a b] #:transparent) +(pretty-format/write (list (both (list 'a 'b) (list "a" "b")))) +] + +} + +@defproc[(pretty-format/display [x any/c] + [columns + (or/c exact-nonnegative-integer? 'infinity) + (pretty-print-columns)]) + string?]{ + +This procedure behaves like @scheme[pretty-format], but it formats values +consistently with @scheme[display] instead of @scheme[print]. + +@examples[#:eval (eval/require 'racket/pretty 'unstable/pretty) +(struct both [a b] #:transparent) +(pretty-format/display (list (both (list 'a 'b) (list "a" "b")))) +] + +} + +@defproc[(pretty-format/print [x any/c] + [columns + (or/c exact-nonnegative-integer? 'infinity) + (pretty-print-columns)]) + string?]{ + +This procedure behaves the same as @scheme[pretty-format], but is named +more explicitly to describe how it formats values. It is included for +symmetry with @scheme[pretty-format/write] and @scheme[pretty-format/display]. + +@examples[#:eval (eval/require 'racket/pretty 'unstable/pretty) +(struct both [a b] #:transparent) +(pretty-format/print (list (both (list 'a 'b) (list "a" "b")))) +] + +} diff --git a/collects/unstable/scribblings/unstable.scrbl b/collects/unstable/scribblings/unstable.scrbl index 1d4603b7c0..bcc223f27b 100644 --- a/collects/unstable/scribblings/unstable.scrbl +++ b/collects/unstable/scribblings/unstable.scrbl @@ -79,6 +79,7 @@ Keep documentation and tests up to date. @include-section["list.scrbl"] @include-section["net.scrbl"] @include-section["path.scrbl"] +@include-section["pretty.scrbl"] @include-section["srcloc.scrbl"] @include-section["string.scrbl"] @include-section["struct.scrbl"]