Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#203 pprint-logical-block and indentation

open
Bruno Haible
clisp (525)
5
2004-04-16
2004-04-16
Antonio Leitao
No

I nailed down a situation where it seems that CLISP
pretty printer becomes confused. Here is the smaller
example I could invent (I'm using '_' in place of spaces:

[124]> (pprint-logical-block (*standard-output* nil)
(format t "~4I")
(princ (princ-to-string #\a))
(princ (princ-to-string #\a)))
________a____a
NIL

The output I was expecting was
____aa

It seems that CLISP is also obeying to the indentation
while computing the princ-to-string expressions.

According to the Hyperspec, "All and only the output
sent to this pretty printing stream is treated as being
in the logical block.". This suggests me that
princ-to-string should not obey to the indentation
specified in the format.

Discussion

  • Sam Steingold
    Sam Steingold
    2004-04-16

    • assigned_to: sds --> haible
    • summary: Pretty printer bug --> pprint-logical-block and indentation
     
  • Sam Steingold
    Sam Steingold
    2006-02-14

    Logged In: YES
    user_id=5735

    From: Raymond Toy <toy@rtp.ericsson.se>
    Subject: pprint bug
    To: Clisp-Devel <clisp-devel@lists.sourceforge.net>
    Date: 27 Feb 2002 15:05:09 -0500

    Given:

    (defun pprint-fdo (fdo-sexp)
    (pprint-logical-block (nil fdo-sexp :prefix "(" :suffix ")")
    (write (pprint-pop))
    (write-char #\space)
    ; (pprint-newline :miser)
    (pprint-indent :current 0)
    (write (pprint-pop))
    (pprint-newline :mandatory)
    (write (pprint-pop))
    (pprint-indent :block 1)
    (pprint-newline :mandatory)
    (loop
    (write (pprint-pop))
    (pprint-exit-if-list-exhausted)
    (write-char #\space)
    (pprint-newline :linear))))

    Clisp ("2.27.2 (released 2001-10-05) (built 3216661407) (memory
    3216748156)") says:

    (progn (terpri)
    (pprint-fdo '(FDO ((I N4 (+ I (- 1))))
    ((> I 3) NIL)
    (TAGBODY
    (F2CL-LIB::FSET (F2CL-LIB::FREF
    A-%DATA% (I) ((1 (+ NW 4))) A-%OFFSET%)
    (COERCE
    (F2CL-LIB::FREF D ((- I 1)) ((1 1024)))
    'SINGLE-FLOAT))
    LABEL150))))

    produces:

    (FDO ((I N4 (+ I (- 1))))
    ((> I 3) NIL)
    (TAGBODY
    (F2CL-LIB::FSET (F2CL-LIB::FREF A-%DATA% (I) ((1 (+
    NW 4))) A-%OFFSET%)
    (COERCE (F2CL-LIB::FREF D ((- I 1)) ((1 1024)))
    'SINGLE-FLOAT))
    LABEL150))

    I don't think this is quite right. It should be more like

    (FDO ((I N4 (+ I (- 1))))
    ((> I 3) NIL)
    (TAGBODY
    (F2CL-LIB::FSET (F2CL-LIB::FREF A-%DATA% (I) ((1 (+ NW
    4))) A-%OFFSET%)
    (COERCE (F2CL-LIB::FREF D ((- I 1)) ((1 1024)))
    'SINGLE-FLOAT))
    LABEL150))

    Ray

    _______________________________________________
    clisp-devel mailing list
    clisp-devel@lists.sourceforge.net
    https://lists.sourceforge.net/lists/listinfo/clisp-devel

     
  • Sam Steingold
    Sam Steingold
    2006-02-14

    Logged In: YES
    user_id=5735

    From: Raymond Toy <toy@rtp.ericsson.se>
    Subject: pretty printing bug?
    To: Clisp-Devel <clisp-devel@lists.sourceforge.net>
    Date: 09 Jan 2002 10:40:44 -0500

    Consider this bit of code:

    (let ((options '((:prune-labels nil) (:auto-save t)
    (:relaxed-array-decls t)
    (:coerce-assigns :as-needed) (:array-type ':simple-array)
    (:array-slicing t))))
    (format t "~2%")
    (pprint-logical-block (nil options :per-line-prefix ";;; ")
    (format t "~&Options: ")
    (write options :case :downcase)))

    CMUCL (and, I think, ACL) prints:

    ;;;
    ;;; Options: ((:prune-labels nil) (:auto-save t)
    (:relaxed-array-decls t)
    ;;; (:coerce-assigns :as-needed) (:array-type
    ':simple-array)
    ;;; (:array-slicing t))

    However, clisp says:

    ;;; Options: ((:prune-labels nil) (:auto-save t)
    (:relaxed-array-decls t)
    ;;; (:coerce-assigns :as-needed) (:array-type
    ':simple-array) (:array-slicing t))

    CMUCL seems to have printed an extra set of ";;;", but I
    don't care
    about that.

    However, I would have expected the second line to line up in
    the same
    way that CMUCL prints it, but perhaps this is perfectly
    legal output?

    Ray

    _______________________________________________
    clisp-devel mailing list
    clisp-devel@lists.sourceforge.net
    https://lists.sourceforge.net/lists/listinfo/clisp-devel

     
  • Sam Steingold
    Sam Steingold
    2006-02-14

    Logged In: YES
    user_id=5735

    From: Raymond Toy <toy@rtp.ericsson.se>
    Subject: 2.28 PP tests
    To: clisp-devel <clisp-devel@lists.sourceforge.net>
    Date: 21 Sep 2001 13:46:12 -0400

    Here are a few random tests that I've done.

    (let ((options '(:a :b aaa bbb ccc ddd eeeeeee ffffffffffff
    gggggggggggg hhhhhhhhhhhhhh iiiiiiiiiiii
    jjjjjjjjjjjjjjj kkkkkkkkkkkkk lllllllllll mmmmmmmmmmm)))
    (pprint-logical-block (nil options :per-line-prefix ";;; ")
    (format t "~&Options: ~S" options)))

    Clisp says:

    *** - FUNCTION: ;;; #<IO SYNONYM-STREAM *TERMINAL-IO*> is
    not a symbol, may not be used as a variable
    ;;; 1. Break ;;; [;;;, 28]>

    (Note the funny extra ";;;" in the prompt. Change the nil
    to t and we
    get:

    ;;; Options:
    ;;; ;;; (:A :B AAA BBB CCC DDD EEEEEEE FFFFFFFFFFFF
    GGGGGGGGGGGG HHHHHHHHHHHHHH IIIIIIIIIIII
    ;;; ;;; JJJJJJJJJJJJJJJ KKKKKKKKKKKKK LLLLLLLLLLL MMMMMMMMMMM)

    I was expecting something like
    ;;; Options: (:A :B AAA BBB CCC DDD EEEEEEE FFFFFFFFFFFF
    GGGGGGGGGGGG
    ;;; HHHHHHHHHHHHHH IIIIIIIIIIII JJJJJJJJJJJJJJJ
    KKKKKKKKKKKKK
    ;;; LLLLLLLLLLL MMMMMMMMMMM)

    This is what CMUCL produces.

    This is a test from XP:

    (format nil (formatter "---~:<~a ~_~a ~_~a~:>--") '(12 3456
    789))

    XP says the answer is "---(12 3456 789)--". Clisp says

    *** - There are not enough arguments left for this directive.
    Current point in control string:
    ---~:<~a ~_~a ~_~a~:>--

    *** - internal error: statement in file "io.d", line 5635
    has been reached!!
    Please send the authors of the program a description how you
    produced this error!

    Another XP test:

    (format nil (formatter "~a~<~a~*~a~:>~a") 1 '(2 3 4 5 6 7) 0)

    XP says the answer is "1240". Clisp says

    *** - EVAL/APPLY: too few arguments given to :LAMBDA

    The other few tests I've tried, Clisp has produced the expected
    results.

    Note that I did not try to verify that what XP expected is
    really what
    the answer should be.

    Ray

    _______________________________________________
    clisp-devel mailing list
    clisp-devel@lists.sourceforge.net
    https://lists.sourceforge.net/lists/listinfo/clisp-devel