[plt-scheme] Re: pretty-printing

From: Robby Findler (robby at cs.uchicago.edu)
Date: Sat Sep 2 16:53:49 EDT 2006

Related to this, you might want to check out the macro stepper by  
Ryan (and the paper at the upcoming Scheme workshop).

Robby

On Sep 2, 2006, at 3:44 PM, Jens Axel Søgaard wrote:

> Paul Graham wrote:
>
> > Is there a way to pretty-print an expr in mzscheme?  There is
> > no reference to it in the index or toc of the manual...
>
> Besides the builtin pretty print there is also pp-syntax, which
> print expanded syntax-objects. This is handy during debugging
> of macros.
>
> <http://ja.soegaard.net/planet/html/soegaard/syntax.plt/current/ 
> doc.txt>
>
>
> > (require (planet "pp-syntax.ss" ("soegaard" "syntax.plt")))
>
> > (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))))
>
> -- 
> Jens Axel Søgaard
>
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>



Posted on the users mailing list.