[plt-scheme] Format a string like code?

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Feb 18 00:36:36 EST 2008

On Feb 17, Ethan Herdrick wrote:
> I want to take this list:
> 
> '(define (foo x) (* 2 (add1 x)  (expt x 2)))
> 
> And get a string like this:
> 
> (define (foo x)
>     (* 2
>        (add1 x)
>        (expt x 2)))
> 
> How?  It looks like pretty-print only breaks lines that have reached a
> certain length.  How about a function like what DrScheme uses to
> indent code?

Try this:

  (pretty-format '(define (foo x) (* 2 (add1 x) (expt x 2))) 20)

(But it looks like it insists on a newline after `*' or none at all.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!


Posted on the users mailing list.