doc.txt

Syntax Pretty Printing

==================================================================================
  Syntax Pretty Printing
==================================================================================

> (require (planet "pp-syntax.ss" ("soegaard" "syntax.plt")))

This package provides functions that pretty prints the
output of EXPAND. The pretty printer attempts to present
the output of EXPAND using simple expression. E.g.
EXPAND will expand (let ((x 1)) 2) into (let-values (((x) 1)) 2),
which the pretty printer will "unexpand" into (let ((x 1)) 2).


FUNCTIONS
---------
  
> (unexpand fully-expanded-syntax)

unexpand : fully-expanded-syntax -> syntax
  Unexpand a piece of fully expanded syntax.
  E.g. simple occurences of let-values are rewritten to use let.


> (unexpand-to-datum fully-expanded-syntax)

unexpand-to-datum : fully-expanded-syntax -> datum
  Unexpand a piece of fully expanded syntax, and return
  the result as a datum.


> (pp-syntax fully-expanded-syntax) 

pp-syntax : fully-expanded-syntax -> 
  Pretty-prints the unexpanded piece of syntax
  

EXAMPLE
-------

> (pp-syntax (expand
              '(begin
                 (letrec ((f (lambda (n)
                               (if (= n 0)
                                   1
                                   (* n (f (- n 1)))))))
                   (begin0 (f 5)
                           (set! x 1)))
                 (define y (let ((z 3)) 2)))))
[prints]

(begin
  (letrec ((f (lambda (n) (if (= n 0) 1 (* n (f (- n 1)))))))
    (begin0 (f 5) (set! x 1)))
  (define y (let ((z 3)) 2)))
  
For comparison  
  (pretty-print (syntax-object->datum (expand <same expression>)))
prints

  (begin
    (letrec-values (((f)
                     (lambda (n)
                       (if (#%app = n (#%datum . 0))
                         (#%datum . 1)
                         (#%app
                          *
                          n
                          (#%app f (#%app - n (#%datum . 1))))))))
      (begin0 (#%app f (#%datum . 5)) (set! x (#%datum . 1))))
    (define-values
      (y)
      (let-values (((z) (#%datum . 3))) (#%datum . 2))))



Keywords: _syntax_  _syntax-object_  _expand_ _debug_