Pretty-printing with format strings
(require pretty-format) | package: pretty-format |
pretty-fprintf is like fprintf
pretty-printf is like printf
pretty-eprintf is like eprintf
pretty-format is like format
procedure
(pretty-fprintf out fmt v ...) → void?
out : output-port? fmt : string? v : any/c
> (require pretty-format)
> (pretty-fprintf (current-output-port) "~a: ~v" "and the values are indented" '(define (f n) (for/list ([i (in-range n)] #:when (odd? i)) (* 2 i))))
and the values are indented: '(define (f n)
(for/list
((i (in-range n)) #:when (odd? i))
(* 2 i)))
procedure
(pretty-printf fmt v ...) → void?
fmt : string? v : any/c
> (require racket/pretty pretty-format)
> (pretty-print-current-style-table (pretty-print-extend-style-table (pretty-print-current-style-table) '(∀ Refine for/and for/and*) '(lambda lambda lambda lambda)))
> (pretty-printf "val ~a : ~s" 'rem-dups '(∀ (X) (-> ([xs : (Listof X)]) ([f : (-> X X Bool)]) (Refine [ys : (Listof X)] (subset? ys xs) (for/and ([x (in-list xs)]) (member x ys f)) (for*/and ([i (in-range (length ys))] [j (in-range i)]) (not (f (nth ys i) (nth ys j))))))))
val rem-dups : (∀ (X)
(->
((xs : (Listof X)))
((f : (-> X X Bool)))
(Refine (ys : (Listof X))
(subset? ys xs)
(for/and ((x (in-list xs))) (member x ys f))
(for*/and
((i (in-range (length ys))) (j (in-range i)))
(not (f (nth ys i) (nth ys j)))))))
procedure
(pretty-eprintf fmt v ...) → void?
fmt : string? v : any/c
procedure
(pretty-format fmt v ...) → string?
fmt : string? v : any/c
> (require racket/pretty pretty-format) > (pretty-print-columns 60)
> (define str (pretty-format "val ~a : ~v = ~s" 'f procedure? '(λ (n) (if (zero? n) 1 (* n (f (sub1 n))))))) > (string-length str) 189
> (displayln str)
val f : #<procedure:procedure?> = (λ (n)
(if (zero? n)
1
(* n (f (sub1 n)))))