Added unstable/pretty with pretty-format/print, /write, and /display.

This commit is contained in:
Carl Eastlund 2010-06-04 20:14:19 -04:00
parent e52fb81aac
commit 4b728da51c
3 changed files with 76 additions and 0 deletions

View File

@ -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))

View File

@ -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"))))
]
}

View File

@ -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"]