Lisp HUG Maillist Archive

lisp-hug@xanalys.com

I'm getting some annoying extra blank lines when using
PPRINT-LOGICAL-BLOCK.

I have these definitions:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 

(defparameter *stream* *standard-output*)

(defun test-no-logical-block ()
  (format *stream* "~&aaaa~%")
  (format *stream* "~&bbbb~%")
  (format *stream* "~&cccc~%"))

(defmacro with-pprint-logical-block (&body body)
  `(pprint-logical-block
       (*stream*
        nil
        :per-line-prefix ";;; ")
     ,@body))

(defun test-with-logical-block ()
  (with-pprint-logical-block
    (test-no-logical-block)))

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

TEST-NO-LOGICAL-BLOCK behaves as I expect (# indicates
printed stuff):

(test-no-logical-block)
# aaaa
# bbbb
# cccc
-> NIL 


TEST-WITH-LOGICAL-BLOCK adds annoying extra blank lines
(FWIW, the behaviour is the same whether *PRINT-PRETTY* is
True or False.)

(test-with-logical-block)
# ;;; 
# ;;; aaaa
# ;;; 
# ;;; bbbb
# ;;; 
# ;;; cccc
# ;;; 
-> NIL 


Are these extra blank lines permitted or is this a bug?

I'm using LispWorks for Windows, 4.2 and 4.3 Beta.


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

Re: lisp-hug@xanalys.com

>>>>> On Fri, 15 Aug 2003 13:32:34 +0100, "Simon Katz" <simon@nomistech.com> said:

    Simon> I'm getting some annoying extra blank lines when using
    Simon> PPRINT-LOGICAL-BLOCK.

    Simon> I have these definitions:

    Simon> vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv 

    Simon> (defparameter *stream* *standard-output*)

    Simon> (defun test-no-logical-block ()
    Simon>   (format *stream* "~&aaaa~%")
    Simon>   (format *stream* "~&bbbb~%")
    Simon>   (format *stream* "~&cccc~%"))

    Simon> (defmacro with-pprint-logical-block (&body body)
    Simon>   `(pprint-logical-block
    Simon>        (*stream*
    Simon>         nil
    Simon>         :per-line-prefix ";;; ")
    Simon>      ,@body))

    Simon> (defun test-with-logical-block ()
    Simon>   (with-pprint-logical-block
    Simon>     (test-no-logical-block)))

    Simon> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    Simon> TEST-NO-LOGICAL-BLOCK behaves as I expect (# indicates
    Simon> printed stuff):

    Simon> (test-no-logical-block)
    Simon> # aaaa
    Simon> # bbbb
    Simon> # cccc
    -> NIL 


    Simon> TEST-WITH-LOGICAL-BLOCK adds annoying extra blank lines
    Simon> (FWIW, the behaviour is the same whether *PRINT-PRETTY* is
    Simon> True or False.)

    Simon> (test-with-logical-block)
    Simon> # ;;; 
    Simon> # ;;; aaaa
    Simon> # ;;; 
    Simon> # ;;; bbbb
    Simon> # ;;; 
    Simon> # ;;; cccc
    Simon> # ;;; 
    -> NIL 

    Simon> Are these extra blank lines permitted or is this a bug?

    Simon> I'm using LispWorks for Windows, 4.2 and 4.3 Beta.

Try using ~_ (pprint-newline) with and without modifiers instead of
~&. It probably interacts better with pprint-logical-block.

__Jason


Re: PPRINT-LOGICAL-BLOCK question (was lisp-hug@xanalys.com)

>>>>> On Sat, 16 Aug 2003 21:02:34 +0100, "Simon Katz" <simon@nomistech.com> said:

    Jason> From: "Jason Trenouth" <jason.trenouth@GlobalGraphics.com>
    Jason> 
    Jason> Try using ~_ (pprint-newline) with and without modifiers instead of
    Jason> ~&. It probably interacts better with pprint-logical-block.

    Simon> Thanks for the suggestion. I've had a look at the Hyperspec and a
    Simon> play, but I don't think ~_ does what I want.

    Simon> I'd been hoping to simply add uses of a WITH-INDENTATION macro
    Simon> to existing code so that I could indent blocks of printed output
    Simon> nicely:


    Simon> (defmacro with-indentation ((stream n &optional (c #\space))
    Simon>                             &body body)
    Simon>   `(pprint-logical-block
    Simon>        (,stream
    Simon>         nil
    Simon>         :per-line-prefix (make-string ,n :initial-element ,c))
    Simon>      ,@body))


    Simon> Perhaps there's another way to write a WITH-INDENTATION macro?
    Simon> Hmmmm.
    Simon> Perhaps I could define my own stream class that:
    Simon> - knows about the current indentation level
    Simon> - passes output on to a "real" stream
    Simon> - makes modifications according to the current indentation level.

As it happens that's exactly what I did myself in Java on a project.

Prettyprinting is a different (more advanced) concept. It is concerned
with filling a page with structured output and working out when best
to put in line breaks. Indenting is then necessary to visually
associate the parts of the structure after such line breaks.

That said, I have recently used pprint-logical-block to do some
indenting. I had more success in LW with PPRINT-INDENT than
:PER-LINE-PREFIX. Unfortunately, the same code in CLISP produced very
different (and inferior) output.

    Simon> When I find time I'll take a look at the documentation for defining
    Simon> ones own streams.

    Simon> For the moment I've simply changed my code to get most of what I want
    Simon> in a different (and more hacky) way.

__Jason


Re: PPRINT-LOGICAL-BLOCK question (was lisp-hug@xanalys.com)

I have a PrettyPrinter implementation in Java.  It implements all of CL 
API sans the macros.

If anybody is interested I will resurrect it.

It is a porting of CMUCL version


Cheers


Marco





On Wednesday, Aug 27, 2003, at 05:08 America/New_York, Jason Trenouth 
wrote:

>>>>>> On Sat, 16 Aug 2003 21:02:34 +0100, "Simon Katz" 
>>>>>> <simon@nomistech.com> said:
>
>     Jason> From: "Jason Trenouth" <jason.trenouth@GlobalGraphics.com>
>     Jason>
>     Jason> Try using ~_ (pprint-newline) with and without modifiers 
> instead of
>     Jason> ~&. It probably interacts better with pprint-logical-block.
>
>     Simon> Thanks for the suggestion. I've had a look at the Hyperspec 
> and a
>     Simon> play, but I don't think ~_ does what I want.
>
>     Simon> I'd been hoping to simply add uses of a WITH-INDENTATION 
> macro
>     Simon> to existing code so that I could indent blocks of printed 
> output
>     Simon> nicely:
>
>
>     Simon> (defmacro with-indentation ((stream n &optional (c #\space))
>     Simon>                             &body body)
>     Simon>   `(pprint-logical-block
>     Simon>        (,stream
>     Simon>         nil
>     Simon>         :per-line-prefix (make-string ,n :initial-element 
> ,c))
>     Simon>      ,@body))
>
>
>     Simon> Perhaps there's another way to write a WITH-INDENTATION 
> macro?
>     Simon> Hmmmm.
>     Simon> Perhaps I could define my own stream class that:
>     Simon> - knows about the current indentation level
>     Simon> - passes output on to a "real" stream
>     Simon> - makes modifications according to the current indentation 
> level.
>
> As it happens that's exactly what I did myself in Java on a project.
>
> Prettyprinting is a different (more advanced) concept. It is concerned
> with filling a page with structured output and working out when best
> to put in line breaks. Indenting is then necessary to visually
> associate the parts of the structure after such line breaks.
>
> That said, I have recently used pprint-logical-block to do some
> indenting. I had more success in LW with PPRINT-INDENT than
> :PER-LINE-PREFIX. Unfortunately, the same code in CLISP produced very
> different (and inferior) output.
>
>     Simon> When I find time I'll take a look at the documentation for 
> defining
>     Simon> ones own streams.
>
>     Simon> For the moment I've simply changed my code to get most of 
> what I want
>     Simon> in a different (and more hacky) way.
>
> __Jason
>
--
Marco Antoniotti
NYU Courant Bioinformatics Group		tel. +1 - 212 - 998 3488
715 Broadway 10th FL				fax. +1 - 212 - 998 3484
New York, NY, 10003, U.S.A.


________________________________________________________________________
This email has been scanned for all viruses by the MessageLabs Email
Security System. For more information on a proactive email security
service working around the clock, around the globe, visit
http://www.messagelabs.com
________________________________________________________________________

Updated at: 2020-12-10 08:59 UTC