2.1 mischief/stylish: Stylish Printing, an Alternative to Pretty Printing
(require mischief/stylish) | package: mischief-dev |
The mischief/stylish collection defines "stylish" printing as an alternative to "pretty" printing from racket/pretty. Stylish printing uses more uniform formatting by default, is easier to customize, and supports printf-style formatted printing.
> (define x (list (list 1 2 3) (vector 4 5 6) (quote-syntax (7 8 9))))
> (stylish-printf #:columns 20 "We can print inputs as values [~v] and expressions [~s]." x x)
We
can
inputs
as
values
[(list
'(1 2 3)
(vector 4 5 6)
#'(7 8 9)
#| eval:1.0 |#)]
and
expressions
[((1 2 3)
#[4 5 6]
#<syntax:1:0 (7 8 9)>)].
> (stylish-print x #:columns 20)
(list
'(1 2 3)
(vector 4 5 6)
#'(7 8 9)
#| eval:1.0 |#)
> (stylish-write x #:columns 20)
((1 2 3)
#[4 5 6]
#<syntax:1:0 (7 8 9)>)
> (stylish-value->expr x) (list 'list ''(1 2 3) '(vector 4 5 6) (stylish-comment-expr "eval:1.0" '#'(7 8 9)))
2.1.1 Rendering Values Converted to Expressions
procedure
(stylish-print x [ port #:expr-style est #:print-style pst #:left left #:right right #:columns cols]) → void? x : any/c port : output-port? = (current-output-port) est : expr-style? = (current-expr-style) pst : print-style? = (current-print-style) left : exact-nonnegative-integer? = 0 right : exact-nonnegative-integer? = 0
cols : (or/c exact-nonnegative-integer? 'infinity) = (current-stylish-print-columns)
procedure
(stylish-println x [ port #:expr-style est #:print-style pst #:left left #:right right #:columns cols]) → void? x : any/c port : output-port? = (current-output-port) est : expr-style? = (current-expr-style) pst : print-style? = (current-print-style) left : exact-nonnegative-integer? = 0 right : exact-nonnegative-integer? = 0
cols : (or/c exact-nonnegative-integer? 'infinity) = (current-stylish-print-columns)
procedure
(stylish-print-as-string x [ #:expr-style est #:print-style pst #:left left #:right right #:columns cols]) → string? x : any/c est : expr-style? = (current-expr-style) pst : print-style? = (current-print-style) left : exact-nonnegative-integer? = 0 right : exact-nonnegative-integer? = 0
cols : (or/c exact-nonnegative-integer? 'infinity) = (current-stylish-print-columns)
procedure
(stylish-print-handler x) → void?
x : any/c
2.1.2 Rendering Values Without Conversion
procedure
(stylish-write x [ port pst #:left left #:right right #:columns cols]) → void? x : any/c port : output-port? = (current-output-port) pst : print-style? = (current-print-style) left : exact-nonnegative-integer? = 0 right : exact-nonnegative-integer? = 0
cols : (or/c exact-nonnegative-integer? 'infinity) = (current-stylish-print-columns)
procedure
(stylish-writeln x [ port pst #:left left #:right right #:columns cols]) → void? x : any/c port : output-port? = (current-output-port) pst : print-style? = (current-print-style) left : exact-nonnegative-integer? = 0 right : exact-nonnegative-integer? = 0
cols : (or/c exact-nonnegative-integer? 'infinity) = (current-stylish-print-columns)
procedure
(stylish-write-as-string x [ pst #:left left #:right right #:columns cols]) → string? x : any/c pst : print-style? = (current-print-style) left : exact-nonnegative-integer? = 0 right : exact-nonnegative-integer? = 0
cols : (or/c exact-nonnegative-integer? 'infinity) = (current-stylish-print-columns)
2.1.3 Converting Values to Expressions
procedure
(stylish-value->expr x [est]) → any/c
x : any/c est : expr-style? = (current-expr-style)
procedure
(stylish-quotable-value? x [est]) → boolean?
x : any/c est : expr-style? = (current-expr-style)
2.1.4 Rendering Values Using Format Strings
procedure
(stylish-printf fmt arg ... [ #:port port #:expr-style est #:print-style pst #:left left #:right right #:columns cols]) → void? fmt : string? arg : any/c port : output-port? = (current-output-port) est : expr-style? = (current-expr-style) pst : print-style? = (current-print-style) left : exact-nonnegative-integer? = 0 right : exact-nonnegative-integer? = 0
cols : (or/c exact-nonnegative-integer? 'infinity) = (current-stylish-print-columns)
procedure
(stylish-format fmt arg ... [ #:expr-style est #:print-style pst #:left left #:right right #:columns cols]) → string? fmt : string? arg : any/c est : expr-style? = (current-expr-style) pst : print-style? = (current-print-style) left : exact-nonnegative-integer? = 0 right : exact-nonnegative-integer? = 0
cols : (or/c exact-nonnegative-integer? 'infinity) = (current-stylish-print-columns)
2.1.5 Custom Stylish Printing
parameter
→ (or/c exact-nonnegative-integer? 'infinity) (current-stylish-print-columns cols) → void? cols : (or/c exact-nonnegative-integer? 'infinity)
procedure
(call-with-stylish-port port proc [ #:left left #:right right #:columns cols]) → any port : output-port? proc : (-> output-port? any) left : exact-nonnegative-integer? = 0 right : exact-nonnegative-integer? = 0
cols : (or/c exact-nonnegative-integer? 'infinity) = (current-stylish-print-columns)
procedure
(stylish-print-separator port [ #:indent indent #:wide? wide?]) → void? port : output-port? indent : exact-nonnegative-integer? = 0 wide? : boolean? = #t
2.1.5.1 Print Styles
procedure
(print-style? x) → boolean?
x : any/c
value
value
value
procedure
x : any/c
procedure
(print-style-extension pred proc) → print-style-extension?
pred : predicate/c proc : (-> pred output-port? print-style? void?)
procedure
(extend-print-style pst ext ... [ #:after? after?]) → print-style? pst : print-style? ext : print-style-extension? after? : boolean? = #false
procedure
(set-print-style-default-printer pst proc) → print-style?
pst : print-style? proc : (or/c (-> any/c output-port? void?) #false)
parameter
(current-print-style pst) → void? pst : print-style?
2.1.5.2 Expression Styles
procedure
(expr-style? x) → boolean?
x : any/c
value
value
value
procedure
x : any/c
procedure
(expr-style-extension pred convert [ quotable? try-quote?]) → expr-style-extension? pred : predicate/c convert : (-> pred expr-style? any/c)
quotable? : (-> pred expr-style? boolean?) = (lambda {x est} #false) try-quote? : boolean? = #true
procedure
(extend-expr-style est ext ... [ #:after? after?]) → expr-style? est : expr-style? ext : expr-style-extension? after? : boolean? = #false
procedure
(set-expr-style-default-convert est proc) → expr-style?
est : expr-style? proc : (or/c (-> any/c any/c) #false)
parameter
(current-expr-style pst) → void? pst : expr-style?
syntax
(with-stylish-port body ...+)
(call-with-stylish-port (current-output-port) (lambda (port) (parameterize {[current-output-port port]} body ...)))
2.1.5.3 Generic Stylish Printing
syntax
procedure
x : stylish-printable?
procedure
x : stylish-printable?
syntax
procedure
x : stylish-printable?
2.1.5.4 Special Expression Types
struct
(struct stylish-comment-expr (comment expr))
comment : string? expr : any/c
struct
(struct stylish-unprintable-expr (name))
name : symbol?