Is there a way to explicitly pretty-print? Something like:
(display '(a XXX b c))
(a b c)
i.e. XXX outputs as some (newline) + spaces.
Afficher les réponses par date
On 24-Jul-09, at 12:56 AM, Stéphane Le Cornec wrote:
Is there a way to explicitly pretty-print? Something like:
(display '(a XXX b c))
(a b c)
i.e. XXX outputs as some (newline) + spaces.
How about
(display '(a "\n " b c))
(a b c)
I'm probably not understanding your question... If you want to pretty print, why not use the pretty-print procedure? The display procedure seems like the wrong choice for pretty printing...
Marc
On 2009-7-24, at 1:35 , Marc Feeley wrote:
On 24-Jul-09, at 12:56 AM, Stéphane Le Cornec wrote:
Is there a way to explicitly pretty-print? Something like:
(display '(a XXX b c))
(a b c)
i.e. XXX outputs as some (newline) + spaces.
How about
(display '(a "\n " b c))
(a b c)
I'm probably not understanding your question... If you want to pretty print, why not use the pretty-print procedure? The display procedure seems like the wrong choice for pretty printing...
Marc
pp has its own logic as to where the whitespace goes. Unless there's a way to explicitly state where the (newline) should go...
Right now, there are a few place with code like this: (display "(manifest " output) (display name output) (newline output) (newline output) (display " (version " output) (write version output) (display ")" output) (newline output)
It would be oh so much clearer to handle it this way:
(write `(manifest ,name (version ,version) ...) output)
This would read back properly, but it is not pretty enough to be human- readable. So I'm trying to have that cake and eat it too, pretty code and pretty output.
On 24-Jul-09, at 10:55 AM, Stéphane Le Cornec wrote:
It would be oh so much clearer to handle it this way:
(write `(manifest ,name (version ,version) ...) output)
This would read back properly, but it is not pretty enough to be human- readable. So I'm trying to have that cake and eat it too, pretty code and pretty output.
So what you really want is a parameterized pretty-printer where such formatting rules can be indicated. That should be possible to add to the current implementation. The biggest problem is the API. What is the form of these rules?
Marc
On 2009-7-24, at 11:28 , Marc Feeley wrote:
On 24-Jul-09, at 10:55 AM, Stéphane Le Cornec wrote:
It would be oh so much clearer to handle it this way:
(write `(manifest ,name (version ,version) ...) output)
This would read back properly, but it is not pretty enough to be human- readable. So I'm trying to have that cake and eat it too, pretty code and pretty output.
So what you really want is a parameterized pretty-printer where such formatting rules can be indicated. That should be possible to add to the current implementation. The biggest problem is the API. What is the form of these rules?
Thanks Marc!
I believe it should be explicit, with markers where the line break will be.
;; I've replaced spaces by column numbers. (aaa 12(bbb) 12(ccc ddd 1234567eee 1234567fff) 12(ggg))
These are the 2 behaviors that appear in these files. - 1st element indents 1 from opening parenthesis, - 2nd element indents 2 from opening parenthesis, - later elements align with 2nd element.
Brainstorming here, but (let ((proc (lambda (port rank open-parenthesis-column rankN-columns- proc) (let ((indent (case rank ((0) (+ open-parenthesis-column 1)) ((1) (+ (rankN-columns-proc 0) 1)) (else (rankN-columns-proc 1))))) (newline port) (display (make-string indent #\space)))))) (pp `(aaa ,(pp-box proc) (bbb) ,(pp-box proc) (ccc ddd ,(pp-box proc) eee ,(pp-box proc) ...))))
There's a more complex issue that requires 2 passes and may be beyond what pp could offer... (aaa987654321aaa 12(bbb7654321bbb 1234(ccccccc1ccc 123456(ddd321ddd)))) where the alignment column is not known before the 1st pass is done. {And why should pp do the 1st pass anyway?} Because of this 2nd use, the proc should be (lambda (port rank current- column open-parenthesis-column rankN-columns-proc) ...).
I hope this can be transmogrified into something useful for all. If there's no easy solution then I'll just eat the cake and be done with it.
On 24-Jul-09, at 11:05 AM, Stéphane Le Cornec wrote:
On 2009-7-24, at 1:35 , Marc Feeley wrote:
How about
(display '(a "\n " b c))
(a b c)
Hum yeah, forgot... Does "\n" converts to CRLF depending on the port settings?
Yes. A "newline" in a string (or as a character) is converted to LF or CR or CR-LF depending on the port's eol-encoding when the stream of characters is converted to the stream of bytes sent to the device.
Marc