pretty-print

Synopsis

(pretty-print object port)

(pretty-print object)

(pp object port)

(pp object)

Parameters

  • object
  • port (optional)

Description

This procedure prints object in a pretty way writing to the specified output port or to (current-output-port) when this optional parameter is omitted. pp is just an alias for pretty-print.

Side Effects

Return Value

unspecified (ok)

Example

This is how pretty-print prints itself:

> (pp pp)
(lambda (obj . opt)
 ((named-lambda
    (() port)
    (if (compound-procedure? obj)
      (set! obj
        (cons 'lambda
              (cons (procedure-parameters obj)
                    (procedure-body obj)))))
    (if (syntax-procedure? obj)
      (set! obj
        `(named-syntax-lambda
           (,(procedure-name obj)
            ,@(procedure-parameters obj))
           ,@(procedure-body obj))))
    (generic-write
      obj
      #f
      79
      (named-lambda (() s) (display s port) #t))
    'ok)
  (if (special-or-pair? opt)
    (special-car opt)
    (current-output-port))))
ok
>

This is an example how a syntactical closure generated with syntax-lambda is printed (cond):

> (pp cond)
(named-syntax-lambda
 (cond expr env)
 (if (null? (cdr expr))
   ()
   (begin
     (define test (cadr expr))
     (define clause2 (cddr expr))
     (if (not (pair? test))
       (error "syntax-error / cond")
       (if (null? (cdr test))
         `(or ,@test (cond ,@clause2))
         (if (eq? (cadadr expr) '=>)
           `(let ((test-result ,(caadr expr))
                  (thunk2
                    (lambda () ,(car (cdr (cdr (car (cdr expr)))))))
                  (thunk3 (lambda () (cond ,@clause2))))
              (if test-result ((thunk2) test-result) (thunk3)))
           (if (eq? 'else (caadr expr))
             (cons 'begin (append (cdadr expr) '()))
             (cons 'if
                   (cons (caadr expr)
                         (cons (cons 'begin (append (cdadr expr) '()))
                               (cons (cons 'cond (append clause2 '()))
                                     '())))))))))))
ok
>

The Inlab Scheme integral networking data types macaddr, macaddr-range, ipaddr and ipaddr-range are printed as desired:

> (pp '(11:22:33:44:55:66 10.1.1.1 ffff::ffee 10.1.1.1-10.1.1.255 ffff::ffee-ffff::ffff))
(11:22:33:44:55:66
 10.1.1.1
 ffff::ffee
 10.1.1.1-10.1.1.255
 ffff::ffee-ffff::ffff)
ok
>