[plt-scheme] Format a string like code?

From: Robby Findler (robby at cs.uchicago.edu)
Date: Wed Feb 20 12:26:26 EST 2008

And, if you want to re-use the code that DrScheme uses, you can. Fire
up a friendly scheme:text% object, insert the text into it, insert
some newlines tabify, and read it back out of the editor. It won't be
fast, but maybe you won't care, since you're already pretty-printing
(which is slow).

Robby

On Feb 20, 2008 11:24 AM, John Clements <clements at brinckerhoff.org> wrote:
>
> On Feb 20, 2008, at 2:29 AM, Ethan Herdrick wrote:
>
> > 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
>
> You say that you want something "like what DrScheme uses to indent
> code."  Keep in mind, though, that DrScheme has extra information in
> the sense that the user explicitly inserts line breaks.  DrScheme
> doesn't have any way of knowing where the line breaks should be
> inserted.
>
> John Clements
>
>
>
> >
> > 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!
> >>
> > _________________________________________________
> >  For list-related administrative tasks:
> >  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>


Posted on the users mailing list.