[plt-scheme] pretty-print not so pretty
On Jan 18, 2007, at 7:22 AM, Kyle Smith wrote:
> Hi folks,
>
> What I'm after is to display the application, whence a result came
> from; this was my attempt:
>
> (require (lib "pretty.ss"))
>
> (define-syntax (phere stx)
> (syntax-case stx ()
> ((_ app ...) #'(begin (pretty-display 'app ...) app ...))))
> (phere (let ([x 0])
> (let ([y 1])
> (display (+ y x)))))
>
>
> Welcome to DrScheme, version 369.3-svn8jan2007.
> Language: Pretty Big (includes MrEd and Advanced Student).
> (let ((x 0)) (let ((y 1)) (display (+ y x))))
> 1
>>
> While it functionally did what I wanted, it didn't show the code as
> I expected:
> (let ((x 0))
> (let ((y 1))
> (display (+ y x))))
>
> I've never used pretty-print before, but I thought it was supposed
> to display the sexp's in some kind-of reasonably acceptable
> standard way, not just a straight run of text. I tried with both
> pretty-print and pretty-display, as shown above. I tried it in
> MzScheme with the same result. Am I missing a parameter that needs
> setting, or some larger concept?
Pretty-print has a broader task than the one you assign it; its job
is to nicely format _any_ s-expression, not just code. For this
reason, pretty-print can't assume that its input should be formatted
to look like scheme code. Instead, pretty-print just tries to make
sure that line breaks fall in nice places, and that lines after the
first are appropriately indented. This means that if the whole
expression fits on one line, pretty-print will cheerfully put the
whole thing on one line.
The thing that you're imagining sounds more complicated. Parts of
its functionality already live in DrScheme--e.g., how many spaces
should DrScheme insert when you hit "Return"--but the difficult
question of how many lines to break something into is (AFAIK) not
addressed. It does sound useful, though, if you want to develop it...
As always, corrections cheerfully accepted.
John Clements
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20070118/0235c73f/attachment.p7s>