[plt-scheme] Format a string like code?

From: Ethan Herdrick (info at reatlas.com)
Date: Wed Feb 20 05:29:55 EST 2008

Unfortunately, as you imply, that doesn't really do what I'd like.

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

gives:

(define (foo x)
  (*
   2
   (add1 x)
   (expt x 2)))

And specifying the columns at which to break the lines won't work for
me; I want this for the general case.

Thanks anyway, Eli.  -Ethan


On Feb 17, 2008 9:36 PM, Eli Barzilay <eli at barzilay.org> wrote:
>
> 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.