[racket] Printing

From: Danny Yoo (dyoo at hashcollision.org)
Date: Sun Oct 7 19:40:57 EDT 2012

On Sun, Oct 7, 2012 at 5:38 AM, Antonio Menezes Leitao
<antonio.menezes.leitao at ist.utl.pt> wrote:
> On Sun, Oct 7, 2012 at 11:35 AM, Neil Van Dyke <neil at neilvandyke.org> wrote:
>> Antonio Menezes Leitao wrote at 10/07/2012 06:23 AM:
>>
>>> Does Racket provide something similar to Common Lisp's *print-level* and
>>> *print-length*?

There's a separate pretty-printer library that might be applicable here:

    http://docs.racket-lang.org/reference/pretty-print.html

It's not turned on unless you enable it.  In DrRacket, the language
settings can turn it on.


Here's a small example:

;;;;;;;;;;;;;;;;;;;;;
#lang racket

(require racket/pretty)

;; Initialize all output going to current-output-port to go through
racket/pretty's pretty printer
(port-write-handler (current-output-port) pretty-write)
(port-display-handler (current-output-port) pretty-display)
(port-print-handler (current-output-port) pretty-print)

;; Also, make REPL output go through there too:
(current-print (lambda (v)
                 (if (void? v)
                     (void)
                     (pretty-print v))))

;; Let's try it out:
(pretty-print-depth 2)
(list 1 (list 2 (list 3 (list 4))))

(pretty-print-depth 3)
(list 1 (list 2 (list 3 (list 4))))
;;;;;;;;;;;;;;;;;;;;;


Hope this helps!

Posted on the users mailing list.