[plt-scheme] Format a string like code?

From: John Clements (clements at brinckerhoff.org)
Date: Wed Feb 20 12:24:20 EST 2008

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



Posted on the users mailing list.